A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.

Dependencies:   mbed MotionSensor

Committer:
el17sm
Date:
Sat May 04 15:39:20 2019 +0000
Revision:
29:6b8411bb040a
Parent:
28:98848e6a77a2
Child:
34:1d5b4da3935e
added Room complete;; started Floor engine;; ; To do:; Floor generation;; More enemies;; Bosses;; Title Screen;; Score;

Who changed what in which revision?

UserRevisionLine numberNew 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 29:6b8411bb040a 21 bool Entity::entity_to_map_collision_test(float pos_x, float pos_y, int * map, bool * doorways)
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 29:6b8411bb040a 29
el17sm 29:6b8411bb040a 30 // Checking if the player walks into a wall if no doorway on that side exists
el17sm 29:6b8411bb040a 31 else if ( !(*(doorways)) && (pos_y < 9) ) {
el17sm 29:6b8411bb040a 32 return true;
el17sm 29:6b8411bb040a 33 }
el17sm 29:6b8411bb040a 34 else if ( !(*(doorways+1)) && (pos_x + hitbox.width - 1 > 81) ) {
el17sm 29:6b8411bb040a 35 return true;
el17sm 29:6b8411bb040a 36 }
el17sm 29:6b8411bb040a 37 else if ( !(*(doorways+2)) && (pos_y + hitbox.width - 1 > 36) ) {
el17sm 29:6b8411bb040a 38 return true;
el17sm 29:6b8411bb040a 39 }
el17sm 29:6b8411bb040a 40 else if ( !(*(doorways+3)) && (pos_x < 2) ) {
el17sm 29:6b8411bb040a 41 return true;
el17sm 29:6b8411bb040a 42 }
el17sm 13:d04a6caba40d 43 }
el17sm 13:d04a6caba40d 44 }
el17sm 13:d04a6caba40d 45 return false;
el17sm 13:d04a6caba40d 46 }
el17sm 13:d04a6caba40d 47
el17sm 29:6b8411bb040a 48 // Mutators
el17sm 7:4aaa37a711a1 49
el17sm 28:98848e6a77a2 50 void Entity::set_position(float x, float y)
el17sm 28:98848e6a77a2 51 {
el17sm 28:98848e6a77a2 52 position.x = x;
el17sm 28:98848e6a77a2 53 position.y = y;
el17sm 28:98848e6a77a2 54 }
el17sm 28:98848e6a77a2 55
el17sm 24:26369d92a06a 56 void Entity::position_add_x(float change_x)
el17sm 24:26369d92a06a 57 {
el17sm 24:26369d92a06a 58 position.x += change_x;
el17sm 24:26369d92a06a 59 }
el17sm 24:26369d92a06a 60 void Entity::position_add_y(float change_y)
el17sm 24:26369d92a06a 61 {
el17sm 24:26369d92a06a 62 position.y += change_y;
el17sm 24:26369d92a06a 63 }
el17sm 24:26369d92a06a 64
el17sm 7:4aaa37a711a1 65 // accessors
el17sm 22:7abf4581bc9b 66 bool Entity::get_moving()
el17sm 22:7abf4581bc9b 67 {
el17sm 22:7abf4581bc9b 68 return moving;
el17sm 22:7abf4581bc9b 69 }
el17sm 28:98848e6a77a2 70 bool Entity::is_damaged_by_collision()
el17sm 28:98848e6a77a2 71 {
el17sm 28:98848e6a77a2 72 return _damage_self_upon_collision;
el17sm 28:98848e6a77a2 73 }
el17sm 28:98848e6a77a2 74 int Entity::get_hp_drop_chance()
el17sm 28:98848e6a77a2 75 {
el17sm 28:98848e6a77a2 76 return _hp_drop_chance;
el17sm 28:98848e6a77a2 77 }
el17sm 22:7abf4581bc9b 78 int Entity::get_hitbox_width()
el17sm 22:7abf4581bc9b 79 {
el17sm 22:7abf4581bc9b 80 return hitbox.width;
el17sm 22:7abf4581bc9b 81 }
el17sm 22:7abf4581bc9b 82 int Entity::get_hitbox_height()
el17sm 22:7abf4581bc9b 83 {
el17sm 22:7abf4581bc9b 84 return hitbox.height;
el17sm 22:7abf4581bc9b 85 }
el17sm 22:7abf4581bc9b 86 int Entity::get_face()
el17sm 22:7abf4581bc9b 87 {
el17sm 22:7abf4581bc9b 88 return face;
el17sm 22:7abf4581bc9b 89 }
el17sm 22:7abf4581bc9b 90 int Entity::get_sprite_width()
el17sm 22:7abf4581bc9b 91 {
el17sm 22:7abf4581bc9b 92 return sprite_size.width;
el17sm 22:7abf4581bc9b 93 }
el17sm 22:7abf4581bc9b 94 int Entity::get_sprite_height()
el17sm 22:7abf4581bc9b 95 {
el17sm 22:7abf4581bc9b 96 return sprite_size.height;
el17sm 22:7abf4581bc9b 97 }
el17sm 22:7abf4581bc9b 98 int Entity::get_offset_x()
el17sm 22:7abf4581bc9b 99 {
el17sm 22:7abf4581bc9b 100 return sprite_size.offset_x;
el17sm 22:7abf4581bc9b 101 }
el17sm 22:7abf4581bc9b 102 int Entity::get_offset_y()
el17sm 22:7abf4581bc9b 103 {
el17sm 22:7abf4581bc9b 104 return sprite_size.offset_y;
el17sm 22:7abf4581bc9b 105 }
el17sm 22:7abf4581bc9b 106 int Entity::get_pos_x()
el17sm 22:7abf4581bc9b 107 {
el17sm 22:7abf4581bc9b 108 return position.x;
el17sm 22:7abf4581bc9b 109 }
el17sm 22:7abf4581bc9b 110 int Entity::get_pos_y()
el17sm 22:7abf4581bc9b 111 {
el17sm 22:7abf4581bc9b 112 return position.y;
el17sm 22:7abf4581bc9b 113 }
el17sm 22:7abf4581bc9b 114 int Entity::get_prev_pos_x()
el17sm 22:7abf4581bc9b 115 {
el17sm 22:7abf4581bc9b 116 return prev_pos.x;
el17sm 22:7abf4581bc9b 117 }
el17sm 22:7abf4581bc9b 118 int Entity::get_prev_pos_y()
el17sm 22:7abf4581bc9b 119 {
el17sm 22:7abf4581bc9b 120 return prev_pos.y;
el17sm 23:5a8f75e93508 121 }
el17sm 23:5a8f75e93508 122 int Entity::get_attack()
el17sm 23:5a8f75e93508 123 {
el17sm 23:5a8f75e93508 124 return attack;
el17sm 23:5a8f75e93508 125 }
el17sm 23:5a8f75e93508 126 int Entity::get_hp()
el17sm 23:5a8f75e93508 127 {
el17sm 23:5a8f75e93508 128 return hp;
el17sm 28:98848e6a77a2 129 }
el17sm 28:98848e6a77a2 130 float Entity::get_velocity()
el17sm 28:98848e6a77a2 131 {
el17sm 28:98848e6a77a2 132 return velocity;
el17sm 22:7abf4581bc9b 133 }