ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Revision:
4:8ec314f806ae
Parent:
3:116913e97fd7
Child:
5:8814d6de77d0
diff -r 116913e97fd7 -r 8ec314f806ae Engine/Engine.cpp
--- a/Engine/Engine.cpp	Wed Apr 10 19:07:41 2019 +0000
+++ b/Engine/Engine.cpp	Thu Apr 11 14:44:14 2019 +0000
@@ -5,35 +5,45 @@
 Engine::~Engine(){
 }
 
-void Engine::init(int floors_width, int floors_height){
+void Engine::init(int floors_width, int floors_height, int doodler_radius){
     _floors_height = floors_height;
     _floors_width = floors_width;
-
-// screen WIDTH =84 and FLOORS_WIDTH = 10
+    _doodler_radius = doodler_radius;
+    
+// initial position of doodler:
+    _doodx = 70/2; // middle
+    _doody = 45; //bottom
+    
+    _dood.init(_doodx, _doody, _doodler_radius);
+    
+// screen WIDTH =84 (but floors only reach 69): 0 left, 69 right
+// FLOORS_WIDTH = 10
 // x- coordinate of floors position is fixed
-    _f1x = rand() % 9 + 2; // random floors position between 2 and 9
-    _f2x = rand() % 17 + 10; // random position between 10 and 17...
-    _f3x = rand() % 25 + 18;
-    _f4x = rand() % 33 + 26;
-    _f5x = rand() % 41 + 34;
-    _f6x = rand() % 49 + 42;
-    _f7x = rand() % 57 + 50;
-    _f8x = rand() % 65 + 58;
-    _f9x = rand() % 73 + 66;
-    _f10x = rand() % 81 + 74;
+    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);
 
-// screen HEIGHT = 48 and FLOORS_HEIGHT = 2
+// screen HEIGHT = 48 (but visible up to 46) 0 up, 46 down
+// FLOORS_HEIGHT = 2
 // y -coordinate for each floor position (depends on doodler)
-    _f1y = rand() % 24 + 2; // random floors position between 24 and 2
-    _f2y = rand() % 46 + 25; // random between 46 and 25
-    _f3y = rand() % 24 + 2;// random between 24 and 2
-    _f4y = rand() % 46 + 25;// random between 46 and 25
-    _f5y = rand() % 24 + 2;// random between 24 and 2
-    _f6y = rand() % 46 + 25;// random between 46 and 25
-    _f7y = rand() % 24 + 2;// random between 24 and 2
-    _f8y = rand() % 46 + 25;// random between 46 and 25
-    _f9y = rand() % 24 + 2;// random between 24 and 2
-    _f10y = rand() % 46 + 25;// random between 46 and 25
+    _f1y = rand()%46; // random floors position between 0 and 45
+    _f2y = rand()%46; 
+    _f3y = rand()%46;
+    _f4y = rand()%46;
+    _f5y = rand()%46;
+    _f6y = rand()%46;
+    _f7y = rand()%46;
+    _f8y = rand()%46;
+    _f9y = rand()%46;
+    _f10y = rand()%46;
     
     _f1.init(_f1x, _f1y, _floors_width, _floors_height);
     _f2.init(_f2x, _f2y, _floors_width, _floors_height);
@@ -48,6 +58,7 @@
 }
 
 void Engine::draw(N5110 &lcd){
+    _dood.draw(lcd);
     _f1.draw(lcd);
     _f2.draw(lcd);
     _f3.draw(lcd);