Ben Evans University Second Year Project. Game Called Defender.
Hello, soldier, you have been specially selected as the defender of planet earth.
Your mission, if you choose to accept it. Fly around the planet and pulverise invading alien ships for as long as you can. Stop the aliens abducting the innocent people on the ground. Be warned if an alien ship manages to abduct a person and take them to top of the screen, they will no longer move randomly and will begin to hunt you down. This sounds like a challenge you were trained for.
But don’t worry soldier you’re not going into battle empty-handed. Your ship is equipped with a state of the art laser beam that has unlimited ammo and four smart bombs that will destroy anything on the screen. The ship also has three lives so use them wisely.
As time goes on more alien ships will arrive on planet earth increasing the difficulty of your mission. And remember the landscape bellow loops around so if you continually fly in the same direction you go to your original position. Good luck soldier.
Diff: GameEngine/GameEngine.cpp
- Revision:
- 30:814674b189f0
- Parent:
- 29:e96d91f1d39c
- Child:
- 31:6015e8ed859c
--- a/GameEngine/GameEngine.cpp Thu May 14 14:19:24 2020 +0000 +++ b/GameEngine/GameEngine.cpp Thu May 14 17:37:37 2020 +0000 @@ -14,10 +14,13 @@ spaceship.init(); map.init(pad); create_alien(); + spaceship_lives = 3; + spaceship_destroyed = false; + reset_map_counter = 0; } void GameEngine::gameplay_loop() { - // clear screen + // clear screen and set contrast lcd.setContrast(pad.read_pot1()); lcd.clear(); @@ -27,12 +30,22 @@ create_bullet(); // Draws - spaceship.draw(lcd); + if (!spaceship_destroyed){ + spaceship.draw(lcd); + } map.draw_map(lcd, d_); draw_aliens(); draw_bullets(); draw_explosions(); - + + // Resets map after set frames so spaceship explosion animation showes + if(spaceship_destroyed){ + reset_map_counter++; + if(reset_map_counter == 50){ + reset_map(); + } + } + // refresh's screen lcd.refresh(); } @@ -86,10 +99,13 @@ alien_bullet_vector.erase(alien_bullet_vector.begin()+ i); } - // Deletes bullet and shaceship if collision detected - if (spaceship.check_collision(alien_bullet_vector[i])){ + // Deletes bullet and shpaceship if collision detected + if (spaceship.check_collision(alien_bullet_vector[i]) && + !spaceship_destroyed ){ create_explosion(spaceship.get_pos()); - alien_bullet_vector.erase(alien_bullet_vector.begin()+ i); + + spaceship_destroyed = true; + alien_bullet_vector.erase(alien_bullet_vector.begin()+ i); } } @@ -110,6 +126,13 @@ alien_vector[i].draw_alien(lcd,spaceship.get_pos(),d_, map.get_length_map(), map.get_position_x_map()); + // deleted spaceship if alien ship touches spaceship + if (spaceship.check_alien_collision(alien_vector[i]) && + !spaceship_destroyed){ + create_explosion(spaceship.get_pos()); + spaceship_destroyed = true; + } + // alien sprites fire bullet randomley if (alien_vector[i].get_alien_fire_counter()%60 == 0){ Weapons alien_bullet; @@ -152,4 +175,11 @@ explosion_vector.erase(explosion_vector.begin()+ i); } } +} + +void GameEngine::reset_map(){ + spaceship.init(); + spaceship_lives--; + spaceship_destroyed = false; + reset_map_counter = 0; } \ No newline at end of file