-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput-component.cpp
More file actions
45 lines (44 loc) · 897 Bytes
/
input-component.cpp
File metadata and controls
45 lines (44 loc) · 897 Bytes
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
#include <iostream>
#include "game.hpp"
#include "defs.hpp"
#include "input-component.hpp"
void InputComponent::update(Entity* entity) {
if (Game::event.type == SDL_KEYDOWN) {
switch (Game::event.key.keysym.sym) {
case SDLK_a:
moving_backward = true;
break;
case SDLK_d:
moving_forward = true;
break;
case SDLK_w:
jumping = true;
break;
case SDLK_s:
looking_down = true;
break;
case SDLK_h:
attack = true;
break;
case SDLK_SPACE:
fire = true;
break;
}
}
if (Game::event.type == SDL_KEYUP) {
switch (Game::event.key.keysym.sym) {
case SDLK_a:
moving_backward = false;
break;
case SDLK_d:
moving_forward = false;
break;
case SDLK_w:
jumping = false;
break;
case SDLK_s:
looking_down = false;
break;
}
}
}