ELEC2645 (2019/20) / Mbed 2 deprecated ELEC2645_Project_el18jkeo

Dependencies:   mbed

Committer:
josh_ohara
Date:
Tue May 26 13:10:12 2020 +0000
Revision:
42:816e444e660b
Parent:
39:5d4277548303
trying to add fsm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
josh_ohara 6:5bea67cc96f9 1 #ifndef SPACEINVADERENGINE_H
josh_ohara 6:5bea67cc96f9 2 #define SPACEINVADERENGINE_H
josh_ohara 6:5bea67cc96f9 3
josh_ohara 6:5bea67cc96f9 4 #include "mbed.h"
josh_ohara 6:5bea67cc96f9 5 #include "N5110.h"
josh_ohara 6:5bea67cc96f9 6 #include "Gamepad.h"
josh_ohara 6:5bea67cc96f9 7 #include "Ship.h"
josh_ohara 12:be491ab6e742 8 #include "Armada.h"
josh_ohara 15:dde4ce4bf7fe 9 #include "Cover.h"
josh_ohara 11:c174d84e4866 10 #include <vector>
josh_ohara 6:5bea67cc96f9 11
josh_ohara 6:5bea67cc96f9 12 #define BORDER 2
josh_ohara 6:5bea67cc96f9 13
josh_ohara 39:5d4277548303 14 /** SpaceInvaderEngine Class
josh_ohara 39:5d4277548303 15 @author Joshua Ohara, el18jkeo, 201291390
josh_ohara 39:5d4277548303 16 @brief Main game engine: checks collsions between objects, updates objects, draws objects
josh_ohara 39:5d4277548303 17 @date May 2020
josh_ohara 39:5d4277548303 18 */
josh_ohara 39:5d4277548303 19
josh_ohara 6:5bea67cc96f9 20 class SpaceInvaderEngine
josh_ohara 6:5bea67cc96f9 21 {
josh_ohara 6:5bea67cc96f9 22
josh_ohara 6:5bea67cc96f9 23 public:
josh_ohara 39:5d4277548303 24 /**Constructor*/
josh_ohara 6:5bea67cc96f9 25 SpaceInvaderEngine();
josh_ohara 39:5d4277548303 26
josh_ohara 39:5d4277548303 27 /**Destructor*/
josh_ohara 8:86cb9a9f8a73 28 ~SpaceInvaderEngine();
josh_ohara 39:5d4277548303 29
josh_ohara 39:5d4277548303 30 /**Initialises all objects in game and sets private variables to inputs*/
josh_ohara 33:d8284dee58db 31 void init(int ship_height, int ship_width, int alien_size, int no_aliens, int armada_column_size, int armada_row_size, int cover_y, int cover1_x, int cover2_x, int cover3_x, int no_rocks, int level); //initialise all needed objects and set private member variables
josh_ohara 39:5d4277548303 32
josh_ohara 39:5d4277548303 33 /**Read the gamepad inputs (buttons and joysticks) for use in functions*/
josh_ohara 33:d8284dee58db 34 void read_input(Gamepad &pad); //read the gamepad input (buttons and joystick)
josh_ohara 39:5d4277548303 35
josh_ohara 39:5d4277548303 36 /**Update all objects in game and check for relevant collisions*/
josh_ohara 33:d8284dee58db 37 void update(Gamepad &pad, N5110 &lcd, int counter, int level); //update all objects
josh_ohara 39:5d4277548303 38
josh_ohara 39:5d4277548303 39 /**Draw all objects in game*/
josh_ohara 33:d8284dee58db 40 void render(N5110 &lcd); //draw all objects
josh_ohara 39:5d4277548303 41
josh_ohara 39:5d4277548303 42 /**Check for collision between ship bullets and aliens*/
josh_ohara 33:d8284dee58db 43 void ship_bullet_alien_collision(Gamepad &pad, N5110 &lcd); //check for collision between the ship bullets and the aliens
josh_ohara 39:5d4277548303 44
josh_ohara 39:5d4277548303 45 /**Check for collision between ship bullets and cover 1*/
josh_ohara 33:d8284dee58db 46 void ship_bullet_cover1_collision(Gamepad &pad, N5110 &lcd); //check for collision between the ship bullets and cover 1
josh_ohara 39:5d4277548303 47
josh_ohara 39:5d4277548303 48 /**Check for collision between ship bullets and cover 2*/
josh_ohara 33:d8284dee58db 49 void ship_bullet_cover2_collision(Gamepad &pad, N5110 &lcd); //check for collision between the ship bullets and cover 2
josh_ohara 39:5d4277548303 50
josh_ohara 39:5d4277548303 51 /**Check for collision between ship bullets and cover 3*/
josh_ohara 33:d8284dee58db 52 void ship_bullet_cover3_collision(Gamepad &pad, N5110 &lcd); //check for collision between the ship bullets and cover 3
josh_ohara 39:5d4277548303 53
josh_ohara 39:5d4277548303 54 /**Check for collision between alien bullets and player ship*/
josh_ohara 33:d8284dee58db 55 void alien_bullet_ship_collision(Gamepad &pad, N5110 &lcd); //check for collision between the alien bullets and the ship
josh_ohara 39:5d4277548303 56
josh_ohara 39:5d4277548303 57 /**Check for collision between alien bullet and cover 3*/
josh_ohara 33:d8284dee58db 58 void alien_bullet_cover3_collision(Gamepad &pad, N5110 &lcd); //check for collision between the alien bullets and cover 3
josh_ohara 39:5d4277548303 59
josh_ohara 39:5d4277548303 60 /**Check for collision between alien bullet and cover 1*/
josh_ohara 33:d8284dee58db 61 void alien_bullet_cover1_collision(Gamepad &pad, N5110 &lcd); //check for collision between the alien bullets and cover 1
josh_ohara 39:5d4277548303 62
josh_ohara 39:5d4277548303 63 /**Check for collision between alien bullet and cover 2*/
josh_ohara 33:d8284dee58db 64 void alien_bullet_cover2_collision(Gamepad &pad, N5110 &lcd); //check for collision between the alien bullets and cover 2
josh_ohara 39:5d4277548303 65
josh_ohara 39:5d4277548303 66 /**Check for collision between aliens and ship*/
josh_ohara 33:d8284dee58db 67 void alien_ship_collision(Gamepad &pad, N5110 &lcd); //check for collision between the aliens and the ship
josh_ohara 39:5d4277548303 68
josh_ohara 39:5d4277548303 69 /**Check for collision between aliens and cover 1*/
josh_ohara 33:d8284dee58db 70 void alien_cover1_collision(Gamepad &pad, N5110 &lcd); //check for collision between the aliens and cover 1
josh_ohara 39:5d4277548303 71
josh_ohara 39:5d4277548303 72 /**Check for collision between aliens and cover 2*/
josh_ohara 33:d8284dee58db 73 void alien_cover2_collision(Gamepad &pad, N5110 &lcd); //check for collision between the aliens and cover 2
josh_ohara 39:5d4277548303 74
josh_ohara 39:5d4277548303 75 /**Check for collision between aliens and cover 3*/
josh_ohara 33:d8284dee58db 76 void alien_cover3_collision(Gamepad &pad, N5110 &lcd); //check for collision between the aliens and cover 3
josh_ohara 39:5d4277548303 77
josh_ohara 39:5d4277548303 78 /**Check for collision between player ship and powerup*/
josh_ohara 39:5d4277548303 79 void ship_powerup_collision(Gamepad &pad, N5110 &lcd); //check for collision between player ship and powerup
josh_ohara 39:5d4277548303 80
josh_ohara 39:5d4277548303 81
josh_ohara 33:d8284dee58db 82 //accessors and mutators//
josh_ohara 39:5d4277548303 83
josh_ohara 39:5d4277548303 84 /**Return the life value of the alien armada
josh_ohara 39:5d4277548303 85 *@return armada life (bool)
josh_ohara 39:5d4277548303 86 */
josh_ohara 33:d8284dee58db 87 bool get_armada_life(); //return the life value of the alien armada
josh_ohara 39:5d4277548303 88
josh_ohara 39:5d4277548303 89 /**Return the life value of the ship
josh_ohara 39:5d4277548303 90 *@return ship life (bool)
josh_ohara 39:5d4277548303 91 */
josh_ohara 33:d8284dee58db 92 bool get_ship_life(); //return the life value of the ship
josh_ohara 39:5d4277548303 93
josh_ohara 39:5d4277548303 94 /**Set the life/hit value to all remaining objects to true or false repsectively at end of level
josh_ohara 39:5d4277548303 95 *@param all life/hit value
josh_ohara 39:5d4277548303 96 */
josh_ohara 33:d8284dee58db 97 void kill_all(); //set life value of all objects to 0
josh_ohara 14:e88bcf5c0887 98
josh_ohara 6:5bea67cc96f9 99 private:
josh_ohara 6:5bea67cc96f9 100
josh_ohara 33:d8284dee58db 101 Armada _armada; //armada (vector of aliens) object
josh_ohara 33:d8284dee58db 102 Ship _ship; //ship object
josh_ohara 42:816e444e660b 103 ShipBulletVector _ship_bullets; //ship bullet vector
josh_ohara 33:d8284dee58db 104 Cover _cover_1; //cover object (vector of rocks)
josh_ohara 33:d8284dee58db 105 Cover _cover_2; //cover object (vector of rocks)
josh_ohara 33:d8284dee58db 106 Cover _cover_3; //cover object (vector of rocks)
josh_ohara 6:5bea67cc96f9 107
josh_ohara 33:d8284dee58db 108 int _ship_height; //height of ship
josh_ohara 33:d8284dee58db 109 int _ship_width; //width of ship
josh_ohara 33:d8284dee58db 110 int _alien_size; //size of alien
josh_ohara 33:d8284dee58db 111 int _alien_number; //number of aliens
josh_ohara 33:d8284dee58db 112 int _armada_column_size; //number of of aliens per column of armada
josh_ohara 33:d8284dee58db 113 int _armada_row_size; //number of aliens per row of armada
josh_ohara 39:5d4277548303 114 bool _powerup; //ship powerup flag
josh_ohara 6:5bea67cc96f9 115
josh_ohara 33:d8284dee58db 116 int _ship_x; //x position of ship
josh_ohara 33:d8284dee58db 117 int _ship_y; //y position of ship
josh_ohara 33:d8284dee58db 118 int _cover_y; //y position of covers
josh_ohara 33:d8284dee58db 119 int _cover_1_x; //x position of cover 1
josh_ohara 33:d8284dee58db 120 int _cover_2_x; //x position of cover 2
josh_ohara 33:d8284dee58db 121 int _cover_3_x; //x position of cover 3
josh_ohara 33:d8284dee58db 122 int _rock_number; //number of rocks per cover
josh_ohara 33:d8284dee58db 123
josh_ohara 12:be491ab6e742 124
josh_ohara 33:d8284dee58db 125 Direction D; //direction of joystick
josh_ohara 33:d8284dee58db 126 float _mag; //magnitude of joystick offset
josh_ohara 6:5bea67cc96f9 127 };
josh_ohara 6:5bea67cc96f9 128
josh_ohara 6:5bea67cc96f9 129 #endif