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:
15:68114eae4053
Parent:
14:bd8c59a4b641
Child:
16:fca1bbb06c44
diff -r bd8c59a4b641 -r 68114eae4053 main.cpp
--- a/main.cpp	Tue Jun 02 18:38:09 2020 +0000
+++ b/main.cpp	Tue Jun 02 21:07:17 2020 +0000
@@ -16,7 +16,7 @@
 #include "N5110.h"
 #include "TetrisGame.h"
 
-// set defaults 
+// set defaults
 #define TETROMINO_WIDTH 4
 #define TETROMINO_HEIGHT 4
 // #define TETROMINO_SIZE 4
@@ -29,6 +29,14 @@
     Direction d;
     float mag;
 };
+// variables //
+
+volatile extern int iH;
+//volatile extern int floor_hit_flag;
+//volatile extern int X[50];
+//volatile extern int Y[50];
+//volatile extern int a;
+//volatile extern int b;
 
 // OBJECTS //
 
@@ -36,73 +44,86 @@
 Gamepad pad;
 TetrisGame tetris;
 
-// VARIABLES //
-
-volatile extern int iH;
-volatile extern int floor_hit_flag;
-volatile extern int a;
-volatile extern int b;
-
-// PROTOTYPES //
+// PROTOTBPES //
 
 void init();
 void update_game(UserInput input);
 void render();
 void welcome();
-int score = 0;
+void fallenblocks(N5110 &lcd, int iH);
+void set_values();
 
-// int ScreenHeight = 84;
-// int ScreenWidth = 48;
-
-// FUNCTIONS // 
+// FUNCTIONS //
 
 int main()
 {
-    int fps = 6; // 6 frames per second 
-    
+    int fps = 6; // 6 frames per second
+
     init(); // initialise and display welcome screen
     welcome(); // wait for user to press start
+
+    render(); // draw initial frame
+    wait(1.0f/fps); // wait one frame period
     
-    render(); // draw initial frame 
-    wait(1.0f/fps); // wait one frame period 
-    
+    set_values();
+
 // game loop
     while(1) {
-        tetris.read_input(pad); // read input 
+        tetris.read_input(pad); // read input
         tetris.update(pad, lcd);
-        tetris.draw(lcd); // re-draw 
-        lcd.refresh(); // refresh screen
-        wait(1.0f/fps); // wait one frame period 
-        
-}
+        lcd.refresh();
+        lcd.clear();
+        tetris.fallenblocks(lcd, iH);
+        tetris.draw(lcd); // re-draw
+        if (tetris.floor_hit_flag==1) {
+            tetris.fallenblocks(lcd, iH);
+            iH++;
+            tetris.X[iH] = tetris.a;
+            tetris.Y[iH] = tetris.b;
+            tetris.floor_hit_flag = 0;
+            printf("iH increased\n");
+        }
+        wait(1.0f/fps); // wait one frame period
+    }
 }
 
 
 // initialise classes and libraries
-void init() {
-    lcd.init(); // initialise lcd 
+void init()
+{
+    lcd.init(); // initialise lcd
     pad.init(); // initialise Gamepad
-    
+
     // initialise the game with correct tetromino sizes etc
     tetris.init(SPEED);
-    
+
 }
 
-void render() { // draws each frame on the lcd 
+void set_values()
+{
+    for(int i=0; i<=50; i++) {
+    tetris.X[i]=0;
+    tetris.Y[i]=0;
+}
+}
+
+void render()   // draws each frame on the lcd
+{
 
     lcd.clear(); // clear screen
-    tetris.draw(lcd); // re-draw 
+    tetris.draw(lcd); // re-draw
     lcd.refresh(); // refresh screen
-    
+
 }
 
 // welcome screen display
-void welcome() {
-    
+void welcome()
+{
+
     lcd.printString("    TETRIS      ",0,1);
     lcd.printString("  Press Start   ",0,4);
     lcd.refresh();
-    
+
     // flash LEDs untile start button pressed
     while (pad.start_pressed() == false) {
         lcd.setContrast(pad.read_pot1());