blob: bc7832d7d3c4e738f8bfc196d69ed59a5e37b101 (
plain) (
blame)
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
|
#include <ctime>
#include <list>
#include "map.h"
#include "state.h"
#include "mapview.h"
#include "renderer.h"
#include <cstdlib>
using namespace::std;
bool quit = false;
State* curGameState;
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
if ((key == GLFW_KEY_ESCAPE) && (action == GLFW_PRESS))
{
quit = true;
}
if (curGameState != NULL)
{
curGameState->input(key, action);
}
}
int main()
{
srand(time(NULL));
GLFWwindow* window = initRenderer();
glfwSwapInterval(1);
glfwSetKeyCallback(window, key_callback);
Map* m = new Map("../maps/embarass.txt");
//Map* m2 = new Map("../maps/cozy.txt");
//m->setLeftMap(m2);
//m2->setRightMap(m);
curGameState = new MapView(m, 100, 100);
Texture* buffer = createTexture(GAME_WIDTH, GAME_HEIGHT);
//Texture* buffer = loadTextureFromBMP("../res/title.png");
double lastTime = glfwGetTime();
int nbFrames = 0;
while (!(quit || glfwWindowShouldClose(window)))
{
double currentTime = glfwGetTime();
nbFrames++;
if (currentTime - lastTime >= 1.0)
{
// printf and reset timer
printf("%f ms/frame\n", 1000.0/double(nbFrames));
nbFrames = 0;
lastTime += 1.0;
}
curGameState->tick();
// Do rendering
curGameState->render(buffer);
renderScreen(buffer);
glfwPollEvents();
}
delete curGameState;
delete m;
destroyRenderer();
return 0;
}
|