From a245066b3c0bc37e575733669296e6bfc46bfaf7 Mon Sep 17 00:00:00 2001 From: SGOrava Date: Sun, 9 Nov 2014 19:06:59 +0100 Subject: [PATCH] Fix bug when Space pressed... --- playstate.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/playstate.cpp b/playstate.cpp index 148f137..8617532 100644 --- a/playstate.cpp +++ b/playstate.cpp @@ -1,8 +1,10 @@ # include "game.hpp" # include "states.hpp" + PlayState PlayState::m_PlayState; + void PlayState::Init() { Map = map(); @@ -64,6 +66,7 @@ void PlayState::HandleEvents ( game* Game ) if ( event.type == SDL_QUIT) Game->Quit(); + /* Game Over - Write name for score */ if( nameEntering == true && nameEntered == false ) { //Get user input @@ -88,13 +91,16 @@ void PlayState::HandleEvents ( game* Game ) name.show_centered(Game); } + /* Game key logic... */ else { switch ( event.type ) { + /* key pressed.... */ case SDL_KEYDOWN: switch ( event.key.keysym.sym ) { + /* ESCAPE - Pause game (run PauseState) */ case SDLK_ESCAPE: { //Game->SetRunning(false); @@ -102,8 +108,10 @@ void PlayState::HandleEvents ( game* Game ) } break; + /* move part to the right */ case SDLK_RIGHT: { + /* */ part p = Part; # ifdef DEBUG @@ -191,7 +199,7 @@ void PlayState::HandleEvents ( game* Game ) { Part.move ( 0, 1 ); - tick = FPS - 1; + tick = ( FPS / ( ( level > 30 ) ? 30 : level ) ) - 1; } break; @@ -213,8 +221,10 @@ void PlayState::HandleEvents ( game* Game ) void PlayState::Update ( game* Game ) { + /* kontrola či je plné hracie pole... */ if ( Map.isFull() ) { + /* Start enter name */ nameEntering = true; if (nameEntered) @@ -246,8 +256,12 @@ void PlayState::Update ( game* Game ) Part.move ( 0, 1 ); } + /* + if ( tick % ( FPS / ( ( level > 30 ) ? 30 : level ) ) != 0 && Map.isCollision ( Part ) && tick != ( FPS / ( ( level > 30 ) ? 30 : level ) ) -1 ) + std::cout << "DEBUG" << std::endl; + */ - if ( Map.isCollision ( Part ) && tick + 1 == ( FPS / ( ( level > 30 ) ? 30 : level ) ) ) + if ( Map.isCollision ( Part ) && ( tick ) == ( FPS / ( ( level > 30 ) ? 30 : level ) ) -1 ) { int count;