Ben Evans / Mbed 2 deprecated Defender_Game

Dependencies:   mbed

Committer:
evanso
Date:
Thu May 14 14:19:24 2020 +0000
Revision:
29:e96d91f1d39c
Parent:
28:a5958497d5ce
Child:
30:814674b189f0
Fixed collision of spaceship bullets and alien. Added collision of alien bullet with spaceship which cause explosion.

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 27:8bb2bd97c319 64 // Variables ---------------------------------------------------------------
evanso 18:11068b98e261 65
evanso 27:8bb2bd97c319 66 /** Define direction d of joystick*/
evanso 15:90b6821bcf64 67 Direction d_;
evanso 18:11068b98e261 68
evanso 27:8bb2bd97c319 69 // Vectors -----------------------------------------------------------------
evanso 27:8bb2bd97c319 70
evanso 27:8bb2bd97c319 71 /** Vector to store each new bullet object*/
evanso 19:1bc0a2d22054 72 std::vector<Weapons> bullet_vector;
evanso 19:1bc0a2d22054 73
evanso 28:a5958497d5ce 74 /** Vector to store each alien bullet object*/
evanso 28:a5958497d5ce 75 std::vector<Weapons> alien_bullet_vector;
evanso 28:a5958497d5ce 76
evanso 27:8bb2bd97c319 77 /** Vector to store each new alien object*/
evanso 20:febd920ec29e 78 std::vector<Alien> alien_vector;
evanso 20:febd920ec29e 79
evanso 27:8bb2bd97c319 80 /** Vector to store each new eplosion object*/
evanso 25:70b55f5bfc87 81 std::vector<Explosion> explosion_vector;
evanso 25:70b55f5bfc87 82
evanso 27:8bb2bd97c319 83 // Objects -----------------------------------------------------------------
evanso 27:8bb2bd97c319 84
evanso 27:8bb2bd97c319 85 /** Define Gamepad object*/
evanso 13:12276eed13ac 86 Gamepad pad;
evanso 13:12276eed13ac 87
evanso 27:8bb2bd97c319 88 /** Define LCD object*/
evanso 13:12276eed13ac 89 N5110 lcd;
evanso 13:12276eed13ac 90
evanso 27:8bb2bd97c319 91 /** Define Spaceship object */
evanso 13:12276eed13ac 92 Spaceship spaceship;
evanso 13:12276eed13ac 93
evanso 27:8bb2bd97c319 94 /** Define Map object*/
evanso 19:1bc0a2d22054 95 Map map;
evanso 7:0af4ced868f5 96 };
evanso 7:0af4ced868f5 97
evanso 7:0af4ced868f5 98 #endif