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:
19:2ad31dbd5d11
Parent:
18:a089d9d184b1
Child:
20:ad685b35a1a4
--- a/TetrisGame/TetrisGame.cpp	Wed Jun 03 10:32:48 2020 +0000
+++ b/TetrisGame/TetrisGame.cpp	Wed Jun 03 12:14:47 2020 +0000
@@ -19,7 +19,7 @@
     _py = 4;
     _speed = speed;
 
-    _tetromino.init(_px, _py); // puts tetromino in middle SHOULD THIS INCLUDE ARRAY????
+    _tetromino.init(_px, _py); // puts tetromino in middle
 
     printf("initiate(%i)\n",_speed);
 
@@ -36,12 +36,17 @@
 {
     // draw elements in lcd buffer
 
-    // board
-    lcd.drawRect(0,0,WIDTH,HEIGHT,FILL_TRANSPARENT);
+//    lcd.drawRect(0,0,WIDTH - 2,HEIGHT,FILL_TRANSPARENT);
+
+    lcd.drawRect(19, 4, 42, HEIGHT - 4, FILL_TRANSPARENT);
+
+//    lcd.drawLine(19, HEIGHT, 61, HEIGHT, 0);
+//    lcd.drawLine(4, 19, HEIGHT, 19, 0);
+//    lcd.drawLine(4, 61, HEIGHT, 61, 0);
 
     _tetromino.draw(lcd);
 
-    printf("draw (%i,%i)\n",_px,_py);
+//    printf("draw (%i,%i)\n",_px,_py);
 
 }
 
@@ -54,7 +59,7 @@
     check_wall_collision(pad, lcd);
     check_tetromino_collisions(pad, lcd);
 
-    printf("update (%i,%i,%i)\n",_px,_py,_d);
+//    printf("update (%i,%i,%i)\n",_px,_py,_d);
 }
 
 
@@ -77,7 +82,7 @@
         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;
 
@@ -88,7 +93,7 @@
     }
     // check if hit roof
     else if (tetromino_pos.y <= 1) {
-        
+
         floor_hit_flag = 0;
 
         printf("roof hit!\n");
@@ -97,7 +102,7 @@
 
     }
 
-    printf("wall collision\n");
+//    printf("wall collision\n");
 
     // SAVE OLD SCREEN AND DROP NEW TETROMINO???? //
 // update tetromino parameters??
@@ -122,22 +127,22 @@
 //        lcd.drawRect(tetromino_pos.x, tetromino_pos.y, 4, 4, FILL_BLACK);
 
         _tetromino.init(_px, _py); // break to loop back or keep this ??
-        
+
         a = tetromino_pos.x;
         b = tetromino_pos.y;
 
         floor_hit_flag = 1;
 
         printf("blocks stacked!\n");
-    } 
-    printf("tetromino collision\n");
+    }
+//    printf("tetromino collision\n");
 }
 
 void TetrisGame::cancel_line(N5110 &lcd)
 {
     int count;
-    for(int j=0; j<=46; j+=1) {
-        for(int i=0; i<=82; i++) {
+    for(int j=4; j<=42; j+=1) {
+        for(int i=19; i<=40; i++) {
             if (lcd.getPixel(i,j)==0) { // if the pixel is empty the counting stops and exits loop
                 count=0;
                 break;
@@ -145,21 +150,21 @@
                 count ++;
             }
         }
-        if(count==83) { // if gets to end of line 
+        if(count==41) { // if gets to end of line
             count = 0;
-            lcd.drawLine(0,j,82,j,0); // clear line
+            lcd.drawLine(19,j,40,j,0); // clear line
             printf("line canceled!\n");
 //           score++;
-            for(int x=0; x<=82; x++) {
+            for(int x=19; x<=40; x++) {
                 for(int y=j; y>=0; y--) {
-                    lcd.setPixel(x,y,false); 
-                    lcd.setPixel(x,y+1); // sets pixel to the one above 
+                    lcd.setPixel(x,y,false);
+                    lcd.setPixel(x,y+1); // sets pixel to the one above
                     printf("line dropped!\n");
                 }
             }
         }
     }
-    printf("cancel line\n");
+//    printf("cancel line\n");
 
 }
 
@@ -183,6 +188,6 @@
         x0 = X[i];
         y0 = Y[i];
         lcd.drawRect(x0, y0, 4, 4, FILL_BLACK);
-        printf("block drawn\n");
+//        printf("block drawn\n");
     }
 }
\ No newline at end of file