// // Created by Zoe Roux on 5/24/21. // #include #include #include "System/Movable/MovableSystem.hpp" #include "System/Renderer/RenderSystem.hpp" #include #include #include "System/Keyboard/KeyboardSystem.hpp" #include "System/Controllable/ControllableSystem.hpp" #include "System/Gamepad/GamepadSystem.hpp" #include #include "Component/Renderer/Drawable2DComponent.hpp" #include "Runner.hpp" #include "Models/GameState.hpp" #include #include #include #include #include #include #include #include #include #include "System/Animation/AnimationsSystem.hpp" #include "Map/Map.hpp" #include "System/MenuControllable/MenuControllableSystem.hpp" #include #include "System/Sound/PlayerSoundManagerSystem.hpp" #include "System/Sound/MenuSoundManagerSystem.hpp" #include "System/Gravity/GravitySystem.hpp" #include "System/BumperTimer/BumperTimerSystem.hpp" #include "System/Music/MusicSystem.hpp" #include "System/Lobby/LobbySystem.hpp" #include "Component/Lobby/LobbyComponent.hpp" namespace BBM { GameState Runner::gameState; void Runner::updateState(WAL::Wal &engine, GameState &state) { auto &view = engine.getScene()->view(); if (RAY::Window::getInstance().shouldClose()) engine.shouldClose = true; if (gameState.currentScene == GameState::SceneID::GameScene || gameState.currentScene == GameState::SceneID::SplashScreen) { for (auto &[_, component]: engine.getScene()->view()) { if (component.pause && gameState.currentScene == GameState::SceneID::GameScene) { gameState.nextScene = GameState::SceneID::PauseMenuScene; break; } else if (gameState.currentScene == GameState::SceneID::SplashScreen && component.jump) { gameState.nextScene = GameState::SceneID::TitleScreenScene; break; } } } if (gameState.nextScene == gameState.currentScene) return; gameState._loadedScenes[gameState.currentScene] = engine.getScene(); engine.changeScene(gameState._loadedScenes[gameState.nextScene]); gameState.currentScene = gameState.nextScene; } void Runner::addSystems(WAL::Wal &wal) { wal.addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem() .addSystem(); } void Runner::enableRaylib(WAL::Wal &wal) { RAY::TraceLog::setLevel(LOG_WARNING); RAY::Window &window = RAY::Window::getInstance(1920, 1080, "Bomberman"); wal.addSystem() .addSystem() .addSystem(window); } void Runner::addMenuControl(WAL::Scene &scene) { scene.addEntity("Keyboard default control") .addComponent() .addComponent(); scene.addEntity("Keyboard second control") .addComponent() .addComponent(ControllableComponent::Layout::KEYBOARD_1); for (int i = 0; i < 4; i++) { scene.addEntity("Gamepad controller") .addComponent() .addComponent(i); } } void Runner::loadScenes() { gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); gameState._loadedScenes[GameState::SceneID::SettingsScene] = loadSettingsMenuScene(); gameState._loadedScenes[GameState::SceneID::PauseMenuScene] = loadPauseMenuScene(); gameState._loadedScenes[GameState::SceneID::TitleScreenScene] = loadTitleScreenScene(); gameState._loadedScenes[GameState::SceneID::CreditScene] = loadCreditScene(); gameState._loadedScenes[GameState::SceneID::SplashScreen] = loadSplashScreenScene(); gameState._loadedScenes[GameState::SceneID::LobbyScene] = loadLobbyScene(); } int Runner::run() { std::srand(std::time(nullptr)); WAL::Wal wal; Runner::addSystems(wal); Runner::enableRaylib(wal); Runner::loadScenes(); wal.changeScene(Runner::gameState._loadedScenes[GameState::SceneID::SplashScreen]); try { wal.run(Runner::updateState, Runner::gameState); return 0; } catch (const std::exception &ex) { std::cerr << ex.what() << std::endl; return 1; } } }