-
Notifications
You must be signed in to change notification settings - Fork 5
/
PlayGame.cpp
99 lines (71 loc) · 1.85 KB
/
PlayGame.cpp
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
#include <GL/glew.h>
#include <GL/glut.h>
#include <GL/freeglut_ext.h>
#include <iostream>
#include "GameStateManager.h"
#include "PlayState.h"
#include "Keyboard.h"
#include "Mouse.h"
#define MAX_FPS 60
GameStateManager stateManager;
PlayState playState;
Keyboard keyboard;
Mouse mouse;
void init() {
stateManager.setState(&playState);
}
void update(void) {
stateManager.update();
}
void render(void) {
stateManager.render();
}
void mainLoop(int value) {
update();
render();
glutTimerFunc(1000/MAX_FPS, mainLoop, value);
}
void changeSize(int w, int h) {
stateManager.changeSize(w, h);
}
void keyboardDown(unsigned char key, int x, int y) {
keyboard.setKeyDown(key);
stateManager.keyboardDown(key, x, y);
}
void keyboardUp(unsigned char key, int x, int y) {
keyboard.setKeyUp(key);
stateManager.keyboardUp(key, x, y);
}
void mouseMove(int x, int y) {
mouse.mouseMove(x, y);
stateManager.mouseMove(x, y);
}
void mousePress(int button, int state, int x, int y) {
mouse.mousePress(button, state, x, y);
mouseMove(x, y);
stateManager.mousePress(button, state, x, y);
}
int main(int argc, char **argv) {
stateManager.addState(&playState);
glutInit(&argc, argv);
system("kill `ps | grep 'aplay'|awk '{print $1}'`") ; // stop any previous background music
system("aplay background.wav&") ; // play sound
glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(1500, 250);
glutInitWindowSize(1200, 600);
glutCreateWindow("3D Maze");
GLenum error = glewInit();
if (error != GLEW_OK) {
printf("Error starting GLEW: %s\n", glewGetErrorString(error));
exit(0);
}
glutTimerFunc(1000/MAX_FPS, mainLoop, 0);
glutDisplayFunc(render);
glutReshapeFunc(changeSize);
glutKeyboardFunc(keyboardDown);
glutKeyboardUpFunc(keyboardUp);
glutMouseFunc(mousePress);
glutPassiveMotionFunc(mouseMove);
init();
glutMainLoop();
}