summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2022-05-21 22:24:01 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2022-05-21 22:59:59 +0200
commitd324ad963c24edf6d19dffc305a38e0b3607b5c1 (patch)
tree10d487be5d723882a12876ea34bf2dcc2233a4d1 /src/game.cpp
parent27a55a2e841e9c248d6b055780a519a7b5ee4263 (diff)
Add piece rotation
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 47526c8..d897aa4 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -104,7 +104,6 @@ bool GameState::cellIsEmpty(Point* p){
return( p->x < GRID_WIDTH && p->x >= 0 && grid[p->y][p->x] == 0 );
}
-void GameState::pressRotate(){}
void GameState::pressDown(){
yspeed_ = 4;
}
@@ -139,3 +138,17 @@ void GameState::pressRight(){
}
piece_ = tmp;
}
+
+void GameState::pressRotate(){
+ Piece tmp = piece_;
+ tmp.rotate();
+ Point* p;
+ // Check if there's space to move to
+ tmp.initIterator();
+ while ( p = tmp.nextAbsBlockPos() ){
+ if(!cellIsEmpty(p)){
+ return;
+ }
+ }
+ piece_ = tmp;
+}