FINAL VERSION

Dependencies:   mbed

Committer:
jamesheavey
Date:
Wed May 08 21:02:49 2019 +0000
Revision:
126:1ac594b5f91a
Parent:
123:39740c246fc2
Child:
129:b47c28c7eaaf
doxygen done for engine;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jamesheavey 27:1b5038b0a7a2 1 #ifndef BREAKOUTENGINE_H
jamesheavey 27:1b5038b0a7a2 2 #define BREAKOUTENGINE_H
jamesheavey 27:1b5038b0a7a2 3
jamesheavey 27:1b5038b0a7a2 4 #include "mbed.h"
jamesheavey 27:1b5038b0a7a2 5 #include "N5110.h"
jamesheavey 27:1b5038b0a7a2 6 #include "Gamepad.h"
jamesheavey 27:1b5038b0a7a2 7 #include "Ball.h"
jamesheavey 27:1b5038b0a7a2 8 #include "Paddle.h"
jamesheavey 27:1b5038b0a7a2 9 #include "Brick.h"
jamesheavey 29:5168318d3e88 10 #include "Laser.h"
jamesheavey 114:280903dd7e06 11 #include "Life_Powerup.h"
jamesheavey 27:1b5038b0a7a2 12
jamesheavey 27:1b5038b0a7a2 13 #include <list>
jamesheavey 27:1b5038b0a7a2 14 #include <iterator>
jamesheavey 114:280903dd7e06 15 #include <ctime> // For time()
jamesheavey 114:280903dd7e06 16 #include <cstdlib> // For srand() and rand()
jamesheavey 40:ac53905346fb 17
jamesheavey 40:ac53905346fb 18 #define GAP_TOP 10
jamesheavey 123:39740c246fc2 19 #define GAP 2
jamesheavey 86:01f33d94e496 20
jamesheavey 126:1ac594b5f91a 21 /** BreajoutEngine Class
jamesheavey 86:01f33d94e496 22 @author James Heavey, University of Leeds
jamesheavey 123:39740c246fc2 23 @brief Controls the Breakout game
jamesheavey 86:01f33d94e496 24 @date May 2019
jamesheavey 123:39740c246fc2 25 */
jamesheavey 27:1b5038b0a7a2 26
jamesheavey 27:1b5038b0a7a2 27 class BreakoutEngine
jamesheavey 27:1b5038b0a7a2 28 {
jamesheavey 27:1b5038b0a7a2 29
jamesheavey 27:1b5038b0a7a2 30 public:
jamesheavey 126:1ac594b5f91a 31
jamesheavey 126:1ac594b5f91a 32 /** Constructor declaration */
jamesheavey 27:1b5038b0a7a2 33 BreakoutEngine();
jamesheavey 126:1ac594b5f91a 34
jamesheavey 126:1ac594b5f91a 35 /** Destructor declaration */
jamesheavey 27:1b5038b0a7a2 36 ~BreakoutEngine();
jamesheavey 126:1ac594b5f91a 37
jamesheavey 126:1ac594b5f91a 38 /** Initialises game variables
jamesheavey 126:1ac594b5f91a 39 * @param paddle_width @details integer width of paddle
jamesheavey 126:1ac594b5f91a 40 * @param paddle_height @details integer height of paddle
jamesheavey 126:1ac594b5f91a 41 * @param ball_size @details integer diameter of ball in pixels
jamesheavey 126:1ac594b5f91a 42 * @param speed @details integer initial speed of ball
jamesheavey 126:1ac594b5f91a 43 */
jamesheavey 64:c3426b417ad9 44 void init(int paddle_width,int paddle_height,int ball_size,int speed);
jamesheavey 126:1ac594b5f91a 45
jamesheavey 126:1ac594b5f91a 46 /** Reads inputs from the Gamepad
jamesheavey 126:1ac594b5f91a 47 * @param &pad @details a Gamepad pointer
jamesheavey 126:1ac594b5f91a 48 */
jamesheavey 105:4e7585d8e5e2 49 void read_input(Gamepad &pad);
jamesheavey 126:1ac594b5f91a 50
jamesheavey 126:1ac594b5f91a 51 /** Updates the Game attributes
jamesheavey 126:1ac594b5f91a 52 * @param &pad @details a Gamepad pointer
jamesheavey 126:1ac594b5f91a 53 */
jamesheavey 27:1b5038b0a7a2 54 void update(Gamepad &pad);
jamesheavey 126:1ac594b5f91a 55
jamesheavey 126:1ac594b5f91a 56 /** Draws the objects' at their respective coordinates on the LCD
jamesheavey 126:1ac594b5f91a 57 * @param &lcd @details a N5110 pointer
jamesheavey 126:1ac594b5f91a 58 */
jamesheavey 27:1b5038b0a7a2 59 void draw(N5110 &lcd);
jamesheavey 126:1ac594b5f91a 60
jamesheavey 126:1ac594b5f91a 61 /** Updates the Gamepad LEDs with lives remaining
jamesheavey 126:1ac594b5f91a 62 * @param &pad @details a Gamepad pointer
jamesheavey 126:1ac594b5f91a 63 */
jamesheavey 27:1b5038b0a7a2 64 void lives_leds(Gamepad &pad);
jamesheavey 126:1ac594b5f91a 65
jamesheavey 126:1ac594b5f91a 66 /** Returns the number of Bricks remaining on screen
jamesheavey 126:1ac594b5f91a 67 * @return returns _number_left
jamesheavey 126:1ac594b5f91a 68 */
jamesheavey 27:1b5038b0a7a2 69 int get_num_left();
jamesheavey 126:1ac594b5f91a 70
jamesheavey 126:1ac594b5f91a 71 /** Returns the score achieved on victory in the previous iteration of the game
jamesheavey 126:1ac594b5f91a 72 * @return returns _prev_score
jamesheavey 126:1ac594b5f91a 73 */
jamesheavey 47:1d1a827be81b 74 int get_prev_score();
jamesheavey 126:1ac594b5f91a 75
jamesheavey 126:1ac594b5f91a 76 /** Sets the member variable _prev_score to current score
jamesheavey 126:1ac594b5f91a 77 * @param prev_score @details the new previous score which is the score achieved at victory
jamesheavey 126:1ac594b5f91a 78 */
jamesheavey 64:c3426b417ad9 79 void set_prev_score(int prev_score);
jamesheavey 126:1ac594b5f91a 80
jamesheavey 126:1ac594b5f91a 81 /** Checks if the ball goes past the screen y boundary
jamesheavey 126:1ac594b5f91a 82 * @param &pad @details a Gamepad pointer
jamesheavey 126:1ac594b5f91a 83 */
jamesheavey 81:735e5ee2c92a 84 bool check_loss(Gamepad &pad);
jamesheavey 126:1ac594b5f91a 85
jamesheavey 126:1ac594b5f91a 86 /** Increments the laser index */
jamesheavey 30:e3d2f0ca416f 87 void inc_index();
jamesheavey 126:1ac594b5f91a 88
jamesheavey 126:1ac594b5f91a 89 /** Resets the laser index to 0 */
jamesheavey 30:e3d2f0ca416f 90 void reset_index();
jamesheavey 126:1ac594b5f91a 91
jamesheavey 126:1ac594b5f91a 92 /** Returns the game (and all relevant objects) to initialised state */
jamesheavey 81:735e5ee2c92a 93 void reset_game();
jamesheavey 126:1ac594b5f91a 94
jamesheavey 126:1ac594b5f91a 95 /** Sets the member variable _number_left to 18 */
jamesheavey 60:63d69184ec0a 96 void reset_num_left();
jamesheavey 126:1ac594b5f91a 97
jamesheavey 126:1ac594b5f91a 98 /** Returns the current score to print to LCD in the game
jamesheavey 126:1ac594b5f91a 99 * @return returns _score
jamesheavey 126:1ac594b5f91a 100 */
jamesheavey 64:c3426b417ad9 101 int get_score();
jamesheavey 126:1ac594b5f91a 102
jamesheavey 126:1ac594b5f91a 103 /** Increment the multiplier if continue is selected upon victory */
jamesheavey 62:64559062e0ec 104 void inc_mult();
jamesheavey 126:1ac594b5f91a 105
jamesheavey 126:1ac594b5f91a 106 /** Resets the multiplier to 0
jamesheavey 126:1ac594b5f91a 107 * @return returns _prev_score
jamesheavey 126:1ac594b5f91a 108 */
jamesheavey 109:5ba766522df0 109 void set_mult_zero();
jamesheavey 126:1ac594b5f91a 110
jamesheavey 126:1ac594b5f91a 111 /** Returns the current multiplier value
jamesheavey 126:1ac594b5f91a 112 * @return returns _multiplier
jamesheavey 126:1ac594b5f91a 113 */
jamesheavey 99:d8f1570faa05 114 int get_mult();
jamesheavey 126:1ac594b5f91a 115
jamesheavey 126:1ac594b5f91a 116 /** Sets the paddle motion options for use in game
jamesheavey 126:1ac594b5f91a 117 * @param tilt @details a bool that sets tilt if true and joystick if false
jamesheavey 126:1ac594b5f91a 118 * @param sens @details a float that is derived from the pot, it multiplies the velocity of the paddle
jamesheavey 126:1ac594b5f91a 119 */
jamesheavey 105:4e7585d8e5e2 120 void set_paddle_motion(bool tilt, float sens);
jamesheavey 126:1ac594b5f91a 121
jamesheavey 126:1ac594b5f91a 122 /** Sets the powerup to a random x position on screen if conditions are met */
jamesheavey 119:473cac51ddf0 123 void check_life_powerup();
jamesheavey 126:1ac594b5f91a 124
jamesheavey 126:1ac594b5f91a 125 /** Returns the number of lives remaining
jamesheavey 126:1ac594b5f91a 126 * @return returns the paddle member variable _lives
jamesheavey 126:1ac594b5f91a 127 */
jamesheavey 126:1ac594b5f91a 128 int get_lives();
jamesheavey 126:1ac594b5f91a 129
jamesheavey 126:1ac594b5f91a 130 /** Resets the paddle lives to 6, used to reset the game */
jamesheavey 116:2793d31ca691 131 void reset_paddle_lives();
jamesheavey 123:39740c246fc2 132
jamesheavey 27:1b5038b0a7a2 133 private:
jamesheavey 27:1b5038b0a7a2 134
jamesheavey 126:1ac594b5f91a 135 void check_wall_collisions(Gamepad &pad);
jamesheavey 27:1b5038b0a7a2 136 void check_paddle_collisions(Gamepad &pad);
jamesheavey 27:1b5038b0a7a2 137 void check_brick_collisions(Gamepad &pad);
jamesheavey 36:cb73014d3a99 138 void check_laser_collisions(Gamepad &pad);
jamesheavey 114:280903dd7e06 139 void check_powerup_collisions(Gamepad &pad);
jamesheavey 27:1b5038b0a7a2 140 void print_scores(N5110 &lcd);
jamesheavey 92:2e6d88e44f56 141 void dec_num_left();
jamesheavey 123:39740c246fc2 142
jamesheavey 27:1b5038b0a7a2 143 int _paddle_width;
jamesheavey 27:1b5038b0a7a2 144 int _paddle_height;
jamesheavey 27:1b5038b0a7a2 145 int _ball_size;
jamesheavey 27:1b5038b0a7a2 146 int _speed;
jamesheavey 30:e3d2f0ca416f 147 int _index;
jamesheavey 62:64559062e0ec 148 int _multiplier;
jamesheavey 82:d1341d632890 149 int _paddley;
jamesheavey 27:1b5038b0a7a2 150 int _number_left;
jamesheavey 47:1d1a827be81b 151 int _prev_score;
jamesheavey 64:c3426b417ad9 152 int _score;
jamesheavey 126:1ac594b5f91a 153 double _cool_time;
jamesheavey 126:1ac594b5f91a 154
jamesheavey 27:1b5038b0a7a2 155 Direction _d;
jamesheavey 27:1b5038b0a7a2 156 float _mag;
jamesheavey 123:39740c246fc2 157
jamesheavey 35:3a614d539a54 158 std::list<Laser> listofLasers;
jamesheavey 35:3a614d539a54 159 std::list<Laser>::iterator it_L;
jamesheavey 123:39740c246fc2 160
jamesheavey 27:1b5038b0a7a2 161 std::list<Brick> listofBricks;
jamesheavey 123:39740c246fc2 162 std::list<Brick>::iterator it_R;
jamesheavey 126:1ac594b5f91a 163
jamesheavey 126:1ac594b5f91a 164 Paddle _paddle;
jamesheavey 126:1ac594b5f91a 165
jamesheavey 126:1ac594b5f91a 166 Ball _ball;
jamesheavey 123:39740c246fc2 167
jamesheavey 27:1b5038b0a7a2 168 Brick _brick11;
jamesheavey 27:1b5038b0a7a2 169 Brick _brick12;
jamesheavey 27:1b5038b0a7a2 170 Brick _brick13;
jamesheavey 27:1b5038b0a7a2 171 Brick _brick14;
jamesheavey 27:1b5038b0a7a2 172 Brick _brick15;
jamesheavey 27:1b5038b0a7a2 173 Brick _brick16;
jamesheavey 27:1b5038b0a7a2 174 Brick _brick21;
jamesheavey 27:1b5038b0a7a2 175 Brick _brick22;
jamesheavey 27:1b5038b0a7a2 176 Brick _brick23;
jamesheavey 27:1b5038b0a7a2 177 Brick _brick24;
jamesheavey 27:1b5038b0a7a2 178 Brick _brick25;
jamesheavey 27:1b5038b0a7a2 179 Brick _brick26;
jamesheavey 27:1b5038b0a7a2 180 Brick _brick31;
jamesheavey 27:1b5038b0a7a2 181 Brick _brick32;
jamesheavey 27:1b5038b0a7a2 182 Brick _brick33;
jamesheavey 27:1b5038b0a7a2 183 Brick _brick34;
jamesheavey 27:1b5038b0a7a2 184 Brick _brick35;
jamesheavey 27:1b5038b0a7a2 185 Brick _brick36;
jamesheavey 123:39740c246fc2 186
jamesheavey 30:e3d2f0ca416f 187 Laser _laser1;
jamesheavey 30:e3d2f0ca416f 188 Laser _laser2;
jamesheavey 30:e3d2f0ca416f 189 Laser _laser3;
jamesheavey 123:39740c246fc2 190
jamesheavey 114:280903dd7e06 191 Life_Powerup _powerup;
jamesheavey 27:1b5038b0a7a2 192
jamesheavey 27:1b5038b0a7a2 193 };
jamesheavey 27:1b5038b0a7a2 194
jamesheavey 27:1b5038b0a7a2 195 #endif