![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test 1 doc
Diff: Engine/Engine.cpp
- Revision:
- 12:eb8d30593e95
- Parent:
- 11:b3024ab59fa5
- Child:
- 13:cb5ed2f0cbd5
diff -r b3024ab59fa5 -r eb8d30593e95 Engine/Engine.cpp --- a/Engine/Engine.cpp Wed May 27 03:52:11 2020 +0000 +++ b/Engine/Engine.cpp Wed May 27 04:22:47 2020 +0000 @@ -43,15 +43,18 @@ enemies.push_back(Enemy(0,75, 20)); enemies.push_back(Enemy(1,20, 0)); enemies.push_back(Enemy(1,60, 30)); - ko = 0; + ko1 = 0; + ko2 = 0; //physics parameters _Ypos = 0; _fall = true; _c = false; - //rands srand(time(NULL)); + + //coins + coin.init(); } @@ -86,6 +89,10 @@ for(int i = 0; i < enemies.size(); i ++) { enemies.at(i).draw(lcd); } + + //coin + coin.draw(lcd); + } @@ -96,8 +103,9 @@ //updates enemy file void Engine::update(Gamepad &pad) { + fellDown(); floorCollide(); - enemyCollide(); + //enemyCollide(); //spawnEnemy(); _p.update(_d,_mag, _Ypos, _fall, _jump); @@ -129,7 +137,7 @@ int a; Vector4 coords[mapSize]; - Vector2D player = _p.get_pos(); + player = _p.get_pos(); //coordinates of platforms for(int i = 0; i < mapSize; i++) { coords[i] = maps[i].get_pos(); @@ -155,17 +163,12 @@ } -////////////////////// SPAWN ENEMY ///////////////////////////////////// -void Engine::spawnEnemy() -{ - -} ////////////////////// 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()); @@ -173,24 +176,49 @@ } 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; + ko1 = 1; //printf("KO\n"); } } - return ko; + return ko1; +} + +///////////////////// FELL DOWN ///////////////////////////////////////////// +bool Engine::fellDown() +{ + if(player.y > HEIGHT - 2) { + ko2 = 1; + } else { + ko2 = 0; + } + return ko2; } + +/////////////////////// KO /////////////////////////////////////////////////// +bool Engine::koed() +{ + + if( ko1 == 1 || ko2 == 1) { + return true; + } else { + return false; + } +} + + ////////////////////// 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"); - } +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, false); + _p.draw(lcd); + //printf("KO RUN\n"); +}