Added restart and level feature

This commit is contained in:
Simponic 2020-07-01 21:29:11 -06:00
parent a57e318e31
commit f3306ade87
5 changed files with 35 additions and 46 deletions

21
LICENSE
View File

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2020 Logan Hunt
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,14 +0,0 @@
# Asteroids-CPP
The game asteroids in c++ using the simplified drawing library provided by my school.
## Requirements
* libglut-dev
* g++
* make
## Running
All that is needed to run is a simple ```make```, and then run the game with ```./a.out```
[![2020-06-30-20-24-32-1.gif](https://i.postimg.cc/k4ZNhdKw/2020-06-30-20-24-32-1.gif)](https://postimg.cc/zbCRV6dR)

Binary file not shown.

View File

@ -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++;
}
}
}

View File

@ -26,6 +26,7 @@ private:
vector<Rock *> rocks;
vector<Bullet *> bullets;
Ship* ship;
int level = 0;
float getClosestDistance( const FlyingObject &obj1 , const FlyingObject &obj2 ) const;