A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
Diff: Entity/Entity.cpp
- Revision:
- 29:6b8411bb040a
- Parent:
- 28:98848e6a77a2
- Child:
- 34:1d5b4da3935e
diff -r 98848e6a77a2 -r 6b8411bb040a Entity/Entity.cpp --- a/Entity/Entity.cpp Thu May 02 21:30:49 2019 +0000 +++ b/Entity/Entity.cpp Sat May 04 15:39:20 2019 +0000 @@ -18,7 +18,7 @@ prev_pos = position; } -bool Entity::matrix_collision_test(float pos_x, float pos_y, int * map) +bool Entity::entity_to_map_collision_test(float pos_x, float pos_y, int * map, bool * doorways) { for (int j = pos_y; j < (int)pos_y + hitbox.height; j++) { for(int i = pos_x; i < (int)pos_x + hitbox.width; i++) { @@ -26,12 +26,26 @@ else if (*((map+j*screen_width)+i) == 1) { return true; } + + // Checking if the player walks into a wall if no doorway on that side exists + else if ( !(*(doorways)) && (pos_y < 9) ) { + return true; + } + else if ( !(*(doorways+1)) && (pos_x + hitbox.width - 1 > 81) ) { + return true; + } + else if ( !(*(doorways+2)) && (pos_y + hitbox.width - 1 > 36) ) { + return true; + } + else if ( !(*(doorways+3)) && (pos_x < 2) ) { + return true; + } } } return false; } -// mutators +// Mutators void Entity::set_position(float x, float y) {