From 57fe8f3c4124819b95164547333a33f4c45eac8d Mon Sep 17 00:00:00 2001 From: Kelly Rauchenberger Date: Sun, 10 Mar 2019 12:07:40 -0400 Subject: 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. --- src/input.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/input.h (limited to 'src/input.h') 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 @@ +#ifndef INPUT_H_0FB34C42 +#define INPUT_H_0FB34C42 + +#include +#include + +/** + * Helper class that detects when a key is newly pressed. + */ +class Input { +public: + + Input() + { + const Uint8* s = SDL_GetKeyboardState(&length_); + + curstate_.assign(s, s + length_); + prevstate_ = curstate_; + } + + void tick(const Uint8* keystate) + { + prevstate_ = std::move(curstate_); + curstate_.assign(keystate, keystate + length_); + } + + bool wasPressed(int scancode) const + { + return curstate_.at(scancode) && !prevstate_.at(scancode); + } + +private: + + int length_; + std::vector curstate_; + std::vector prevstate_; +}; + +#endif /* end of include guard: INPUT_H_0FB34C42 */ -- cgit 1.4.1