input, changes

This commit is contained in:
2026-03-16 08:21:04 +01:00
parent d522881358
commit f6a1e59ebb
12 changed files with 109 additions and 44 deletions

27
src/game/input.cpp Normal file
View File

@@ -0,0 +1,27 @@
#include <game/input.hpp>
namespace Game {
const bool* Input::mCurrentKeyStates = nullptr;
bool* Input::mPreviousKeyStates = nullptr;
int Input::mNumKeys = 0;
void Input::update() {
mPreviousKeyStates = const_cast<bool*>(mCurrentKeyStates);
mCurrentKeyStates = SDL_GetKeyboardState(&mNumKeys);
}
bool Input::isKeyPressed(SDL_Scancode key) {
if (key < 0 || key >= mNumKeys) return false;
return mCurrentKeyStates[key];
}
bool Input::isKeyJustPressed(SDL_Scancode key) {
if (key < 0 || key >= mNumKeys) return false;
return mCurrentKeyStates[key] && (!mPreviousKeyStates || !mPreviousKeyStates[key]);
}
bool Input::isKeyJustReleased(SDL_Scancode key) {
if (key < 0 || key >= mNumKeys) return false;
return (!mCurrentKeyStates[key]) && mPreviousKeyStates && mPreviousKeyStates[key];
}
}