-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
64 lines (56 loc) · 1.24 KB
/
main.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
#include "classes.h"
#include <cctype>
#define FPS 10
extern short sDirection;
extern int matr;
void display_callback()
{
glClear(GL_COLOR_BUFFER_BIT);
playGame();
glutSwapBuffers();
}
void reshape_callback(int width, int height)
{
glViewport(0,0,(GLsizei)width, (GLsizei)height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0.0, COLUMNS, 0.0, ROWS, -1.0, 1.0);
glMatrixMode(GL_MODELVIEW);
}
void timer_callback(int)
{
glutPostRedisplay();
glutTimerFunc(1000/FPS, timer_callback, 0);
}
void keyboard_callback(unsigned char key, int, int)
{
switch (key)
{
case 'w':
sDirection=UP;
break;
case 's':
sDirection=DOWN;
break;
case 'd':
sDirection=RIGHT;
break;
case 'a':
sDirection=LEFT;
break;
default:
sDirection = STAY;
}
}
int main(int argc, char *argv[]) {
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowSize(COLUMNS*20, ROWS*20);
glutCreateWindow("Game");
glutDisplayFunc(display_callback);
glutReshapeFunc(reshape_callback);
glutTimerFunc(0, timer_callback, 0);
glutKeyboardFunc(keyboard_callback);
glutMainLoop();
return 0;
}