-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinputmanager.cpp
More file actions
178 lines (168 loc) · 5.02 KB
/
inputmanager.cpp
File metadata and controls
178 lines (168 loc) · 5.02 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
#include "inputmanager.hpp"
#include "renderer.hpp"
#include "manager.hpp"
#include "roommanager.hpp"
#include "room.hpp"
#ifdef WIN32
#include <SDL.h>
#include <windows.h>
#else
#include <SDL/SDL.h>
#endif
#include <memory>
Inputmanager::Inputmanager()
{
fprintf(stderr, "Inputmanager being hired...\n");
synthMappings = std::shared_ptr<SynthMapping>(new SynthMapping());
}
Inputmanager::~Inputmanager()
{
fprintf(stderr, "Inputmanager being fired...\n");
}
// Resets all keys as pressable at the beginning of the loop
// TODO: Make into a keystate array
void Inputmanager::resetKeys()
{
triggeredLeft = false;
triggeredRight = false;
triggeredUp = false;
triggeredDown = false;
triggeredA = false;
triggeredD = false;
triggeredZ = false;
triggeredX = false;
triggeredK = false;
}
void Inputmanager::checkInput()
{
std::shared_ptr<Room> currentRoom = manager.getRoomMgr()->giveCurrentRoom();
if (currentRoom->getType() == 3 || currentRoom->getType() == 4) // cinematics / text
{
SDL_Event e;
while (SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_QUIT:
manager.stop();
break;
case SDL_KEYDOWN:
switch (e.key.keysym.sym)
{
case SDLK_ESCAPE:
currentRoom->iterateSprites();
break;
case SDLK_RETURN:
currentRoom->iterateSprites();
break;
}
break;
}
}
} else
{
SDL_Event e;
while (SDL_PollEvent(&e))
{
switch (e.type)
{
case SDL_QUIT:
manager.stop();
break;
case SDL_KEYDOWN:
switch (e.key.keysym.sym)
{
case SDLK_ESCAPE:
manager.stop();
break;
case SDLK_a:
currentRoom->toggleShaders();
break;
case SDLK_q:
currentRoom->shaderAction1();
break;
case SDLK_w:
currentRoom->shaderAction2();
break;
case SDLK_e:
currentRoom->shaderAction3();
break;
case SDLK_r:
currentRoom->shaderAction4();
break;
case SDLK_t:
currentRoom->shaderAction5();
break;
case SDLK_y:
currentRoom->shaderAction6();
break;
case SDLK_u:
currentRoom->shaderAction7();
break;
case SDLK_i:
currentRoom->shaderAction8();
break;
case SDLK_UP:
renderer.moveForwards();
break;
case SDLK_DOWN:
renderer.moveBackwards();
break;
case SDLK_LEFT:
renderer.moveLeft();
break;
case SDLK_RIGHT:
renderer.moveRight();
break;
case SDLK_h:
renderer.panUp();
break;
case SDLK_j:
renderer.panDown();
break;
case SDLK_n:
renderer.panLeft();
break;
case SDLK_m:
renderer.panRight();
break;
}
break;
}
}
}
}
void Inputmanager::handleSynthEvents(unsigned char input_data[])
{
fprintf(stderr, "%d %d %d %d\n", input_data[0], input_data[1], input_data[2], input_data[3]);
if (input_data[0] == 144)
{
if (input_data[2] == 64)
{
synthMappings->pushKeyDown(input_data[1]);
}
else if (input_data[2] == 0)
{
synthMappings->pullKeyUp(input_data[1]);
}
}
else if (input_data[0] == 123)
{
fprintf(stderr, "All keys up\n");
synthMappings->allKeysUp();
}
else
{
fprintf(stderr, "fail safe\n");
synthMappings->allKeysUp();
}
manager.getRoomMgr()->giveCurrentRoom()->synthAction(input_data);
}
int* Inputmanager::getSynthKeysDown()
{
return synthMappings->getDownKeys();
}
int* Inputmanager::getSynthDownTimes()
{
return synthMappings->getDownTimes();
}