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:
Wed May 27 02:06:05 2020 +0000
Revision:
87:832ca78426b5
Parent:
86:eecd168c3a23
Final Submission. I have read and agreed with Statement of Academic Integrity.

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