All there but errors need fixing

Dependencies:   mbed

Overview:

Rookie Tetris is a jigsaw style game based on the classic Tetris.

A block will appear at the top of the screen, you must move it (your options for movement are left, right and down - you cannot move up the board). The block will stop when it if placed either on the floor of the board or on-top of another block.

Your goal is to fill a complete row of the board with the blocks; when you do so the row will delete and the pattern above it will drop down. The game is over when your pattern is tall enough to reach to the top of the board!

Controls:

Use the joystick to move your block! Your block cannot move out of the parameters of the board.

Pot 2 controls the contrast of the screen.

Revision:
13:600a34a047ca
Parent:
12:965b39a2e049
Child:
14:bd8c59a4b641
diff -r 965b39a2e049 -r 600a34a047ca TetrisGame/TetrisGame.cpp
--- a/TetrisGame/TetrisGame.cpp	Mon Jun 01 22:52:07 2020 +0000
+++ b/TetrisGame/TetrisGame.cpp	Tue Jun 02 16:08:21 2020 +0000
@@ -1,13 +1,15 @@
 #include "TetrisGame.h"
 
+volatile int iH;
+
 TetrisGame::TetrisGame()
 {
-    
+
 }
 
 TetrisGame::~TetrisGame()
 {
-    
+
 }
 
 void TetrisGame::init(int speed)
@@ -18,11 +20,11 @@
     _px = 40;
     _py = 4;
     _speed = speed;
-    
+
     _tetromino.init(_px, _py); // puts tetromino in middle SHOULD THIS INCLUDE ARRAY????
-    
+
     printf("initiate(%i)\n",_speed);
-    
+
 }
 
 
@@ -34,26 +36,26 @@
 
 void TetrisGame::draw(N5110 &lcd)
 {
-    // draw elements in lcd buffer 
-    
+    // draw elements in lcd buffer
+
     // board
     lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
-    
+
     _tetromino.draw(lcd);
-    
+
     printf("draw (%i,%i)\n",_px,_py);
-    
+
 }
 
 void TetrisGame::update(Gamepad &pad, N5110 &lcd)
 {
     // check_score(pad);
-    
+
     _tetromino.update(_d,_mag);
-    
+
     check_wall_collision(pad, lcd);
     check_tetromino_collisions(pad, lcd);
-    
+
     printf("update (%i,%i,%i)\n",_px,_py,_d);
 }
 
@@ -62,37 +64,43 @@
 {
     Vector2D tetromino_pos = _tetromino.get_pos();
     Vector2D tetromino_velocity = _tetromino.get_velocity();
-    
+    floor_hit_flag = 0;
+
     // check if hit floor
     if (tetromino_pos.y + 4 >= (HEIGHT-1) ) {
-        
+
         tetromino_pos.y = (HEIGHT-1) - 4;
-        tetromino_velocity.y = 0;
-        
+//        tetromino_velocity.y = 0;
+
         pad.tone(750.0,0.1);
-        
-        cancel_line(lcd); // check if line full and cancel + drop down if it is 
-        
+
+//        cancel_line(lcd); // check if line full and cancel + drop down if it is
+
         lcd.drawRect(tetromino_pos.x, tetromino_pos.y, 4, 4, FILL_BLACK);
-                
+
         _tetromino.init(_px, _py); // drop new shame
         
+        a = tetromino_pos.x;
+        b = tetromino_pos.y;
+
+        floor_hit_flag = 1;
+
         printf("floor hit!\n");
-        
+
     }
     // check if hit roof
     else if (tetromino_pos.y <= 1) {
-        
+
         printf("roof hit!\n");
-        
+
         exit_game(lcd);
-                
+
     }
-    
+
     printf("wall collision\n");
-    
+
     // SAVE OLD SCREEN AND DROP NEW TETROMINO???? //
- // update tetromino parameters??   
+// update tetromino parameters??
 }
 
 void TetrisGame::check_tetromino_collisions(Gamepad &pad, N5110 &lcd)
@@ -101,64 +109,75 @@
     Vector2D tetromino_velocity = _tetromino.get_velocity();
 
     if (
-    (lcd.getPixel(tetromino_pos.x, tetromino_pos.y + 4) == 1) || // not sure if it should be 4 or 5 ??? 
-    (lcd.getPixel(tetromino_pos.x + 1, tetromino_pos.y + 4) == 1) || 
-    (lcd.getPixel(tetromino_pos.x + 2, tetromino_pos.y + 4) == 1) ||
-    (lcd.getPixel(tetromino_pos.x + 3, tetromino_pos.y + 4) == 1)
+        (lcd.getPixel(tetromino_pos.x, tetromino_pos.y + 4) == 1) || // not sure if it should be 4 or 5 ???
+        (lcd.getPixel(tetromino_pos.x + 1, tetromino_pos.y + 4) == 1) ||
+        (lcd.getPixel(tetromino_pos.x + 2, tetromino_pos.y + 4) == 1) ||
+        (lcd.getPixel(tetromino_pos.x + 3, tetromino_pos.y + 4) == 1)
     ) {
         tetromino_velocity.x = 0;
-        
+
         pad.tone(1000.0,0.1);
         cancel_line(lcd);
-        
-        lcd.drawRect(tetromino_pos.x, tetromino_pos.y, 4, 4, FILL_BLACK);
-            
+
+//        lcd.drawRect(tetromino_pos.x, tetromino_pos.y, 4, 4, FILL_BLACK);
+
         _tetromino.init(_px, _py); // break to loop back or keep this ??
-        
+
         printf("blocks stacked!\n");
-        }
-        printf("tetromino collision\n");
+    }
+    printf("tetromino collision\n");
 }
 
-void TetrisGame::cancel_line(N5110 &lcd) 
+void TetrisGame::cancel_line(N5110 &lcd)
 {
-        int count;
+    int count;
     for(int j=0; j<=46; j+=1) {
-    for(int i=0; i<=82; i++) {
-        if (lcd.getPixel(i,j)==0) {
-            count=0;
-            break;
-        } else if (lcd.getPixel(i,j)==1){
-            count ++;
-              }
+        for(int i=0; i<=82; i++) {
+            if (lcd.getPixel(i,j)==0) {
+                count=0;
+                break;
+            } else if (lcd.getPixel(i,j)==1) {
+                count ++;
             }
+        }
         if(count==83) {
             count = 0;
             lcd.drawLine(0,j,82,j,0); // clear line
             printf("line canceled!\n");
- //           score++;
+//           score++;
             for(int x=0; x<=82; x++) {
                 for(int y=j; y>=0; y--) {
                     lcd.setPixel(x,y,false);
                     lcd.setPixel(x,y+1);
                     printf("line dropped!\n");
-                    }
                 }
             }
         }
+    }
     printf("cancel line\n");
 
-} 
+}
 
-void TetrisGame::exit_game(N5110 &lcd) {
-     lcd.clear();
-     lcd.printString(" GAME OVER ",0, 3);
-     lcd.refresh();
-     wait(10);
-     printf("game over!\n");
-     lcd.clear();
-     lcd.printString(" press RESET ",0,6);
-     lcd.refresh();
-     printf("press reset!\n");
-     exit(1.0);
-}  
+void TetrisGame::exit_game(N5110 &lcd)
+{
+    lcd.clear();
+    lcd.printString(" GAME OVER ",0, 3);
+    lcd.refresh();
+    wait(10);
+    printf("game over!\n");
+    lcd.clear();
+    lcd.printString(" press RESET ",0,6);
+    lcd.refresh();
+    printf("press reset!\n");
+    exit(1.0);
+}
+
+void TetrisGame::fallenblocks(N5110 &lcd, int iH)
+{
+    for (int i=0; i<=iH; i++) {
+        x0 = X[i];
+        y0 = Y[i];
+        lcd.drawRect(x0, y0, x0 + 4, y0 + 4, FILL_BLACK);
+        printf("block drawn\n");
+    }
+}