ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18rs

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
el18rs
Date:
Mon Jun 01 17:33:16 2020 +0000
Parent:
8:cebb2aca8e19
Child:
10:7310c9440547
Commit message:
el18rs 201259470;

Changed in this revision

TetrisGame/TetrisGame.cpp Show annotated file Show diff for this revision Revisions of this file
TetrisGame/TetrisGame.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/TetrisGame/TetrisGame.cpp	Mon Jun 01 16:39:13 2020 +0000
+++ b/TetrisGame/TetrisGame.cpp	Mon Jun 01 17:33:16 2020 +0000
@@ -10,16 +10,16 @@
     
 }
 
-void TetrisGame::init(int height, int width)
+void TetrisGame::init(int tetromino_height, int tetromino_width, int speed)
 {
     // initialise game parameters
-    _height = height;
-    _width = width;
-//    _x = WIDTH/2 - _width/2;
-//    _y = HEIGHT;
-//    _speed = speed;
+    _tetromino_height = tetromino_height;
+    _tetromino_width = tetromino_width;
+    _px = WIDTH/2 - _tetromino_width/2;
+    _py = HEIGHT;
+    _speed = speed;
     
-    _tetromino.init(_height, _width); // puts tetromino in middle SHOULD THIS INCLUDE ARRAY????
+    _tetromino.init(_tetromino_height, _tetromino_width); // puts tetromino in middle SHOULD THIS INCLUDE ARRAY????
     
 }
 
@@ -60,9 +60,9 @@
     Vector2D tetromino_velocity = _tetromino.get_velocity();
     
     // check if hit floor
-    if (tetromino_pos.y + 4 >= (HEIGHT-1) ) {
+    if (tetromino_pos.y + _tetromino_height >= (HEIGHT-1) ) {
         
-        tetromino_pos.y = (HEIGHT-1) - 4;
+        tetromino_pos.y = (HEIGHT-1) - _tetromino_height;
         tetromino_velocity.y = 0;
         
         pad.tone(750.0,0.1);
@@ -103,7 +103,7 @@
         
         lcd.drawRect(tetromino_pos.x, tetromino_pos.y, 4, 4, FILL_BLACK);
             
-        _tetromino.init(4, 4); // break to loop back or keep this ??
+        _tetromino.init(_tetromino_width, _tetromino_height); // break to loop back or keep this ??
         }
 }
 
--- a/TetrisGame/TetrisGame.h	Mon Jun 01 16:39:13 2020 +0000
+++ b/TetrisGame/TetrisGame.h	Mon Jun 01 17:33:16 2020 +0000
@@ -13,7 +13,7 @@
     TetrisGame();
     ~TetrisGame();
     
-    void init(int height, int width);
+    void init(int tetromino_height, int tetromino_width, int speed);
     void read_input(Gamepad &pad);
     void update(Gamepad &pad, N5110 &lcd);
     void draw(N5110 &lcd);
@@ -31,10 +31,10 @@
     // Tetromino _p1;
     
 
-    int _x;
-    int _y;
-    int _height;
-    int _width;
+    int _px;
+    int _py;
+    int _tetromino_height;
+    int _tetromino_width;
     int _speed;
     
     Tetromino _tetromino;
--- a/main.cpp	Mon Jun 01 16:39:13 2020 +0000
+++ b/main.cpp	Mon Jun 01 17:33:16 2020 +0000
@@ -78,7 +78,7 @@
     pad.init(); // initialise Gamepad
     
     // initialise the game with correct tetromino sizes etc
-    tetris.init(4,4);
+    tetris.init(4,4,1);
     
 }