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:
- 37:a404860171a9
- Parent:
- 34:1d5b4da3935e
- Child:
- 38:09832e662803
- Child:
- 39:0c2521949429
--- a/RoomEngine/RoomEngine.cpp Tue May 07 01:11:07 2019 +0000 +++ b/RoomEngine/RoomEngine.cpp Tue May 07 03:47:39 2019 +0000 @@ -126,15 +126,6 @@ wait_ms(1000/40); // setting FPS } -bool RoomEngine::check_player_death() -{ - // Player Death - if (player->get_hp() <= 0) { - return true; - } - return false; -} - int RoomEngine::check_player_room_position() // returns 0,1,2,3 if the player exits the respective directions, returns 4 if the player is in the room { if (player->get_pos_y() < 0) { @@ -251,13 +242,20 @@ break; // only let 1 enemy damage player at a time } } + if (room->valid_collectibles[i]) { + if(entity_collision(*player, *room->collectibles[i])) { + player->take_damage(room->collectibles[i]->get_attack()); + delete room->collectibles[i]; + room->valid_collectibles[i] = false; + break; // only let 1 heart heal player at a time + } + } } } void RoomEngine::check_damage_enemies() { check_damage_enemies_by_bullets(); - check_damage_enemies_by_collisions(); } void RoomEngine::check_damage_enemies_by_bullets() @@ -279,33 +277,22 @@ } } -void RoomEngine::check_damage_enemies_by_collisions() -{ - for (int i = 0; i < MAX_ENEMIES; i++) { - if (room->valid_enemies[i]) { - if((room->enemies[i]->is_damaged_by_collision()) && (entity_collision(*player, *room->enemies[i]))) { - room->enemies[i]->take_damage(player->get_attack()); - } - } - } -} - void RoomEngine::check_enemies_death() { // Enemy Death for (int i = 0; i < MAX_ENEMIES; i++) { - if (room->valid_enemies[i]) { - if(room->enemies[i]->get_hp() <= 0) { - float temp_pos_x = room->enemies[i]->get_pos_x(); - float temp_pos_y = room->enemies[i]->get_pos_y(); - delete room->enemies[i]; - if ((rand() % 100) < room->enemies[i]->get_hp_drop_chance()){ - room->enemies[i] = new Health(temp_pos_x, temp_pos_y); - } else { - room->valid_enemies[i] = false; + if((room->valid_enemies[i]) && (room->enemies[i]->get_hp() <= 0)) { + if ((rand() % 100) < room->enemies[i]->get_hp_drop_chance()){ + for (int j = 0; j < MAX_ENEMIES; j++) { + if (!room->valid_collectibles[j]) { + room->collectibles[j] = new Health(room->enemies[i]->get_pos_x(), room->enemies[i]->get_pos_y()); // Spawn a health drop + room->valid_collectibles[j] = true; + break; + } } } - + delete room->enemies[i]; + room->valid_enemies[i] = false; } } } @@ -332,7 +319,7 @@ } // Entity Collision Repulsion for (int i = 0; i < MAX_ENEMIES; i++) { - if (room->valid_enemies[i] && !room->enemies[i]->is_damaged_by_collision()) { + if (room->valid_enemies[i]) { room->enemies[i]->position_add_x(entity_move_check_x(room->enemies[i], room->enemies, MAX_ENEMIES, i, room->valid_enemies)); room->enemies[i]->position_add_y(entity_move_check_y(room->enemies[i], room->enemies, MAX_ENEMIES, i, room->valid_enemies)); } @@ -420,6 +407,7 @@ //lcd.drawSprite(0,0,screen_height,screen_width,(char *)level_map[1]); player->draw(lcd); room->draw_enemies(lcd); + room->draw_collectibles(lcd); room->draw_room_overlay(lcd); if (_L) { draw_health(lcd);