more component stuff
This commit is contained in:
30
include/components/PlayerInput.h
Normal file
30
include/components/PlayerInput.h
Normal 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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user