summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp48
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;
+}