Fix bug when Space pressed...

This commit is contained in:
SGOrava 2014-11-09 19:06:59 +01:00
parent f9fd68befe
commit a245066b3c

View File

@ -1,8 +1,10 @@
# include "game.hpp" # include "game.hpp"
# include "states.hpp" # include "states.hpp"
PlayState PlayState::m_PlayState; PlayState PlayState::m_PlayState;
void PlayState::Init() void PlayState::Init()
{ {
Map = map(); Map = map();
@ -64,6 +66,7 @@ void PlayState::HandleEvents ( game* Game )
if ( event.type == SDL_QUIT) if ( event.type == SDL_QUIT)
Game->Quit(); Game->Quit();
/* Game Over - Write name for score */
if( nameEntering == true && nameEntered == false ) if( nameEntering == true && nameEntered == false )
{ {
//Get user input //Get user input
@ -88,13 +91,16 @@ void PlayState::HandleEvents ( game* Game )
name.show_centered(Game); name.show_centered(Game);
} }
/* Game key logic... */
else else
{ {
switch ( event.type ) switch ( event.type )
{ {
/* key pressed.... */
case SDL_KEYDOWN: case SDL_KEYDOWN:
switch ( event.key.keysym.sym ) switch ( event.key.keysym.sym )
{ {
/* ESCAPE - Pause game (run PauseState) */
case SDLK_ESCAPE: case SDLK_ESCAPE:
{ {
//Game->SetRunning(false); //Game->SetRunning(false);
@ -102,8 +108,10 @@ void PlayState::HandleEvents ( game* Game )
} }
break; break;
/* move part to the right */
case SDLK_RIGHT: case SDLK_RIGHT:
{ {
/* */
part p = Part; part p = Part;
# ifdef DEBUG # ifdef DEBUG
@ -191,7 +199,7 @@ void PlayState::HandleEvents ( game* Game )
{ {
Part.move ( 0, 1 ); Part.move ( 0, 1 );
tick = FPS - 1; tick = ( FPS / ( ( level > 30 ) ? 30 : level ) ) - 1;
} }
break; break;
@ -213,8 +221,10 @@ void PlayState::HandleEvents ( game* Game )
void PlayState::Update ( game* Game ) void PlayState::Update ( game* Game )
{ {
/* kontrola či je plné hracie pole... */
if ( Map.isFull() ) if ( Map.isFull() )
{ {
/* Start enter name */
nameEntering = true; nameEntering = true;
if (nameEntered) if (nameEntered)
@ -246,8 +256,12 @@ void PlayState::Update ( game* Game )
Part.move ( 0, 1 ); 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; int count;