A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
Entity/Entity.cpp@28:98848e6a77a2, 2019-05-02 (annotated)
- Committer:
- el17sm
- Date:
- Thu May 02 21:30:49 2019 +0000
- Revision:
- 28:98848e6a77a2
- Parent:
- 27:a1b41626f57c
- Child:
- 29:6b8411bb040a
Entrance and Exit done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17sm | 7:4aaa37a711a1 | 1 | #include "Entity.h" |
el17sm | 7:4aaa37a711a1 | 2 | |
el17sm | 28:98848e6a77a2 | 3 | // Functions |
el17sm | 22:7abf4581bc9b | 4 | void Entity::undo_move_x(bool status_x) |
el17sm | 22:7abf4581bc9b | 5 | { |
el17sm | 22:7abf4581bc9b | 6 | if (status_x) { |
el17sm | 13:d04a6caba40d | 7 | position.x = prev_pos.x; |
el17sm | 13:d04a6caba40d | 8 | } |
el17sm | 13:d04a6caba40d | 9 | } |
el17sm | 22:7abf4581bc9b | 10 | void Entity::undo_move_y(bool status_y) |
el17sm | 22:7abf4581bc9b | 11 | { |
el17sm | 22:7abf4581bc9b | 12 | if (status_y) { |
el17sm | 13:d04a6caba40d | 13 | position.y = prev_pos.y; |
el17sm | 13:d04a6caba40d | 14 | } |
el17sm | 13:d04a6caba40d | 15 | } |
el17sm | 22:7abf4581bc9b | 16 | void Entity::update_prev_pos() |
el17sm | 22:7abf4581bc9b | 17 | { |
el17sm | 22:7abf4581bc9b | 18 | prev_pos = position; |
el17sm | 26:abbc19edc5c1 | 19 | } |
el17sm | 7:4aaa37a711a1 | 20 | |
el17sm | 27:a1b41626f57c | 21 | bool Entity::matrix_collision_test(float pos_x, float pos_y, int * map) |
el17sm | 27:a1b41626f57c | 22 | { |
el17sm | 22:7abf4581bc9b | 23 | for (int j = pos_y; j < (int)pos_y + hitbox.height; j++) { |
el17sm | 22:7abf4581bc9b | 24 | for(int i = pos_x; i < (int)pos_x + hitbox.width; i++) { |
el17sm | 27:a1b41626f57c | 25 | if ((j>=screen_height) || (i>=screen_width) || (j<0) || (i<0)) {} // To allow movement towards outside of the map |
el17sm | 27:a1b41626f57c | 26 | else if (*((map+j*screen_width)+i) == 1) { |
el17sm | 13:d04a6caba40d | 27 | return true; |
el17sm | 13:d04a6caba40d | 28 | } |
el17sm | 13:d04a6caba40d | 29 | } |
el17sm | 13:d04a6caba40d | 30 | } |
el17sm | 13:d04a6caba40d | 31 | return false; |
el17sm | 13:d04a6caba40d | 32 | } |
el17sm | 13:d04a6caba40d | 33 | |
el17sm | 13:d04a6caba40d | 34 | // mutators |
el17sm | 7:4aaa37a711a1 | 35 | |
el17sm | 28:98848e6a77a2 | 36 | void Entity::set_position(float x, float y) |
el17sm | 28:98848e6a77a2 | 37 | { |
el17sm | 28:98848e6a77a2 | 38 | position.x = x; |
el17sm | 28:98848e6a77a2 | 39 | position.y = y; |
el17sm | 28:98848e6a77a2 | 40 | } |
el17sm | 28:98848e6a77a2 | 41 | |
el17sm | 24:26369d92a06a | 42 | void Entity::position_add_x(float change_x) |
el17sm | 24:26369d92a06a | 43 | { |
el17sm | 24:26369d92a06a | 44 | position.x += change_x; |
el17sm | 24:26369d92a06a | 45 | } |
el17sm | 24:26369d92a06a | 46 | void Entity::position_add_y(float change_y) |
el17sm | 24:26369d92a06a | 47 | { |
el17sm | 24:26369d92a06a | 48 | position.y += change_y; |
el17sm | 24:26369d92a06a | 49 | } |
el17sm | 24:26369d92a06a | 50 | |
el17sm | 7:4aaa37a711a1 | 51 | // accessors |
el17sm | 22:7abf4581bc9b | 52 | bool Entity::get_moving() |
el17sm | 22:7abf4581bc9b | 53 | { |
el17sm | 22:7abf4581bc9b | 54 | return moving; |
el17sm | 22:7abf4581bc9b | 55 | } |
el17sm | 28:98848e6a77a2 | 56 | bool Entity::is_damaged_by_collision() |
el17sm | 28:98848e6a77a2 | 57 | { |
el17sm | 28:98848e6a77a2 | 58 | return _damage_self_upon_collision; |
el17sm | 28:98848e6a77a2 | 59 | } |
el17sm | 28:98848e6a77a2 | 60 | int Entity::get_hp_drop_chance() |
el17sm | 28:98848e6a77a2 | 61 | { |
el17sm | 28:98848e6a77a2 | 62 | return _hp_drop_chance; |
el17sm | 28:98848e6a77a2 | 63 | } |
el17sm | 22:7abf4581bc9b | 64 | int Entity::get_hitbox_width() |
el17sm | 22:7abf4581bc9b | 65 | { |
el17sm | 22:7abf4581bc9b | 66 | return hitbox.width; |
el17sm | 22:7abf4581bc9b | 67 | } |
el17sm | 22:7abf4581bc9b | 68 | int Entity::get_hitbox_height() |
el17sm | 22:7abf4581bc9b | 69 | { |
el17sm | 22:7abf4581bc9b | 70 | return hitbox.height; |
el17sm | 22:7abf4581bc9b | 71 | } |
el17sm | 22:7abf4581bc9b | 72 | int Entity::get_face() |
el17sm | 22:7abf4581bc9b | 73 | { |
el17sm | 22:7abf4581bc9b | 74 | return face; |
el17sm | 22:7abf4581bc9b | 75 | } |
el17sm | 22:7abf4581bc9b | 76 | int Entity::get_sprite_width() |
el17sm | 22:7abf4581bc9b | 77 | { |
el17sm | 22:7abf4581bc9b | 78 | return sprite_size.width; |
el17sm | 22:7abf4581bc9b | 79 | } |
el17sm | 22:7abf4581bc9b | 80 | int Entity::get_sprite_height() |
el17sm | 22:7abf4581bc9b | 81 | { |
el17sm | 22:7abf4581bc9b | 82 | return sprite_size.height; |
el17sm | 22:7abf4581bc9b | 83 | } |
el17sm | 22:7abf4581bc9b | 84 | int Entity::get_offset_x() |
el17sm | 22:7abf4581bc9b | 85 | { |
el17sm | 22:7abf4581bc9b | 86 | return sprite_size.offset_x; |
el17sm | 22:7abf4581bc9b | 87 | } |
el17sm | 22:7abf4581bc9b | 88 | int Entity::get_offset_y() |
el17sm | 22:7abf4581bc9b | 89 | { |
el17sm | 22:7abf4581bc9b | 90 | return sprite_size.offset_y; |
el17sm | 22:7abf4581bc9b | 91 | } |
el17sm | 22:7abf4581bc9b | 92 | int Entity::get_pos_x() |
el17sm | 22:7abf4581bc9b | 93 | { |
el17sm | 22:7abf4581bc9b | 94 | return position.x; |
el17sm | 22:7abf4581bc9b | 95 | } |
el17sm | 22:7abf4581bc9b | 96 | int Entity::get_pos_y() |
el17sm | 22:7abf4581bc9b | 97 | { |
el17sm | 22:7abf4581bc9b | 98 | return position.y; |
el17sm | 22:7abf4581bc9b | 99 | } |
el17sm | 22:7abf4581bc9b | 100 | int Entity::get_prev_pos_x() |
el17sm | 22:7abf4581bc9b | 101 | { |
el17sm | 22:7abf4581bc9b | 102 | return prev_pos.x; |
el17sm | 22:7abf4581bc9b | 103 | } |
el17sm | 22:7abf4581bc9b | 104 | int Entity::get_prev_pos_y() |
el17sm | 22:7abf4581bc9b | 105 | { |
el17sm | 22:7abf4581bc9b | 106 | return prev_pos.y; |
el17sm | 23:5a8f75e93508 | 107 | } |
el17sm | 23:5a8f75e93508 | 108 | int Entity::get_attack() |
el17sm | 23:5a8f75e93508 | 109 | { |
el17sm | 23:5a8f75e93508 | 110 | return attack; |
el17sm | 23:5a8f75e93508 | 111 | } |
el17sm | 23:5a8f75e93508 | 112 | int Entity::get_hp() |
el17sm | 23:5a8f75e93508 | 113 | { |
el17sm | 23:5a8f75e93508 | 114 | return hp; |
el17sm | 28:98848e6a77a2 | 115 | } |
el17sm | 28:98848e6a77a2 | 116 | float Entity::get_velocity() |
el17sm | 28:98848e6a77a2 | 117 | { |
el17sm | 28:98848e6a77a2 | 118 | return velocity; |
el17sm | 22:7abf4581bc9b | 119 | } |