James Heavey / Mbed 2 deprecated EL17JH

Dependencies:   mbed

Committer:
jamesheavey
Date:
Wed May 08 23:35:45 2019 +0000
Revision:
130:46f3fac2bdf9
Parent:
129:b47c28c7eaaf
Child:
131:c227bbfb38b0
doxy update

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 130:46f3fac2bdf9 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 130:46f3fac2bdf9 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 130:46f3fac2bdf9 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 130:46f3fac2bdf9 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 /** Sets the member variable _prev_score to current score
jamesheavey 126:1ac594b5f91a 67 * @param prev_score @details the new previous score which is the score achieved at victory
jamesheavey 126:1ac594b5f91a 68 */
jamesheavey 64:c3426b417ad9 69 void set_prev_score(int prev_score);
jamesheavey 126:1ac594b5f91a 70
jamesheavey 126:1ac594b5f91a 71 /** Increments the laser index */
jamesheavey 30:e3d2f0ca416f 72 void inc_index();
jamesheavey 126:1ac594b5f91a 73
jamesheavey 126:1ac594b5f91a 74 /** Resets the laser index to 0 */
jamesheavey 30:e3d2f0ca416f 75 void reset_index();
jamesheavey 126:1ac594b5f91a 76
jamesheavey 126:1ac594b5f91a 77 /** Returns the game (and all relevant objects) to initialised state */
jamesheavey 81:735e5ee2c92a 78 void reset_game();
jamesheavey 126:1ac594b5f91a 79
jamesheavey 126:1ac594b5f91a 80 /** Sets the member variable _number_left to 18 */
jamesheavey 60:63d69184ec0a 81 void reset_num_left();
jamesheavey 126:1ac594b5f91a 82
jamesheavey 126:1ac594b5f91a 83 /** Increment the multiplier if continue is selected upon victory */
jamesheavey 62:64559062e0ec 84 void inc_mult();
jamesheavey 126:1ac594b5f91a 85
jamesheavey 126:1ac594b5f91a 86 /** Resets the multiplier to 0
jamesheavey 126:1ac594b5f91a 87 * @return returns _prev_score
jamesheavey 126:1ac594b5f91a 88 */
jamesheavey 109:5ba766522df0 89 void set_mult_zero();
jamesheavey 126:1ac594b5f91a 90
jamesheavey 126:1ac594b5f91a 91 /** Sets the paddle motion options for use in game
jamesheavey 126:1ac594b5f91a 92 * @param tilt @details a bool that sets tilt if true and joystick if false
jamesheavey 126:1ac594b5f91a 93 * @param sens @details a float that is derived from the pot, it multiplies the velocity of the paddle
jamesheavey 126:1ac594b5f91a 94 */
jamesheavey 105:4e7585d8e5e2 95 void set_paddle_motion(bool tilt, float sens);
jamesheavey 126:1ac594b5f91a 96
jamesheavey 126:1ac594b5f91a 97 /** Sets the powerup to a random x position on screen if conditions are met */
jamesheavey 119:473cac51ddf0 98 void check_life_powerup();
jamesheavey 126:1ac594b5f91a 99
jamesheavey 129:b47c28c7eaaf 100 /** Resets the paddle lives to 6, used to reset the game */
jamesheavey 129:b47c28c7eaaf 101 void reset_paddle_lives();
jamesheavey 129:b47c28c7eaaf 102
jamesheavey 129:b47c28c7eaaf 103 /** Decrements the number of bricks left on screen when one is destroyed */
jamesheavey 129:b47c28c7eaaf 104 void dec_num_left();
jamesheavey 129:b47c28c7eaaf 105
jamesheavey 129:b47c28c7eaaf 106 /** Returns the number of Bricks remaining on screen
jamesheavey 129:b47c28c7eaaf 107 * @return returns _number_left
jamesheavey 129:b47c28c7eaaf 108 */
jamesheavey 129:b47c28c7eaaf 109 int get_num_left();
jamesheavey 129:b47c28c7eaaf 110
jamesheavey 129:b47c28c7eaaf 111 /** Returns the score achieved on victory in the previous iteration of the game
jamesheavey 129:b47c28c7eaaf 112 * @return returns _prev_score
jamesheavey 129:b47c28c7eaaf 113 */
jamesheavey 129:b47c28c7eaaf 114 int get_prev_score();
jamesheavey 129:b47c28c7eaaf 115
jamesheavey 126:1ac594b5f91a 116 /** Returns the number of lives remaining
jamesheavey 126:1ac594b5f91a 117 * @return returns the paddle member variable _lives
jamesheavey 126:1ac594b5f91a 118 */
jamesheavey 126:1ac594b5f91a 119 int get_lives();
jamesheavey 126:1ac594b5f91a 120
jamesheavey 129:b47c28c7eaaf 121 /** Returns the current multiplier value
jamesheavey 129:b47c28c7eaaf 122 * @return returns _multiplier
jamesheavey 129:b47c28c7eaaf 123 */
jamesheavey 129:b47c28c7eaaf 124 int get_mult();
jamesheavey 129:b47c28c7eaaf 125
jamesheavey 129:b47c28c7eaaf 126 /** Checks if the ball goes past the screen y boundary
jamesheavey 130:46f3fac2bdf9 127 * @param pad @details a Gamepad pointer
jamesheavey 129:b47c28c7eaaf 128 */
jamesheavey 129:b47c28c7eaaf 129 bool check_loss(Gamepad &pad);
jamesheavey 129:b47c28c7eaaf 130
jamesheavey 129:b47c28c7eaaf 131 /** Returns the current score to print to LCD in the game
jamesheavey 129:b47c28c7eaaf 132 * @return returns _score
jamesheavey 129:b47c28c7eaaf 133 */
jamesheavey 129:b47c28c7eaaf 134 int get_score();
jamesheavey 123:39740c246fc2 135
jamesheavey 27:1b5038b0a7a2 136 private:
jamesheavey 27:1b5038b0a7a2 137
jamesheavey 126:1ac594b5f91a 138 void check_wall_collisions(Gamepad &pad);
jamesheavey 27:1b5038b0a7a2 139 void check_paddle_collisions(Gamepad &pad);
jamesheavey 27:1b5038b0a7a2 140 void check_brick_collisions(Gamepad &pad);
jamesheavey 36:cb73014d3a99 141 void check_laser_collisions(Gamepad &pad);
jamesheavey 114:280903dd7e06 142 void check_powerup_collisions(Gamepad &pad);
jamesheavey 27:1b5038b0a7a2 143 void print_scores(N5110 &lcd);
jamesheavey 123:39740c246fc2 144
jamesheavey 27:1b5038b0a7a2 145 int _paddle_width;
jamesheavey 27:1b5038b0a7a2 146 int _paddle_height;
jamesheavey 27:1b5038b0a7a2 147 int _ball_size;
jamesheavey 27:1b5038b0a7a2 148 int _speed;
jamesheavey 30:e3d2f0ca416f 149 int _index;
jamesheavey 62:64559062e0ec 150 int _multiplier;
jamesheavey 82:d1341d632890 151 int _paddley;
jamesheavey 27:1b5038b0a7a2 152 int _number_left;
jamesheavey 47:1d1a827be81b 153 int _prev_score;
jamesheavey 64:c3426b417ad9 154 int _score;
jamesheavey 126:1ac594b5f91a 155 double _cool_time;
jamesheavey 126:1ac594b5f91a 156
jamesheavey 27:1b5038b0a7a2 157 Direction _d;
jamesheavey 27:1b5038b0a7a2 158 float _mag;
jamesheavey 123:39740c246fc2 159
jamesheavey 35:3a614d539a54 160 std::list<Laser> listofLasers;
jamesheavey 35:3a614d539a54 161 std::list<Laser>::iterator it_L;
jamesheavey 123:39740c246fc2 162
jamesheavey 27:1b5038b0a7a2 163 std::list<Brick> listofBricks;
jamesheavey 123:39740c246fc2 164 std::list<Brick>::iterator it_R;
jamesheavey 126:1ac594b5f91a 165
jamesheavey 126:1ac594b5f91a 166 Paddle _paddle;
jamesheavey 126:1ac594b5f91a 167
jamesheavey 126:1ac594b5f91a 168 Ball _ball;
jamesheavey 123:39740c246fc2 169
jamesheavey 27:1b5038b0a7a2 170 Brick _brick11;
jamesheavey 27:1b5038b0a7a2 171 Brick _brick12;
jamesheavey 27:1b5038b0a7a2 172 Brick _brick13;
jamesheavey 27:1b5038b0a7a2 173 Brick _brick14;
jamesheavey 27:1b5038b0a7a2 174 Brick _brick15;
jamesheavey 27:1b5038b0a7a2 175 Brick _brick16;
jamesheavey 27:1b5038b0a7a2 176 Brick _brick21;
jamesheavey 27:1b5038b0a7a2 177 Brick _brick22;
jamesheavey 27:1b5038b0a7a2 178 Brick _brick23;
jamesheavey 27:1b5038b0a7a2 179 Brick _brick24;
jamesheavey 27:1b5038b0a7a2 180 Brick _brick25;
jamesheavey 27:1b5038b0a7a2 181 Brick _brick26;
jamesheavey 27:1b5038b0a7a2 182 Brick _brick31;
jamesheavey 27:1b5038b0a7a2 183 Brick _brick32;
jamesheavey 27:1b5038b0a7a2 184 Brick _brick33;
jamesheavey 27:1b5038b0a7a2 185 Brick _brick34;
jamesheavey 27:1b5038b0a7a2 186 Brick _brick35;
jamesheavey 27:1b5038b0a7a2 187 Brick _brick36;
jamesheavey 123:39740c246fc2 188
jamesheavey 30:e3d2f0ca416f 189 Laser _laser1;
jamesheavey 30:e3d2f0ca416f 190 Laser _laser2;
jamesheavey 30:e3d2f0ca416f 191 Laser _laser3;
jamesheavey 123:39740c246fc2 192
jamesheavey 114:280903dd7e06 193 Life_Powerup _powerup;
jamesheavey 27:1b5038b0a7a2 194
jamesheavey 27:1b5038b0a7a2 195 };
jamesheavey 27:1b5038b0a7a2 196
jamesheavey 27:1b5038b0a7a2 197 #endif