Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Thu May 14 17:37:37 2020 +0000
Revision:
30:814674b189f0
Parent:
29:e96d91f1d39c
Child:
31:6015e8ed859c
Added if alien and ship collide the ship is destroyed.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
evanso 11:ab578a151f67 1 #ifndef GAMEENGINE_H
evanso 11:ab578a151f67 2 #define GAMEENGINE_H
evanso 7:0af4ced868f5 3
evanso 27:8bb2bd97c319 4 // Included libraries ----------------------------------------------------------
evanso 7:0af4ced868f5 5 #include "mbed.h"
evanso 7:0af4ced868f5 6 #include "N5110.h"
evanso 7:0af4ced868f5 7 #include "Gamepad.h"
evanso 8:dd1037c5435b 8 #include "Spaceship.h"
evanso 8:dd1037c5435b 9 #include "Map.h"
evanso 17:25d79cca203a 10 #include "Weapons.h"
evanso 19:1bc0a2d22054 11 #include "Alien.h"
evanso 25:70b55f5bfc87 12 #include "Explosion.h"
evanso 18:11068b98e261 13 #include <vector>
evanso 7:0af4ced868f5 14
evanso 11:ab578a151f67 15 /** GameEngine class
evanso 27:8bb2bd97c319 16 * @brief Runs the different parts of the game
evanso 27:8bb2bd97c319 17 * @author Benjamin Evans, University of Leeds
evanso 27:8bb2bd97c319 18 * @date April 2020
evanso 27:8bb2bd97c319 19 */
evanso 7:0af4ced868f5 20 class GameEngine {
evanso 7:0af4ced868f5 21 public:
evanso 7:0af4ced868f5 22 /** Constructor */
evanso 7:0af4ced868f5 23 GameEngine();
evanso 7:0af4ced868f5 24
evanso 7:0af4ced868f5 25 /** Destructor */
evanso 7:0af4ced868f5 26 ~GameEngine();
evanso 7:0af4ced868f5 27
evanso 14:7419c680656f 28 /** Initalises GameEngine */
evanso 13:12276eed13ac 29 void init();
evanso 7:0af4ced868f5 30
evanso 14:7419c680656f 31 /** Main gameplay loop that runs playable part of game */
evanso 13:12276eed13ac 32 void gameplay_loop();
evanso 15:90b6821bcf64 33
evanso 27:8bb2bd97c319 34 // Accessors and mutators --------------------------------------------------
evanso 11:ab578a151f67 35
evanso 11:ab578a151f67 36 private:
evanso 27:8bb2bd97c319 37 // Function prototypes -----------------------------------------------------
evanso 18:11068b98e261 38
evanso 27:8bb2bd97c319 39 /** Gets joystick direction from gamepad and stores it in d_ */
evanso 18:11068b98e261 40 void read_joystick_direction();
evanso 11:ab578a151f67 41
evanso 27:8bb2bd97c319 42 /** Creats bullet object if button A is pressed and stores in vector */
evanso 19:1bc0a2d22054 43 void create_bullet();
evanso 19:1bc0a2d22054 44
evanso 27:8bb2bd97c319 45 /** Draws each bullet object and deleted object after set movement
evanso 27:8bb2bd97c319 46 * distance
evanso 27:8bb2bd97c319 47 */
evanso 19:1bc0a2d22054 48 void draw_bullets();
evanso 13:12276eed13ac 49
evanso 22:053c11a202e1 50 /** Creats alien object and stores in vector*/
evanso 20:febd920ec29e 51 void create_alien();
evanso 20:febd920ec29e 52
evanso 27:8bb2bd97c319 53 /** Draws each alien object and deletes both objects if collision
evanso 27:8bb2bd97c319 54 * detected
evanso 27:8bb2bd97c319 55 */
evanso 20:febd920ec29e 56 void draw_aliens();
evanso 20:febd920ec29e 57
evanso 27:8bb2bd97c319 58 /** Creats bullet object if button A is pressed and stores in vector */
evanso 29:e96d91f1d39c 59 void create_explosion(Vector2D destroyed_position);
evanso 25:70b55f5bfc87 60
evanso 27:8bb2bd97c319 61 /** Draws each explosion object if collision detected */
evanso 25:70b55f5bfc87 62 void draw_explosions();
evanso 25:70b55f5bfc87 63
evanso 30:814674b189f0 64 /** Resets the map after spaceship death*/
evanso 30:814674b189f0 65 void reset_map();
evanso 30:814674b189f0 66
evanso 27:8bb2bd97c319 67 // Variables ---------------------------------------------------------------
evanso 18:11068b98e261 68
evanso 27:8bb2bd97c319 69 /** Define direction d of joystick*/
evanso 15:90b6821bcf64 70 Direction d_;
evanso 18:11068b98e261 71
evanso 30:814674b189f0 72 /** Number of spaceship lives remaining*/
evanso 30:814674b189f0 73 int spaceship_lives;
evanso 30:814674b189f0 74
evanso 30:814674b189f0 75 /** Flag for if spaceship is destroyed*/
evanso 30:814674b189f0 76 bool spaceship_destroyed;
evanso 30:814674b189f0 77
evanso 30:814674b189f0 78 /** Fcounter to reset map after set amount of frames*/
evanso 30:814674b189f0 79 int reset_map_counter;
evanso 30:814674b189f0 80
evanso 27:8bb2bd97c319 81 // Vectors -----------------------------------------------------------------
evanso 27:8bb2bd97c319 82
evanso 27:8bb2bd97c319 83 /** Vector to store each new bullet object*/
evanso 19:1bc0a2d22054 84 std::vector<Weapons> bullet_vector;
evanso 19:1bc0a2d22054 85
evanso 28:a5958497d5ce 86 /** Vector to store each alien bullet object*/
evanso 28:a5958497d5ce 87 std::vector<Weapons> alien_bullet_vector;
evanso 28:a5958497d5ce 88
evanso 27:8bb2bd97c319 89 /** Vector to store each new alien object*/
evanso 20:febd920ec29e 90 std::vector<Alien> alien_vector;
evanso 20:febd920ec29e 91
evanso 27:8bb2bd97c319 92 /** Vector to store each new eplosion object*/
evanso 25:70b55f5bfc87 93 std::vector<Explosion> explosion_vector;
evanso 25:70b55f5bfc87 94
evanso 27:8bb2bd97c319 95 // Objects -----------------------------------------------------------------
evanso 27:8bb2bd97c319 96
evanso 27:8bb2bd97c319 97 /** Define Gamepad object*/
evanso 13:12276eed13ac 98 Gamepad pad;
evanso 13:12276eed13ac 99
evanso 27:8bb2bd97c319 100 /** Define LCD object*/
evanso 13:12276eed13ac 101 N5110 lcd;
evanso 13:12276eed13ac 102
evanso 27:8bb2bd97c319 103 /** Define Spaceship object */
evanso 13:12276eed13ac 104 Spaceship spaceship;
evanso 13:12276eed13ac 105
evanso 27:8bb2bd97c319 106 /** Define Map object*/
evanso 19:1bc0a2d22054 107 Map map;
evanso 7:0af4ced868f5 108 };
evanso 7:0af4ced868f5 109
evanso 7:0af4ced868f5 110 #endif