![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
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@21:be18f33da757, 2019-04-25 (annotated)
- Committer:
- el17sm
- Date:
- Thu Apr 25 05:27:43 2019 +0000
- Revision:
- 21:be18f33da757
- Parent:
- 14:3361879490b2
- Child:
- 23:5a8f75e93508
Snake half done no clear screen error
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 | 13:d04a6caba40d | 3 | // functions |
el17sm | 21:be18f33da757 | 4 | void Entity::undo_move_x(bool status_x) |
el17sm | 21:be18f33da757 | 5 | { |
el17sm | 21:be18f33da757 | 6 | if (status_x) { |
el17sm | 13:d04a6caba40d | 7 | position.x = prev_pos.x; |
el17sm | 13:d04a6caba40d | 8 | } |
el17sm | 13:d04a6caba40d | 9 | } |
el17sm | 21:be18f33da757 | 10 | void Entity::undo_move_y(bool status_y) |
el17sm | 21:be18f33da757 | 11 | { |
el17sm | 21:be18f33da757 | 12 | if (status_y) { |
el17sm | 13:d04a6caba40d | 13 | position.y = prev_pos.y; |
el17sm | 13:d04a6caba40d | 14 | } |
el17sm | 13:d04a6caba40d | 15 | } |
el17sm | 21:be18f33da757 | 16 | void Entity::update_prev_pos() |
el17sm | 21:be18f33da757 | 17 | { |
el17sm | 21:be18f33da757 | 18 | prev_pos = position; |
el17sm | 21:be18f33da757 | 19 | }; |
el17sm | 7:4aaa37a711a1 | 20 | |
el17sm | 21:be18f33da757 | 21 | bool Entity::matrix_collision_test(float pos_x, float pos_y, int map_no) |
el17sm | 21:be18f33da757 | 22 | { |
el17sm | 21:be18f33da757 | 23 | for (int j = pos_y; j < (int)pos_y + hitbox.height; j++) { |
el17sm | 21:be18f33da757 | 24 | for(int i = pos_x; i < (int)pos_x + hitbox.width; i++) { |
el17sm | 13:d04a6caba40d | 25 | if ((j>=48) || (i>=84) || (j<0) || (i<0)) {} |
el17sm | 13:d04a6caba40d | 26 | else if ((level_map[0][j][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 | 21:be18f33da757 | 34 | void Entity::take_damage(int damage) |
el17sm | 21:be18f33da757 | 35 | { |
el17sm | 13:d04a6caba40d | 36 | hp -= damage; |
el17sm | 13:d04a6caba40d | 37 | } |
el17sm | 13:d04a6caba40d | 38 | |
el17sm | 21:be18f33da757 | 39 | bool Entity::death_check() |
el17sm | 21:be18f33da757 | 40 | { |
el17sm | 21:be18f33da757 | 41 | if (hp <= 0) { |
el17sm | 14:3361879490b2 | 42 | return true; |
el17sm | 14:3361879490b2 | 43 | } |
el17sm | 14:3361879490b2 | 44 | return false; |
el17sm | 14:3361879490b2 | 45 | } |
el17sm | 14:3361879490b2 | 46 | |
el17sm | 13:d04a6caba40d | 47 | // mutators |
el17sm | 7:4aaa37a711a1 | 48 | |
el17sm | 7:4aaa37a711a1 | 49 | // accessors |
el17sm | 21:be18f33da757 | 50 | bool Entity::get_moving() |
el17sm | 21:be18f33da757 | 51 | { |
el17sm | 21:be18f33da757 | 52 | return moving; |
el17sm | 21:be18f33da757 | 53 | } |
el17sm | 21:be18f33da757 | 54 | int Entity::get_hitbox_width() |
el17sm | 21:be18f33da757 | 55 | { |
el17sm | 21:be18f33da757 | 56 | return hitbox.width; |
el17sm | 21:be18f33da757 | 57 | } |
el17sm | 21:be18f33da757 | 58 | int Entity::get_hitbox_height() |
el17sm | 21:be18f33da757 | 59 | { |
el17sm | 21:be18f33da757 | 60 | return hitbox.height; |
el17sm | 21:be18f33da757 | 61 | } |
el17sm | 21:be18f33da757 | 62 | int Entity::get_face() |
el17sm | 21:be18f33da757 | 63 | { |
el17sm | 21:be18f33da757 | 64 | return face; |
el17sm | 21:be18f33da757 | 65 | } |
el17sm | 21:be18f33da757 | 66 | int Entity::get_sprite_width() |
el17sm | 21:be18f33da757 | 67 | { |
el17sm | 21:be18f33da757 | 68 | return sprite_size.width; |
el17sm | 21:be18f33da757 | 69 | } |
el17sm | 21:be18f33da757 | 70 | int Entity::get_sprite_height() |
el17sm | 21:be18f33da757 | 71 | { |
el17sm | 21:be18f33da757 | 72 | return sprite_size.height; |
el17sm | 21:be18f33da757 | 73 | } |
el17sm | 21:be18f33da757 | 74 | int Entity::get_offset_x() |
el17sm | 21:be18f33da757 | 75 | { |
el17sm | 21:be18f33da757 | 76 | return sprite_size.offset_x; |
el17sm | 21:be18f33da757 | 77 | } |
el17sm | 21:be18f33da757 | 78 | int Entity::get_offset_y() |
el17sm | 21:be18f33da757 | 79 | { |
el17sm | 21:be18f33da757 | 80 | return sprite_size.offset_y; |
el17sm | 21:be18f33da757 | 81 | } |
el17sm | 21:be18f33da757 | 82 | int Entity::get_pos_x() |
el17sm | 21:be18f33da757 | 83 | { |
el17sm | 21:be18f33da757 | 84 | return position.x; |
el17sm | 21:be18f33da757 | 85 | } |
el17sm | 21:be18f33da757 | 86 | int Entity::get_pos_y() |
el17sm | 21:be18f33da757 | 87 | { |
el17sm | 21:be18f33da757 | 88 | return position.y; |
el17sm | 21:be18f33da757 | 89 | } |
el17sm | 21:be18f33da757 | 90 | int Entity::get_prev_pos_x() |
el17sm | 21:be18f33da757 | 91 | { |
el17sm | 21:be18f33da757 | 92 | return prev_pos.x; |
el17sm | 21:be18f33da757 | 93 | } |
el17sm | 21:be18f33da757 | 94 | int Entity::get_prev_pos_y() |
el17sm | 21:be18f33da757 | 95 | { |
el17sm | 21:be18f33da757 | 96 | return prev_pos.y; |
el17sm | 21:be18f33da757 | 97 | } |