diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-10 12:07:40 -0400 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2019-03-10 12:07:40 -0400 |
commit | 57fe8f3c4124819b95164547333a33f4c45eac8d (patch) | |
tree | 99dd89a0c1cf0a8ceaa2ff941549d631950efd11 /src/input.h | |
parent | bf34f891c5c09e6c8a42797085860fa80ab53814 (diff) | |
download | dispatcher-57fe8f3c4124819b95164547333a33f4c45eac8d.tar.gz dispatcher-57fe8f3c4124819b95164547333a33f4c45eac8d.tar.bz2 dispatcher-57fe8f3c4124819b95164547333a33f4c45eac8d.zip |
Editor now allows tile placement
You can scroll through the three layers (map, track, object) with Z/X. You can swap between focusing on the map and the tileset with TAB. You can place tiles with enter or space. Pretty rudimentary, but it's a start.
Diffstat (limited to 'src/input.h')
-rw-r--r-- | src/input.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/src/input.h b/src/input.h new file mode 100644 index 0000000..ad8b761 --- /dev/null +++ b/src/input.h | |||
@@ -0,0 +1,39 @@ | |||
1 | #ifndef INPUT_H_0FB34C42 | ||
2 | #define INPUT_H_0FB34C42 | ||
3 | |||
4 | #include <SDL.h> | ||
5 | #include <vector> | ||
6 | |||
7 | /** | ||
8 | * Helper class that detects when a key is newly pressed. | ||
9 | */ | ||
10 | class Input { | ||
11 | public: | ||
12 | |||
13 | Input() | ||
14 | { | ||
15 | const Uint8* s = SDL_GetKeyboardState(&length_); | ||
16 | |||
17 | curstate_.assign(s, s + length_); | ||
18 | prevstate_ = curstate_; | ||
19 | } | ||
20 | |||
21 | void tick(const Uint8* keystate) | ||
22 | { | ||
23 | prevstate_ = std::move(curstate_); | ||
24 | curstate_.assign(keystate, keystate + length_); | ||
25 | } | ||
26 | |||
27 | bool wasPressed(int scancode) const | ||
28 | { | ||
29 | return curstate_.at(scancode) && !prevstate_.at(scancode); | ||
30 | } | ||
31 | |||
32 | private: | ||
33 | |||
34 | int length_; | ||
35 | std::vector<Uint8> curstate_; | ||
36 | std::vector<Uint8> prevstate_; | ||
37 | }; | ||
38 | |||
39 | #endif /* end of include guard: INPUT_H_0FB34C42 */ | ||