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@32:fe6359ef9916, 2019-05-06 (annotated)
- Committer:
- el17sm
- Date:
- Mon May 06 08:56:48 2019 +0000
- Revision:
- 32:fe6359ef9916
- Parent:
- 29:6b8411bb040a
- Child:
- 34:1d5b4da3935e
A bit of code cleanup;; Draw functions are now inside the classes;; Moved classes into it's folders;
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 | bool moving; |
el17sm | 22:7abf4581bc9b | 11 | struct Hitbox { |
el17sm | 22:7abf4581bc9b | 12 | int width; |
el17sm | 22:7abf4581bc9b | 13 | int height; |
el17sm | 22:7abf4581bc9b | 14 | }; |
el17sm | 22:7abf4581bc9b | 15 | Hitbox hitbox; |
el17sm | 22:7abf4581bc9b | 16 | struct SpriteSize { |
el17sm | 22:7abf4581bc9b | 17 | int width; |
el17sm | 22:7abf4581bc9b | 18 | int height; |
el17sm | 22:7abf4581bc9b | 19 | // Top-left corner of sprite is offset_x |
el17sm | 22:7abf4581bc9b | 20 | // to the right of top-left corner of hitbox |
el17sm | 22:7abf4581bc9b | 21 | int offset_x; |
el17sm | 22:7abf4581bc9b | 22 | // Top-left corner of sprite is offset_y |
el17sm | 22:7abf4581bc9b | 23 | // above of top-left corner of hitbox |
el17sm | 22:7abf4581bc9b | 24 | int offset_y; |
el17sm | 22:7abf4581bc9b | 25 | }; |
el17sm | 22:7abf4581bc9b | 26 | SpriteSize sprite_size; |
el17sm | 22:7abf4581bc9b | 27 | struct Position { |
el17sm | 22:7abf4581bc9b | 28 | float x; |
el17sm | 22:7abf4581bc9b | 29 | float y; |
el17sm | 22:7abf4581bc9b | 30 | }; |
el17sm | 22:7abf4581bc9b | 31 | Position position; |
el17sm | 22:7abf4581bc9b | 32 | Position prev_pos; |
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 | 22:7abf4581bc9b | 38 | FrameCount frame; |
el17sm | 22:7abf4581bc9b | 39 | int hp; |
el17sm | 23:5a8f75e93508 | 40 | int attack; |
el17sm | 22:7abf4581bc9b | 41 | int face; |
el17sm | 22:7abf4581bc9b | 42 | float velocity; |
el17sm | 28:98848e6a77a2 | 43 | bool _damage_self_upon_collision; |
el17sm | 28:98848e6a77a2 | 44 | int _hp_drop_chance; |
el17sm | 22:7abf4581bc9b | 45 | |
el17sm | 22:7abf4581bc9b | 46 | public: |
el17sm | 22:7abf4581bc9b | 47 | // Function |
el17sm | 29:6b8411bb040a | 48 | virtual void move(float, float, int * map, bool * doorways) = 0; // movement control and miscellaneous updates |
el17sm | 23:5a8f75e93508 | 49 | virtual void take_damage(int) = 0; |
el17sm | 32:fe6359ef9916 | 50 | virtual void draw(N5110 &lcd) = 0; |
el17sm | 22:7abf4581bc9b | 51 | void undo_move_x(bool); |
el17sm | 22:7abf4581bc9b | 52 | void undo_move_y(bool); |
el17sm | 22:7abf4581bc9b | 53 | void update_prev_pos(); |
el17sm | 29:6b8411bb040a | 54 | bool entity_to_map_collision_test(float pos_x, float pos_y, int * map, bool * doorways); |
el17sm | 22:7abf4581bc9b | 55 | |
el17sm | 22:7abf4581bc9b | 56 | // Mutator |
el17sm | 28:98848e6a77a2 | 57 | void set_position(float x, float y); |
el17sm | 24:26369d92a06a | 58 | void position_add_x(float); |
el17sm | 24:26369d92a06a | 59 | void position_add_y(float); |
el17sm | 24:26369d92a06a | 60 | |
el17sm | 22:7abf4581bc9b | 61 | // Accessors |
el17sm | 22:7abf4581bc9b | 62 | bool get_moving(); |
el17sm | 28:98848e6a77a2 | 63 | bool is_damaged_by_collision(); |
el17sm | 28:98848e6a77a2 | 64 | int get_hp_drop_chance(); |
el17sm | 22:7abf4581bc9b | 65 | int get_hitbox_width(); |
el17sm | 22:7abf4581bc9b | 66 | int get_hitbox_height(); |
el17sm | 22:7abf4581bc9b | 67 | int get_face(); |
el17sm | 22:7abf4581bc9b | 68 | int get_sprite_width(); |
el17sm | 22:7abf4581bc9b | 69 | int get_sprite_height(); |
el17sm | 22:7abf4581bc9b | 70 | int get_offset_x(); |
el17sm | 22:7abf4581bc9b | 71 | int get_offset_y(); |
el17sm | 22:7abf4581bc9b | 72 | int get_pos_x(); |
el17sm | 22:7abf4581bc9b | 73 | int get_pos_y(); |
el17sm | 22:7abf4581bc9b | 74 | int get_prev_pos_x(); |
el17sm | 22:7abf4581bc9b | 75 | int get_prev_pos_y(); |
el17sm | 23:5a8f75e93508 | 76 | int get_attack(); |
el17sm | 23:5a8f75e93508 | 77 | int get_hp(); |
el17sm | 28:98848e6a77a2 | 78 | float get_velocity(); |
el17sm | 10:1a3499f6b583 | 79 | |
el17sm | 10:1a3499f6b583 | 80 | }; |
el17sm | 10:1a3499f6b583 | 81 | |
el17sm | 10:1a3499f6b583 | 82 | #endif |