ELEC2645 (2019/20)
/
ELEC2645_Project_el18jb
test 1 doc
Diff: Engine/Engine.cpp
- Revision:
- 10:9317a62bd4d0
- Parent:
- 9:9830d3a78572
- Child:
- 11:b3024ab59fa5
diff -r 9830d3a78572 -r 9317a62bd4d0 Engine/Engine.cpp --- a/Engine/Engine.cpp Wed May 27 00:49:39 2020 +0000 +++ b/Engine/Engine.cpp Wed May 27 02:00:08 2020 +0000 @@ -2,7 +2,6 @@ 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; ////////////////////// DRAW MAP ////////////////////////// @@ -40,8 +39,10 @@ _p.init(_px, _py); //ennemy - enemies.push_back(Enemy(0, 0)); - enemies.push_back(Enemy(75, 0)); + enemies.push_back(Enemy(0,0, 10)); + enemies.push_back(Enemy(0,75, 20)); + enemies.push_back(Enemy(1,20, 0)); + enemies.push_back(Enemy(1,60, 30)); //physics parameters @@ -94,33 +95,34 @@ ////////////////////// UPDATE ////////////////////////// //provide the player file with necessary Joystick values +//updates enemy file void Engine::update(Gamepad &pad) { floorCollide(); - efloorCollide(); - spawnEnemy(); - + //spawnEnemy(); _p.update(_d,_mag, _Ypos, _fall, _jump); for(int i = 0; i < enemies.size(); i ++) { - enemies.at(i).update(_eYpos.at(i), _efall.at(i)); - //printf("Enemy %i!\n", i); + enemies.at(i).update(2,2); } - /* - if (_c == true) { +} + - //debug - //printf("collison\n"); - } else { +/* + if (_c == true) { - //debug - //printf("no collison\n"); - } - //enemmyCollide(pad); + //debug + //printf("collison\n"); + } else { + + //debug + //printf("no collison\n"); } - */ + //enemmyCollide(pad); } +*/ + ////////////////////// FLOOR COLLISION ////////////////////////// void Engine::floorCollide() @@ -158,86 +160,7 @@ 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 ) { - 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; - } - - } - } - } -////////////////////// ENNEMY FLOOR COLLISION ////////////////////////// -void Engine::efloorCollide() -{ - vector <Vector2D> epos; - Vector4 coord[mapSize]; - int b; - //coordinates of platforms - for(int i = 0; i < mapSize; i++) { - coord[i] = maps[i].get_pos(); - } - 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; - 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) { - b = j; - _e = true; - //printf("%f, %f\n", epos.at(j).x,epos.at(j).y ); - } - } - } - } - - if(_e == true) { - _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; - } - } - } - -} -