diff options
author | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-05-21 21:36:37 +0200 |
---|---|---|
committer | Ekaitz Zarraga <ekaitz@elenq.tech> | 2022-05-21 21:36:37 +0200 |
commit | 41d2578d3401e38fa8600a533ad5998dc39e7be5 (patch) | |
tree | 8199af62e448b1010bab8ec4caca98d7ada860ff /src/game.cpp | |
parent | 3ce5ae75abd2de874b6c33214ea44063f11a0d4d (diff) |
add move sideways capability
Diffstat (limited to 'src/game.cpp')
-rw-r--r-- | src/game.cpp | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/src/game.cpp b/src/game.cpp index 1ed8cc0..17000a0 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -51,20 +51,14 @@ void GameState::update( unsigned int dt ){ Piece tmp = piece_; tmp.advance(); Point* p; - tmp.initIterator(); - // Check if there's space to move forward - bool canadvance; + tmp.initIterator(); while ( p = tmp.nextAbsBlockPos() ){ - if ( grid[p->y][p->x] == 0 ){ - canadvance = true; - } else { - canadvance = false; + if(!cellIsEmpty(p)){ + return; } } - if ( canadvance ){ - piece_ = tmp; - } + piece_ = tmp; } // If timer finished, level up @@ -106,6 +100,9 @@ void GameState::render(){ renderer_->update(); } +bool GameState::cellIsEmpty(Point* p){ + return( grid[p->y][p->x] == 0 ); +} void GameState::pressRotate(){} void GameState::pressDown(){ @@ -115,7 +112,30 @@ void GameState::releaseDown(){ yspeed_ = 1; } -void GameState::pressLeft(){} -void GameState::releaseLeft(){} -void GameState::pressRight(){} -void GameState::releaseRight(){} +void GameState::pressLeft(){ + Piece tmp = piece_; + tmp.move_left(); + Point* p; + + // Check if there's space to move to + tmp.initIterator(); + while ( p = tmp.nextAbsBlockPos() ){ + if(!cellIsEmpty(p)){ + return; + } + } + piece_ = tmp; +} +void GameState::pressRight(){ + Piece tmp = piece_; + tmp.move_right(); + Point* p; + // Check if there's space to move to + tmp.initIterator(); + while ( p = tmp.nextAbsBlockPos() ){ + if(!cellIsEmpty(p)){ + return; + } + } + piece_ = tmp; +} |