A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
Snake.h
00001 #ifndef SNAKE_H 00002 #define SNAKE_H 00003 #include "Entity.h" 00004 00005 /**Snake Class 00006 @author Steven Mahasin 00007 @brief Creates a Snake which inherits the Entity class, this is one of the mobs that spawns in the normal rooms. 00008 @date May 2019 00009 */ 00010 class Snake : public Entity 00011 { 00012 00013 public: 00014 /** Constructor 00015 * @brief creates a snake at positions pos_x and pos_y 00016 * @param pos_x @details initialise _position.x 00017 * @param pos_y @details initialise _position.y 00018 */ 00019 Snake(float pos_x, float pos_y); 00020 00021 // Functions 00022 /** 00023 * @brief calls the movement functions to move the snake in the desired way 00024 * @param x_value @details player's x-position 00025 * @param y_value @details player's y-position 00026 * @param map @details the 2d map array that dictates where there are walls or empty space 00027 * @param doorways @details an array that dictates which side of the wall has a doorway 00028 */ 00029 virtual void move(float x_value, float y_value, char * map, bool * doorways); 00030 /** 00031 * @brief reduce hp by damage 00032 * @param damage @details the amount of damage to be taken 00033 */ 00034 virtual void take_damage(int damage); 00035 /** 00036 * @brief a virtual function of drawing the snake onto the screen 00037 * @param lcd @details the screen where the snake is drawn on 00038 */ 00039 virtual void draw(N5110 &lcd); 00040 00041 private: 00042 // Member Function 00043 /** 00044 * @brief updates _prev_face into _face 00045 */ 00046 void update_prev_face(); 00047 /** 00048 * @brief gets the sprite array 00049 * @return char pointer array of the corresponding snake sprite frame 00050 */ 00051 char * get_frame(); 00052 /** 00053 * @brief changes the face everytime the snake finish slithering, towards the player 00054 * @param diff_x @details the difference between the player x-position and the snake x-position 00055 * @param diff_y @details the difference between the player y-position and the snake y-position 00056 */ 00057 void update_face(float diff_x, float diff_y); 00058 /** 00059 * @brief function moves the snake in a slither effect 00060 */ 00061 void move_snake(); 00062 /** 00063 * @brief increase _frame.count which increases _frame.number to animate snake 00064 */ 00065 void increment_frame(); 00066 00067 // Member Mutator 00068 /** 00069 * @brief updates the hitbox status and sprite status of the snake since different face has unique hitbox and sprite status 00070 * @param _hitbox_width @details the width of the hitbox 00071 * @param _hitbox_height @details the height of the hitbox 00072 * @param _sprite_size_width @details the width of the sprite 00073 * @param _sprite_size_height @details the height of the sprite 00074 * @param _sprite_size_offset_x @details the x-offset of the sprite to the hitbox 00075 * @param _sprite_size_offset_y @details the y-offset of the sprite to the hitbox 00076 * @param max_frame @details the maximum number of frames for animation 00077 */ 00078 void update_hitbox(int _hitbox_width, int _hitbox_height, int _sprite_size_width, int _sprite_size_height, int _sprite_size_offset_x, int _sprite_size_offset_y, int max_frame); 00079 00080 // Member Variable 00081 /** 00082 * @brief an index to choose which velocity the snake currently has, this is to add the slither effect 00083 */ 00084 int _velocity_index; 00085 /** 00086 * @brief the previous face of the snake, to detect change in snake's face 00087 */ 00088 int _prev_face; 00089 00090 }; 00091 00092 const float snake_velocity_pattern[6] = {0, 0.15, 0.25, 0.5, 0.1, -0.1}; 00093 00094 const char sprite_snake_x[2][4][7][12] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X] 00095 { 00096 // Right 00097 { 00098 {0,0,0,0,0,0,0,0,1,1,1,0,}, 00099 {0,0,0,0,0,0,0,1,1,1,2,1,}, 00100 {0,0,0,0,0,0,0,1,1,1,1,1,}, 00101 {0,0,0,0,0,0,0,1,1,1,0,0,}, 00102 {0,0,0,0,0,0,0,0,1,1,1,0,}, 00103 {0,0,1,1,1,1,0,1,1,1,1,0,}, 00104 {1,1,1,0,1,1,1,1,1,1,0,0,}, 00105 }, 00106 { 00107 {0,0,0,0,0,0,0,0,1,1,1,0,}, 00108 {0,0,0,0,0,0,0,1,1,1,2,1,}, 00109 {0,0,0,0,0,0,0,1,1,1,1,1,}, 00110 {0,0,0,0,0,0,0,1,1,1,0,0,}, 00111 {0,0,0,0,0,0,0,0,1,1,1,0,}, 00112 {0,1,1,1,1,0,1,1,1,1,1,0,}, 00113 {1,0,0,1,1,1,1,1,1,1,0,0,}, 00114 }, 00115 { 00116 {0,0,0,0,0,0,0,0,1,1,1,0,}, 00117 {0,0,0,0,0,0,0,1,1,1,2,1,}, 00118 {0,0,0,0,0,0,0,1,1,1,1,1,}, 00119 {0,0,0,0,0,0,0,1,1,1,0,0,}, 00120 {1,0,0,0,0,0,0,0,1,1,1,0,}, 00121 {0,1,0,0,1,1,1,1,1,1,1,0,}, 00122 {0,0,1,1,1,0,1,1,1,1,0,0,}, 00123 }, 00124 { 00125 {0,0,0,0,0,0,0,0,1,1,1,0,}, 00126 {0,0,0,0,0,0,0,1,1,1,2,1,}, 00127 {0,0,0,0,0,0,0,1,1,1,1,1,}, 00128 {0,0,0,0,0,0,0,1,1,1,0,0,}, 00129 {0,0,0,0,0,0,0,0,1,1,1,0,}, 00130 {1,1,0,1,1,1,1,1,1,1,1,0,}, 00131 {0,0,1,1,0,1,1,1,1,1,0,0,}, 00132 } 00133 }, 00134 { 00135 // Left 00136 { 00137 {0,1,1,1,0,0,0,0,0,0,0,0,}, 00138 {1,2,1,1,1,0,0,0,0,0,0,0,}, 00139 {1,1,1,1,1,0,0,0,0,0,0,0,}, 00140 {0,0,1,1,1,0,0,0,0,0,0,0,}, 00141 {0,1,1,1,0,0,0,0,0,0,0,0,}, 00142 {0,1,1,1,1,0,1,1,1,1,0,0,}, 00143 {0,0,1,1,1,1,1,1,0,1,1,1,}, 00144 }, 00145 { 00146 {0,1,1,1,0,0,0,0,0,0,0,0,}, 00147 {1,2,1,1,1,0,0,0,0,0,0,0,}, 00148 {1,1,1,1,1,0,0,0,0,0,0,0,}, 00149 {0,0,1,1,1,0,0,0,0,0,0,0,}, 00150 {0,1,1,1,0,0,0,0,0,0,0,0,}, 00151 {0,1,1,1,1,1,0,1,1,1,1,0,}, 00152 {0,0,1,1,1,1,1,1,1,0,0,1,}, 00153 }, 00154 { 00155 {0,1,1,1,0,0,0,0,0,0,0,0,}, 00156 {1,2,1,1,1,0,0,0,0,0,0,0,}, 00157 {1,1,1,1,1,0,0,0,0,0,0,0,}, 00158 {0,0,1,1,1,0,0,0,0,0,0,0,}, 00159 {0,1,1,1,0,0,0,0,0,0,0,1,}, 00160 {0,1,1,1,1,1,1,1,0,0,1,0,}, 00161 {0,0,1,1,1,1,0,1,1,1,0,0,}, 00162 }, 00163 { 00164 {0,1,1,1,0,0,0,0,0,0,0,0,}, 00165 {1,2,1,1,1,0,0,0,0,0,0,0,}, 00166 {1,1,1,1,1,0,0,0,0,0,0,0,}, 00167 {0,0,1,1,1,0,0,0,0,0,0,0,}, 00168 {0,1,1,1,0,0,0,0,0,0,0,0,}, 00169 {0,1,1,1,1,1,1,1,1,0,1,1,}, 00170 {0,0,1,1,1,1,1,0,1,1,0,0,}, 00171 } 00172 } 00173 }; 00174 00175 const char sprite_snake_y[2][6][12][6] = { // Player [Face][SpriteAnimationFrame][Size_Y][Size_X] 00176 { 00177 // Up 00178 { 00179 {0,1,1,1,1,0,}, 00180 {1,1,1,1,1,1,}, 00181 {1,1,1,1,1,1,}, 00182 {0,1,1,1,1,0,}, 00183 {0,0,1,1,0,0,}, 00184 {0,1,1,1,0,0,}, 00185 {0,1,1,0,0,0,}, 00186 {0,0,1,1,0,0,}, 00187 {0,0,0,1,1,0,}, 00188 {0,0,0,1,1,0,}, 00189 {0,0,1,1,0,0,}, 00190 {0,1,0,0,0,0,}, 00191 }, 00192 { 00193 {0,1,1,1,1,0,}, 00194 {1,1,1,1,1,1,}, 00195 {1,1,1,1,1,1,}, 00196 {0,1,1,1,1,0,}, 00197 {0,0,1,1,0,0,}, 00198 {0,0,1,1,0,0,}, 00199 {0,1,1,0,0,0,}, 00200 {0,1,1,0,0,0,}, 00201 {0,0,1,1,0,0,}, 00202 {0,0,0,1,1,0,}, 00203 {0,0,0,0,1,0,}, 00204 {0,0,1,1,0,0,}, 00205 }, 00206 { 00207 {0,1,1,1,1,0,}, 00208 {1,1,1,1,1,1,}, 00209 {1,1,1,1,1,1,}, 00210 {0,1,1,1,1,0,}, 00211 {0,0,1,1,0,0,}, 00212 {0,0,0,1,1,0,}, 00213 {0,0,1,1,0,0,}, 00214 {0,1,1,0,0,0,}, 00215 {0,1,1,0,0,0,}, 00216 {0,0,1,1,0,0,}, 00217 {0,0,0,0,1,0,}, 00218 {0,0,0,1,0,0,}, 00219 }, 00220 { 00221 {0,1,1,1,1,0,}, 00222 {1,1,1,1,1,1,}, 00223 {1,1,1,1,1,1,}, 00224 {0,1,1,1,1,0,}, 00225 {0,0,1,1,0,0,}, 00226 {0,0,1,1,1,0,}, 00227 {0,0,0,1,1,0,}, 00228 {0,0,1,1,0,0,}, 00229 {0,1,1,0,0,0,}, 00230 {0,1,1,0,0,0,}, 00231 {0,0,1,1,0,0,}, 00232 {0,0,0,0,1,0,}, 00233 }, 00234 { 00235 {0,1,1,1,1,0,}, 00236 {1,1,1,1,1,1,}, 00237 {1,1,1,1,1,1,}, 00238 {0,1,1,1,1,0,}, 00239 {0,0,1,1,0,0,}, 00240 {0,0,1,1,0,0,}, 00241 {0,0,0,1,1,0,}, 00242 {0,0,0,1,1,0,}, 00243 {0,0,1,1,0,0,}, 00244 {0,1,1,0,0,0,}, 00245 {0,1,0,0,0,0,}, 00246 {0,0,1,1,0,0,}, 00247 }, 00248 { 00249 {0,1,1,1,1,0,}, 00250 {1,1,1,1,1,1,}, 00251 {1,1,1,1,1,1,}, 00252 {0,1,1,1,1,0,}, 00253 {0,0,1,1,0,0,}, 00254 {0,1,1,0,0,0,}, 00255 {0,0,1,1,0,0,}, 00256 {0,0,0,1,1,0,}, 00257 {0,0,0,1,1,0,}, 00258 {0,0,1,1,0,0,}, 00259 {0,1,0,0,0,0,}, 00260 {0,0,1,0,0,0,}, 00261 } 00262 }, 00263 { 00264 // Down 00265 { 00266 {0,0,0,0,1,0,}, 00267 {0,0,1,1,0,0,}, 00268 {0,1,1,0,0,0,}, 00269 {0,1,1,0,0,0,}, 00270 {0,0,1,1,0,0,}, 00271 {0,0,0,1,1,0,}, 00272 {0,1,1,1,1,0,}, 00273 {1,1,1,1,1,1,}, 00274 {1,2,1,1,2,1,}, 00275 {0,1,1,1,1,0,}, 00276 {0,0,1,1,0,0,}, 00277 {0,0,1,1,0,0,}, 00278 }, 00279 { 00280 {0,0,1,1,0,0,}, 00281 {0,1,0,0,0,0,}, 00282 {0,1,1,0,0,0,}, 00283 {0,0,1,1,0,0,}, 00284 {0,0,0,1,1,0,}, 00285 {0,0,0,1,1,0,}, 00286 {0,1,1,1,1,0,}, 00287 {1,1,1,1,1,1,}, 00288 {1,2,1,1,2,1,}, 00289 {0,1,1,1,1,0,}, 00290 {0,0,1,1,0,0,}, 00291 {0,0,1,1,0,0,}, 00292 }, 00293 { 00294 {0,0,1,0,0,0,}, 00295 {0,1,0,0,0,0,}, 00296 {0,0,1,1,0,0,}, 00297 {0,0,0,1,1,0,}, 00298 {0,0,0,1,1,0,}, 00299 {0,0,1,1,0,0,}, 00300 {0,1,1,1,1,0,}, 00301 {1,1,1,1,1,1,}, 00302 {1,2,1,1,2,1,}, 00303 {0,1,1,1,1,0,}, 00304 {0,0,1,1,0,0,}, 00305 {0,0,1,1,0,0,}, 00306 }, 00307 { 00308 {0,1,0,0,0,0,}, 00309 {0,0,1,1,0,0,}, 00310 {0,0,0,1,1,0,}, 00311 {0,0,0,1,1,0,}, 00312 {0,0,1,1,0,0,}, 00313 {0,1,1,0,0,0,}, 00314 {0,1,1,1,1,0,}, 00315 {1,1,1,1,1,1,}, 00316 {1,2,1,1,2,1,}, 00317 {0,1,1,1,1,0,}, 00318 {0,0,1,1,0,0,}, 00319 {0,0,1,1,0,0,}, 00320 }, 00321 { 00322 {0,0,1,1,0,0,}, 00323 {0,0,0,0,1,0,}, 00324 {0,0,0,1,1,0,}, 00325 {0,0,1,1,0,0,}, 00326 {0,1,1,0,0,0,}, 00327 {0,1,1,0,0,0,}, 00328 {0,1,1,1,1,0,}, 00329 {1,1,1,1,1,1,}, 00330 {1,2,1,1,2,1,}, 00331 {0,1,1,1,1,0,}, 00332 {0,0,1,1,0,0,}, 00333 {0,0,1,1,0,0,}, 00334 }, 00335 { 00336 {0,0,0,1,0,0,}, 00337 {0,0,0,0,1,0,}, 00338 {0,0,1,1,0,0,}, 00339 {0,1,1,0,0,0,}, 00340 {0,1,1,0,0,0,}, 00341 {0,0,1,1,0,0,}, 00342 {0,1,1,1,1,0,}, 00343 {1,1,1,1,1,1,}, 00344 {1,2,1,1,2,1,}, 00345 {0,1,1,1,1,0,}, 00346 {0,0,1,1,0,0,}, 00347 {0,0,1,1,0,0,}, 00348 } 00349 } 00350 }; 00351 00352 #endif
Generated on Tue Jul 19 2022 23:32:07 by 1.7.2