A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
Entity/Entity.h@58:c8d90bb7404a, 2019-05-09 (annotated)
- Committer:
- el17sm
- Date:
- Thu May 09 14:43:45 2019 +0000
- Revision:
- 58:c8d90bb7404a
- Parent:
- 57:1c12361b6e3d
- Child:
- 59:fd4669864b67
Fully Doxygenated
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17sm | 10:1a3499f6b583 | 1 | #ifndef ENTITY_H |
el17sm | 10:1a3499f6b583 | 2 | #define ENTITY_H |
el17sm | 10:1a3499f6b583 | 3 | #include "sprites.h" |
el17sm | 10:1a3499f6b583 | 4 | #include "math.h" |
el17sm | 32:fe6359ef9916 | 5 | #include "N5110.h" |
el17sm | 10:1a3499f6b583 | 6 | |
el17sm | 58:c8d90bb7404a | 7 | /**Entity Abstract Class |
el17sm | 58:c8d90bb7404a | 8 | @author Steven Mahasin |
el17sm | 58:c8d90bb7404a | 9 | @brief Creates an Entity which holds entity datas, functions(movements, damaged actions, collision test, etc), accessors and functions to be inherited by child classes |
el17sm | 58:c8d90bb7404a | 10 | @date May 2019 |
el17sm | 58:c8d90bb7404a | 11 | */ |
el17sm | 10:1a3499f6b583 | 12 | class Entity |
el17sm | 22:7abf4581bc9b | 13 | { |
el17sm | 22:7abf4581bc9b | 14 | protected: |
el17sm | 22:7abf4581bc9b | 15 | struct Hitbox { |
el17sm | 22:7abf4581bc9b | 16 | int width; |
el17sm | 22:7abf4581bc9b | 17 | int height; |
el17sm | 22:7abf4581bc9b | 18 | }; |
el17sm | 22:7abf4581bc9b | 19 | struct SpriteSize { |
el17sm | 22:7abf4581bc9b | 20 | int width; |
el17sm | 22:7abf4581bc9b | 21 | int height; |
el17sm | 22:7abf4581bc9b | 22 | // Top-left corner of sprite is offset_x |
el17sm | 22:7abf4581bc9b | 23 | // to the right of top-left corner of hitbox |
el17sm | 22:7abf4581bc9b | 24 | int offset_x; |
el17sm | 22:7abf4581bc9b | 25 | // Top-left corner of sprite is offset_y |
el17sm | 58:c8d90bb7404a | 26 | // below of top-left corner of hitbox |
el17sm | 22:7abf4581bc9b | 27 | int offset_y; |
el17sm | 22:7abf4581bc9b | 28 | }; |
el17sm | 22:7abf4581bc9b | 29 | struct Position { |
el17sm | 22:7abf4581bc9b | 30 | float x; |
el17sm | 22:7abf4581bc9b | 31 | float y; |
el17sm | 22:7abf4581bc9b | 32 | }; |
el17sm | 22:7abf4581bc9b | 33 | struct FrameCount { |
el17sm | 22:7abf4581bc9b | 34 | int count; |
el17sm | 22:7abf4581bc9b | 35 | int number; |
el17sm | 22:7abf4581bc9b | 36 | int max; |
el17sm | 22:7abf4581bc9b | 37 | }; |
el17sm | 58:c8d90bb7404a | 38 | /** |
el17sm | 58:c8d90bb7404a | 39 | * @brief A struct containing hitbox data for the entity |
el17sm | 58:c8d90bb7404a | 40 | * @info width and height |
el17sm | 58:c8d90bb7404a | 41 | */ |
el17sm | 57:1c12361b6e3d | 42 | Hitbox _hitbox; |
el17sm | 58:c8d90bb7404a | 43 | /** |
el17sm | 58:c8d90bb7404a | 44 | * @brief A struct containing sprite size data for the entity, to be used when drawing sprites on top of their hitboxes |
el17sm | 58:c8d90bb7404a | 45 | * @info sprite width, sprite height, sprite offset x from hitbox, sprite offset y from hitbox |
el17sm | 58:c8d90bb7404a | 46 | */ |
el17sm | 57:1c12361b6e3d | 47 | SpriteSize _sprite_size; |
el17sm | 58:c8d90bb7404a | 48 | /** |
el17sm | 58:c8d90bb7404a | 49 | * @brief A struct containing the position of the entity, this position is the top-left corner of the hitbox |
el17sm | 58:c8d90bb7404a | 50 | */ |
el17sm | 57:1c12361b6e3d | 51 | Position _position; |
el17sm | 58:c8d90bb7404a | 52 | /** |
el17sm | 58:c8d90bb7404a | 53 | * @brief A struct containing the position of the entity one loop behind |
el17sm | 58:c8d90bb7404a | 54 | */ |
el17sm | 57:1c12361b6e3d | 55 | Position _prev_pos; |
el17sm | 58:c8d90bb7404a | 56 | /** |
el17sm | 58:c8d90bb7404a | 57 | * @brief A struct containing frame count, frame number and frame max. Used to animate entities |
el17sm | 58:c8d90bb7404a | 58 | */ |
el17sm | 57:1c12361b6e3d | 59 | FrameCount _frame; |
el17sm | 58:c8d90bb7404a | 60 | /** |
el17sm | 58:c8d90bb7404a | 61 | * @brief The health point of an entity |
el17sm | 58:c8d90bb7404a | 62 | */ |
el17sm | 57:1c12361b6e3d | 63 | int _hp; |
el17sm | 58:c8d90bb7404a | 64 | /** |
el17sm | 58:c8d90bb7404a | 65 | * @brief The damage the entity does if it attacks another entity |
el17sm | 58:c8d90bb7404a | 66 | */ |
el17sm | 57:1c12361b6e3d | 67 | int _attack; |
el17sm | 58:c8d90bb7404a | 68 | /** |
el17sm | 58:c8d90bb7404a | 69 | * @brief The direction the entity is facing |
el17sm | 58:c8d90bb7404a | 70 | */ |
el17sm | 57:1c12361b6e3d | 71 | int _face; |
el17sm | 58:c8d90bb7404a | 72 | /** |
el17sm | 58:c8d90bb7404a | 73 | * @brief The speed the entity moves |
el17sm | 58:c8d90bb7404a | 74 | */ |
el17sm | 57:1c12361b6e3d | 75 | float _velocity; |
el17sm | 58:c8d90bb7404a | 76 | /** |
el17sm | 58:c8d90bb7404a | 77 | * @brief The chance(out of 100) of dropping a heart when the entity is deleted. |
el17sm | 58:c8d90bb7404a | 78 | */ |
el17sm | 28:98848e6a77a2 | 79 | int _hp_drop_chance; |
el17sm | 22:7abf4581bc9b | 80 | |
el17sm | 22:7abf4581bc9b | 81 | public: |
el17sm | 22:7abf4581bc9b | 82 | // Function |
el17sm | 58:c8d90bb7404a | 83 | /** |
el17sm | 58:c8d90bb7404a | 84 | * @brief a virtual function movement of the entity to be inherited |
el17sm | 58:c8d90bb7404a | 85 | * @param x_value @details either joystick x or player's x position |
el17sm | 58:c8d90bb7404a | 86 | * @param y_value @details either joystick y or player's y position |
el17sm | 58:c8d90bb7404a | 87 | * @param map @details the 2d map array that dictates where there are walls or empty space |
el17sm | 58:c8d90bb7404a | 88 | * @param doorways @details an array that dictates which side of the wall has a doorway |
el17sm | 58:c8d90bb7404a | 89 | */ |
el17sm | 58:c8d90bb7404a | 90 | virtual void move(float x_value, float y_value, char * map, bool * doorways) = 0; // movement control and miscellaneous updates |
el17sm | 58:c8d90bb7404a | 91 | /** |
el17sm | 58:c8d90bb7404a | 92 | * @brief a virtual function of the action when taking damage to be inherited |
el17sm | 58:c8d90bb7404a | 93 | * @param damage @details the amount of damage to be taken |
el17sm | 58:c8d90bb7404a | 94 | */ |
el17sm | 58:c8d90bb7404a | 95 | virtual void take_damage(int damage) = 0; |
el17sm | 58:c8d90bb7404a | 96 | /** |
el17sm | 58:c8d90bb7404a | 97 | * @brief a virtual function of drawing the entity to be inherited |
el17sm | 58:c8d90bb7404a | 98 | * @param lcd @details the screen where the entity is drawn on |
el17sm | 58:c8d90bb7404a | 99 | */ |
el17sm | 32:fe6359ef9916 | 100 | virtual void draw(N5110 &lcd) = 0; |
el17sm | 58:c8d90bb7404a | 101 | /** |
el17sm | 58:c8d90bb7404a | 102 | * @brief a function to undo entity's movement in the x direction if condition is true |
el17sm | 58:c8d90bb7404a | 103 | * @param condition @details a boolean statement |
el17sm | 58:c8d90bb7404a | 104 | */ |
el17sm | 51:4d0cd75e7ed3 | 105 | void undo_move_x(bool condition); |
el17sm | 58:c8d90bb7404a | 106 | /** |
el17sm | 58:c8d90bb7404a | 107 | * @brief a function to undo entity's movement in the y direction if condition is true |
el17sm | 58:c8d90bb7404a | 108 | * @param condition @details a boolean statement |
el17sm | 58:c8d90bb7404a | 109 | */ |
el17sm | 51:4d0cd75e7ed3 | 110 | void undo_move_y(bool condition); |
el17sm | 58:c8d90bb7404a | 111 | /** |
el17sm | 58:c8d90bb7404a | 112 | * @brief updates the _prev_pos into _position |
el17sm | 58:c8d90bb7404a | 113 | */ |
el17sm | 22:7abf4581bc9b | 114 | void update_prev_pos(); |
el17sm | 58:c8d90bb7404a | 115 | /** |
el17sm | 58:c8d90bb7404a | 116 | * @brief checks if the entity collides the map |
el17sm | 58:c8d90bb7404a | 117 | * @param pos_x @details entity's x-position |
el17sm | 58:c8d90bb7404a | 118 | * @param pos_y @details entity's y-position |
el17sm | 58:c8d90bb7404a | 119 | * @param two_d_map @details the 2d map array that dictates where there are walls or empty space |
el17sm | 58:c8d90bb7404a | 120 | * @param doorways @details an array that dictates which side of the wall has a doorway |
el17sm | 58:c8d90bb7404a | 121 | * @return true if entity collide with the map |
el17sm | 58:c8d90bb7404a | 122 | */ |
el17sm | 51:4d0cd75e7ed3 | 123 | bool entity_to_map_collision_test(float pos_x, float pos_y, char * two_d_map, bool * doorways); |
el17sm | 22:7abf4581bc9b | 124 | |
el17sm | 22:7abf4581bc9b | 125 | // Mutator |
el17sm | 58:c8d90bb7404a | 126 | /** |
el17sm | 58:c8d90bb7404a | 127 | * @brief mutates position of the entity to x and y |
el17sm | 58:c8d90bb7404a | 128 | * @param x @details x-coordinate value |
el17sm | 58:c8d90bb7404a | 129 | * @param y @details y-coordinate value |
el17sm | 58:c8d90bb7404a | 130 | */ |
el17sm | 28:98848e6a77a2 | 131 | void set_position(float x, float y); |
el17sm | 58:c8d90bb7404a | 132 | /** |
el17sm | 58:c8d90bb7404a | 133 | * @brief adds change_x onto x-position of the entity |
el17sm | 58:c8d90bb7404a | 134 | * @param change_x @details displacement x |
el17sm | 58:c8d90bb7404a | 135 | */ |
el17sm | 51:4d0cd75e7ed3 | 136 | void position_add_x(float change_x); |
el17sm | 58:c8d90bb7404a | 137 | /** |
el17sm | 58:c8d90bb7404a | 138 | * @brief adds change_y onto y-position of the entity |
el17sm | 58:c8d90bb7404a | 139 | * @param change_y @details displacement y |
el17sm | 58:c8d90bb7404a | 140 | */ |
el17sm | 51:4d0cd75e7ed3 | 141 | void position_add_y(float change_y); |
el17sm | 24:26369d92a06a | 142 | |
el17sm | 22:7abf4581bc9b | 143 | // Accessors |
el17sm | 58:c8d90bb7404a | 144 | /** |
el17sm | 58:c8d90bb7404a | 145 | * @brief gets the entity's chance to drop a health |
el17sm | 58:c8d90bb7404a | 146 | * @return _hp_drop_chance |
el17sm | 58:c8d90bb7404a | 147 | */ |
el17sm | 28:98848e6a77a2 | 148 | int get_hp_drop_chance(); |
el17sm | 58:c8d90bb7404a | 149 | /** |
el17sm | 58:c8d90bb7404a | 150 | * @brief gets the entity's hitbox width |
el17sm | 58:c8d90bb7404a | 151 | * @return _hitbox.width |
el17sm | 58:c8d90bb7404a | 152 | */ |
el17sm | 22:7abf4581bc9b | 153 | int get_hitbox_width(); |
el17sm | 58:c8d90bb7404a | 154 | /** |
el17sm | 58:c8d90bb7404a | 155 | * @brief gets the entity's hitbox height |
el17sm | 58:c8d90bb7404a | 156 | * @return _hitbox.height |
el17sm | 58:c8d90bb7404a | 157 | */ |
el17sm | 22:7abf4581bc9b | 158 | int get_hitbox_height(); |
el17sm | 58:c8d90bb7404a | 159 | /** |
el17sm | 58:c8d90bb7404a | 160 | * @brief gets the entity's face |
el17sm | 58:c8d90bb7404a | 161 | * @return _face |
el17sm | 58:c8d90bb7404a | 162 | */ |
el17sm | 22:7abf4581bc9b | 163 | int get_face(); |
el17sm | 58:c8d90bb7404a | 164 | /** |
el17sm | 58:c8d90bb7404a | 165 | * @brief gets the entity's sprite width |
el17sm | 58:c8d90bb7404a | 166 | * @return _sprite_size.width |
el17sm | 58:c8d90bb7404a | 167 | */ |
el17sm | 22:7abf4581bc9b | 168 | int get_sprite_width(); |
el17sm | 58:c8d90bb7404a | 169 | /** |
el17sm | 58:c8d90bb7404a | 170 | * @brief gets the entity's sprite height |
el17sm | 58:c8d90bb7404a | 171 | * @return _sprite_size.height |
el17sm | 58:c8d90bb7404a | 172 | */ |
el17sm | 22:7abf4581bc9b | 173 | int get_sprite_height(); |
el17sm | 58:c8d90bb7404a | 174 | /** |
el17sm | 58:c8d90bb7404a | 175 | * @brief gets the entity's sprite x-offset |
el17sm | 58:c8d90bb7404a | 176 | * @return _sprite_size.offset_x |
el17sm | 58:c8d90bb7404a | 177 | */ |
el17sm | 22:7abf4581bc9b | 178 | int get_offset_x(); |
el17sm | 58:c8d90bb7404a | 179 | /** |
el17sm | 58:c8d90bb7404a | 180 | * @brief gets the entity's sprite y-offset |
el17sm | 58:c8d90bb7404a | 181 | * @return _sprite_size.offset_y |
el17sm | 58:c8d90bb7404a | 182 | */ |
el17sm | 22:7abf4581bc9b | 183 | int get_offset_y(); |
el17sm | 58:c8d90bb7404a | 184 | /** |
el17sm | 58:c8d90bb7404a | 185 | * @brief gets the entity's x-position |
el17sm | 58:c8d90bb7404a | 186 | * @return _position.x |
el17sm | 58:c8d90bb7404a | 187 | */ |
el17sm | 22:7abf4581bc9b | 188 | int get_pos_x(); |
el17sm | 58:c8d90bb7404a | 189 | /** |
el17sm | 58:c8d90bb7404a | 190 | * @brief gets the entity's y-position |
el17sm | 58:c8d90bb7404a | 191 | * @return _position.y |
el17sm | 58:c8d90bb7404a | 192 | */ |
el17sm | 22:7abf4581bc9b | 193 | int get_pos_y(); |
el17sm | 58:c8d90bb7404a | 194 | /** |
el17sm | 58:c8d90bb7404a | 195 | * @brief gets the entity's previous x-position |
el17sm | 58:c8d90bb7404a | 196 | * @return _prev_pos.x |
el17sm | 58:c8d90bb7404a | 197 | */ |
el17sm | 22:7abf4581bc9b | 198 | int get_prev_pos_x(); |
el17sm | 58:c8d90bb7404a | 199 | /** |
el17sm | 58:c8d90bb7404a | 200 | * @brief gets the entity's previous y-position |
el17sm | 58:c8d90bb7404a | 201 | * @return _prev_pos.y |
el17sm | 58:c8d90bb7404a | 202 | */ |
el17sm | 22:7abf4581bc9b | 203 | int get_prev_pos_y(); |
el17sm | 58:c8d90bb7404a | 204 | /** |
el17sm | 58:c8d90bb7404a | 205 | * @brief gets the entity's attack |
el17sm | 58:c8d90bb7404a | 206 | * @return _attack |
el17sm | 58:c8d90bb7404a | 207 | */ |
el17sm | 23:5a8f75e93508 | 208 | int get_attack(); |
el17sm | 58:c8d90bb7404a | 209 | /** |
el17sm | 58:c8d90bb7404a | 210 | * @brief gets the entity's hp |
el17sm | 58:c8d90bb7404a | 211 | * @return _hp |
el17sm | 58:c8d90bb7404a | 212 | */ |
el17sm | 23:5a8f75e93508 | 213 | int get_hp(); |
el17sm | 58:c8d90bb7404a | 214 | /** |
el17sm | 58:c8d90bb7404a | 215 | * @brief gets the entity's velocity |
el17sm | 58:c8d90bb7404a | 216 | * @return _velocity |
el17sm | 58:c8d90bb7404a | 217 | */ |
el17sm | 28:98848e6a77a2 | 218 | float get_velocity(); |
el17sm | 10:1a3499f6b583 | 219 | |
el17sm | 10:1a3499f6b583 | 220 | }; |
el17sm | 10:1a3499f6b583 | 221 | |
el17sm | 10:1a3499f6b583 | 222 | #endif |