// // Created by Zoe Roux on 5/24/21. // #include #include #include "System/Movable/MovableSystem.hpp" #include "System/Renderer/RenderSystem.hpp" #include #include #include #include #include #include "System/Keyboard/KeyboardSystem.hpp" #include "System/Controllable/ControllableSystem.hpp" #include "Component/Movable/MovableComponent.hpp" #include "Component/Controllable/ControllableComponent.hpp" #include "Component/Keyboard/KeyboardComponent.hpp" #include "System/Gamepad/GamepadSystem.hpp" #include #include "Component/Button/ButtonComponent.hpp" #include #include #include "Component/Renderer/CameraComponent.hpp" #include "Component/Renderer/Drawable3DComponent.hpp" #include "Component/Renderer/Drawable2DComponent.hpp" #include "Runner.hpp" #include "Models/GameState.hpp" #include #include #include #include #include #include #include #include "Component/Animation/AnimationsComponent.hpp" #include "System/Animation/AnimationsSystem.hpp" #include "Map/Map.hpp" #include "System/MenuControllable/MenuControllableSystem.hpp" #include namespace RAY3D = RAY::Drawables::Drawables3D; namespace RAY2D = RAY::Drawables::Drawables2D; namespace BBM { GameState Runner::gameState; void Runner::updateState(WAL::Wal &engine, GameState &state) { auto &view = engine.scene->view(); // You can change the scene here or update the game state based on entities values. // If you want to keep a scene loaded but not running, store it in the state.loadedScenes. // If you don't need the scene anymore, remember to remove it from the loadedScene array. if (RAY::Window::getInstance().shouldClose()) engine.shouldClose = true; if (gameState.currentScene == GameState::SceneID::GameScene) { for (auto &[_, component]: view) { if (component.pause) { gameState.nextScene = GameState::SceneID::PauseMenuScene; break; } } } if (gameState.nextScene == gameState.currentScene) return; gameState._loadedScenes[gameState.currentScene] = engine.scene; engine.scene = gameState._loadedScenes[gameState.nextScene]; } void Runner::addSystems(WAL::Wal &wal) { wal.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); } std::shared_ptr Runner::loadTitleScreenScene() { auto scene = std::make_shared(); scene->addEntity("control") .addComponent() .addComponent(); scene->addEntity("background") .addComponent() .addComponent("assets/plain_menu_background.png"); scene->addEntity("logo") .addComponent(320, 180, 0) .addComponent("assets/logo_big.png"); scene->addEntity("text_prompt") .addComponent(1920 / 2.5, 1080 - 130, 0) .addComponent("Press space", 70, RAY::Vector2(), ORANGE) .addComponent() .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; }); //needed material //music //sound return scene; } std::shared_ptr Runner::loadMainMenuScene() { auto scene = std::make_shared(); scene->addEntity("Control entity") .addComponent() .addComponent(); scene->addEntity("background") .addComponent() .addComponent("assets/plain_menu_background.png"); scene->addEntity("logo") .addComponent(1920 / 3, 180, 0) .addComponent("assets/logo_small.png"); auto &play = scene->addEntity("play button") .addComponent(1920 / 2.5, 1080 - 540, 0) .addComponent("assets/buttons/button_new_game.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_new_game.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_new_game_hovered.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::GameScene; }); auto &settings = scene->addEntity("settings button") .addComponent(1920 / 2.5, 1080 - 360, 0) .addComponent("assets/buttons/button_settings.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_settings.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_settings_hovered.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::SettingsScene; }); auto &exit = scene->addEntity("exit button") .addComponent(1920 / 2.5, 1080 - 180, 0) .addComponent("assets/buttons/button_exit.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_exit.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_exit_hovered.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { wal.shouldClose = true; }); play.getComponent().setButtonLinks(&exit, &settings); settings.getComponent().setButtonLinks(&play, &exit); exit.getComponent().setButtonLinks(&settings, &play); //needed material //music //sound return scene; } std::shared_ptr Runner::loadPauseMenuScene() { auto scene = std::make_shared(); scene->addEntity("Control entity") .addComponent() .addComponent(); scene->addEntity("background") .addComponent() .addComponent("assets/plain_menu_background.png"); scene->addEntity("logo") .addComponent(1920 / 3, 180, 0) .addComponent("assets/logo_small.png"); auto &play = scene->addEntity("play button") .addComponent(1920 / 2.5, 1080 - 540, 0) .addComponent("assets/buttons/button_back.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back_hovered.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::GameScene; }); auto &settings = scene->addEntity("settings button") .addComponent(1920 / 2.5, 1080 - 360, 0) .addComponent("assets/buttons/button_settings.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_settings.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_settings_hovered.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::SettingsScene; }); auto &exit = scene->addEntity("exit button") .addComponent(1920 / 2.5, 1080 - 180, 0) .addComponent("assets/buttons/button_exit.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_exit.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_exit_hovered.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; }); //needed material //music //sound play.getComponent().setButtonLinks(&exit, &settings); settings.getComponent().setButtonLinks(&play, &exit); exit.getComponent().setButtonLinks(&settings, &play); return scene; } std::shared_ptr Runner::loadSettingsMenuScene() { auto scene = std::make_shared(); scene->addEntity("Control entity") .addComponent() .addComponent(); scene->addEntity("background") .addComponent() .addComponent("assets/plain_menu_background.png"); scene->addEntity("logo") .addComponent(1920 / 3, 180, 0) .addComponent("assets/logo_small.png"); auto &music = scene->addEntity("music text") .addComponent(1920 / 2.5, 1080 - 540, 0) .addComponent("Music Volume", 70, RAY::Vector2(), ORANGE) .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { entity.getComponent().drawable->setColor(BLACK); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { entity.getComponent().drawable->setColor(ORANGE); }); auto &musicUp = scene->addEntity("music up button") .addComponent(1920 / 3, 1080 - 540, 0) .addComponent("assets/buttons/button_plus.png") .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_plus.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_plus_hovered.png"); }); auto &musicDown = scene->addEntity("music down button") .addComponent(1920 / 1.5, 1080 - 540, 0) .addComponent("assets/buttons/button_minus.png") .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_minus.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_minus_hovered.png"); }); auto &sound = scene->addEntity("sound text") .addComponent(1920 / 2.5, 1080 - 360, 0) .addComponent("Sound Volume", 70, RAY::Vector2(), ORANGE) .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { entity.getComponent().drawable->setColor(BLACK); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { entity.getComponent().drawable->setColor(ORANGE); }); auto &soundUp = scene->addEntity("sound up button") .addComponent(1920 / 3, 1080 - 360, 0) .addComponent("assets/buttons/button_plus.png") .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_plus.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_plus_hovered.png"); }); auto &soundDown = scene->addEntity("sound down button") .addComponent(1920 / 1.5, 1080 - 360, 0) .addComponent("assets/buttons/button_minus.png") .addComponent() .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_minus.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_minus_hovered.png"); }); auto &debug = scene->addEntity("debug text") .addComponent(1920 / 2.5, 1080 - 180, 0) .addComponent("Debug Mode: Off", 70, RAY::Vector2(), ORANGE) .addComponent([](WAL::Entity &entity, WAL::Wal &wal) { RAY2D::Text *text = dynamic_cast(entity.getComponent().drawable.get()); if (text->getString().find("Off") != std::string::npos) { text->setText("Debug Mode: On"); wal.getSystem().setDebug(true); } else { text->setText("Debug Mode: Off"); wal.getSystem().setDebug(false); } }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { entity.getComponent().drawable->setColor(BLACK); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { entity.getComponent().drawable->setColor(ORANGE); }); auto &back = scene->addEntity("back to menu") .addComponent(10, 1080 - 85, 0) .addComponent("assets/buttons/button_back.png") .addComponent([](WAL::Entity &entity, WAL::Wal &) { gameState.nextScene = BBM::GameState::SceneID::MainMenuScene; }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back.png"); }) .addComponent([](WAL::Entity &entity, WAL::Wal &) { RAY::Texture *texture = dynamic_cast(entity.getComponent().drawable.get()); texture->use("assets/buttons/button_back_hovered.png"); }); //needed material // back button // back button asset //music //sound music.getComponent().setButtonLinks(&back, &sound, &musicUp, &musicDown); musicUp.getComponent().setButtonLinks(&debug, &sound, nullptr, &music); musicDown.getComponent().setButtonLinks(&debug, &sound, &music); sound.getComponent().setButtonLinks(&music, &debug, &soundUp, &soundDown); soundUp.getComponent().setButtonLinks(&music, &debug, nullptr, &sound); soundDown.getComponent().setButtonLinks(&music, &debug, &sound); debug.getComponent().setButtonLinks(&sound, &back); back.getComponent().setButtonLinks(&debug, &music); return scene; } std::shared_ptr Runner::loadGameScene() { auto scene = std::make_shared(); scene->addEntity("player") .addComponent() .addComponent("assets/player/player.iqm", std::make_pair(MAP_DIFFUSE, "assets/player/blue.png")) .addComponent() .addComponent() .addComponent() .addComponent(RAY::ModelAnimations("assets/player/player.iqm"), 3) .addComponent(1) .addComponent() .addComponent() .addComponent(1, [](WAL::Entity &entity) { auto &animation = entity.getComponent(); animation.setAnimIndex(5); }); scene->addEntity("camera") .addComponent(8, 20, 7) .addComponent(Vector3f(8, 0, 8)); // scene->addEntity("cube") // .addComponent(5, 0, 5) // .addComponent(Vector3f(-5, 0, -5), Vector3f(3, 3, 3), RED) // .addComponent() // .addComponent() // .addComponent(WAL::Callback(), &MapGenerator::wallCollide, 3); MapGenerator::loadMap(16, 16, MapGenerator::createMap(16, 16), scene); return scene; } void Runner::loadScenes() { gameState._loadedScenes[GameState::SceneID::MainMenuScene] = loadMainMenuScene(); gameState._loadedScenes[GameState::SceneID::GameScene] = loadGameScene(); gameState._loadedScenes[GameState::SceneID::SettingsScene] = loadSettingsMenuScene(); gameState._loadedScenes[GameState::SceneID::PauseMenuScene] = loadPauseMenuScene(); gameState._loadedScenes[GameState::SceneID::TitleScreenScene] = loadTitleScreenScene(); } int Runner::run() { std::srand(std::time(nullptr)); WAL::Wal wal; Runner::addSystems(wal); Runner::enableRaylib(wal); Runner::loadScenes(); wal.scene = Runner::gameState._loadedScenes[GameState::SceneID::TitleScreenScene]; try { wal.run(Runner::updateState, Runner::gameState); return 0; } catch (const std::exception &ex) { std::cerr << ex.what() << std::endl; return 1; } } }