#include #include "Runner.hpp" #include #include "Component/Button/ButtonComponent.hpp" #include "Component/Music/MusicComponent.hpp" #include "Component/Position/PositionComponent.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" #include "Component/Sound/SoundComponent.hpp" #include "Drawables/Texture.hpp" #include "Drawables/2D/Text.hpp" #include "Component/Score/ScoreComponent.hpp" #include "Model/Model.hpp" #include "System/Lobby/LobbySystem.hpp" #include "Component/Tag/TagComponent.hpp" namespace RAY2D = RAY::Drawables::Drawables2D; namespace RAY3D = RAY::Drawables::Drawables3D; namespace BBM { std::shared_ptr Runner::loadScoreScene(WAL::Scene &gameScene) { auto scene = std::make_shared(); std::vector playersIconPath; std::vector> players; static const std::map sounds = { {SoundComponent::BOMB, "assets/sounds/click.ogg"} }; static const std::vector tilesColor = { GOLD, GRAY, BROWN, PURPLE }; static const std::vector rankName = { "1st", "2nd", "3rd", "4th" }; for (WAL::Entity &entity: gameScene.view()) players.emplace_back(entity); std::sort(players.begin(), players.end(), [](WAL::Entity &entityA, WAL::Entity &entityB) { return entityA.getComponent().aliveTime > entityB.getComponent().aliveTime; }); auto bestTime = players.front().get().getComponent().aliveTime; int playerID = 0; for (auto &entity : players) { auto *model = dynamic_cast(entity.get().getComponent().drawable.get()); std::string path = model->getTextureByMaterial(MAP_DIFFUSE).getResourcePath(); playersIconPath.push_back(path.replace(path.find("textures"), std::string("textures").size(), "icons")); auto &newPlayer = scene->addEntity("add"); newPlayer.addComponent(playerID++, newPlayer, newPlayer); auto &lobby = newPlayer.getComponent(); lobby.layout = entity.get().getComponent().layout; auto start = path.find_last_of('/') + 1; std::string color = path.substr(start, path.find_last_of('.') - start); auto iterator = std::find(LobbySystem::colors.begin(), LobbySystem::colors.end(), color); lobby.color = static_cast(iterator - LobbySystem::colors.begin()); } addMenuControl(*scene, sounds); scene->addEntity("Audio resources") .addComponent("assets/musics/music_result.ogg") .addComponent(sounds); scene->addEntity("background") .addComponent() .addComponent("assets/backgrounds/score.png"); scene->addEntity("white background") .addComponent(200, 100, 0) .addComponent(Vector2f(), Vector2f(1525, 550), RAY::Color(BLACK).setA(150)); scene->addEntity("scene title text") .addComponent(1920 / 3.25, 100, 0) .addComponent("GAME OVER", 120, RAY::Vector2(), ORANGE); scene->addEntity("scene title text") .addComponent(1920 / 2.37, 250, 0) .addComponent("CONGRATS", 50, RAY::Vector2(), ORANGE); for (std::size_t i = 0; i < players.size(); i++) { std::size_t place = i; if (players[i].get().getComponent().aliveTime == bestTime) place = 0; scene->addEntity("player tile") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) .addComponent(RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), RAY::Vector2(200, 200), tilesColor[place]); scene->addEntity("player rank name") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.75, 0) .addComponent(rankName[place], 30, RAY::Vector2(224 * (i + 1) + 200 * i, 1080 / 3), tilesColor[place]); scene->addEntity("player") .addComponent(224 * (i + 1) + 200 * i, 1080 / 2.5, 0) .addComponent(playersIconPath[i]); } auto &play = scene->addEntity("play button") .addComponent(1920 / 2.5, 1080 - 180, 0) .addComponent("assets/buttons/button_new_game.png") .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_new_game.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_new_game_hovered.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { LobbySystem::switchToGame(wal); }); auto &back = scene->addEntity("back to main menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") .addComponent([](WAL::Entity &, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { auto *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back_hovered.png"); }); back.getComponent().setButtonLinks(&play, nullptr, nullptr, &play); play.getComponent().setButtonLinks(nullptr, &back, &back); return scene; } }