Fixed input bug (see SDL2 Engine Deck)
This commit is contained in:
parent
e4de32f9f7
commit
fe13bac080
Binary file not shown.
@ -16,6 +16,7 @@
|
||||
class KeyboardController : public Component
|
||||
{
|
||||
public:
|
||||
// bool keyIsAlreadyPressed[];
|
||||
TransformComponent *transform;
|
||||
SpriteComponent *sprite;
|
||||
|
||||
@ -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:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -274,7 +274,7 @@ void Game::render()
|
||||
{
|
||||
p->draw();
|
||||
}
|
||||
|
||||
if (gsm->currentState==GameStateManager::ST_TITLESCREEN){
|
||||
for (auto& guiElement : gui)
|
||||
{
|
||||
guiElement->draw();
|
||||
@ -283,26 +283,9 @@ void Game::render()
|
||||
{
|
||||
letter->draw();
|
||||
}
|
||||
// Vector2D origPt;
|
||||
// Vector2D destPt;
|
||||
// origPt.Zero();
|
||||
// destPt.x = 320.0*gScale;
|
||||
// destPt.y = 240.0*gScale;
|
||||
// drawLine(origPt,destPt,255,0,0);
|
||||
// Vector2D pt1, pt2, pt3, pt4;
|
||||
// pt1.x = 80.0*gScale;
|
||||
// pt1.y = 80.0*gScale;
|
||||
// pt2.x = 120.0*gScale;
|
||||
// pt2.y = 80.0*gScale;
|
||||
// pt3.x = 80.0*gScale;
|
||||
// pt3.y = 120.0*gScale;
|
||||
// pt4.x = 120.0*gScale;
|
||||
// pt4.y = 120.0*gScale;
|
||||
// Draw box with colors
|
||||
// drawLine(pt1,pt2,0,0,255);
|
||||
// drawLine(pt1,pt3,0,255,0);
|
||||
// drawLine(pt2,pt4,255,255,0);
|
||||
// drawLine(pt3,pt4,255,0,0);
|
||||
}
|
||||
|
||||
|
||||
SDL_RenderPresent(renderer);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user