Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
BreakoutEngine.h
00001 #ifndef BREAKOUTENGINE_H 00002 #define BREAKOUTENGINE_H 00003 00004 #include "mbed.h" 00005 #include "N5110.h" 00006 #include "Gamepad.h" 00007 #include "Ball.h" 00008 #include "Paddle.h" 00009 #include "Brick.h" 00010 #include "Laser.h" 00011 #include "Life_Powerup.h" 00012 00013 #include <list> 00014 #include <iterator> 00015 #include <ctime> // For time() 00016 #include <cstdlib> // For srand() and rand() 00017 00018 #define GAP_TOP 10 00019 #define GAP 2 00020 00021 /** BreakoutEngine Class 00022 @author James Heavey, University of Leeds 00023 @brief Controls the Breakout game 00024 @date May 2019 00025 */ 00026 00027 class BreakoutEngine 00028 { 00029 00030 public: 00031 00032 /** Constructor declaration */ 00033 BreakoutEngine(); 00034 00035 /** Destructor declaration */ 00036 ~BreakoutEngine(); 00037 00038 /** Initialises game variables 00039 * @param paddle_width @details integer width of paddle 00040 * @param paddle_height @details integer height of paddle 00041 * @param ball_size @details integer diameter of ball in pixels 00042 * @param speed @details integer initial speed of ball 00043 */ 00044 void init(int paddle_width,int paddle_height,int ball_size,int speed); 00045 00046 /** Reads inputs from the Gamepad 00047 * @param pad @details a Gamepad pointer 00048 */ 00049 void read_input(Gamepad &pad); 00050 00051 /** Updates the Game attributes 00052 * @param pad @details a Gamepad pointer 00053 */ 00054 void update(Gamepad &pad); 00055 00056 /** Draws the objects' at their respective coordinates on the LCD 00057 * @param lcd @details a N5110 pointer 00058 */ 00059 void draw(N5110 &lcd); 00060 00061 /** Updates the Gamepad LEDs with lives remaining 00062 * @param pad @details a Gamepad pointer 00063 */ 00064 void lives_leds(Gamepad &pad); 00065 00066 /** Sets the variable _prev_score to current score 00067 * @param prev_score @details the new previous score which is the score achieved at victory 00068 */ 00069 void set_prev_score(int prev_score); 00070 00071 /** Increments the laser index */ 00072 void inc_index(); 00073 00074 /** Resets the laser index to 0 */ 00075 void reset_index(); 00076 00077 /** Returns the game (and all relevant objects) to initialised state */ 00078 void reset_game(); 00079 00080 /** Sets the variable _number_left to 18 */ 00081 void reset_num_left(); 00082 00083 /** Increment the multiplier if continue is selected upon victory */ 00084 void inc_mult(); 00085 00086 /** Resets the multiplier to 0 00087 * @returns _prev_score 00088 */ 00089 void reset_mult(); 00090 00091 /** Sets the paddle motion options for use in game 00092 * @param tilt @details a bool that sets tilt if true and joystick if false 00093 * @param sens @details a float that is derived from the pot, it multiplies the velocity of the paddle 00094 */ 00095 void set_paddle_motion(bool tilt, float sens); 00096 00097 /** Sets the powerup to a random x position on screen if conditions are met */ 00098 void check_life_powerup(); 00099 00100 /** Resets the paddle lives to 6, used to reset the game */ 00101 void reset_paddle_lives(); 00102 00103 /** Decrements the number of bricks left on screen when one is destroyed */ 00104 void dec_num_left(); 00105 00106 /** Returns the number of Bricks remaining on screen 00107 * @returns _number_left 00108 */ 00109 int get_num_left(); 00110 00111 /** Returns the score achieved on victory in the previous iteration of the game 00112 * @returns _prev_score 00113 */ 00114 int get_prev_score(); 00115 00116 /** Returns the number of lives remaining 00117 * @returns the paddle variable _lives 00118 */ 00119 int get_paddle_lives(); 00120 00121 /** Returns the current multiplier value 00122 * @returns _multiplier 00123 */ 00124 int get_mult(); 00125 00126 /** Checks if the ball goes past the screen y boundary 00127 * @param pad @details a Gamepad pointer 00128 * @returns a bool; true if ball is off screen, false 00129 */ 00130 bool check_loss(Gamepad &pad); 00131 00132 /** Returns the current score to print to LCD in the game 00133 * @returns _score 00134 */ 00135 int get_score(); 00136 00137 private: 00138 00139 void check_wall_collisions(Gamepad &pad); 00140 void check_paddle_collisions(Gamepad &pad); 00141 void check_brick_collisions(Gamepad &pad); 00142 void check_laser_collisions(Gamepad &pad); 00143 void check_powerup_collisions(Gamepad &pad); 00144 void print_scores(N5110 &lcd); 00145 00146 int _paddle_width; 00147 int _paddle_height; 00148 int _ball_size; 00149 int _speed; 00150 int _index; 00151 int _multiplier; 00152 int _paddley; 00153 int _number_left; 00154 int _prev_score; 00155 int _score; 00156 double _cool_time; 00157 00158 Direction _d; 00159 float _mag; 00160 00161 std::list<Laser> listofLasers; 00162 std::list<Laser>::iterator it_L; 00163 00164 std::list<Brick> listofBricks; 00165 std::list<Brick>::iterator it_R; 00166 00167 Paddle _paddle; 00168 00169 Ball _ball; 00170 00171 Brick _brick11; 00172 Brick _brick12; 00173 Brick _brick13; 00174 Brick _brick14; 00175 Brick _brick15; 00176 Brick _brick16; 00177 Brick _brick21; 00178 Brick _brick22; 00179 Brick _brick23; 00180 Brick _brick24; 00181 Brick _brick25; 00182 Brick _brick26; 00183 Brick _brick31; 00184 Brick _brick32; 00185 Brick _brick33; 00186 Brick _brick34; 00187 Brick _brick35; 00188 Brick _brick36; 00189 00190 Laser _laser1; 00191 Laser _laser2; 00192 Laser _laser3; 00193 00194 Life_Powerup _powerup; 00195 00196 }; 00197 00198 #endif
Generated on Wed Jul 13 2022 09:05:52 by
1.7.2