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:
23:cbfa9d1ee3db
Parent:
22:403759d2f093
Child:
24:8868a01f4a8c
--- a/TetrisGame/TetrisGame.cpp	Wed Jun 03 16:44:09 2020 +0000
+++ b/TetrisGame/TetrisGame.cpp	Wed Jun 03 19:52:59 2020 +0000
@@ -41,13 +41,14 @@
 
     _tetromino.draw(lcd);
 
+    print_scores(lcd);
+
 //    printf("draw (%i,%i)\n",_px,_py);
 
 }
 
 void TetrisGame::update(Gamepad &pad, N5110 &lcd) // update values
 {
-    // check_score(pad);
 
     _tetromino.update(_d,_mag);
 
@@ -81,7 +82,7 @@
             exit_game(lcd); // game over
         }
 
-        printf("floor hit!\n");
+//        printf("floor hit!\n");
 
     }
 //    printf("wall collision\n");
@@ -112,7 +113,7 @@
             exit_game(lcd); // game over
         }
 
-        printf("blocks stacked!\n");
+//        printf("blocks stacked!\n");
     }
 //    printf("tetromino collision\n");
 }
@@ -123,20 +124,21 @@
         for(int i=20; i<=60; i++) {
             if (lcd.getPixel(i,j)==0) { // if the pixel is empty the counting stops and exits loop (row is not full)
                 count=0;
-                printf("line not full\n");
+//                printf("line not full\n");
                 break;
             } else if (lcd.getPixel(i,j)==1) { // if the pixel is full carries on counting
                 count ++;
-                printf("counting... count=%i\n",count);
+//                printf("counting... count=%i\n",count);
             }
             if (count==48) { // if gets to end of line
                 count = 0;
                 printf("line full\n");
 //                lcd.drawRect(20,j,40,4,FILL_WHITE); // clear line
                 c = j;
+                d = i;
                 clear_line_flag = 1;
                 floor_hit_flag = 0;
-                printf("line canceled!\n");
+//                printf("line canceled!\n");
             }
 //           score++;
 //            for(int x=20; x<=60; x++) {
@@ -148,20 +150,20 @@
 //            }
         }
     }
-    printf("cancel line\n");
+//    printf("cancel line\n");
 }
 
 void TetrisGame::exit_game(N5110 &lcd)
 {
     lcd.clear();
-    lcd.printString(" GAME OVER ",0, 3);
+    lcd.printString(" GAME OVER \n",0, 3);
     lcd.refresh();
     wait(10);
-    printf("game over!\n");
+//    printf("game over!\n");
     lcd.clear();
     lcd.printString(" press RESET ",0,6);
     lcd.refresh();
-    printf("press reset!\n");
+//    printf("press reset!\n");
     exit(1.0);
 }
 
@@ -175,10 +177,47 @@
     }
 }
 
-void TetrisGame::clearline(N5110 &lcd, int iP)
+void TetrisGame::currentscreen(N5110 &lcd)
+{
+    for (int i=0; i<=83; i++) {
+        for (int j=0; j<=47; j++) {
+            if(lcd.getPixel(i,j)) { //if pixel is set
+                buffer[i][j] = 1;
+            } else { // pixel is clear
+                buffer[i][j] = 0;
+            }
+        }
+    }
+}
+
+void TetrisGame::clearline(N5110 &lcd, int iB)
 {
     for (int i=0; i<=iB; i++) {
         z0 = Z[i];
+        q0 = Q[i];
         lcd.drawRect(20, z0, 40, 4, FILL_WHITE);
     }
+    currentscreen(lcd);
+    for (int x=20; x<=60; x++) {
+        for (int y=c; y>=0; y--) {
+            if (buffer[x][y]) {
+                lcd.setPixel(x,y, false);
+                lcd.setPixel(x,y+4);
+            }
+        }
+    }
+}
+
+void TetrisGame::print_scores(N5110 &lcd)
+{
+    char buffer[15];
+    sprintf(buffer,"%d",_score);
+    lcd.printString(buffer, WIDTH - 20, 10);
+}
+
+void TetrisGame::check_score(Gamepad &pad)
+{
+    if ( clear_line_flag == 1) {
+        _score+=10;
+    }
 }
\ No newline at end of file