This repository has been archived by the owner on Feb 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controller.cpp
238 lines (200 loc) · 4.46 KB
/
Controller.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
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
/*
* Controller.cpp
*
* Created on: Apr 5, 2013
* Author: lucasmello
*/
#include <iostream>
#include <vector>
#include "Controller.h"
#include "GameEngine/Participants/PlayerParticipant.h"
#include "GameEngine/Map.h"
using namespace std;
extern int window_weight;
extern int window_height;
extern int window_id;
extern PlayerParticipant playerp;
extern Map runningMap;
bool player_moving=false;
GLfloat look_angle=200;
GLfloat look_angle_Y=0;
GLfloat mov_angle=0;
float mouse_sensivity=0.35;
bool uppressed=false;
bool downpressed=false;
bool leftpressed=false;
bool rightpressed=false;
bool jumping=false;
bool travarMouse=true;
bool debugmode_on=false;
void updatePlayerSpeed(){
if(!uppressed and !rightpressed and !leftpressed and !downpressed and player_moving){
playerp.AddRunSpeed(-PLAYER_BASE_RUNSPEED);
player_moving=false;
}else{
if(not player_moving){
playerp.AddRunSpeed(PLAYER_BASE_RUNSPEED);
player_moving=true;
}
}
mov_angle=0;
if(rightpressed)
mov_angle+=45;
if(leftpressed)
mov_angle-=45;
if(not uppressed and not downpressed)
mov_angle*=2;
if(downpressed){
mov_angle=-mov_angle;
mov_angle+=180;
}
playerp.speed_ang_xz=look_angle+mov_angle;
if( playerp.speed_ang_xz>360)
playerp.speed_ang_xz-=360;
if( playerp.speed_ang_xz<0)
playerp.speed_ang_xz+=360;
}
//void mouseFunc(int button, int state, int x, int y){
// cout << "button: " << button << "; state: " << state << "; x,y" << x << ',' << y << endl;
//}
void mousePassiveFunc(int x, int y){
if(not travarMouse){
return;
}
int dx,dz;
dx=window_weight/2-x;
dz=window_height/2-y;
if(dx==0 and dz==0)
return;
look_angle_Y+=dz*mouse_sensivity;
if(look_angle_Y > MAX_ANGLE_VIEW)
look_angle_Y=MAX_ANGLE_VIEW;
if(look_angle_Y < -MAX_ANGLE_VIEW)
look_angle_Y=-MAX_ANGLE_VIEW;
look_angle-=dx*mouse_sensivity;
if(look_angle>360)
look_angle-=360;
if(look_angle<0)
look_angle+=360;
playerp.speed_ang_xz=look_angle+mov_angle;
if( playerp.speed_ang_xz>360)
playerp.speed_ang_xz-=360;
if( playerp.speed_ang_xz<0)
playerp.speed_ang_xz+=360;
glutWarpPointer(window_weight/2,window_height/2);
glutPostRedisplay();
}
void keyboardReleased(unsigned char key, int x, int y){
switch (key) {
case 'w':
uppressed=false;
break;
case 'a':
leftpressed=false;
break;
case 'd':
rightpressed=false;
break;
case 's':
downpressed=false;
break;
case 'q':
playerp.AddVerticalSpeed(+0.02);
break;
case 'e':
playerp.AddVerticalSpeed(-0.02);
break;
default:
return;
}
updatePlayerSpeed();
}
void keyboardPressed(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(0);
break;
case '!':
runningMap.resetMap();
return;
case '$':
runningMap.endMap();
return;
case 'x': //+senbilidade
if(mouse_sensivity < 1)
mouse_sensivity+=0.05;
return;
case 'z':
if(mouse_sensivity > 0.06)
mouse_sensivity-=0.05;
return;
case ';':
travarMouse=not travarMouse;
glutWarpPointer(window_weight/2,window_height/2);
return;
case 'w':
uppressed=true;
break;
case 'd':
rightpressed=true;
break;
case 'a':
leftpressed=true;
break;
case 's':
downpressed=true;
break;
case 'q':
if(debugmode_on)
playerp.AddVerticalSpeed(-0.02);
break;
case 'e':
if(debugmode_on)
playerp.AddVerticalSpeed(+0.02);
break;
case '%':
debugmode_on=!debugmode_on;
return;
case ' ': //SPACE
if(not debugmode_on){
playerp.jump();
}
return;
default:
return;
}
updatePlayerSpeed();
}
void menu(int num){
switch(num){
case 0:
glutDestroyWindow(window_id);
exit(0);
break;
case 1: //+senbilidade
if(mouse_sensivity < 1)
mouse_sensivity+=0.05;
break;
case 2:
if(mouse_sensivity > 0.06)
mouse_sensivity-=0.05;
break;
case 3:
runningMap.resetMap();
break;
case 4:
travarMouse=not travarMouse;
glutWarpPointer(window_weight/2,window_height/2);
break;
}
}
void createMenu(void){
glutCreateMenu(menu);
glutAddMenuEntry("Recomecar Fase [!]", 3);
glutAddMenuEntry("+Sensibilidade Mouse [x]", 1);
glutAddMenuEntry("-Sensibilidade Mouse [z]", 2);
glutAddMenuEntry("Travar/Destravar Mouse [;]", 4);
glutAddMenuEntry("Quit [ESC]", 0);
glutAttachMenu(GLUT_RIGHT_BUTTON);
}