test 1 doc

Dependencies:   mbed Gamepad2

Revision:
14:58887d7e1072
Parent:
13:cb5ed2f0cbd5
diff -r cb5ed2f0cbd5 -r 58887d7e1072 Engine/Engine.cpp
--- a/Engine/Engine.cpp	Wed May 27 04:36:22 2020 +0000
+++ b/Engine/Engine.cpp	Wed May 27 07:48:27 2020 +0000
@@ -31,6 +31,8 @@
 ////////////////////// INIT ////////////////////////////
 void Engine::init()
 {
+    t.start();
+
     //init coord
     _px = WIDTH / 2;
     _py = 5;
@@ -50,11 +52,32 @@
     _Ypos = 0;
     _fall = true;
     _c = false;
-    //rands
-    srand(time(NULL));
 
     //coins
     coin.init();
+        middlesX.push_back(10);
+        middlesX.push_back(77);
+        middlesX.push_back(55);
+        middlesX.push_back(72);
+        middlesX.push_back(16);
+        middlesX.push_back(27);
+        middlesX.push_back(45);
+        //{10, 77, 55, 72, 15, 27, 45};
+        
+        middlesY.push_back(6);
+        middlesY.push_back(10);
+        middlesY.push_back(21);
+        middlesY.push_back(40);
+        middlesY.push_back(30);
+        middlesY.push_back(13);
+        middlesY.push_back(36);
+        
+     //{6, 10, 21, 40, 30, 13, 36};
+
+    //counter
+    counter =0;
+    score = 0;
+
 }
 
 
@@ -77,21 +100,12 @@
 //draw both player and map
 void Engine::draw(N5110 &lcd)
 {
-
-
-    // player
-    _p.draw(lcd);
-
-    // map
-    drawMap(lcd);
-
-    //enemies
-    for(int i = 0; i < enemies.size(); i ++) {
+    _p.draw(lcd);   // player
+    drawMap(lcd);   // map
+    for(int i = 0; i < enemies.size(); i ++) { //enemies
         enemies.at(i).draw(lcd);
     }
-
-    //coin
-    coin.draw(lcd);
+    coin.draw(lcd); //coin
 
 }
 
@@ -103,16 +117,18 @@
 //updates enemy file
 void Engine::update(Gamepad &pad)
 {
-    //fellDown();
-    coinTaken();
+    f = rand()%7+1;
+    fellDown();
+    coinTaken(pad);
+    coin.show(pad);
     floorCollide();
-    //enemyCollide();
-    //spawnEnemy();
+    enemyCollide();
     _p.update(_d,_mag, _Ypos, _fall, _jump);
 
     for(int i = 0; i < enemies.size(); i ++) {
         enemies.at(i).update(2);
     }
+    score =  getScore();
 
 }
 
@@ -131,11 +147,14 @@
 }
 */
 
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+                        //COLLISIONS//
+
 
 ////////////////////// FLOOR COLLISION //////////////////////////
 void Engine::floorCollide()
 {
-
     int a;
     Vector4 coords[mapSize];
     player = _p.get_pos();
@@ -164,22 +183,45 @@
 }
 
 
+//////////////////////get score /////////////////////////
+int Engine::getScore(){
+        return counter;
+    }
+    
+
+
 ////////////////////// GOT COIN /////////////////////////////////////////
-void Engine::coinTaken(){
-        coinPos = coin.get_pos();
-        if(player.x+4 >= coinPos.x-2 & player.y+4 >= coinPos.y-2 & player.x+4 <= coinPos.x+2 & player.y+4 <= coinPos.x+2){
-                coin.set_pos(10, 10);
-            }
+void Engine::coinTaken(Gamepad &pad)
+{
+
+    //rands
+    //srand((unsigned) time(NULL));
+
+    coinPos = coin.get_pos();
+    if(player.x+4 >= coinPos.x-2 & player.y+4 >= coinPos.y-2 & player.x+4 <= coinPos.x+2 & player.y+4 <= coinPos.x+2 || pad.A_pressed()) {
+        //printf("%i, %i\n",x[f], y[f]);
+        coin.set_pos(middlesX.at(f), middlesY.at(f));
+        //printf("TAKEN\n");
+        //printf("%i\n", f);
+        pad.tone(600, 0.15);
+        counter++;
     }
+}
 
 
 
+
+
+
+///////////////////////////////////////////////////////////////////////////
+///////////////////////////////////////////////////////////////////////////
+                        //DEATHS//
+
+
 ////////////////////// ENNEMY COLLIDE ///////////////////////////////////
 bool Engine::enemyCollide()
 {
     vector <Vector2D> epos;
-
-
     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);
@@ -208,7 +250,6 @@
 /////////////////////// KO ///////////////////////////////////////////////////
 bool Engine::koed()
 {
-    
     if( ko1 == 1 || ko2 == 1) {
         return true;
     } else {
@@ -226,8 +267,6 @@
     wait(0.5);
     lcd.inverseMode();
     wait(0.5);
-    _p.update(_d, 0, _Ypos, true, false);
-    _p.draw(lcd);
     //printf("KO RUN\n");
 }