A rouge-like rpg, heavily inspired on the binding of isaac. Running on a FRDM-K64F Mbed board. C++.
Dependencies: mbed MotionSensor
Diff: RoomEngine/RoomEngine.cpp
- Revision:
- 41:0697508a28ba
- Parent:
- 40:cbcbf6fc1421
- Child:
- 42:cdcda895cb1b
--- a/RoomEngine/RoomEngine.cpp Tue May 07 12:42:12 2019 +0000 +++ b/RoomEngine/RoomEngine.cpp Tue May 07 17:02:30 2019 +0000 @@ -1,11 +1,10 @@ #include "RoomEngine.h" // Constructor -RoomEngine::RoomEngine(float global_contrast, Player *current_player) +RoomEngine::RoomEngine(float global_contrast) { _room_x = 5; _room_y = 5; _global_contrast = global_contrast; - current_player->set_position(39, 27); } // Destructor @@ -30,16 +29,16 @@ for(int i = 0; i<50; i++) { switch(side) { case 0 : - set_mapped_coord(0, -((3 +player->get_sprite_height()) / (50 * player->get_velocity()))); + set_mapped_coord(0, -((4 + player->get_sprite_height()) / (50 * player->get_velocity()))); break; case 1 : - set_mapped_coord(-((3 +player->get_hitbox_width()) / (50 * player->get_velocity())), 0); + set_mapped_coord(-((4 + player->get_hitbox_width()) / (50 * player->get_velocity())), 0); break; case 2 : - set_mapped_coord(0, ((3 +player->get_hitbox_height()) / (50 * player->get_velocity()))); + set_mapped_coord(0, ((4 + player->get_hitbox_height()) / (50 * player->get_velocity()))); break; case 3 : - set_mapped_coord(((3 +player->get_hitbox_width()) / (50 * player->get_velocity())), 0); + set_mapped_coord(((4 + player->get_hitbox_width()) / (50 * player->get_velocity())), 0); break; } move_player(); @@ -113,6 +112,7 @@ { check_damage(); check_enemies_death(); + check_walls_collision(); move(); player->buttons(_A, _B, _Y, _X); } @@ -298,6 +298,28 @@ } } +void RoomEngine::check_walls_collision() +{ + // Enemy + for (int i = 0; i < MAX_ENEMIES; i++) { + if(room->valid_enemies[i]) { + room->enemies[i]->undo_move_x(entity_move_check_x(room->enemies[i], room->walls, 2, 10, room->valid_walls)); + room->enemies[i]->undo_move_y(entity_move_check_y(room->enemies[i], room->walls, 2, 10, room->valid_walls)); + } + } + // Player + player->undo_move_x(entity_move_check_x(player, room->walls, 2, 10, room->valid_walls)); + player->undo_move_y(entity_move_check_y(player, room->walls, 2, 10, room->valid_walls)); + // Bullets + for (int i = 0; i < bullets_max; i++) { + for (int j = 0; j < 2; j++) { + if ((player->valid_bullets[i]) && (room->valid_walls[j]) && (entity_collision(*player->bullets_array[i], *room->walls[j]))) { + delete player->bullets_array[i]; player->valid_bullets[i] = false; + } + } + } +} + void RoomEngine::move() { move_player(); @@ -343,7 +365,7 @@ player->set_position(85, 25); break; case 4 : - player->set_position(39, 27); + player->set_position(39, 37); break; } } @@ -411,8 +433,7 @@ player->draw(lcd); } player->draw_bullets(lcd, j); - room->draw_enemies(lcd, j); - room->draw_collectibles(lcd, j); + room->draw(lcd, j); } room->draw_room_overlay(lcd);