test 1 doc

Dependencies:   mbed Gamepad2

Revision:
11:b3024ab59fa5
Parent:
10:9317a62bd4d0
Child:
12:eb8d30593e95
diff -r 9317a62bd4d0 -r b3024ab59fa5 Engine/Engine.cpp
--- a/Engine/Engine.cpp	Wed May 27 02:00:08 2020 +0000
+++ b/Engine/Engine.cpp	Wed May 27 03:52:11 2020 +0000
@@ -1,6 +1,6 @@
 #include "Engine.h"
 
-Platform maps[6] = {Platform(0, 40, 20, 3), Platform(0, 14, 20, 3), Platform(64, 14, 10, 3), Platform(70, 40, 20, 3), Platform(5, 20, 30, 3), Platform(55, 30, 25, 3)};
+Platform maps[7] = {Platform(0, 10, 20, 3), Platform(70, 14, 14, 3), Platform(40, 25, 30, 3), Platform(65, 44, 15, 3), Platform(5, 35, 20, 3), Platform(25, 17, 5, 3),Platform(40, 40, 10, 3)};
 int mapSize = sizeof(maps)/sizeof(*maps);
 
 
@@ -43,7 +43,7 @@
     enemies.push_back(Enemy(0,75, 20));
     enemies.push_back(Enemy(1,20, 0));
     enemies.push_back(Enemy(1,60, 30));
-
+    ko = 0;
 
     //physics parameters
     _Ypos = 0;
@@ -86,8 +86,6 @@
     for(int i = 0; i < enemies.size(); i ++) {
         enemies.at(i).draw(lcd);
     }
-
-
 }
 
 
@@ -99,11 +97,12 @@
 void Engine::update(Gamepad &pad)
 {
     floorCollide();
+    enemyCollide();
     //spawnEnemy();
     _p.update(_d,_mag, _Ypos, _fall, _jump);
 
     for(int i = 0; i < enemies.size(); i ++) {
-        enemies.at(i).update(2,2);
+        enemies.at(i).update(2);
     }
 
 }
@@ -162,5 +161,36 @@
 
 }
 
+////////////////////// ENNEMY COLLIDE ///////////////////////////////////
+bool Engine::enemyCollide()
+{
+    vector <Vector2D> epos;
+    Vector2D player = _p.get_pos();
+
+    for (int i = 0; i < enemies.size(); i++) {
+        epos.push_back(enemies.at(i).get_pos());
+        //printf("coord %i, at %f, %f\n", i, epos.at(i).x, epos.at(i).y);
+    }
+    for (int i=0; i<epos.size(); i++) {
+        if(player.x < epos.at(i).x + 7  && player.y < epos.at(i).y + 5 && player.x+9 > epos.at(i).x && player.y> epos.at(i).y) {
+            ko = 1;
+            //printf("KO\n");
+        }
+    }
+    return ko; 
+}
+
+////////////////////// GAME OVER ///////////////////////////////////////////
+void Engine::gameOver(N5110 &lcd){
+            lcd.inverseMode();
+            wait(0.5);
+            lcd.normalMode();
+            wait(0.5);
+            lcd.inverseMode();
+            wait(0.5);
+            _p.update(_d, 0, _Ypos, true, _jump);
+            _p.draw(lcd);
+            printf("KO RUN\n");
+    }