#include "input_system.h" #include "game.h" #include "character_system.h" #include "message_system.h" #include "script_system.h" struct Input { bool left = false; bool right = false; bool up = false; bool down = false; }; void InputSystem::tick(double dt) { SDL_Event e; while (SDL_PollEvent(&e)) { if (e.type == SDL_QUIT || (e.type == SDL_KEYDOWN && e.key.keysym.sym == SDLK_ESCAPE)) { game_.quit(); return; } else if (e.type == SDL_KEYDOWN) { if (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT) { for (int spriteId : game_.getSprites()) { Sprite& sprite = game_.getSprite(spriteId); if (sprite.controllable) { game_.getSystem().beginCrouch(spriteId); } } } else if (e.key.keysym.sym == SDLK_a) { // TODO: Remove this, it's just for testing. /*if (game_.getSystem().getCutsceneBarsProgress() == 1.0) { game_.getSystem().hideCutsceneBars(); } else { game_.getSystem().displayCutsceneBars(); }*/ //game_.getSystem().displayMessage("Some people always try to avoid fighting when there are enemies around. You know the type, right? They use the dash ability to zoom right by. I guess you could say they're followers of \"peace at any price\".", "Sparrow", SpeakerType::Woman); //game_.getSystem().displayMessage("Lucas. You're awful at hide-and-seek, you know that? Try harder.", "Kumatora", SpeakerType::Woman); //game_.getSystem().displayMessage("Hi Tooth! I hope you're having a good day.", "Lucas", SpeakerType::Boy); game_.getSystem().runScript("script0001"); } else if (e.key.keysym.sym == SDLK_b) { // TODO: Remove this, it's just for testing. game_.getSystem().advanceText(); } } else if (e.type == SDL_KEYUP && (e.key.keysym.sym == SDLK_LSHIFT || e.key.keysym.sym == SDLK_RSHIFT)) { for (int spriteId : game_.getSprites()) { Sprite& sprite = game_.getSprite(spriteId); if (sprite.controllable) { game_.getSystem().endCrouch(spriteId); } } } } Input keystate; const Uint8* state = SDL_GetKeyboardState(NULL); keystate.left = state[SDL_SCANCODE_LEFT]; keystate.right = state[SDL_SCANCODE_RIGHT]; keystate.up = state[SDL_SCANCODE_UP]; keystate.down = state[SDL_SCANCODE_DOWN]; for (int spriteId : game_.getSprites()) { Sprite& sprite = game_.getSprite(spriteId); if (sprite.controllable) { bool directed = false; Direction dir = Direction::left; if (keystate.up) { directed = true; dir = Direction::up; } else if (keystate.down) { directed = true; dir = Direction::down; } if (keystate.left) { directed = true; if (dir == Direction::up) { dir = Direction::up_left; } else if (dir == Direction::down) { dir = Direction::down_left; } else { dir = Direction::left; } } else if (keystate.right) { directed = true; if (dir == Direction::up) { dir = Direction::up_right; } else if (dir == Direction::down) { dir = Direction::down_right; } else { dir = Direction::right; } } if (directed) { game_.getSystem().moveInDirection(spriteId, dir); } else { game_.getSystem().stopDirecting(spriteId); } } } }