-
Notifications
You must be signed in to change notification settings - Fork 2
/
Input.cpp
68 lines (62 loc) · 1.31 KB
/
Input.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
#include "Input.h"
#include "Engine.h"
#include <unordered_map>
Input::Input()
{
mousePosition = new Vector2( 0, 0);
SDL_ShowCursor(SDL_DISABLE);
}
Input::~Input()
{
}
void Input::ProcessInput()
{
SDL_Event e;
while (SDL_PollEvent(&e))
{
if (e.type == SDL_QUIT || e.key.keysym.sym == SDLK_ESCAPE)
{
Engine::Quit();
}
else if (e.type == SDL_KEYDOWN || e.type == SDL_KEYUP)
{
switch (e.key.keysym.sym)
{
case SDLK_w:
keyStateMap[MOVE_UP] = e.type == SDL_KEYDOWN ? true : false;
break;
case SDLK_s:
keyStateMap[MOVE_DOWN] = e.type == SDL_KEYDOWN ? true : false;
break;
case SDLK_a:
keyStateMap[MOVE_LEFT] = e.type == SDL_KEYDOWN ? true : false;
break;
case SDLK_d:
keyStateMap[MOVE_RIGHT] = e.type == SDL_KEYDOWN ? true : false;
break;
default:
break;
}
}
else if (e.type == SDL_MOUSEBUTTONDOWN || e.type == SDL_MOUSEBUTTONUP)
{
if (SDL_BUTTON(SDL_BUTTON_LEFT))
{
keyStateMap[SHOOT] = e.type == SDL_MOUSEBUTTONDOWN ? true : false;
printf("captured mouse click");
}
}
}
int mousePosX, mousePosY;
SDL_GetMouseState(&mousePosX, &mousePosY);
mousePosition->X = mousePosX;
mousePosition->Y = mousePosY;
}
bool Input::KeyPressed(InputEvent input)
{
return keyStateMap[input];
}
Vector2* Input::GetMousePosition()
{
return mousePosition;
}