diff --git a/headers/config.h b/headers/config.h index ce664a1..884a3c7 100644 --- a/headers/config.h +++ b/headers/config.h @@ -19,6 +19,8 @@ public: unsigned torpedo_length; // auto defined from width unsigned player_width; + unsigned alien_speed; + bool loadConfig(); }; diff --git a/headers/game.h b/headers/game.h index 1ad40ec..f6bf4aa 100644 --- a/headers/game.h +++ b/headers/game.h @@ -13,9 +13,11 @@ class Game { private: PixelManager pm; Config conf; - unsigned baseX; - unsigned baseY; + + position basePos; aliensGrid grid; + bool direction = true; + vector missiles; vector torpedos; unsigned playerX; @@ -31,6 +33,7 @@ private: void moveTorpedos(); bool checkMissilesAndPlayer(); bool checkTorpedosAndInvaders(); + bool invadersTouchFloor(); public: // in case someone wants to mess with the code, here's a minimal API, costs nothing to us Game(); diff --git a/src/game_basics.cpp b/src/game_basics.cpp index e9f7c8c..dbca7ff 100644 --- a/src/game_basics.cpp +++ b/src/game_basics.cpp @@ -33,6 +33,16 @@ void Game::deathMenuHandler(){ // potential options... } } + +bool Game::invadersTouchFloor(){ + for(aliensLine& line : grid){ + if(basePos.getY()+line.size()*conf.alien_size>=pm.getScreenHeight()){ + return true; + } + } + return false; +} + /** * Plays the game, and returns once the game is finished * @@ -46,7 +56,7 @@ unsigned Game::playGame(){ // returns when game is finished // GAMELOOP while(true){ managePlayer(); - if(manageInvaders())return INVADERS_WINS; + if(manageInvaders() && invadersTouchFloor())return INVADERS_WINS; unsigned res = manageAllCollisions(); // also advances missiles + torpedos if(res!=0)return res; display(); @@ -60,8 +70,8 @@ void Game::display() { for (unsigned i = 0; i < this->grid.size(); ++i){ for (unsigned j = 0; j < this->grid[0].size(); ++j){ pm.dessinerInvader1(nsGraphics::Vec2D( - baseX+j*conf.alien_size+j*conf.distance, - baseY+i*conf.alien_size+i*conf.distance + basePos.getX()+j*conf.alien_size+j*conf.distance, + basePos.getY()+i*conf.alien_size+i*conf.distance )); } } diff --git a/src/game_managers.cpp b/src/game_managers.cpp index 84d7f5a..83f3b1a 100644 --- a/src/game_managers.cpp +++ b/src/game_managers.cpp @@ -11,9 +11,32 @@ void Game::managePlayer(){ /** Makes the invaders play once, and check lower bounds * - * @return true if the invaders crossed the first line of the grid, else false + * @return true if the invaders went down from one line (and we should check boundaries), else false */ bool Game::manageInvaders(){ + if(direction){ // go to the right + int end = basePos.getX(); // start position + end+= grid.size()*conf.alien_size; // add the aliens + end+= (grid.size()-1)*conf.distance; // add the distance between aliens + + // you got the end ! + + if(end+conf.alien_speed=0){ + basePos.setX(basePos.getX()-conf.alien_speed); + }else{ + basePos.setY(basePos.getY()-conf.alien_size); + direction = !direction; + return true; + } + } return false; } diff --git a/src/pixelManager.cpp b/src/pixelManager.cpp index 73906ca..86df221 100644 --- a/src/pixelManager.cpp +++ b/src/pixelManager.cpp @@ -45,4 +45,8 @@ unsigned PixelManager::showDeathMenu() { unsigned PixelManager::getScreenHeight() { return 0; +} + +unsigned PixelManager::getScreenWidth() { + return 0; } \ No newline at end of file