-
Notifications
You must be signed in to change notification settings - Fork 0
/
inputSystem.cpp
138 lines (132 loc) · 3.82 KB
/
inputSystem.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
#include "inputSystem.h"
#include "game.h"
#include "KeyEvent.h"
InputSystem::InputSystem()
{
}
InputSystem::~InputSystem()
{
cleanup();
}
void InputSystem::cleanup()
{
}
void InputSystem::init()
{
}
void InputSystem::checkForInput()
{
sf::Event e;
while(Game::getInstance()->getGraphics().mDisplay.pollEvent(e))
{
if(e.type == sf::Event::Closed)
{
gpEventSystem->fireEvent(new QuitEvent());
}
else if(e.type == sf::Event::MouseButtonPressed)
{
MouseButton mb;
switch(e.mouseButton.button)
{
case sf::Mouse::Button::Left:
mb = MouseButton::LEFT;
break;
case sf::Mouse::Button::Right:
mb = MouseButton::RIGHT;
break;
default:
mb = MouseButton::LEFT;
}
sf::Vector2i mousePos = sf::Mouse::getPosition(Game::getInstance()->getGraphics().mDisplay);
gpEventSystem->fireEvent(new MouseClickEvent(Vector2D((float)mousePos.x, (float)mousePos.y), mb));
}
else if(e.type == sf::Event::KeyPressed)
{
switch(e.key.code)
{
case sf::Keyboard::Left:
gpEventSystem->fireEvent(new KeyPressedEvent(Key::LEFT));
break;
case sf::Keyboard::Right:
gpEventSystem->fireEvent(new KeyPressedEvent(Key::RIGHT));
break;
case sf::Keyboard::Up:
gpEventSystem->fireEvent(new KeyPressedEvent(Key::UP));
break;
case sf::Keyboard::Down:
gpEventSystem->fireEvent(new KeyPressedEvent(Key::DOWN));
break;
case sf::Keyboard::D:
gpEventSystem->fireEvent(new KeyPressedEvent(Key::D));
break;
case sf::Keyboard::A:
gpEventSystem->fireEvent(new KeyPressedEvent(Key::A));
break;
case sf::Keyboard::Space:
gpEventSystem->fireEvent(new KeyPressedEvent(Key::SPACE));
break;
default:
break;
}
}
else if(e.type == sf::Event::KeyReleased)
{
switch(e.key.code)
{
case sf::Keyboard::Left:
gpEventSystem->fireEvent(new KeyReleasedEvent(Key::LEFT));
break;
case sf::Keyboard::Right:
gpEventSystem->fireEvent(new KeyReleasedEvent(Key::RIGHT));
break;
case sf::Keyboard::Up:
gpEventSystem->fireEvent(new KeyReleasedEvent(Key::UP));
break;
case sf::Keyboard::D:
gpEventSystem->fireEvent(new KeyReleasedEvent(Key::D));
break;
case sf::Keyboard::A:
gpEventSystem->fireEvent(new KeyReleasedEvent(Key::A));
break;
case sf::Keyboard::Down:
gpEventSystem->fireEvent(new KeyReleasedEvent(Key::DOWN));
break;
default:
break;
}
}
else if(e.type == sf::Event::MouseWheelMoved)
{
const Vector2D cursorLocation = Vector2D((float)e.mouseWheel.x, (float)e.mouseWheel.y);
switch(e.mouseWheel.delta)
{
case 1:
gpEventSystem->fireEvent(new MouseWheelEvent(MouseWheel::UP, cursorLocation));
break;
case -1:
gpEventSystem->fireEvent(new MouseWheelEvent(MouseWheel::DOWN, cursorLocation));
break;
}
}
}
if(Game::getInstance()->getGamestate() == Gamestate::PLAYING)
{
/*
if mouse is clicked
fire a mouse click event containing coords of click
board will listen to this, and it will resolve click
in board: if click landed on city adjacent to active pawn, move that pawn
if click landed on same city of active pawn and no active cards, reduce that city's disease cubes
if click landed on a card, set that card to active and resolve that in any future clicks (eg set card to active, then click on own city to perform
charter flight action, or do trades if player clicks in card area of another player, etc)
if wasd is pressed
fire move camera event in direction of wasd press. game will listen to this one and adjust the view accordingly
if wasd is released
fire stop camera move event as above
*/
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Escape))
{
gpEventSystem->fireEvent(new QuitEvent());
}
}