Ben Evans University Second Year Project. Game Called Defender.

Dependencies:   mbed

https://os.mbed.com/media/uploads/evanso/84bc1a30759fd6a1e3f1fd1fae3e97c2.png

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.

Committer:
evanso
Date:
Mon May 25 15:07:24 2020 +0000
Revision:
80:870bc6b4bf08
Child:
82:3211b31e9421
Split GameEngine class into two different classes to reduce its size The parent class PlayEngine was created to hold the function that control the interaction between classes in the playable part of the game and so they can be unit tested.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 80:870bc6b4bf08 1 #ifndef PLAYENGINE_H
evanso 80:870bc6b4bf08 2 #define PLAYENGINE_H
evanso 80:870bc6b4bf08 3
evanso 80:870bc6b4bf08 4 // Included libraries ----------------------------------------------------------
evanso 80:870bc6b4bf08 5 #include "mbed.h"
evanso 80:870bc6b4bf08 6 #include "N5110.h"
evanso 80:870bc6b4bf08 7 #include "Gamepad.h"
evanso 80:870bc6b4bf08 8 #include "Spaceship.h"
evanso 80:870bc6b4bf08 9 #include "Map.h"
evanso 80:870bc6b4bf08 10 #include "Weapons.h"
evanso 80:870bc6b4bf08 11 #include "Alien.h"
evanso 80:870bc6b4bf08 12 #include "Explosion.h"
evanso 80:870bc6b4bf08 13 #include "People.h"
evanso 80:870bc6b4bf08 14 #include "Settings.h"
evanso 80:870bc6b4bf08 15 #include <vector>
evanso 80:870bc6b4bf08 16
evanso 80:870bc6b4bf08 17 /** PlayEngine Class
evanso 80:870bc6b4bf08 18 * @brief Runs the interactions betwween the different classes in the playable
evanso 80:870bc6b4bf08 19 * part of the game. Also to break down the size of game engine class. Means I
evanso 80:870bc6b4bf08 20 * can define the functions publically to test them then inheret them privetly.
evanso 80:870bc6b4bf08 21 * @author Benjamin Evans, University of Leeds
evanso 80:870bc6b4bf08 22 * @date May 2020
evanso 80:870bc6b4bf08 23 */
evanso 80:870bc6b4bf08 24 class PlayEngine {
evanso 80:870bc6b4bf08 25 public:
evanso 80:870bc6b4bf08 26
evanso 80:870bc6b4bf08 27 // Function prototypes -----------------------------------------------------
evanso 80:870bc6b4bf08 28
evanso 80:870bc6b4bf08 29 //Spaceship Control
evanso 80:870bc6b4bf08 30 /** Gets joystick direction from gamepad and stores it in d_ */
evanso 80:870bc6b4bf08 31 void read_joystick_direction();
evanso 80:870bc6b4bf08 32
evanso 80:870bc6b4bf08 33 /** Gets the pitch and roll of the gamepad and calculates d_ */
evanso 80:870bc6b4bf08 34 void read_accelerometer_direction(float roll, float pitch);
evanso 80:870bc6b4bf08 35
evanso 80:870bc6b4bf08 36 /** Turns on specific leds depending on how many lives left */
evanso 80:870bc6b4bf08 37 void spaceship_lives_leds();
evanso 80:870bc6b4bf08 38
evanso 80:870bc6b4bf08 39 //Weapon Control
evanso 80:870bc6b4bf08 40 /** Creates weapons object if button A is pressed and stores in vector*/
evanso 80:870bc6b4bf08 41 void create_weapons_bullets();
evanso 80:870bc6b4bf08 42
evanso 80:870bc6b4bf08 43 /** Creates smart bomb if button B is pressed */
evanso 80:870bc6b4bf08 44 void create_weapons_smart_bomb();
evanso 80:870bc6b4bf08 45
evanso 80:870bc6b4bf08 46 /** Draws each bullet object and deleted object after set movement
evanso 80:870bc6b4bf08 47 * distance
evanso 80:870bc6b4bf08 48 */
evanso 80:870bc6b4bf08 49 void draw_bullets();
evanso 80:870bc6b4bf08 50
evanso 80:870bc6b4bf08 51 //Alien Control
evanso 80:870bc6b4bf08 52 /** Spawns aliens in random position of the screen*/
evanso 80:870bc6b4bf08 53 void spawn_aliens();
evanso 80:870bc6b4bf08 54
evanso 80:870bc6b4bf08 55 /** Creats alien object and stores in vector*/
evanso 80:870bc6b4bf08 56 void create_alien();
evanso 80:870bc6b4bf08 57
evanso 80:870bc6b4bf08 58 /** Checks for alien people collision and sets abduction movements
evanso 80:870bc6b4bf08 59 * @param i @details iterator from draw_alien for loop
evanso 80:870bc6b4bf08 60 */
evanso 80:870bc6b4bf08 61 void check_alien_people_collision(int i);
evanso 80:870bc6b4bf08 62
evanso 80:870bc6b4bf08 63 /** Gets alien to fire bullets randomley towards spaceship
evanso 80:870bc6b4bf08 64 * @param i @details iterator from draw_alien for loop
evanso 80:870bc6b4bf08 65 */
evanso 80:870bc6b4bf08 66 void alliens_fire_bullets(int i);
evanso 80:870bc6b4bf08 67
evanso 80:870bc6b4bf08 68 /**Deletes bullet and alien if collision detected and draws explosion
evanso 80:870bc6b4bf08 69 * @param i @details iterator from draw_alien for loop
evanso 80:870bc6b4bf08 70 */
evanso 80:870bc6b4bf08 71 void delete_aliens(int i);
evanso 80:870bc6b4bf08 72
evanso 80:870bc6b4bf08 73 /** Draws each alien object and deletes both objects if collision
evanso 80:870bc6b4bf08 74 * detected
evanso 80:870bc6b4bf08 75 */
evanso 80:870bc6b4bf08 76 void draw_aliens();
evanso 80:870bc6b4bf08 77
evanso 80:870bc6b4bf08 78 //Explotion Control
evanso 80:870bc6b4bf08 79 /** Creates bullet object if button A is pressed and stores in vector */
evanso 80:870bc6b4bf08 80 void create_explosion(Vector2D destroyed_position);
evanso 80:870bc6b4bf08 81
evanso 80:870bc6b4bf08 82 /** Draws each explosion object if collision detected */
evanso 80:870bc6b4bf08 83 void draw_explosions();
evanso 80:870bc6b4bf08 84
evanso 80:870bc6b4bf08 85 //People Control
evanso 80:870bc6b4bf08 86 /** Spawns people in random places at bottom of screen */
evanso 80:870bc6b4bf08 87 void spawn_people();
evanso 80:870bc6b4bf08 88
evanso 80:870bc6b4bf08 89 /** Spawns people in random position at bottom of the screen*/
evanso 80:870bc6b4bf08 90 void create_people();
evanso 80:870bc6b4bf08 91
evanso 80:870bc6b4bf08 92 /** Draws each people object */
evanso 80:870bc6b4bf08 93 void draw_people();
evanso 80:870bc6b4bf08 94
evanso 80:870bc6b4bf08 95 //Map Control
evanso 80:870bc6b4bf08 96 /** Resets map after set time so spaceship explosion animation showes */
evanso 80:870bc6b4bf08 97 void reset_map_timer();
evanso 80:870bc6b4bf08 98
evanso 80:870bc6b4bf08 99 /** Resets the map after spaceship death and timer has ended */
evanso 80:870bc6b4bf08 100 void reset_map();
evanso 80:870bc6b4bf08 101
evanso 80:870bc6b4bf08 102 // Varibles ----------------------------------------------------------------
evanso 80:870bc6b4bf08 103
evanso 80:870bc6b4bf08 104 //Spacehip Control
evanso 80:870bc6b4bf08 105 /** Define points*/
evanso 80:870bc6b4bf08 106 int points_;
evanso 80:870bc6b4bf08 107
evanso 80:870bc6b4bf08 108 /** Define direction d of joystick*/
evanso 80:870bc6b4bf08 109 Direction d_;
evanso 80:870bc6b4bf08 110
evanso 80:870bc6b4bf08 111 /** Flag for if spaceship is destroyed*/
evanso 80:870bc6b4bf08 112 bool spaceship_destroyed_;
evanso 80:870bc6b4bf08 113
evanso 80:870bc6b4bf08 114 /** Number of spaceship lives remaining*/
evanso 80:870bc6b4bf08 115 int spaceship_lives_;
evanso 80:870bc6b4bf08 116
evanso 80:870bc6b4bf08 117 // Weapon Control
evanso 80:870bc6b4bf08 118 /** Counter for smart bomb timer*/
evanso 80:870bc6b4bf08 119 int smart_bomb_timer_;
evanso 80:870bc6b4bf08 120
evanso 80:870bc6b4bf08 121 /** Counter for bullet timer*/
evanso 80:870bc6b4bf08 122 int bullet_timer_;
evanso 80:870bc6b4bf08 123
evanso 80:870bc6b4bf08 124 /** Counter for how smart bombs left*/
evanso 80:870bc6b4bf08 125 int smart_bomb_counter_;
evanso 80:870bc6b4bf08 126
evanso 80:870bc6b4bf08 127 // Alien Control
evanso 80:870bc6b4bf08 128 /** Counter for spawning aliens*/
evanso 80:870bc6b4bf08 129 int spawn_alien_counter_;
evanso 80:870bc6b4bf08 130
evanso 80:870bc6b4bf08 131 /** Numeber of aliens on the screen at a time*/
evanso 80:870bc6b4bf08 132 int alien_number_;
evanso 80:870bc6b4bf08 133
evanso 80:870bc6b4bf08 134 /** Miltiplier to increase number of alien as time goes on */
evanso 80:870bc6b4bf08 135 int spawn_time_multipler_;
evanso 80:870bc6b4bf08 136
evanso 80:870bc6b4bf08 137 // Map Control
evanso 80:870bc6b4bf08 138 /** Counter to reset map after set amount of frames*/
evanso 80:870bc6b4bf08 139 int reset_map_counter_;
evanso 80:870bc6b4bf08 140
evanso 80:870bc6b4bf08 141 //FX sound
evanso 80:870bc6b4bf08 142 /** Hold on or off depending if sound fx are set on or off */
evanso 80:870bc6b4bf08 143 SoundParts sound_fx_;
evanso 80:870bc6b4bf08 144
evanso 80:870bc6b4bf08 145 // Vectors -----------------------------------------------------------------
evanso 80:870bc6b4bf08 146
evanso 80:870bc6b4bf08 147 /** Vector to store each new bullet object*/
evanso 80:870bc6b4bf08 148 std::vector<Weapons> bullet_vector;
evanso 80:870bc6b4bf08 149
evanso 80:870bc6b4bf08 150 /** Vector to store each alien bullet object*/
evanso 80:870bc6b4bf08 151 std::vector<Weapons> alien_bullet_vector;
evanso 80:870bc6b4bf08 152
evanso 80:870bc6b4bf08 153 /** Vector to store each new alien object*/
evanso 80:870bc6b4bf08 154 std::vector<Alien> alien_vector;
evanso 80:870bc6b4bf08 155
evanso 80:870bc6b4bf08 156 /** Vector to store each new eplosion object*/
evanso 80:870bc6b4bf08 157 std::vector<Explosion> explosion_vector;
evanso 80:870bc6b4bf08 158
evanso 80:870bc6b4bf08 159 /** Vector to store each new people object*/
evanso 80:870bc6b4bf08 160 std::vector<People> people_vector;
evanso 80:870bc6b4bf08 161
evanso 80:870bc6b4bf08 162 // Objects -----------------------------------------------------------------
evanso 80:870bc6b4bf08 163
evanso 80:870bc6b4bf08 164 /** Define Gamepad object */
evanso 80:870bc6b4bf08 165 Gamepad pad;
evanso 80:870bc6b4bf08 166
evanso 80:870bc6b4bf08 167 /** Define LCD object */
evanso 80:870bc6b4bf08 168 N5110 lcd;
evanso 80:870bc6b4bf08 169
evanso 80:870bc6b4bf08 170 /** Define Spaceship object */
evanso 80:870bc6b4bf08 171 Spaceship spaceship;
evanso 80:870bc6b4bf08 172
evanso 80:870bc6b4bf08 173 /** Define Map object */
evanso 80:870bc6b4bf08 174 Map map;
evanso 80:870bc6b4bf08 175
evanso 80:870bc6b4bf08 176 /** Define Weapons object */
evanso 80:870bc6b4bf08 177 Weapons weapons;
evanso 80:870bc6b4bf08 178 };
evanso 80:870bc6b4bf08 179
evanso 80:870bc6b4bf08 180 #endif