From d324ad963c24edf6d19dffc305a38e0b3607b5c1 Mon Sep 17 00:00:00 2001 From: Ekaitz Zarraga Date: Sat, 21 May 2022 22:24:01 +0200 Subject: Add piece rotation --- src/game.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/game.cpp') 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; +} -- cgit v1.2.3