Fixed input bug (see SDL2 Engine Deck)

This commit is contained in:
2021-02-18 14:20:11 -05:00
parent e4de32f9f7
commit fe13bac080
3 changed files with 31 additions and 48 deletions

View File

@ -16,7 +16,8 @@
class KeyboardController : public Component
{
public:
TransformComponent *transform;
// bool keyIsAlreadyPressed[];
TransformComponent *transform;
SpriteComponent *sprite;
Game *game;
@ -52,7 +53,10 @@ public:
sprite->spriteFlip = SDL_FLIP_HORIZONTAL;
break;
case SDLK_k:
// game->printDebug("");
if (!Game::debugCollisionBoxes)
{ Game::debugCollisionBoxes = true; }
else
{Game::debugCollisionBoxes = false; }
break;
case SDLK_j:
if (Mix_PlayChannel(-1, Game::assets->GetSoundClip("bwoop"),0) == 0)
@ -63,12 +67,17 @@ public:
sprite->Play("Jump");
transform->velocity.y = -2;
break;
case SDLK_u:
Game::gsm->AdvanceState();
break;
case SDLK_i:
Game::gsm->GameOver();
break;
default:
break;
}
}
if (Game::event.type == SDL_KEYUP)
else if (Game::event.type == SDL_KEYUP)
{
switch (Game::event.key.keysym.sym)
{
@ -98,11 +107,6 @@ public:
}
break;
case SDLK_k:
SDL_Delay(100);
if (!Game::debugCollisionBoxes)
{ Game::debugCollisionBoxes = true; }
else
{Game::debugCollisionBoxes = false; }
break;
case SDLK_j:
transform->velocity.y = 0;
@ -110,11 +114,8 @@ public:
Game::gravityOnPlayer = true;
break;
case SDLK_u:
// Advance the GSM state via the u key
Game::gsm->AdvanceState();
break;
case SDLK_i:
Game::gsm->GameOver();
break;
case SDLK_ESCAPE: // exit the game when Escape pressed
Game::isRunning = false;
@ -124,7 +125,6 @@ public:
}
}
}
};