ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Revision:
5:8814d6de77d0
Parent:
4:8ec314f806ae
Child:
6:848d1e4c1a31
diff -r 8ec314f806ae -r 8814d6de77d0 Engine/Engine.cpp
--- a/Engine/Engine.cpp	Thu Apr 11 14:44:14 2019 +0000
+++ b/Engine/Engine.cpp	Sat Apr 13 17:37:52 2019 +0000
@@ -6,44 +6,40 @@
 }
 
 void Engine::init(int floors_width, int floors_height, int doodler_radius){
+    _floors_width = floors_width;    
     _floors_height = floors_height;
-    _floors_width = floors_width;
     _doodler_radius = doodler_radius;
     
-// initial position of doodler:
-    _doodx = 70/2; // middle
-    _doody = 45; //bottom
+    _dood.init(_doodler_radius);
     
-    _dood.init(_doodx, _doody, _doodler_radius);
-    
-// screen WIDTH =84 (but floors only reach 69): 0 left, 69 right
+// screen WIDTH =84 (but floors only visible to 70): 0 left, 70 right
 // FLOORS_WIDTH = 10
 // x- coordinate of floors position is fixed
     srand(time(0)); // initializes random number generator
     _f1x = rand()%6; // random floors position between 0 and 5
-    _f2x = 7 +(rand()%6); 
-    _f3x = 14 +(rand()%6);
-    _f4x = 21 +(rand()%6);
-    _f5x = 28 +(rand()%6);
-    _f6x = 35 +(rand()%6);
-    _f7x = 42 +(rand()%6);
-    _f8x = 49 +(rand()%6);
-    _f9x = 56 +(rand()%6); 
-    _f10x = 63 +(rand()%6);
+    _f2x = 8 +(rand()%6); 
+    _f3x = 16 +(rand()%6);
+    _f4x = 24 +(rand()%6);
+    _f5x = 32 +(rand()%6);
+    _f6x = 40 +(rand()%6);
+    _f7x = 48 +(rand()%6);
+    _f8x = 56 +(rand()%6);
+    _f9x = 64 +(rand()%6); 
+    _f10x = 70/2; // one floor always at the middle bottom initially
 
-// screen HEIGHT = 48 (but visible up to 46) 0 up, 46 down
+// screen HEIGHT = 48 (0 up & 48 down)
 // FLOORS_HEIGHT = 2
 // y -coordinate for each floor position (depends on doodler)
     _f1y = rand()%46; // random floors position between 0 and 45
     _f2y = rand()%46; 
     _f3y = rand()%46;
-    _f4y = rand()%46;
+    _f4y = 10+(rand()%36);
     _f5y = rand()%46;
     _f6y = rand()%46;
     _f7y = rand()%46;
     _f8y = rand()%46;
     _f9y = rand()%46;
-    _f10y = rand()%46;
+    _f10y = 46; // one floor always at the middle bottom initially
     
     _f1.init(_f1x, _f1y, _floors_width, _floors_height);
     _f2.init(_f2x, _f2y, _floors_width, _floors_height);
@@ -54,7 +50,12 @@
     _f7.init(_f7x, _f7y, _floors_width, _floors_height);
     _f8.init(_f8x, _f8y, _floors_width, _floors_height);
     _f9.init(_f9x, _f9y, _floors_width, _floors_height);
-    _f10.init(_f10x, _f10y, _floors_width, _floors_height);
+    _f10.init(_f10x, _f10y, _floors_width, _floors_height); 
+}
+
+void Engine::read_input(Gamepad &pad){
+    _d = pad.get_direction();
+    _mag = pad.get_mag();
 }
 
 void Engine::draw(N5110 &lcd){
@@ -70,4 +71,19 @@
     _f9.draw(lcd);
     _f10.draw(lcd);
     
-}
\ No newline at end of file
+}
+
+void Engine::update(Gamepad &pad){
+    _dood.update(_d, _mag);
+    _f1.update();
+    _f2.update();
+    _f3.update();
+    _f4.update();
+    _f5.update();
+    _f6.update();
+    _f7.update();
+    _f8.update();
+    _f9.update();
+    _f10.update();
+    
+}