![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
test 1 doc
Diff: Engine/Engine.cpp
- Revision:
- 9:9830d3a78572
- Parent:
- 8:d19b30a6cd69
- Child:
- 10:9317a62bd4d0
diff -r d19b30a6cd69 -r 9830d3a78572 Engine/Engine.cpp --- a/Engine/Engine.cpp Tue May 26 22:15:42 2020 +0000 +++ b/Engine/Engine.cpp Wed May 27 00:49:39 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, 20, 3), Platform(64, 40, 20, 3), Platform(5, 30, 30, 3), Platform(50, 30, 30, 3)}; +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)}; int mapSize = sizeof(maps)/sizeof(*maps); vector <Enemy> enemies; @@ -49,6 +49,8 @@ _fall = true; _c = false; + //rands + srand(time(NULL)); } @@ -101,7 +103,7 @@ _p.update(_d,_mag, _Ypos, _fall, _jump); for(int i = 0; i < enemies.size(); i ++) { - enemies.at(i).update(_eYpos, _efall); + enemies.at(i).update(_eYpos.at(i), _efall.at(i)); //printf("Enemy %i!\n", i); } @@ -155,11 +157,30 @@ ////////////////////// SPAWN ENEMY ///////////////////////////////////// void Engine::spawnEnemy() { + + for(int i = 0; i < enemies.size(); i ++) { //printf("%s", enemies.at(i).fell() ? "true\n" : "false\n"); if ( enemies.at(i).fell() == true ) { - enemies.erase(enemies.begin() + i); - enemies.push_back(Enemy(1,1)); + int f = rand()%2; + if ( f == 0) { + place =1; + } else if ( f ==1) { + place = 0; + } + printf("%s\n", f ? "true" : "false"); + //enemies.erase(enemies.begin() + i); + switch(place) { + case 1: + enemies.at(i).set_pos(0,0); + //enemies.push_back(Enemy(0,0)); + break; + case 0: + enemies.at(i).set_pos(0,75); + //enemies.push_back(Enemy(0,75)); + break; + } + } } @@ -179,12 +200,15 @@ for(int i = 0; i <enemies.size(); i++) { epos.push_back(enemies.at(i).get_pos()); + _eYpos.push_back(1); + _efall.push_back(true); + //printf("pos of %i: %f, %f\n", i, epos.at(i).x, epos.at(i).y); } - +/* if(_e == false) { - _efall = true; + //_efall = true; for(int i=0; i<mapSize; i++) { for(int j=0; j < epos.size(); j++) { if(epos.at(j).x >= coord[i].x && epos.at(j).x+1 <= coord[i].x + coord[i].width && epos.at(j).y+6 >= coord[i].y && epos.at(j).y+6 <= coord[i].y + coord[i].height) { @@ -197,11 +221,23 @@ } if(_e == true) { - _eYpos = coord[b].y - 8; - _efall = false; + _eYpos.at(i) = coord[b].y - 8; + _efall.at(i) = false; _e = false; //printf("enemy fall"); } +*/ + for(int i=0; i < mapSize; i++){ + for(int j=0; j< epos.size(); j++){ + if(epos.at(j).x >= coord[i].x && epos.at(j).x+1 <= coord[i].x + coord[i].width && epos.at(j).y+6 >= coord[i].y && epos.at(j).y+6 <= coord[i].y + coord[i].height){ + _eYpos.at(i) = coord[i].y - 8; + _efall.at(i) = false; + } + else{ + _efall.at(i) = true; + } + } + } }