Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
GameEngine/GameEngine.h
- Committer:
- evanso
- Date:
- 2020-05-17
- Revision:
- 41:5959256f4aab
- Parent:
- 40:71f947254fda
- Child:
- 42:3aed75338272
File content as of revision 41:5959256f4aab:
#ifndef GAMEENGINE_H #define GAMEENGINE_H // Included libraries ---------------------------------------------------------- #include "mbed.h" #include "N5110.h" #include "Gamepad.h" #include "Spaceship.h" #include "Map.h" #include "Weapons.h" #include "Alien.h" #include "Explosion.h" #include "People.h" #include "HUD.h" #include "Menu.h" #include <cmath> #include <vector> /** GameEngine class * @brief Runs the different parts of the game * @author Benjamin Evans, University of Leeds * @date April 2020 */ class GameEngine { public: /** Constructor */ GameEngine(); /** Destructor */ ~GameEngine(); /** Initalises GameEngine */ void init(); /** Main gameplay loop that runs playable part of game */ void gameplay_loop(); // Accessors and mutators -------------------------------------------------- private: // Function prototypes ----------------------------------------------------- // Menu Control /** Switch statement to run run different menu options */ void game_select_part(); /** Runs the menu */ void run_menu(); /** Runs the play game part of menu */ void run_play(); /** Runs settings part of games */ void run_settings(); /** Runs settings part of games*/ void run_saved_games(); //Spaceship Control /** Gets joystick direction from gamepad and stores it in d_ */ void read_joystick_direction(); /** Turns on specific leds depending on how many lives left */ void spaceship_lives_leds(); //Weapon Control /** Creates weapons object if button A is pressed and stores in vector*/ void create_weapons_bullets(); /** Creates smart bomb if button B is pressed */ void create_weapons_smart_bomb(); /** Draws each bullet object and deleted object after set movement * distance */ void draw_bullets(); //Alien Control /** Spawns aliens in random position of the screen*/ void spawn_aliens(); /** Creats alien object and stores in vector*/ void create_alien(); /** Checks for alien people collision and sets abduction movements * @param i @details iterator from draw_alien for loop */ void check_alien_people_collision(int i); /** Gets alien to fire bullets randomley towards spaceship * @param i @details iterator from draw_alien for loop */ void alliens_fire_bullets(int i); /**Deletes bullet and alien if collision detected and draws explosion * @param i @details iterator from draw_alien for loop */ void delete_aliens(int i); /** Draws each alien object and deletes both objects if collision * detected */ void draw_aliens(); //Explotion Control /** Creates bullet object if button A is pressed and stores in vector */ void create_explosion(Vector2D destroyed_position); /** Draws each explosion object if collision detected */ void draw_explosions(); //People Control /** Spawns people in random places at bottom of screen */ void spawn_people(); /** Spawns people in random position at bottom of the screen*/ void create_people(); /** Draws each people object */ void draw_people(); //Map Control /** Resets map after set time so spaceship explosion animation showes */ void reset_map_timer(); /** Resets the map after spaceship death and timer has ended */ void reset_map(); // Variables --------------------------------------------------------------- // Menu Control MenuParts current_menu_part_; //Spacehip Control /** Define points*/ int points; /** Define direction d of joystick*/ Direction d_; /** Flag for if spaceship is destroyed*/ bool spaceship_destroyed; /** Number of spaceship lives remaining*/ int spaceship_lives; // Map Control /** Counter to reset map after set amount of frames*/ int reset_map_counter; // Alien Control /** Counter for spawning aliens*/ int spawn_alien_counter; /** Counter for numeber of aliens*/ int alien_number_counter; /** Counter for spawning aliens*/ double spawn_alien_rate; // Weapon Control /** Counter for smart bomb timer*/ int smart_bomb_timer; /** Counter for bullet timer*/ int bullet_timer; /** Counter for how smart bombs left*/ int smart_bomb_counter; // Vectors ----------------------------------------------------------------- /** Vector to store each new bullet object*/ std::vector<Weapons> bullet_vector; /** Vector to store each alien bullet object*/ std::vector<Weapons> alien_bullet_vector; /** Vector to store each new alien object*/ std::vector<Alien> alien_vector; /** Vector to store each new eplosion object*/ std::vector<Explosion> explosion_vector; /** Vector to store each new people object*/ std::vector<People> people_vector; // Objects ----------------------------------------------------------------- /** Define Gamepad object*/ Gamepad pad; /** Define LCD object*/ N5110 lcd; /** Define Spaceship object */ Spaceship spaceship; /** Define Map object*/ Map map; /** Define Weapons object*/ Weapons weapons; /** Define HUD object*/ HUD hud; /** Define Menu object*/ Menu menu; }; #endif