summaryrefslogtreecommitdiff
path: root/src/game.cpp
diff options
context:
space:
mode:
authorSimponic <loganthebean222@gmail.com>2020-07-01 21:29:11 -0600
committerSimponic <loganthebean222@gmail.com>2020-07-01 21:29:11 -0600
commitf3306ade87229040cbb181770839ba80f188b682 (patch)
tree5d20c58dcb6a2ebd9fe3120307c53aa2beed3022 /src/game.cpp
parenta57e318e314a78ff555b78edbdebd1b8ded44de6 (diff)
downloadasteroids-cs165-f3306ade87229040cbb181770839ba80f188b682.tar.gz
asteroids-cs165-f3306ade87229040cbb181770839ba80f188b682.zip
Added restart and level feature
Diffstat (limited to 'src/game.cpp')
-rw-r--r--src/game.cpp45
1 files changed, 34 insertions, 11 deletions
diff --git a/src/game.cpp b/src/game.cpp
index a2aa491..f7d4054 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -26,7 +26,7 @@ Game :: Game ( const Point &tl , const Point &br ) : topLeft ( tl ) , bottomRigh
vector<Rock *> Game :: createRocks()
{
vector<Rock *> initRocks;
- for ( int i = 0; i < random ( 5 , 8 ); i++ )
+ for ( int i = 0; i < random ( 5 + 2 * this->level , 8 + 2 * this->level ); i++ )
{
Point rockPoint = Point ( random( -190 , 190 ) , random ( -190 , 190 ) );
Velocity velocity;
@@ -136,14 +136,16 @@ void Game :: cleanUpZombies()
bullets.erase( bullets.begin() + i );
}
}
- for ( int i = 0; i < rocks.size(); i++ )
- {
- if ( !rocks[i]->isAlive() )
- {
- delete rocks[i];
- rocks[i] = NULL;
- rocks.erase( rocks.begin() + i );
- }
+ if (rocks.size() > 0) {
+ for ( int i = 0; i < rocks.size(); i++ )
+ {
+ if ( !rocks[i]->isAlive() )
+ {
+ delete rocks[i];
+ rocks[i] = NULL;
+ rocks.erase( rocks.begin() + i );
+ }
+ }
}
}
@@ -209,6 +211,14 @@ void Game :: draw ( const Interface &ui )
drawBullets();
drawNumber ( Point ( -170 , 170 ) , (int) ship->getFuel() );
drawText ( Point ( -170 , 180 ) , "FUEL:" );
+ drawNumber ( Point (-170, 130) , (int) level);
+ drawText ( Point(-170, 140), "LEVEL:");
+ if (!ship->isAlive()) {
+ drawText( Point ( -90 , 0 ) , "Play again? (space to continue)");
+ }
+ if (rocks.size() == 0 && ship->isAlive()) {
+ drawText( Point ( -90 , 0 ) , "Press space to continue to next level ");
+ }
}
// Draw rocks
@@ -241,7 +251,7 @@ void Game :: drawBullets()
// Handle in-game input
void Game::handleInput(const Interface & ui)
{
- if ( ship->isAlive() )
+ if ( ship->isAlive() && rocks.size() > 0 )
{
if ( ui.isUp() )
{
@@ -274,5 +284,18 @@ void Game::handleInput(const Interface & ui)
ship->setThrusting ( false );
}
}
-
+ else if ( !ship->isAlive() && rocks.size() > 0){
+ if ( ui.isSpace() ) {
+ rocks = createRocks();
+ ship = new Ship ( Point() );
+ level = 0;
+ }
+ }
+ else if ( ship->isAlive() && rocks.size() == 0) {
+ if ( ui.isSpace() ) {
+ rocks = createRocks();
+ ship = new Ship ( Point() );
+ level++;
+ }
+ }
}