-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontrols.cpp
More file actions
276 lines (265 loc) · 5.59 KB
/
controls.cpp
File metadata and controls
276 lines (265 loc) · 5.59 KB
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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
float eyex,eyey,eyea=-33,eye2a=29;
int bodyx=10,bodyy,bodyz=10;
int stx,sty,view,stc=1,kill,jump,vely,inmotion;
float cutoff=0;
float rectangle_rotation = 0,cx,cy,cz;
float vx,vy,vz,off;
double kill_time,jump_time;
float zoom=1,viewx,viewy;
void keyboard (GLFWwindow* window, int key, int scancode, int action, int mods)
{
/* int i=arr[bodyy][bodyx][bodyz];
float x = 2.5+platform[i].x;
float z = platform[i].z+2;
float angle = atan2(cx-x,cz-z);
if(angle >= 45 && angle <135) angle=90;
else if((angle >= 135 && angle <= 180) || (angle<=-135)) angle=180;
else if((angle >= 0 && angle <= 45) || (angle<=0 && angle>=-45)) angle=0;
else angle = 270;
cout<<angle<<endl;
*/
int counter=0;
double current_time = glfwGetTime();
if (action == GLFW_RELEASE) {
switch (key) {
case GLFW_KEY_H:
viewy++;
break;
case GLFW_KEY_B:
viewx--;
break;
case GLFW_KEY_N:
viewy--;
break;
case GLFW_KEY_M:
viewx++;
break;
case GLFW_KEY_Z:
zoom+=0.3;
break;
case GLFW_KEY_X:
zoom-=0.3;
zoom = max(0.5f,zoom);
break;
case GLFW_KEY_DOWN:
if(view==4 || view==5){
break;
}
rectangle_rotation = 0;
if(arrr[bodyy][bodyx][bodyz+1]==3) break;
//rectangle_rotation = (angle + 180);
//if(rectangle_rotation>=360) rectangle_rotation-=360;
bodyz++;
current_time = glfwGetTime();
inmotion = 0;
if(motion[bodyy][bodyx][bodyz]){
if(hight[bodyy][bodyx][bodyz]>5&& !jump)
bodyz=25;
else{
inmotion = 1;
}
}
if(bodyz>=20){
kill=1;
red_count = 0;
memset(redc,0,sizeof(redc));
kill_time = current_time;
bodyx=10;
bodyz=10;
view=0;
cutoff=0;
}
break;
case GLFW_KEY_UP:
if(view==4 || view==5){
int a=sin(rectangle_rotation*M_PI/180.0);
int b=cos(rectangle_rotation*M_PI/180.0);
if(arrr[bodyy][bodyx-a][bodyz-b]==3) break;
bodyx-=a;
bodyz-=b;
if(bodyz<0 || bodyx<0 || bodyz>=20 || bodyx>=20){
kill=1;
memset(redc,0,sizeof(redc));
red_count = 0;
kill_time = current_time;
bodyx=10;
bodyz=10;
view=0;
cutoff=0;
}
break;
}
rectangle_rotation=180;
if(arrr[bodyy][bodyx][bodyz-1]==3) break;
bodyz--;
// bodyx += sin(rectangle_rotation*M_PI/180.0);
// bodyz += cos(rectangle_rotation*M_PI/180.0);
// cout<<rectangle_rotation<<endl;
// cout<<cos(rectangle_rotation*M_PI/180.0)<<" "<<sin(rectangle_rotation*M_PI/180.0)<<endl;
current_time = glfwGetTime();
inmotion = 0;
if(motion[bodyy][bodyx][bodyz]){
if(hight[bodyy][bodyx][bodyz]>5&& !jump)
bodyz=-5;
else{
inmotion = 1;
}
}
if(bodyz<0){
kill=1;
red_count = 0;
memset(redc,0,sizeof(redc));
kill_time = current_time;
bodyx=10;
bodyz=10;
view=0;
cutoff=0;
}
break;
case GLFW_KEY_LEFT:
if(view==4 || view==5){
rectangle_rotation += 90;
if(rectangle_rotation >= 360) rectangle_rotation -= 360;
break;
}
rectangle_rotation = 90;
//if(rectangle_rotation>=360) rectangle_rotation-=360;
if(arrr[bodyy][bodyx-1][bodyz]==3) break;
bodyx--;
inmotion = 0;
if(motion[bodyy][bodyx][bodyz]){
if(hight[bodyy][bodyx][bodyz]>5&& !jump)
bodyx=-5;
else{
inmotion = 1;
}
}
current_time = glfwGetTime();
if(bodyx<0){
kill=1;
memset(redc,0,sizeof(redc));
red_count = 0;
kill_time = current_time;
bodyx=10;
bodyz=10;
view=0;
cutoff=0;
}
break;
case GLFW_KEY_RIGHT:
if(view==4 || view==5){
rectangle_rotation += 270;
if(rectangle_rotation >= 360) rectangle_rotation -= 360;
break;
}
rectangle_rotation = 270;
//rectangle_rotation = (angle+90);
//if(rectangle_rotation>=360) rectangle_rotation-=360;
if(arrr[bodyy][bodyx+1][bodyz]==3) break;
bodyx++;
inmotion = 0;
if(motion[bodyy][bodyx][bodyz]){
if(hight[bodyy][bodyx][bodyz]>5 && !jump)
bodyx=25;
else{
inmotion = 1;
}
}
if(bodyx>=20){
kill=1;
memset(redc,0,sizeof(redc));
red_count = 0;
kill_time = current_time;
bodyx=10;
bodyz=10;
view=0;
cutoff=0;
}
break;
case GLFW_KEY_SPACE:
if(!jump && !inside[bodyy][bodyx][bodyz]){
jump=1;
vely = 3;
jump_time = current_time;
}
break;
case GLFW_KEY_P:
counter++;
case GLFW_KEY_O:
counter++;
case GLFW_KEY_I:
counter++;
case GLFW_KEY_U:
counter++;
case GLFW_KEY_Y:
counter++;
case GLFW_KEY_T:
counter++;
view=6-counter;
stc=1;
break;
case GLFW_KEY_S:
sty=0;
break;
case GLFW_KEY_A:
stx=0;
break;
case GLFW_KEY_W:
sty=0;
break;
case GLFW_KEY_D:
stx=0;
break;
default:
break;
}
}
else if (action == GLFW_PRESS) {
switch (key) {
case GLFW_KEY_ESCAPE:
quit(window);
break;
case GLFW_KEY_S:
sty=1;
break;
case GLFW_KEY_A:
stx=1;
break;
case GLFW_KEY_W:
sty=2;
break;
case GLFW_KEY_D:
stx=2;
break;
default:
break;
}
}
}
void keyboardChar (GLFWwindow* window, unsigned int key)
{
switch (key) {
case 'Q':
case 'q':
quit(window);
break;
default:
break;
}
}
void mouseButton (GLFWwindow* window, int button, int action, int mods)
{
switch (button) {
case GLFW_MOUSE_BUTTON_LEFT:
if (action == GLFW_RELEASE)
// triangle_rot_dir *= -1;
break;
// case GLFW_MOUSE_BUTTON_RIGHT:
// if (action == GLFW_RELEASE) {
// rectangle_rot_dir *= -1;
// }
// break;
default:
break;
}
}