-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.adept
111 lines (90 loc) · 3.62 KB
/
main.adept
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// ----------------------------- main.adept -----------------------------
// Module for driving all the other parts of the game
// ----------------------------------------------------------------------
pragma compiler_version '2.1'
pragma project_name 'Adept2DPlatformer'
import 'glfw/glfw.adept'
import 'sys/cstdio.adept'
import 'sys/cstdlib.adept'
import 'menu.adept'
import 'model.adept'
import 'shader.adept'
import 'gamedata.adept'
import 'resources.adept'
import 'input.adept'
import 'render.adept'
func main() int {
unless glfwInit(), puts('Failed to init glfw'); return 1
#if __macos__
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
#end
monitor *GLFWmonitor = glfwGetPrimaryMonitor()
video_mode *GLFWvidmode = glfwGetVideoMode(monitor)
window *GLFWwindow = glfwCreateWindow(video_mode.width, video_mode.height, 'Purple Void', monitor, null)
if window == null {
puts('Failed to create window')
glfwTerminate()
return 1
}
// Setup opengl
glfwMakeContextCurrent(window)
glfwSwapInterval(1)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LESS)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN)
openglInit()
soundInit()
resources Resources; gamedata GameData; display_ratio float
resources.load(); gamedata.load(&resources)
resources.music.play()
#if __macos__
current_time double = 0.0
previous_time double = glfwGetTime()
#end
until glfwWindowShouldClose(window) {
#if __macos__
current_time = glfwGetTime()
if current_time - previous_time < 1.0 / 60.0,
continue
previous_time += 1.0 / 60.0
#end
if gamedata.scene == SCENE_START_MENU {
glClearColor(0.8f, 0.0f, 0.8f, 0.0f)
glClear(GL_COLOR_BUFFER_BIT)
glClear(GL_DEPTH_BUFFER_BIT)
glfwGetFramebufferSize(window, &gamedata.win_width, &gamedata.win_height)
glViewport(0, 0, gamedata.win_width, gamedata.win_height)
display_ratio = cast float gamedata.win_width / cast float gamedata.win_height
gamedata.width = 800.0f * display_ratio
gamedata.height = 800.0f
gamedata.projection.ortho(0.0f, gamedata.width, gamedata.height, 0.0f, 1.0f, -1.0f)
menuInput(window, &resources, &gamedata)
menuRender(&resources, &gamedata)
} else if gamedata.scene == SCENE_GAME {
if gamedata.theme == THEME_PURPLE, glClearColor(0.8f, 0.0f, 0.8f, 0.0f)
else if gamedata.theme == THEME_GREEN, glClearColor(0.196078431, 0.643137255, 0.196078431, 0.0f)
glClear(GL_COLOR_BUFFER_BIT)
glClear(GL_DEPTH_BUFFER_BIT)
glfwGetFramebufferSize(window, &gamedata.win_width, &gamedata.win_height)
glViewport(0, 0, gamedata.win_width, gamedata.win_height)
display_ratio = cast float gamedata.win_width / cast float gamedata.win_height
gamedata.width = 800.0f * display_ratio
gamedata.height = 800.0f
gamedata.projection.ortho(0.0f, gamedata.width, gamedata.height, 0.0f, 1.0f, -1.0f)
input(window, &resources, &gamedata)
render(&resources, &gamedata)
}
glfwSwapBuffers(window)
glfwPollEvents()
}
gamedata.destroy()
resources.destroy()
glfwDestroyWindow(window)
glfwTerminate()
return 0
}