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.
Dependencies: mbed MotionSensor
Player.h
00001 #ifndef PLAYER_H 00002 #define PLAYER_H 00003 #include "Entity.h" 00004 #include "Bullets.h" 00005 #define INVULNERABILITY_PERIOD 50 00006 00007 const int bullets_max = 20; 00008 /**Player Class 00009 @author Steven Mahasin 00010 @brief Creates a Player which inherits the Entity class, contains functions that accepts all user interractions (buttons, joystick, etc) 00011 @date May 2019 00012 */ 00013 class Player : public Entity 00014 { 00015 private: 00016 00017 // Member Variables 00018 /** 00019 * @brief a counter that increments to give a delay to the fire rate of player 00020 */ 00021 int _fire_rate_counter; 00022 /** 00023 * @brief a delay between each shot 00024 */ 00025 int _fire_rate_delay; 00026 /** 00027 * @brief the speed of the bullets created by this player 00028 */ 00029 int _bullet_speed; 00030 /** 00031 * @brief a counter that increments, allowing player to be invulnerable to a certain period defined 00032 */ 00033 int _invulnerability_counter; 00034 00035 // Private Functions 00036 /** 00037 * @brief movement of the player 00038 * @param mapped_x @details joystick x 00039 * @param mapped_y @details joystick y 00040 * @param map @details the 2d map array that dictates where there are walls or empty space 00041 * @param doorways @details an array that dictates which side of the wall has a doorway 00042 */ 00043 void move_player(float mapped_x, float mapped_y, char * map, bool * doorways); 00044 /** 00045 * @brief movement of the bullets shot by this player 00046 */ 00047 void move_bullets(); 00048 /** 00049 * @brief to increment the _frame protected variable, for animation of player 00050 * @param mapped_x @details joystick x 00051 * @param mapped_y @details joystick y 00052 */ 00053 void increment_frames(float mapped_x, float mapped_y); 00054 /** 00055 * @brief getting the needed frame of animation of player 00056 * @return char pointer array to the corresponding player frame 00057 */ 00058 char * get_frame(); 00059 /** 00060 * @brief draws the player onto the screen 00061 * @param lcd @details the screen the player is drawn onto 00062 */ 00063 void draw_player(N5110 &lcd); 00064 00065 public: 00066 /** Constructor 00067 * @brief creates a player at positions pos_x and pos_y 00068 * @param pos_x @details initialise _position.x 00069 * @param pos_y @details initialise _position.y 00070 */ 00071 Player(float pos_x, float pos_y); 00072 /** Deconstructors */ 00073 ~Player(); 00074 00075 // Accessors 00076 /** 00077 * @brief getting the player's bullet speed 00078 * @return _bullet_speed 00079 */ 00080 int get_bullet_speed(); 00081 /** 00082 * @brief getting the heart sprite's width 00083 * @return width of the heart sprite 00084 */ 00085 int get_hearts_width(); 00086 /** 00087 * @brief getting the heart sprite's height 00088 * @return height of the heart sprite 00089 */ 00090 int get_hearts_height(); 00091 /** 00092 * @brief getting the heart sprite char array 00093 * @return char pointer array to the heart sprite 00094 */ 00095 char * get_hearts_sprite(); 00096 00097 // Functions 00098 /** 00099 * @brief function calls both movement of player and movement of bullets 00100 * @param x_value @details joystick x 00101 * @param y_value @details joystick y 00102 * @param map @details the 2d map array that dictates where there are walls or empty space 00103 * @param doorways @details an array that dictates which side of the wall has a doorway 00104 */ 00105 virtual void move(float x_value, float y_value, char * map, bool * doorways); 00106 /** 00107 * @brief reduce _hp by damage 00108 * @param damage @details the amount of damage to be taken 00109 */ 00110 virtual void take_damage(int damage); 00111 /** 00112 * @brief a virtual function of drawing the player onto the screen 00113 * @param lcd @details the screen where the player is drawn on 00114 */ 00115 virtual void draw(N5110 &lcd); 00116 /** 00117 * @brief a virtual function of drawing the bullets the player shot onto the screen if j is the correct y-position of the bullets 00118 * @param lcd @details the screen where the bullets is drawn on 00119 * @param j @details which y-position hitboxes are currently being printed 00120 */ 00121 void draw_bullets(N5110 &lcd, int j); 00122 /** 00123 * @brief attempts to delete any bullets that goes out of bounds (out of screen or onto a wall) 00124 * @param map @details the 2d map array that dictates where there are walls or empty space 00125 * @param doorawys @details an array that dictates which side of the wall has a doorway 00126 * @return true if any bullets is successfully deleted 00127 */ 00128 bool delete_out_of_bounds_bullets(char * map, bool * doorways); 00129 /** 00130 * @brief deletes any existing bullets 00131 */ 00132 void delete_bullets(); 00133 /** 00134 * @brief shoots bullets at the direction of the buttons 00135 * @param button_A @details button down 00136 * @param button_B @details button right 00137 * @param button_Y @details button up 00138 * @param button_X @details button left 00139 */ 00140 void buttons(bool button_A, bool button_B, bool button_Y, bool button_X); 00141 00142 // Variables 00143 /** 00144 * @brief a bullets pointer array that holds all the possible bullets the player can shoot 00145 */ 00146 Bullets *bullets_array[bullets_max]; 00147 /** 00148 * @brief a boolean array that dictates which bullets in the bullets array exist 00149 */ 00150 bool valid_bullets[bullets_max]; 00151 00152 }; 00153 00154 // Sprite 00155 const char sprite_heart[9][9] = { 00156 {0,1,1,0,0,0,1,1,0,}, 00157 {1,1,1,1,0,1,1,1,1,}, 00158 {1,2,1,1,1,1,1,1,1,}, 00159 {1,2,1,1,1,1,1,1,1,}, 00160 {1,2,1,1,1,1,1,1,1,}, 00161 {0,1,2,1,1,1,1,1,0,}, 00162 {0,0,1,1,1,1,1,0,0,}, 00163 {0,0,0,1,1,1,0,0,0,}, 00164 {0,0,0,0,1,0,0,0,0,} 00165 }; 00166 00167 const char sprite_dying_player [5][12][12] = { // sprite_dying_player [Frame][Size_Y][Size_X] 00168 { 00169 {0,1,1,1,1,0,0,0,0,0,0,0,}, 00170 {1,1,1,1,1,1,0,0,0,0,0,0,}, 00171 {1,2,1,1,1,1,0,0,0,0,0,0,}, 00172 {1,1,1,1,1,1,0,0,0,0,0,0,}, 00173 {0,1,1,1,1,0,0,0,0,0,0,0,}, 00174 {0,0,1,1,0,0,0,0,0,0,0,0,}, 00175 {0,0,1,1,0,0,0,0,0,0,0,0,}, 00176 {0,0,1,1,0,0,0,0,0,0,0,0,}, 00177 {0,0,1,1,0,0,0,0,0,0,0,0,}, 00178 {0,0,0,1,0,0,0,0,0,0,0,0,}, 00179 {0,0,0,1,0,0,0,0,0,0,0,0,}, 00180 {0,0,1,1,0,0,0,0,0,0,0,0,}, 00181 }, 00182 { 00183 {0,0,0,0,1,1,1,0,0,0,0,0,}, 00184 {0,0,0,1,2,1,1,1,0,0,0,0,}, 00185 {0,0,0,1,1,1,1,1,0,0,0,0,}, 00186 {0,0,0,1,1,1,1,1,0,0,0,0,}, 00187 {0,0,0,0,1,1,1,0,0,0,0,0,}, 00188 {0,1,1,1,1,0,0,0,0,0,0,0,}, 00189 {0,0,1,1,1,0,0,0,0,0,0,0,}, 00190 {0,0,1,1,0,0,0,0,0,0,0,0,}, 00191 {0,1,1,1,0,0,0,0,0,0,0,0,}, 00192 {0,1,0,1,0,0,0,0,0,0,0,0,}, 00193 {1,0,0,1,0,0,0,0,0,0,0,0,}, 00194 {0,0,1,1,0,0,0,0,0,0,0,0,}, 00195 }, 00196 { 00197 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00198 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00199 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00200 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00201 {0,0,0,0,1,0,0,0,1,1,1,0,}, 00202 {0,0,0,0,0,1,0,1,1,2,1,1,}, 00203 {0,0,0,0,0,1,1,1,1,1,1,1,}, 00204 {0,0,0,1,1,1,1,1,1,1,1,1,}, 00205 {0,1,1,1,1,1,1,0,1,1,1,0,}, 00206 {1,0,0,1,1,0,0,0,0,0,0,0,}, 00207 {0,0,1,0,0,0,0,0,0,0,0,0,}, 00208 {0,1,0,0,0,0,0,0,0,0,0,0,}, 00209 }, 00210 { 00211 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00212 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00213 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00214 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00215 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00216 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00217 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00218 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00219 {1,0,0,0,1,0,0,0,1,1,1,0,}, 00220 {0,1,1,0,0,1,1,1,1,2,1,1,}, 00221 {1,0,0,1,1,1,1,1,1,1,1,1,}, 00222 {1,1,1,1,1,1,1,1,1,1,1,1,}, 00223 }, 00224 { 00225 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00226 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00227 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00228 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00229 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00230 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00231 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00232 {0,0,0,0,0,0,0,0,0,0,0,0,}, 00233 {0,0,0,0,0,0,0,0,1,1,1,0,}, 00234 {0,0,0,0,0,0,0,1,1,1,1,1,}, 00235 {1,0,0,1,1,1,1,1,1,1,1,1,}, 00236 {1,1,1,1,1,1,1,1,1,1,1,1,}, 00237 } 00238 }; 00239 00240 00241 const char sprite_transparent_player[12][6] = { 00242 {0,0,0,0,0,0,}, 00243 {0,0,0,0,0,0,}, 00244 {0,0,0,0,0,0,}, 00245 {0,0,0,0,0,0,}, 00246 {0,0,0,0,0,0,}, 00247 {0,0,0,0,0,0,}, 00248 {0,0,0,0,0,0,}, 00249 {0,0,0,0,0,0,}, 00250 {0,0,0,0,0,0,}, 00251 {0,0,0,0,0,0,}, 00252 {0,0,0,0,0,0,}, 00253 {0,0,0,0,0,0,} 00254 }; 00255 00256 const char sprite_player [4][4][12][6] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X] 00257 { 00258 // Up 00259 { 00260 {0,1,1,1,1,0,}, 00261 {1,1,1,1,1,1,}, 00262 {1,1,1,1,1,1,}, 00263 {1,1,1,1,1,1,}, 00264 {0,1,1,1,1,0,}, 00265 {0,0,1,1,0,0,}, 00266 {0,1,1,1,1,0,}, 00267 {1,0,1,1,0,1,}, 00268 {1,0,1,1,0,1,}, 00269 {0,0,1,1,0,0,}, 00270 {0,1,0,0,1,0,}, 00271 {0,1,0,0,1,0,} 00272 }, 00273 { 00274 {0,1,1,1,1,0,}, 00275 {1,1,1,1,1,1,}, 00276 {1,1,1,1,1,1,}, 00277 {1,1,1,1,1,1,}, 00278 {0,1,1,1,1,0,}, 00279 {0,0,1,1,0,0,}, 00280 {0,1,1,1,1,0,}, 00281 {1,0,1,1,0,1,}, 00282 {0,0,1,1,0,1,}, 00283 {0,0,1,1,0,0,}, 00284 {0,1,0,0,1,0,}, 00285 {0,1,0,0,0,0,} 00286 }, 00287 { 00288 {0,1,1,1,1,0,}, 00289 {1,1,1,1,1,1,}, 00290 {1,1,1,1,1,1,}, 00291 {1,1,1,1,1,1,}, 00292 {0,1,1,1,1,0,}, 00293 {0,0,1,1,0,0,}, 00294 {0,1,1,1,1,0,}, 00295 {1,0,1,1,0,1,}, 00296 {1,0,1,1,0,1,}, 00297 {0,0,1,1,0,0,}, 00298 {0,1,0,0,1,0,}, 00299 {0,1,0,0,1,0,} 00300 }, 00301 { 00302 {0,1,1,1,1,0,}, 00303 {1,1,1,1,1,1,}, 00304 {1,1,1,1,1,1,}, 00305 {1,1,1,1,1,1,}, 00306 {0,1,1,1,1,0,}, 00307 {0,0,1,1,0,0,}, 00308 {0,1,1,1,1,0,}, 00309 {1,0,1,1,0,1,}, 00310 {1,0,1,1,0,0,}, 00311 {0,0,1,1,0,0,}, 00312 {0,1,0,0,1,0,}, 00313 {0,0,0,0,1,0,} 00314 } 00315 }, 00316 { 00317 // Right 00318 { 00319 {0,1,1,1,1,0,}, 00320 {1,1,1,1,1,1,}, 00321 {1,1,1,1,2,1,}, 00322 {1,1,1,1,1,1,}, 00323 {0,1,1,1,1,0,}, 00324 {0,0,1,1,0,0,}, 00325 {0,0,1,1,0,0,}, 00326 {0,0,1,1,0,0,}, 00327 {0,0,1,1,0,0,}, 00328 {0,0,1,0,0,0,}, 00329 {0,0,1,0,0,0,}, 00330 {0,0,1,1,0,0,} 00331 }, 00332 { 00333 {0,1,1,1,1,0,}, 00334 {1,1,1,1,1,1,}, 00335 {1,1,1,1,2,1,}, 00336 {1,1,1,1,1,1,}, 00337 {0,1,1,1,1,0,}, 00338 {0,0,1,1,0,0,}, 00339 {0,0,1,1,0,0,}, 00340 {0,0,1,1,0,0,}, 00341 {0,0,1,1,0,0,}, 00342 {0,0,1,0,1,0,}, 00343 {0,1,0,0,1,0,}, 00344 {0,1,0,0,0,1,} 00345 }, 00346 { 00347 {0,1,1,1,1,0,}, 00348 {1,1,1,1,1,1,}, 00349 {1,1,1,1,2,1,}, 00350 {1,1,1,1,1,1,}, 00351 {0,1,1,1,1,0,}, 00352 {0,0,1,1,0,0,}, 00353 {0,0,1,1,0,0,}, 00354 {0,0,1,1,0,0,}, 00355 {0,0,1,1,0,0,}, 00356 {0,0,1,0,0,0,}, 00357 {0,0,1,0,0,0,}, 00358 {0,0,1,1,0,0,} 00359 }, 00360 { 00361 {0,1,1,1,1,0,}, 00362 {1,1,1,1,1,1,}, 00363 {1,1,1,1,2,1,}, 00364 {1,1,1,1,1,1,}, 00365 {0,1,1,1,1,0,}, 00366 {0,0,1,1,0,0,}, 00367 {0,0,1,1,0,0,}, 00368 {0,0,1,1,0,0,}, 00369 {0,0,1,1,0,0,}, 00370 {0,0,1,0,1,0,}, 00371 {0,1,0,0,1,0,}, 00372 {0,1,0,0,0,1,} 00373 } 00374 }, 00375 { 00376 // Down 00377 { 00378 {0,1,1,1,1,0,}, 00379 {1,1,1,1,1,1,}, 00380 {1,2,1,1,2,1,}, 00381 {1,1,2,2,1,1,}, 00382 {0,1,1,1,1,0,}, 00383 {0,0,1,1,0,0,}, 00384 {0,1,1,1,1,0,}, 00385 {1,0,1,1,0,1,}, 00386 {1,0,1,1,0,1,}, 00387 {0,0,1,1,0,0,}, 00388 {0,1,0,0,1,0,}, 00389 {0,1,0,0,1,0,} 00390 }, 00391 { 00392 {0,1,1,1,1,0,}, 00393 {1,1,1,1,1,1,}, 00394 {1,2,1,1,2,1,}, 00395 {1,1,2,2,1,1,}, 00396 {0,1,1,1,1,0,}, 00397 {0,0,1,1,0,0,}, 00398 {0,1,1,1,1,0,}, 00399 {1,0,1,1,0,1,}, 00400 {0,0,1,1,0,1,}, 00401 {0,0,1,1,0,0,}, 00402 {0,1,0,0,1,0,}, 00403 {0,1,0,0,0,0,} 00404 }, 00405 { 00406 {0,1,1,1,1,0,}, 00407 {1,1,1,1,1,1,}, 00408 {1,2,1,1,2,1,}, 00409 {1,1,2,2,1,1,}, 00410 {0,1,1,1,1,0,}, 00411 {0,0,1,1,0,0,}, 00412 {0,1,1,1,1,0,}, 00413 {1,0,1,1,0,1,}, 00414 {1,0,1,1,0,1,}, 00415 {0,0,1,1,0,0,}, 00416 {0,1,0,0,1,0,}, 00417 {0,1,0,0,1,0,} 00418 }, 00419 { 00420 {0,1,1,1,1,0,}, 00421 {1,1,1,1,1,1,}, 00422 {1,2,1,1,2,1,}, 00423 {1,1,2,2,1,1,}, 00424 {0,1,1,1,1,0,}, 00425 {0,0,1,1,0,0,}, 00426 {0,1,1,1,1,0,}, 00427 {1,0,1,1,0,1,}, 00428 {1,0,1,1,0,0,}, 00429 {0,0,1,1,0,0,}, 00430 {0,1,0,0,1,0,}, 00431 {0,0,0,0,1,0,} 00432 } 00433 }, 00434 { 00435 // Left 00436 { 00437 {0,1,1,1,1,0,}, 00438 {1,1,1,1,1,1,}, 00439 {1,2,1,1,1,1,}, 00440 {1,1,1,1,1,1,}, 00441 {0,1,1,1,1,0,}, 00442 {0,0,1,1,0,0,}, 00443 {0,0,1,1,0,0,}, 00444 {0,0,1,1,0,0,}, 00445 {0,0,1,1,0,0,}, 00446 {0,0,0,1,0,0,}, 00447 {0,0,0,1,0,0,}, 00448 {0,0,1,1,0,0,} 00449 }, 00450 { 00451 {0,1,1,1,1,0,}, 00452 {1,1,1,1,1,1,}, 00453 {1,2,1,1,1,1,}, 00454 {1,1,1,1,1,1,}, 00455 {0,1,1,1,1,0,}, 00456 {0,0,1,1,0,0,}, 00457 {0,0,1,1,0,0,}, 00458 {0,0,1,1,0,0,}, 00459 {0,0,1,1,0,0,}, 00460 {0,1,0,1,0,0,}, 00461 {0,1,0,0,1,0,}, 00462 {1,0,0,0,1,0,} 00463 }, 00464 { 00465 {0,1,1,1,1,0,}, 00466 {1,1,1,1,1,1,}, 00467 {1,2,1,1,1,1,}, 00468 {1,1,1,1,1,1,}, 00469 {0,1,1,1,1,0,}, 00470 {0,0,1,1,0,0,}, 00471 {0,0,1,1,0,0,}, 00472 {0,0,1,1,0,0,}, 00473 {0,0,1,1,0,0,}, 00474 {0,0,0,1,0,0,}, 00475 {0,0,0,1,0,0,}, 00476 {0,0,1,1,0,0,} 00477 }, 00478 { 00479 {0,1,1,1,1,0,}, 00480 {1,1,1,1,1,1,}, 00481 {1,2,1,1,1,1,}, 00482 {1,1,1,1,1,1,}, 00483 {0,1,1,1,1,0,}, 00484 {0,0,1,1,0,0,}, 00485 {0,0,1,1,0,0,}, 00486 {0,0,1,1,0,0,}, 00487 {0,0,1,1,0,0,}, 00488 {0,1,0,1,0,0,}, 00489 {0,1,0,0,1,0,}, 00490 {1,0,0,0,1,0,} 00491 } 00492 } 00493 }; 00494 00495 #endif
Generated on Tue Jul 19 2022 23:32:07 by
1.7.2