-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_client.c
212 lines (192 loc) · 3.58 KB
/
main_client.c
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/**
* GLUT main app for things.
*/
#include "tools.h"
#include "game.h"
#include "game_client.h"
// Global status things.
int key[256];
int specialKey[256];
//from game.c
extern player_t p[2];
// Key press handler, normal keys.
void handleKeypress(unsigned char k, int x, int y)
{
key[k] = 1;
switch(k)
{
case 27: // Escape
exit(0);
case 'p': // Neat for debugging
sleep(1);
break;
//player B movement
case 'w':
p[1].input.forwards = 1;
break;
case 's':
p[1].input.backwards = 1;
break;
case 'a':
p[1].input.left = 1;
break;
case 'd':
p[1].input.right = 1;
break;
case 'f':
p[1].input.shoot = 1;
break;
case 'g':
p[1].input.dodgeDown = 1;
break;
case 'h':
p[1].input.dodgeUp = 1;
break;
//player A shoot & dodge
case '-':
p[0].input.shoot = 1;
break;
case ',':
p[0].input.dodgeDown = 1;
break;
case '.':
p[0].input.dodgeUp = 1;
break;
}
}
void handleKeyUp(unsigned char k, int x, int y)
{
key[k] = 0;
switch(k)
{
//player B movement
case 'w':
p[1].input.forwards = 0;
break;
case 's':
p[1].input.backwards = 0;
break;
case 'a':
p[1].input.left = 0;
break;
case 'd':
p[1].input.right = 0;
break;
case 'f':
p[1].input.shoot = 0;
break;
case 'g':
p[1].input.dodgeDown = 0;
break;
case 'h':
p[1].input.dodgeUp = 0;
break;
//player A shoot & dodge
case '-':
p[0].input.shoot = 0;
break;
case ',':
p[0].input.dodgeDown = 0;
break;
case '.':
p[0].input.dodgeUp = 0;
break;
}
}
// Key press handler, special keys.
void handleSpecialKeypress(int k, int x, int y)
{
specialKey[k] = 1;
switch(k)
{
//player A movement
case GLUT_KEY_UP:
p[0].input.forwards = 1;
break;
case GLUT_KEY_DOWN:
p[0].input.backwards = 1;
break;
case GLUT_KEY_LEFT:
p[0].input.left = 1;
break;
case GLUT_KEY_RIGHT:
p[0].input.right = 1;
break;
}
}
void handleSpecialUp(int k, int x, int y)
{
specialKey[k] = 0;
switch(k)
{
//player A movement
case GLUT_KEY_UP:
p[0].input.forwards = 0;
break;
case GLUT_KEY_DOWN:
p[0].input.backwards = 0;
break;
case GLUT_KEY_LEFT:
p[0].input.left = 0;
break;
case GLUT_KEY_RIGHT:
p[0].input.right = 0;
break;
}
}
// Resize handler.
void handleResize(int w, int h) {
glViewport( 0, 0, w, h );
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
gluPerspective( 45.0, (float)w / (float)h, 1.0, 200.0 );
}
// Scene drawing
void drawScene() {
gameDraw();
glutSwapBuffers();
}
// Called every 10 milliseconds to update things on screen
void update(int value) {
if( gameUpdate() ) {
gameCleanup();
graphicCleanup();
exit(1);
}
glutPostRedisplay();
glutTimerFunc( 10, update, 0 );
}
// Initialization functions.
void initOGL(int argc, char** argv) {
glutInit( &argc, argv );
glutInitDisplayMode( GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
// Build modestring.
char modeString[255];
modeString[0] = 0;
sprintf(modeString, "%dx%d:24", (int) screenHeight, (int) screenWidth);
glutGameModeString( modeString );
glutEnterGameMode();
// Alternative: Windowed.
//glutCreateWindow("Fages");
glewInit();
}
void initFunctions() {
memset( key, 0, 256 );
memset( specialKey, 0, 256 );
glutDisplayFunc( drawScene );
glutKeyboardFunc( handleKeypress );
glutKeyboardUpFunc( handleKeyUp );
glutSpecialFunc( handleSpecialKeypress );
glutSpecialUpFunc( handleSpecialUp );
glutReshapeFunc( handleResize );
glutTimerFunc( 10, update, 0 );
}
int main(int argc, char** argv)
{
initOGL( argc, argv );
initFunctions();
graphicInit();
gameInit();
glutMainLoop();
return 0;
}