diff options
Diffstat (limited to 'src/main.cpp')
-rw-r--r-- | src/main.cpp | 67 |
1 files changed, 2 insertions, 65 deletions
diff --git a/src/main.cpp b/src/main.cpp index bc7832d..c552d2a 100644 --- a/src/main.cpp +++ b/src/main.cpp | |||
@@ -1,77 +1,14 @@ | |||
1 | #include <ctime> | 1 | #include <ctime> |
2 | #include <list> | 2 | #include <list> |
3 | #include "map.h" | ||
4 | #include "state.h" | ||
5 | #include "mapview.h" | ||
6 | #include "renderer.h" | 3 | #include "renderer.h" |
7 | #include <cstdlib> | 4 | #include <cstdlib> |
8 | 5 | #include "game.h" | |
9 | using namespace::std; | ||
10 | |||
11 | bool quit = false; | ||
12 | |||
13 | State* curGameState; | ||
14 | |||
15 | void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) | ||
16 | { | ||
17 | if ((key == GLFW_KEY_ESCAPE) && (action == GLFW_PRESS)) | ||
18 | { | ||
19 | quit = true; | ||
20 | } | ||
21 | |||
22 | if (curGameState != NULL) | ||
23 | { | ||
24 | curGameState->input(key, action); | ||
25 | } | ||
26 | } | ||
27 | 6 | ||
28 | int main() | 7 | int main() |
29 | { | 8 | { |
30 | srand(time(NULL)); | 9 | srand(time(NULL)); |
31 | 10 | ||
32 | GLFWwindow* window = initRenderer(); | 11 | Game::getInstance().execute(); |
33 | glfwSwapInterval(1); | ||
34 | glfwSetKeyCallback(window, key_callback); | ||
35 | |||
36 | Map* m = new Map("../maps/embarass.txt"); | ||
37 | //Map* m2 = new Map("../maps/cozy.txt"); | ||
38 | |||
39 | //m->setLeftMap(m2); | ||
40 | //m2->setRightMap(m); | ||
41 | |||
42 | curGameState = new MapView(m, 100, 100); | ||
43 | |||
44 | Texture* buffer = createTexture(GAME_WIDTH, GAME_HEIGHT); | ||
45 | //Texture* buffer = loadTextureFromBMP("../res/title.png"); | ||
46 | |||
47 | double lastTime = glfwGetTime(); | ||
48 | int nbFrames = 0; | ||
49 | |||
50 | while (!(quit || glfwWindowShouldClose(window))) | ||
51 | { | ||
52 | double currentTime = glfwGetTime(); | ||
53 | nbFrames++; | ||
54 | if (currentTime - lastTime >= 1.0) | ||
55 | { | ||
56 | // printf and reset timer | ||
57 | printf("%f ms/frame\n", 1000.0/double(nbFrames)); | ||
58 | nbFrames = 0; | ||
59 | lastTime += 1.0; | ||
60 | } | ||
61 | |||
62 | curGameState->tick(); | ||
63 | |||
64 | // Do rendering | ||
65 | curGameState->render(buffer); | ||
66 | renderScreen(buffer); | ||
67 | |||
68 | glfwPollEvents(); | ||
69 | } | ||
70 | |||
71 | delete curGameState; | ||
72 | delete m; | ||
73 | |||
74 | destroyRenderer(); | ||
75 | 12 | ||
76 | return 0; | 13 | return 0; |
77 | } | 14 | } |