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@57:1c12361b6e3d, 2019-05-09 (annotated)
- Committer:
- el17sm
- Date:
- Thu May 09 09:50:19 2019 +0000
- Revision:
- 57:1c12361b6e3d
- Parent:
- 51:4d0cd75e7ed3
- Child:
- 58:c8d90bb7404a
All protected member has a _ before them
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 | 10:1a3499f6b583 | 7 | class Entity |
el17sm | 22:7abf4581bc9b | 8 | { |
el17sm | 22:7abf4581bc9b | 9 | protected: |
el17sm | 22:7abf4581bc9b | 10 | struct Hitbox { |
el17sm | 22:7abf4581bc9b | 11 | int width; |
el17sm | 22:7abf4581bc9b | 12 | int height; |
el17sm | 22:7abf4581bc9b | 13 | }; |
el17sm | 22:7abf4581bc9b | 14 | struct SpriteSize { |
el17sm | 22:7abf4581bc9b | 15 | int width; |
el17sm | 22:7abf4581bc9b | 16 | int height; |
el17sm | 22:7abf4581bc9b | 17 | // Top-left corner of sprite is offset_x |
el17sm | 22:7abf4581bc9b | 18 | // to the right of top-left corner of hitbox |
el17sm | 22:7abf4581bc9b | 19 | int offset_x; |
el17sm | 22:7abf4581bc9b | 20 | // Top-left corner of sprite is offset_y |
el17sm | 22:7abf4581bc9b | 21 | // above of top-left corner of hitbox |
el17sm | 22:7abf4581bc9b | 22 | int offset_y; |
el17sm | 22:7abf4581bc9b | 23 | }; |
el17sm | 22:7abf4581bc9b | 24 | struct Position { |
el17sm | 22:7abf4581bc9b | 25 | float x; |
el17sm | 22:7abf4581bc9b | 26 | float y; |
el17sm | 22:7abf4581bc9b | 27 | }; |
el17sm | 22:7abf4581bc9b | 28 | struct FrameCount { |
el17sm | 22:7abf4581bc9b | 29 | int count; |
el17sm | 22:7abf4581bc9b | 30 | int number; |
el17sm | 22:7abf4581bc9b | 31 | int max; |
el17sm | 22:7abf4581bc9b | 32 | }; |
el17sm | 57:1c12361b6e3d | 33 | Hitbox _hitbox; |
el17sm | 57:1c12361b6e3d | 34 | SpriteSize _sprite_size; |
el17sm | 57:1c12361b6e3d | 35 | Position _position; |
el17sm | 57:1c12361b6e3d | 36 | Position _prev_pos; |
el17sm | 57:1c12361b6e3d | 37 | FrameCount _frame; |
el17sm | 57:1c12361b6e3d | 38 | int _hp; |
el17sm | 57:1c12361b6e3d | 39 | int _attack; |
el17sm | 57:1c12361b6e3d | 40 | int _face; |
el17sm | 57:1c12361b6e3d | 41 | float _velocity; |
el17sm | 28:98848e6a77a2 | 42 | int _hp_drop_chance; |
el17sm | 22:7abf4581bc9b | 43 | |
el17sm | 22:7abf4581bc9b | 44 | public: |
el17sm | 22:7abf4581bc9b | 45 | // Function |
el17sm | 34:1d5b4da3935e | 46 | virtual void move(float, float, char * map, bool * doorways) = 0; // movement control and miscellaneous updates |
el17sm | 23:5a8f75e93508 | 47 | virtual void take_damage(int) = 0; |
el17sm | 32:fe6359ef9916 | 48 | virtual void draw(N5110 &lcd) = 0; |
el17sm | 51:4d0cd75e7ed3 | 49 | void undo_move_x(bool condition); |
el17sm | 51:4d0cd75e7ed3 | 50 | void undo_move_y(bool condition); |
el17sm | 22:7abf4581bc9b | 51 | void update_prev_pos(); |
el17sm | 51:4d0cd75e7ed3 | 52 | bool entity_to_map_collision_test(float pos_x, float pos_y, char * two_d_map, bool * doorways); |
el17sm | 22:7abf4581bc9b | 53 | |
el17sm | 22:7abf4581bc9b | 54 | // Mutator |
el17sm | 28:98848e6a77a2 | 55 | void set_position(float x, float y); |
el17sm | 51:4d0cd75e7ed3 | 56 | void position_add_x(float change_x); |
el17sm | 51:4d0cd75e7ed3 | 57 | void position_add_y(float change_y); |
el17sm | 24:26369d92a06a | 58 | |
el17sm | 22:7abf4581bc9b | 59 | // Accessors |
el17sm | 28:98848e6a77a2 | 60 | int get_hp_drop_chance(); |
el17sm | 22:7abf4581bc9b | 61 | int get_hitbox_width(); |
el17sm | 22:7abf4581bc9b | 62 | int get_hitbox_height(); |
el17sm | 22:7abf4581bc9b | 63 | int get_face(); |
el17sm | 22:7abf4581bc9b | 64 | int get_sprite_width(); |
el17sm | 22:7abf4581bc9b | 65 | int get_sprite_height(); |
el17sm | 22:7abf4581bc9b | 66 | int get_offset_x(); |
el17sm | 22:7abf4581bc9b | 67 | int get_offset_y(); |
el17sm | 22:7abf4581bc9b | 68 | int get_pos_x(); |
el17sm | 22:7abf4581bc9b | 69 | int get_pos_y(); |
el17sm | 22:7abf4581bc9b | 70 | int get_prev_pos_x(); |
el17sm | 22:7abf4581bc9b | 71 | int get_prev_pos_y(); |
el17sm | 23:5a8f75e93508 | 72 | int get_attack(); |
el17sm | 23:5a8f75e93508 | 73 | int get_hp(); |
el17sm | 28:98848e6a77a2 | 74 | float get_velocity(); |
el17sm | 10:1a3499f6b583 | 75 | |
el17sm | 10:1a3499f6b583 | 76 | }; |
el17sm | 10:1a3499f6b583 | 77 | |
el17sm | 10:1a3499f6b583 | 78 | #endif |