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:
- 49:3f83ed62d123
- Parent:
- 47:6e31b195ce3c
- Child:
- 50:2c5cb92a5361
--- a/RoomEngine/RoomEngine.cpp Thu May 09 02:46:44 2019 +0000 +++ b/RoomEngine/RoomEngine.cpp Thu May 09 04:24:30 2019 +0000 @@ -26,29 +26,22 @@ void RoomEngine::entrance_scene(N5110 &lcd, Gamepad &gamepad) { int side = check_player_room_position(); - for(int i = 0; i<50; i++) { - switch(side) { + switch(side) { // Setting movement of player as it enters the screen (velocity) case 0 : - set_mapped_coord(0, -((4 + player->get_sprite_height()) / (50 * player->get_velocity()))); - break; + set_mapped_coord(0, -((4 + player->get_sprite_height()) / (50 * player->get_velocity()))); break; case 1 : - set_mapped_coord(-((4 + player->get_hitbox_width()) / (50 * player->get_velocity())), 0); - break; + set_mapped_coord(-((4 + player->get_hitbox_width()) / (50 * player->get_velocity())), 0); break; case 2 : - set_mapped_coord(0, ((4 + player->get_hitbox_height()) / (50 * player->get_velocity()))); - break; + set_mapped_coord(0, ((4 + player->get_hitbox_height()) / (50 * player->get_velocity()))); break; case 3 : - set_mapped_coord(((4 + player->get_hitbox_width()) / (50 * player->get_velocity())), 0); - break; + set_mapped_coord(((4 + player->get_hitbox_width()) / (50 * player->get_velocity())), 0); break; } move_player(); render(lcd, gamepad); - if (0.75 - (i * 0.005) > _global_contrast) { + if (0.75 - (i * 0.005) > _global_contrast) { // Fade in lcd.setContrast(0.75 - (i * 0.005)); - } else { - lcd.setContrast(_global_contrast); - } + } else { lcd.setContrast(_global_contrast);} } } @@ -57,23 +50,19 @@ int side = check_player_room_position(); for(int i = 0; i<50; i++) { - switch(side) { + switch(side) { // Setting movement of player as it exits the screen (velocity) case 0 : - set_mapped_coord(0, (player->get_velocity() / 2)); - break; + set_mapped_coord(0, (player->get_velocity() / 2)); break; case 1 : - set_mapped_coord((player->get_velocity() / 2), 0); - break; + set_mapped_coord((player->get_velocity() / 2), 0); break; case 2 : - set_mapped_coord(0, -(player->get_velocity() / 2)); - break; + set_mapped_coord(0, -(player->get_velocity() / 2)); break; case 3 : - set_mapped_coord(-(player->get_velocity() / 2), 0); - break; + set_mapped_coord(-(player->get_velocity() / 2), 0); break; } move_player(); render(lcd, gamepad); - lcd.setContrast(_global_contrast + (i * 0.005)); + lcd.setContrast(_global_contrast + (i * 0.005)); // Fade out } lcd.setContrast(0.75); } @@ -195,14 +184,12 @@ float RoomEngine::entity_move_check_x(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[]) { for (int i = 0; i < no_of_enemies; i++) { - if (valid_enemies[i]) { - if(i != current_entity) { - if (((array[i]->get_prev_pos_x() <= a->get_pos_x()) && (a->get_pos_x() <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1)) || - ((array[i]->get_prev_pos_x() <= a->get_pos_x() + a->get_hitbox_width() - 1) && (a->get_pos_x() + a->get_hitbox_width() - 1 <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1))) { - if (((array[i]->get_prev_pos_y() <= a->get_prev_pos_y()) && (a->get_prev_pos_y() <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1)) || - ((array[i]->get_prev_pos_y() <= a->get_prev_pos_y() + a->get_hitbox_height() - 1) && (a->get_prev_pos_y() + a->get_hitbox_height() - 1 <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1))) { - return (2*((a->get_pos_x() > array[i]->get_prev_pos_x()) - 0.5)); - } + if ((valid_enemies[i]) && (i != current_entity)) { // only check if entity b exists and entity a is not the same as entity b + if (((array[i]->get_prev_pos_x() <= a->get_pos_x()) && (a->get_pos_x() <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1)) || + ((array[i]->get_prev_pos_x() <= a->get_pos_x() + a->get_hitbox_width() - 1) && (a->get_pos_x() + a->get_hitbox_width() - 1 <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1))) { + if (((array[i]->get_prev_pos_y() <= a->get_prev_pos_y()) && (a->get_prev_pos_y() <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1)) || + ((array[i]->get_prev_pos_y() <= a->get_prev_pos_y() + a->get_hitbox_height() - 1) && (a->get_prev_pos_y() + a->get_hitbox_height() - 1 <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1))) { + return (2*((a->get_pos_x() > array[i]->get_prev_pos_x()) - 0.5)); } } } @@ -214,14 +201,12 @@ float RoomEngine::entity_move_check_y(Entity *a, Entity *array[], int no_of_enemies, int current_entity, bool valid_enemies[]) { for (int i = 0; i < no_of_enemies; i++) { - if (valid_enemies[i]) { - if(i != current_entity) { - if (((array[i]->get_prev_pos_x() <= a->get_prev_pos_x()) && (a->get_prev_pos_x() <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1)) || - ((array[i]->get_prev_pos_x() <= a->get_prev_pos_x() + a->get_hitbox_width() - 1) && (a->get_prev_pos_x() + a->get_hitbox_width() - 1 <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1))) { - if (((array[i]->get_prev_pos_y() <= a->get_pos_y()) && (a->get_pos_y() <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1)) || - ((array[i]->get_prev_pos_y() <= a->get_pos_y() + a->get_hitbox_height() - 1) && (a->get_pos_y() + a->get_hitbox_height() - 1 <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1))) { - return (2*((a->get_pos_y() > array[i]->get_prev_pos_y()) - 0.5)); - } + if ((valid_enemies[i]) && (i != current_entity)) { // only check if entity b exists and entity a is not the same as entity b + if (((array[i]->get_prev_pos_x() <= a->get_prev_pos_x()) && (a->get_prev_pos_x() <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1)) || + ((array[i]->get_prev_pos_x() <= a->get_prev_pos_x() + a->get_hitbox_width() - 1) && (a->get_prev_pos_x() + a->get_hitbox_width() - 1 <= array[i]->get_prev_pos_x() + array[i]->get_hitbox_width() - 1))) { + if (((array[i]->get_prev_pos_y() <= a->get_pos_y()) && (a->get_pos_y() <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1)) || + ((array[i]->get_prev_pos_y() <= a->get_pos_y() + a->get_hitbox_height() - 1) && (a->get_pos_y() + a->get_hitbox_height() - 1 <= array[i]->get_prev_pos_y() + array[i]->get_hitbox_height() - 1))) { + return (2*((a->get_pos_y() > array[i]->get_prev_pos_y()) - 0.5)); } } } @@ -374,44 +359,32 @@ char * paused_screen = lcd.readScreen(); int pause_timer = 2; lcd.drawSpriteTransparent(20, 20, 9, 45, (char *)pause_sprite); - wait(0.05); while(gamepad.check_event(Gamepad::START_PRESSED)) { - lcd.clear(); - lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen); - if (pause_timer % 10 <= 4) { - lcd.drawSpriteTransparent(20, 20, 9, 45, (char *)pause_sprite); - } - lcd.refresh(); - pause_timer++; - wait_ms(1000/40); + draw_pause_screen(lcd, paused_screen, pause_timer); } - wait(0.05); pause_timer += 2; while(!gamepad.check_event(Gamepad::START_PRESSED)) { - lcd.clear(); - lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen); - if (pause_timer % 10 <= 4) { - lcd.drawSpriteTransparent(20, 20, 9, 45, (char *)pause_sprite); - } - lcd.refresh(); - pause_timer++; - wait_ms(1000/40); + draw_pause_screen(lcd, paused_screen, pause_timer); } - wait(0.05); pause_timer += 2; while(gamepad.check_event(Gamepad::START_PRESSED)) { - lcd.clear(); - lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen); - if (pause_timer % 10 <= 4) { - lcd.drawSpriteTransparent(20, 20, 9, 45, (char *)pause_sprite); - } - lcd.refresh(); - pause_timer++; - wait_ms(1000/40); + draw_pause_screen(lcd, paused_screen, pause_timer); } } } +void RoomEngine::draw_pause_screen(N5110 &lcd, char * paused_screen, int &pause_timer) +{ + lcd.clear(); + lcd.drawSprite(0, 0, HEIGHT, WIDTH, paused_screen); + if (pause_timer % 10 <= 4) { + lcd.drawSpriteTransparent(20, 20, 9, 45, (char *)pause_sprite); + } + lcd.refresh(); + pause_timer++; + wait_ms(1000/40); +} + void RoomEngine::draw(N5110 &lcd) { room->draw_room(lcd);