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:
- 30:ec915d24d3e9
- Parent:
- 29:6b8411bb040a
- Child:
- 31:ab24d028ddfd
diff -r 6b8411bb040a -r ec915d24d3e9 RoomEngine/RoomEngine.cpp --- a/RoomEngine/RoomEngine.cpp Sat May 04 15:39:20 2019 +0000 +++ b/RoomEngine/RoomEngine.cpp Sun May 05 18:04:43 2019 +0000 @@ -1,8 +1,10 @@ #include "RoomEngine.h" -RoomEngine::RoomEngine() + +RoomEngine::RoomEngine(float global_contrast) { _room_x = 5; _room_y = 5; + _global_contrast = global_contrast; } RoomEngine::~RoomEngine() @@ -39,7 +41,11 @@ } move_player(); render(lcd, gamepad); - lcd.setContrast(0.75 - (i * 0.005)); + if (0.75 - (i * 0.005) > _global_contrast) { + lcd.setContrast(0.75 - (i * 0.005)); + } else { + lcd.setContrast(_global_contrast); + } } } @@ -64,8 +70,9 @@ } move_player(); render(lcd, gamepad); - lcd.setContrast(0.5 + (i * 0.005)); + lcd.setContrast(_global_contrast + (i * 0.005)); } + lcd.setContrast(0.75); } void RoomEngine::update_current_room() @@ -255,9 +262,7 @@ { for (int i = 0; i < bullets_max; i++) { if (player->valid_bullets[i]) { - if (player->bullets_array[i]->out_of_bounds_check(room->get_current_map_2d(), room->get_doorways())) { - player->valid_bullets[i] = false; - delete player->bullets_array[i]; + if (player->update_bullets(room->get_current_map_2d(), room->get_doorways())) { } else { for (int j = 0; j < MAX_ENEMIES; j++) { if (room->valid_enemies[j] && (entity_collision(*player->bullets_array[i], *room->enemies[j]))) { @@ -307,7 +312,6 @@ { move_player(); move_enemies(); - move_bullets(); } void RoomEngine::move_player() @@ -326,22 +330,13 @@ } // Entity Collision Repulsion for (int i = 0; i < MAX_ENEMIES; i++) { - if (room->valid_enemies[i]) { + if (room->valid_enemies[i] && !room->enemies[i]->is_damaged_by_collision()) { 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)); } } } -void RoomEngine::move_bullets() -{ - for (int i = 0; i < bullets_max; i++) { - if (player->valid_bullets[i]) { - player->bullets_array[i]->move(player->get_bullet_speed(), 0, 0, room->get_doorways()); - } - } -} - void RoomEngine::update_player_position(int side) { switch(side) { @@ -421,24 +416,14 @@ { room->draw_room(lcd); //lcd.drawSprite(0,0,screen_height,screen_width,(int *)level_map[1]); - draw_player(lcd); + player->draw(lcd); draw_enemies(lcd); - draw_bullets(lcd); room->draw_room_overlay(lcd); if (_L) { draw_health(lcd); } } -void RoomEngine::draw_player(N5110 &lcd) -{ - lcd.drawSpriteTransparent(player->get_pos_x()-player->get_offset_x(), - player->get_pos_y()-player->get_offset_y(), - player->get_sprite_height(), - player->get_sprite_width(), - player->get_frame()); -} - void RoomEngine::draw_enemies(N5110 &lcd) { for (int i = 0; i < MAX_ENEMIES; i++) { @@ -452,19 +437,6 @@ } } -void RoomEngine::draw_bullets(N5110 &lcd) -{ - for (int i = 0; i < bullets_max; i++) { - if (player->valid_bullets[i]) { - lcd.drawSpriteTransparent(player->bullets_array[i]->get_pos_x()-player->bullets_array[i]->get_offset_x(), - player->bullets_array[i]->get_pos_y()-player->bullets_array[i]->get_offset_y(), - player->bullets_array[i]->get_sprite_height(), - player->bullets_array[i]->get_sprite_width(), - player->bullets_array[i]->get_frame()); - } - } -} - void RoomEngine::draw_health(N5110 &lcd) { for (int i = 0; i < player->get_hp(); i++){