Matis Requis 201241242

Dependencies:   mbed

Tempest Game

Game Screen

https://os.mbed.com/media/uploads/MatisRequis/tempest_board_wiki.png The board is made of 12 columns. The Hero stays at the top of the column

Game Controls

https://os.mbed.com/media/uploads/MatisRequis/gamepad_buttons.png

To control the hero spaceship point the joystick to the column you want the hero to go to.

Press the A button to shoot a bullet in the column you are currently in.

Committer:
MatisRequis
Date:
Tue May 26 16:31:22 2020 +0000
Revision:
10:2ae9d4145410
Parent:
9:759b419fec3b
Finished code with comments

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MatisRequis 2:d59a92e65bd9 1 #ifndef TEMPESTENGINE_H
MatisRequis 2:d59a92e65bd9 2 #define TEMPESTENGINE_H
MatisRequis 2:d59a92e65bd9 3
MatisRequis 10:2ae9d4145410 4 // Included Libraries
MatisRequis 2:d59a92e65bd9 5 #include "mbed.h"
MatisRequis 2:d59a92e65bd9 6 #include "N5110.h"
MatisRequis 2:d59a92e65bd9 7 #include "Gamepad.h"
MatisRequis 6:037dfa5064a1 8 #include "Bullet.h"
MatisRequis 4:8e3ba8d6d915 9 #include "Hero.h"
MatisRequis 3:54132cf073d7 10 #include "Board.h"
MatisRequis 9:759b419fec3b 11 #include "Alien.h"
MatisRequis 2:d59a92e65bd9 12
MatisRequis 6:037dfa5064a1 13 #include <vector>
MatisRequis 9:759b419fec3b 14 #include <cstdlib>
MatisRequis 9:759b419fec3b 15 #include <ctime>
MatisRequis 6:037dfa5064a1 16
MatisRequis 10:2ae9d4145410 17 /** TempestEngine Class
MatisRequis 10:2ae9d4145410 18 * @brief Interacts all the other classes together and builds the game
MatisRequis 10:2ae9d4145410 19 * @author Matis Requis
MatisRequis 10:2ae9d4145410 20 * @date May, 2020
MatisRequis 10:2ae9d4145410 21 */
MatisRequis 2:d59a92e65bd9 22 class TempestEngine {
MatisRequis 2:d59a92e65bd9 23
MatisRequis 2:d59a92e65bd9 24 public:
MatisRequis 2:d59a92e65bd9 25
MatisRequis 10:2ae9d4145410 26 /** Constructor */
MatisRequis 2:d59a92e65bd9 27 TempestEngine();
MatisRequis 10:2ae9d4145410 28
MatisRequis 10:2ae9d4145410 29 /** Destructor */
MatisRequis 2:d59a92e65bd9 30 ~TempestEngine();
MatisRequis 2:d59a92e65bd9 31
MatisRequis 10:2ae9d4145410 32
MatisRequis 10:2ae9d4145410 33 //GAME FUNCTIONS
MatisRequis 10:2ae9d4145410 34 /** Initialises the GameEngine*/
MatisRequis 4:8e3ba8d6d915 35 void init();
MatisRequis 10:2ae9d4145410 36
MatisRequis 10:2ae9d4145410 37 /** Reads the input of the board
MatisRequis 10:2ae9d4145410 38 * @param pad @details gamepad object
MatisRequis 10:2ae9d4145410 39 */
MatisRequis 4:8e3ba8d6d915 40 void read_input(Gamepad &pad);
MatisRequis 10:2ae9d4145410 41
MatisRequis 10:2ae9d4145410 42 /** Draws the game using functions from other classes
MatisRequis 10:2ae9d4145410 43 * @param lcd @details N5110 object
MatisRequis 10:2ae9d4145410 44 */
MatisRequis 2:d59a92e65bd9 45 void draw(N5110 &lcd);
MatisRequis 10:2ae9d4145410 46
MatisRequis 10:2ae9d4145410 47 /** Updates the game */
MatisRequis 4:8e3ba8d6d915 48 void update();
MatisRequis 9:759b419fec3b 49
MatisRequis 10:2ae9d4145410 50
MatisRequis 10:2ae9d4145410 51 //CLASS INTERACTION FUNCTIONS
MatisRequis 10:2ae9d4145410 52
MatisRequis 10:2ae9d4145410 53 /** Displays the score
MatisRequis 10:2ae9d4145410 54 * @param lcd @details N5110 object
MatisRequis 10:2ae9d4145410 55 */
MatisRequis 10:2ae9d4145410 56 void display_score(N5110 &lcd);
MatisRequis 10:2ae9d4145410 57
MatisRequis 10:2ae9d4145410 58 /** Displays the amount of lives left
MatisRequis 10:2ae9d4145410 59 * @param lcd @details N5110 object
MatisRequis 10:2ae9d4145410 60 */
MatisRequis 10:2ae9d4145410 61 void display_lives(N5110 &lcd);
MatisRequis 10:2ae9d4145410 62
MatisRequis 10:2ae9d4145410 63 /** Checks for collision between an alien and a bullet */
MatisRequis 10:2ae9d4145410 64 void check_alien_bullet_colision();
MatisRequis 10:2ae9d4145410 65
MatisRequis 10:2ae9d4145410 66 /** Checks if the player is out of lives
MatisRequis 10:2ae9d4145410 67 * @return 0 or 1 @details returns 1 if the player is out of lives, otherwise 0
MatisRequis 10:2ae9d4145410 68 */
MatisRequis 10:2ae9d4145410 69 int game_over();
MatisRequis 10:2ae9d4145410 70
MatisRequis 10:2ae9d4145410 71
MatisRequis 10:2ae9d4145410 72 //BULLET FUNCTIONS
MatisRequis 10:2ae9d4145410 73
MatisRequis 10:2ae9d4145410 74 /** Creates new bullets when A is pressed */
MatisRequis 6:037dfa5064a1 75 void create_bullets();
MatisRequis 10:2ae9d4145410 76
MatisRequis 10:2ae9d4145410 77 /** Iterates through the bullets and draws them
MatisRequis 10:2ae9d4145410 78 * @param lcd @details N5110 object
MatisRequis 10:2ae9d4145410 79 */
MatisRequis 6:037dfa5064a1 80 void draw_bullets(N5110 &lcd);
MatisRequis 10:2ae9d4145410 81
MatisRequis 10:2ae9d4145410 82 /** Updates all the bullets positions and removes them once they have reached the bottom */
MatisRequis 9:759b419fec3b 83 void update_bullets();
MatisRequis 9:759b419fec3b 84
MatisRequis 10:2ae9d4145410 85 //ALIEN FUNCTIONS
MatisRequis 10:2ae9d4145410 86
MatisRequis 10:2ae9d4145410 87 /** Spawns new aliens randomly every 15-25 frames */
MatisRequis 9:759b419fec3b 88 void create_aliens();
MatisRequis 10:2ae9d4145410 89
MatisRequis 10:2ae9d4145410 90 /** Draws all the created aliens
MatisRequis 10:2ae9d4145410 91 * @param lcd @details N5110 object
MatisRequis 10:2ae9d4145410 92 */
MatisRequis 9:759b419fec3b 93 void draw_aliens(N5110 &lcd);
MatisRequis 10:2ae9d4145410 94
MatisRequis 10:2ae9d4145410 95 /** Updates all the aliens positions and removes them when they have reached the top of the board */
MatisRequis 9:759b419fec3b 96 void update_aliens();
MatisRequis 2:d59a92e65bd9 97
MatisRequis 10:2ae9d4145410 98
MatisRequis 10:2ae9d4145410 99 /////////////////VECTOR/////////////////
MatisRequis 10:2ae9d4145410 100
MatisRequis 10:2ae9d4145410 101 /** Stores all the bullets created */
MatisRequis 10:2ae9d4145410 102 std::vector<Bullet> bullet_vect;
MatisRequis 10:2ae9d4145410 103
MatisRequis 10:2ae9d4145410 104 /** Stores all the aliens spawned */
MatisRequis 10:2ae9d4145410 105 std::vector<Alien> alien_vect;
MatisRequis 10:2ae9d4145410 106
MatisRequis 2:d59a92e65bd9 107 private:
MatisRequis 6:037dfa5064a1 108 //////////////////OBJECTS////////////////////
MatisRequis 10:2ae9d4145410 109
MatisRequis 10:2ae9d4145410 110 /** Board object */
MatisRequis 6:037dfa5064a1 111 Board _board;
MatisRequis 10:2ae9d4145410 112
MatisRequis 10:2ae9d4145410 113 /** Hero object */
MatisRequis 6:037dfa5064a1 114 Hero _hero;
MatisRequis 7:94bc3e21d664 115
MatisRequis 6:037dfa5064a1 116 /////////////////VARIABLES////////////////
MatisRequis 10:2ae9d4145410 117 int _shooting_speed;
MatisRequis 4:8e3ba8d6d915 118 float _d;
MatisRequis 2:d59a92e65bd9 119 int _a;
MatisRequis 10:2ae9d4145410 120 int _bullet_countdown;
MatisRequis 9:759b419fec3b 121 int _alien_timer;
MatisRequis 9:759b419fec3b 122 int _alienspeed;
MatisRequis 10:2ae9d4145410 123 int _score;
MatisRequis 10:2ae9d4145410 124 int _herolives;
MatisRequis 6:037dfa5064a1 125
MatisRequis 10:2ae9d4145410 126
MatisRequis 2:d59a92e65bd9 127 };
MatisRequis 2:d59a92e65bd9 128
MatisRequis 2:d59a92e65bd9 129 #endif