forked from bamster/bamster
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
177 lines (129 loc) · 3.42 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
// vim: set ts=4 sw=4 expandtab sts=4:
#include <iostream>
#include <X11/Xlib.h>
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#include <GLUT/glut.h>
#else
#include <GL/glut.h>
#endif
#include "imageloader.h"
#include "keyLogger.h"
#include "game.h"
const unsigned int elapsedUSecs = 2;
int hamsterPos=0;
void handelKeypress(unsigned char key, int x, int y) {
switch (key)
case 27: //Escape
exit(0);
}
using std::cout;
GLsizei wh = 130 ;
GLsizei ww = 130 ;
//dot.cpp
// initial height of window
// initial width of window
void plot ( void );
void MyInit
( );
game* theBamsterGame;
void plot ( void ) {
glClear ( GL_COLOR_BUFFER_BIT ); //clear pixel buffer
theBamsterGame->plot();
glFlush();
}
void myInit ( void ) {
cout << glGetString(GL_VERSION) <<"\n";
cout << glGetString(GL_VENDOR) <<"\n";
glClearColor ( 0.0, 0.0, 0.0, 0.0 ); //white background
glColor3f(0.0f, 1.0f,0.0f);
// green drawing colour
glPointSize(10.0);
// 10 pixel dot!
glMatrixMode ( GL_PROJECTION );
glLoadIdentity ( );
gluOrtho2D ( 0.0, (GLdouble)ww, 0.0, (GLdouble)wh ); //Display area
glEnable(GL_COLOR_MATERIAL);
}
void handleKeypress (unsigned char key, int x, int y)
{
switch (key) {
case 27:
// cleanup();
exit(0);
case 32:
pressedKeys.spaceKey= true;
break;
}
}
void handleKeyReleased (unsigned char key, int x, int y)
{
switch (key) {
case 32:
pressedKeys.spaceKey = false;
break;
}
}
void timerCallback (int value)
{
theBamsterGame->timerCallback();
theBamsterGame->plot();
glFlush();
/* Do timer processing */
/* maybe glutPostRedisplay(), if necessary */
/* call back again after elapsedUSecs have passed */
glutTimerFunc (elapsedUSecs, timerCallback, value);
}
void handleSpecialKeyReleased(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT:
pressedKeys.leftKey = false;
break;
case GLUT_KEY_RIGHT:
pressedKeys.rightKey = false;
break;
case GLUT_KEY_UP:
pressedKeys.upKey = false;
break;
case GLUT_KEY_DOWN:
pressedKeys.downKey = false;
break;
case 32: // 32 is spacebar
pressedKeys.spaceKey= false;
break;
}
}
void handleSpecialKeypress(int key, int x, int y) {
switch (key) {
case GLUT_KEY_LEFT:
pressedKeys.leftKey = true;
break;
case GLUT_KEY_RIGHT:
pressedKeys.rightKey = true;
break;
case GLUT_KEY_UP:
pressedKeys.upKey = true;
break;
case GLUT_KEY_DOWN:
pressedKeys.downKey = true;
break;
}
}
int main(int argc, char **argv) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_SINGLE | GLUT_RGB );
glutInitWindowSize( ww, wh ); // window size
glutInitWindowPosition ( 0, 0 ); // & position on screen
glutCreateWindow( "It's BAMster Time!" );
myInit ( );
theBamsterGame = new game();
object::activGame = theBamsterGame;
glutDisplayFunc (plot );
glutTimerFunc ( 40,timerCallback,1 ) ;
glutKeyboardFunc(handleKeypress);
glutKeyboardUpFunc(handleKeyReleased);
glutSpecialFunc(handleSpecialKeypress);
glutSpecialUpFunc(handleSpecialKeyReleased);
glutMainLoop ( );
return 0;
}