Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed MotionSensor
Entity.cpp
00001 #include "Entity.h" 00002 00003 // Functions 00004 void Entity::undo_move_x(bool condition) 00005 { 00006 if (condition) { 00007 _position.x = _prev_pos.x; 00008 } 00009 } 00010 void Entity::undo_move_y(bool condition) 00011 { 00012 if (condition) { 00013 _position.y = _prev_pos.y; 00014 } 00015 } 00016 void Entity::update_prev_pos() 00017 { 00018 _prev_pos = _position; 00019 } 00020 00021 bool Entity::entity_to_map_collision_test(float pos_x, float pos_y, char * two_d_map, bool * doorways) // Returns true if the entity clashes a wall 00022 { 00023 for (int j = pos_y; j < (int)pos_y + _hitbox.height; j++) { 00024 for(int i = pos_x; i < (int)pos_x + _hitbox.width; i++) { 00025 if ((j>=screen_height) || (i>=screen_width) || (j<0) || (i<0)) {} // To allow movement towards outside of the map 00026 else if (*((two_d_map+j*screen_width)+i) == 1) { // if entity clashes the 2d map 00027 return true; 00028 } 00029 00030 // Checking if the player walks into a wall if no doorway on that side exists 00031 else if ( !(*(doorways)) && (pos_y <= 10) ) { 00032 return true; 00033 } 00034 else if ( !(*(doorways+1)) && (pos_x + _hitbox.width - 1 >= 81) ) { 00035 return true; 00036 } 00037 else if ( !(*(doorways+2)) && (pos_y + _hitbox.height - 1 >= 45) ) { 00038 return true; 00039 } 00040 else if ( !(*(doorways+3)) && (pos_x <= 3) ) { 00041 return true; 00042 } 00043 } 00044 } 00045 return false; 00046 } 00047 00048 // Mutators 00049 00050 void Entity::set_position(float x, float y) 00051 { 00052 _position.x = x; 00053 _position.y = y; 00054 } 00055 00056 void Entity::position_add_x(float change_x) 00057 { 00058 _position.x += change_x; 00059 } 00060 void Entity::position_add_y(float change_y) 00061 { 00062 _position.y += change_y; 00063 } 00064 00065 // Accessors 00066 int Entity::get_hp_drop_chance() 00067 { 00068 return _hp_drop_chance; 00069 } 00070 int Entity::get_hitbox_width() 00071 { 00072 return _hitbox.width; 00073 } 00074 int Entity::get_hitbox_height() 00075 { 00076 return _hitbox.height; 00077 } 00078 int Entity::get_face() 00079 { 00080 return _face; 00081 } 00082 int Entity::get_sprite_width() 00083 { 00084 return _sprite_size.width; 00085 } 00086 int Entity::get_sprite_height() 00087 { 00088 return _sprite_size.height; 00089 } 00090 int Entity::get_offset_x() 00091 { 00092 return _sprite_size.offset_x; 00093 } 00094 int Entity::get_offset_y() 00095 { 00096 return _sprite_size.offset_y; 00097 } 00098 int Entity::get_pos_x() 00099 { 00100 return _position.x; 00101 } 00102 int Entity::get_pos_y() 00103 { 00104 return _position.y; 00105 } 00106 int Entity::get_prev_pos_x() 00107 { 00108 return _prev_pos.x; 00109 } 00110 int Entity::get_prev_pos_y() 00111 { 00112 return _prev_pos.y; 00113 } 00114 int Entity::get_attack() 00115 { 00116 return _attack; 00117 } 00118 int Entity::get_hp() 00119 { 00120 return _hp; 00121 } 00122 float Entity::get_velocity() 00123 { 00124 return _velocity; 00125 }
Generated on Tue Jul 19 2022 23:32:07 by
1.7.2