more component stuff

This commit is contained in:
Josh Lyon
2025-08-13 22:21:37 -06:00
parent f6de0ed9f3
commit 7259d9307b
8 changed files with 151 additions and 43 deletions

View File

@@ -0,0 +1,30 @@
#include "components/InputComponent.h"
#include "GameState.h"
#include <SDL3/SDL_keycode.h>
class PlayerInput : public InputComponent {
GameState update(SDL_Event const* event) {
if (SDL_EVENT_QUIT == event->type || SDLK_ESCAPE == event->key.key) {
return GameState::STOPPING;
}
// currently dont care about anything other than down
if (SDL_EVENT_KEY_DOWN != event->type) {
return GameState::RUNNING;
}
if (SDLK_W == event->key.key) {
moveUp = event->key.type == SDL_EVENT_KEY_DOWN;
}
if (SDLK_S == event->key.key) {
moveDown = event->key.type == SDL_EVENT_KEY_DOWN;
}
if (SDLK_A == event->key.key) {
moveLeft = event->key.type == SDL_EVENT_KEY_DOWN;
}
if (SDLK_D == event->key.key) {
moveRight = event->key.type == SDL_EVENT_KEY_DOWN;
}
return GameState::RUNNING;
}
};