#include #if _DEBUG // ReSharper disable once CppUnusedIncludeDirective #if __has_include() #include #endif #endif #include "DuvelEngine.h" #include "SceneManager.h" #include "ResourceManager.h" #include "GameObject.h" #include "TextureComponent.h" #include "AnimatedTextureComponent.h" #include "TextComponent.h" #include "MainMenuComponent.h" #include "TimedSceneSwitchComponent.h" #include "Scene.h" #include "FPSComponent.h" #include "RotatorComponent.h" #include "BubblesGeneratorComponent.h" #include "LevelComponent.h" #include "TimedSetActiveComponent.h" #include "PlayerComponent.h" #include "ColliderComponent.h" #include "RigidbodyComponent.h" #include "PlayerLivesComponent.h" #include "PlayerScoreComponent.h" #include "GameOverComponent.h" #include "LevelWinComponent.h" #include "ZenChanComponent.h" #include "InputManager.h" #include "GameState.h" #include "ServiceLocator.h" #include "SDLSoundSystem.h" #include "SoundCommand.h" #include "GameCommands.h" #include "MuteMusicCommand.h" //using namespace dae; namespace dae { void load() { GameState::GetInstance().LoadHighScores(); GameState::GetInstance().SetPlayer1Lives(3); GameState::GetInstance().SetPlayer2Lives(3); GameState::GetInstance().SetPlayer1Score(0); GameState::GetInstance().SetPlayer2Score(0); GameState::GetInstance().SetLevelId(1); float screenWidth = 256 * 2; float screenHeight = 224 * 2; auto& soundSystem = ServiceLocator::GetSoundSystem(); soundSystem.RegisterSound(0, "../Data/Sfx/opening.wav"); soundSystem.RegisterSound(1, "../Data/Sfx/bublbobl-051_insert_coin.wav"); soundSystem.RegisterSound(2, "../Data/Sfx/bublbobl-040_jump.wav"); soundSystem.RegisterSound(3, "../Data/Sfx/bublbobl-047_shoot_bubble.wav"); soundSystem.RegisterSound(4, "../Data/Sfx/bublbobl-012_death.wav"); soundSystem.RegisterSound(5, "../Data/Sfx/bublbobl-036_enemy_death.wav"); soundSystem.RegisterSound(6, "../Data/Sfx/bublbobl-014_pickup_food.wav"); soundSystem.RegisterMusic(0, "../Data/Music/intro_music.mp3"); soundSystem.RegisterMusic(1, "../Data/Music/main_theme.mp3"); soundSystem.RegisterMusic(2, "../Data/Music/main_theme_hurry.mp3"); soundSystem.RegisterMusic(3, "../Data/Music/game_over.mp3"); soundSystem.RegisterMusic(4, "../Data/Music/highscore_screen.mp3"); soundSystem.RegisterMusic(5, "../Data/Music/super_drunk.mp3"); auto& input = InputManager::GetInstance(); auto arcadeFont = ResourceManager::GetInstance().LoadFont("Emulogic.ttf", 16); // ************** // MainMenu Scene // ************** #pragma region MainMenuScene auto& pMainMenuScene = SceneManager::GetInstance().CreateScene("MainMenu"); // Game Logo auto pLogoGo = new GameObject(); auto pLogoAnimTexComp = pLogoGo->AddComponent(new AnimatedTextureComponent("logo_animated.png", 356, 288, 3, 2)); pLogoAnimTexComp->SetSpritesPerSecond(30); pLogoAnimTexComp->Play(0, 5); pLogoGo->SetPosition(screenWidth / 2.f - pLogoAnimTexComp->GetSpriteWidth() / 2.f, 30.f); pMainMenuScene.Add(pLogoGo); // Company logo auto pTaitoGo = new GameObject(); auto pTaitoAnimTexComp = pTaitoGo->AddComponent(new AnimatedTextureComponent("taito_dae.png", 144, 30, 4, 2)); pTaitoAnimTexComp->SetSpritesPerSecond(2); pTaitoAnimTexComp->Play(0, 6, false, true); pTaitoGo->SetPosition(screenWidth / 2.f - pTaitoAnimTexComp->GetSpriteWidth() / 2.f, 322.f); pMainMenuScene.Add(pTaitoGo); // Bottom Text auto pMenuTextGo = new GameObject(); auto pMenuTextComp = pMenuTextGo->AddComponent(new TextComponent("© TAITO CORPORATION 1986", arcadeFont, 255, 255, 255)); pMenuTextGo->SetPosition(screenWidth / 2.f - pMenuTextComp->GetWidth() / 2.f, 364); pMenuTextComp->SetSecondaryText("© HOWEST DAE 2023"); pMenuTextComp->RecenterOnDraw(true, screenWidth); pMenuTextComp->SetColorOverTime(255, 255, 255, 0, 0, 0, 1.f / (2.f / 3.f), 2, true); pMainMenuScene.Add(pMenuTextGo); pMenuTextGo = new GameObject(); pMenuTextComp = pMenuTextGo->AddComponent(new TextComponent("ALL RIGHTS RESERVED", arcadeFont, 255, 255, 255)); pMenuTextGo->SetPosition(screenWidth / 2.f - pMenuTextComp->GetWidth() / 2.f, 396); pMenuTextComp->SetSecondaryText("POWERED BY DUVEL ENGINE"); pMenuTextComp->RecenterOnDraw(true, screenWidth); pMenuTextComp->SetColorOverTime(255, 255, 255, 0, 0, 0, 1.f / (2.f / 3.f), 2, true); pMainMenuScene.Add(pMenuTextGo); // UI Text auto p1UpGo = new GameObject(); auto p1UpTextComp = p1UpGo->AddComponent(new TextComponent("1UP", arcadeFont, 0, 255, 0)); p1UpGo->SetPosition(88 - p1UpTextComp->GetWidth() / 2.f, -4.f); pMainMenuScene.Add(p1UpGo); auto p1ScoreGo = new GameObject(); auto p1ScoreTextComp = p1ScoreGo->AddComponent(new TextComponent(" 00", arcadeFont, 255, 255, 255)); p1ScoreGo->SetPosition(88 - p1ScoreTextComp->GetWidth() / 2.f, 12.f); pMainMenuScene.Add(p1ScoreGo); auto pHighScoreTitleGo = new GameObject(); auto pHighScoreTitleTextComp = pHighScoreTitleGo->AddComponent(new TextComponent("HIGH SCORE", arcadeFont, 255, 0, 0)); pHighScoreTitleGo->SetPosition(screenWidth / 2.f - pHighScoreTitleTextComp->GetWidth() / 2.f, -4.f); pMainMenuScene.Add(pHighScoreTitleGo); auto pHighScoreGo = new GameObject(); pHighScoreGo->SetName("HighScoreText"); auto pHighScoreTextComp = pHighScoreGo->AddComponent(new TextComponent(" 30000", arcadeFont, 255, 255, 255)); pHighScoreGo->SetPosition(screenWidth / 2.f - pHighScoreTextComp->GetWidth() / 2.f, 12.f); pMainMenuScene.Add(pHighScoreGo); auto p2UpGo = new GameObject(); auto p2UpTextComp = p2UpGo->AddComponent(new TextComponent("2UP", arcadeFont, 0, 187, 255)); p2UpGo->SetPosition(screenWidth - 88 - p2UpTextComp->GetWidth() / 2.f, -4.f); pMainMenuScene.Add(p2UpGo); auto p2ScoreGo = new GameObject(); auto p2ScoreTextComp = p2ScoreGo->AddComponent(new TextComponent(" 00", arcadeFont, 255, 255, 255)); p2ScoreGo->SetPosition(screenWidth - 88 - p2ScoreTextComp->GetWidth() / 2.f, 12.f); pMainMenuScene.Add(p2ScoreGo); // GameMode Selection Menu auto pGameModesContainerGo = new GameObject(); pMainMenuScene.Add(pGameModesContainerGo); pGameModesContainerGo->SetActive(false); // Select GameMode Title auto pGameModeTitleGo = new GameObject(); auto pGameModeTitleTextComp = pGameModeTitleGo->AddComponent(new TextComponent("- SELECT GAMEMODE -", arcadeFont, 255, 255, 255)); pGameModeTitleGo->SetPosition(screenWidth / 2.f - pGameModeTitleTextComp->GetWidth() / 2.f, 92.f); pGameModeTitleGo->SetParent(pGameModesContainerGo); // 1 Player auto pSinglePlayerGo = new GameObject(); auto pSinglePlayerTextComp = pSinglePlayerGo->AddComponent(new TextComponent("1 PLAYER", arcadeFont, 255, 255, 255)); pSinglePlayerGo->SetPosition(screenWidth / 2.f - pSinglePlayerTextComp->GetWidth() / 2.f, 156.f); pSinglePlayerGo->SetParent(pGameModesContainerGo); // 2 Player Co-Op auto pCoopGo = new GameObject(); auto pCoopTextComp = pCoopGo->AddComponent(new TextComponent("CO-OP", arcadeFont, 128, 128, 128)); pCoopGo->SetPosition(screenWidth / 2.f - pCoopTextComp->GetWidth() / 2.f, 188.f); pCoopGo->SetParent(pGameModesContainerGo); // 2 Player Versus auto pVersusGo = new GameObject(); auto pVersusTextComp = pVersusGo->AddComponent(new TextComponent("VERSUS", arcadeFont, 128, 128, 128)); pVersusGo->SetPosition(screenWidth / 2.f - pVersusTextComp->GetWidth() / 2.f, 220.f); pVersusGo->SetParent(pGameModesContainerGo); // Selection Arrow auto pSelectionArrowGo = new GameObject(); auto pSelectionArrowTexComp = pSelectionArrowGo->AddComponent(new AnimatedTextureComponent("selection_arrow.png", 16, 16, 2, 1)); pSelectionArrowGo->SetPosition(pSinglePlayerGo->GetWorldPosition().x - 24.f, pSinglePlayerGo->GetWorldPosition().y + 2); pSelectionArrowTexComp->SetSpritesPerSecond(2); pSelectionArrowTexComp->Play(0, 1, false); pSelectionArrowGo->SetParent(pGameModesContainerGo); // MainMenuGo auto pMainMenuGo = new GameObject(); auto pMainMenuComp = pMainMenuGo->AddComponent(new MainMenuComponent(pLogoGo, pGameModesContainerGo, pSinglePlayerGo, pCoopGo, pVersusGo, pSelectionArrowGo)); pMainMenuScene.Add(pMainMenuGo); // Commands Command* pMainMenuConfirmCommand = new MM_Confirm(pMainMenuGo, soundSystem, 0, 1.f); input.AddControllerCommand(pMainMenuScene.GetId(), 0, ControllerButton::Start, PressType::DOWN, pMainMenuConfirmCommand); pMainMenuConfirmCommand = new MM_Confirm(pMainMenuGo, soundSystem, 0, 1.f); input.AddControllerCommand(pMainMenuScene.GetId(), 0, ControllerButton::ButtonA, PressType::DOWN, pMainMenuConfirmCommand); pMainMenuConfirmCommand = new MM_Confirm(pMainMenuGo, soundSystem, 0, 1.f); input.AddKeyboardCommand(pMainMenuScene.GetId(), SDL_SCANCODE_RETURN, PressType::DOWN, pMainMenuConfirmCommand); Command* pMainMenuUpCommand = new MM_Select(pMainMenuGo, -1); input.AddControllerCommand(pMainMenuScene.GetId(), 0, ControllerButton::DPadUp, PressType::DOWN, pMainMenuUpCommand); pMainMenuUpCommand = new MM_Select(pMainMenuGo, -1); input.AddKeyboardCommand(pMainMenuScene.GetId(), SDL_SCANCODE_UP, PressType::DOWN, pMainMenuUpCommand); Command* pMainMenuDownCommand = new MM_Select(pMainMenuGo, 1); input.AddControllerCommand(pMainMenuScene.GetId(), 0, ControllerButton::DPadDown, PressType::DOWN, pMainMenuDownCommand); pMainMenuDownCommand = new MM_Select(pMainMenuGo, 1); input.AddKeyboardCommand(pMainMenuScene.GetId(), SDL_SCANCODE_DOWN, PressType::DOWN, pMainMenuDownCommand); Command* pMainMenuBackCommand = new MM_Back(pMainMenuGo); input.AddControllerCommand(pMainMenuScene.GetId(), 0, ControllerButton::Back, PressType::DOWN, pMainMenuBackCommand); // Restart Function auto RestartMainMenu = [&soundSystem, pMainMenuComp, pHighScoreTextComp]() { soundSystem.StopMusic(); soundSystem.Play(0, 1.f); pMainMenuComp->SetState(MainMenuState::LOGO); pMainMenuComp->SetSelection(0); auto savedScores = GameState::GetInstance().GetSavedHighScores(); pHighScoreTextComp->SetText(std::to_string(savedScores[4].second)); GameState::GetInstance().SetHighScore(savedScores[4].second); /* GameState::GetInstance().SetPlayer1Score(0); GameState::GetInstance().SetPlayer2Score(0); GameState::GetInstance().SetHighScore(30000); */ GameState::GetInstance().SetLevelId(1); //std::cout << "restarted main menu\n"; }; pMainMenuScene.SetRestartFunction(RestartMainMenu); #pragma endregion MainMenuScene // *********** // Intro Scene // *********** #pragma region IntroScene auto& pIntroScene = SceneManager::GetInstance().CreateScene("Intro"); auto pBackgroundStars = new GameObject(); auto pStarsAnimTexComp = pBackgroundStars->AddComponent(new AnimatedTextureComponent("stars_animated.png", static_cast(screenWidth), static_cast(screenHeight), 2, 2)); pStarsAnimTexComp->SetSpritesPerSecond(2); pStarsAnimTexComp->Play(0, 3, false, true); pIntroScene.Add(pBackgroundStars); // Text auto pTextGo = new GameObject(); auto pTextComp0 = pTextGo->AddComponent(new TextComponent("NOW,IT IS BEGINNING OF A", arcadeFont, 0, 0, 0)); pTextComp0->SetColorOverTime(0, 0, 0, 255, 0, 0, 2.0f); pTextGo->SetPosition(screenWidth / 2.f - pTextComp0->GetWidth() / 2.f, 28); pIntroScene.Add(pTextGo); pTextGo = new GameObject(); auto pTextComp1 = pTextGo->AddComponent(new TextComponent("FANTASTIC STORY!! LET'S MAKE A", arcadeFont, 255, 0, 0)); pTextComp1->SetColorOverTime(0, 0, 0, 255, 0, 0, 2.0f); pTextGo->SetPosition(screenWidth / 2.f - pTextComp1->GetWidth() / 2.f, 60); pIntroScene.Add(pTextGo); pTextGo = new GameObject(); auto pTextComp2 = pTextGo->AddComponent(new TextComponent("JOURNEY TO THE CAVE OF MONSTERS!", arcadeFont, 255, 0, 0)); pTextComp2->SetColorOverTime(0, 0, 0, 255, 0, 0, 2.0f); pTextGo->SetPosition(screenWidth / 2.f - pTextComp2->GetWidth() / 2.f, 92); pIntroScene.Add(pTextGo); pTextGo = new GameObject(); auto pTextComp3 = pTextGo->AddComponent(new TextComponent("GOOD LUCK!", arcadeFont, 255, 0, 0)); pTextComp3->SetColorOverTime(0, 0, 0, 255, 0, 0, 2.0f); pTextGo->SetPosition(screenWidth / 2.f - pTextComp3->GetWidth() / 2.f, 124); pIntroScene.Add(pTextGo); // Rotating players auto pPlayerOne = new GameObject(); auto pAnimTexComp = pPlayerOne->AddComponent(new AnimatedTextureComponent("player1.png", 64, 64, 8, 5)); pAnimTexComp->SetSpritesPerSecond(5); pAnimTexComp->Play(30, 31); pPlayerOne->AddComponent(new RotatorComponent(16.f, 4.f, false)); auto pPlayerOneRotationPointGo = new GameObject(); pPlayerOneRotationPointGo->SetPosition(screenWidth / 4 - pAnimTexComp->GetSpriteWidth() / 2.f, screenHeight / 2 - pAnimTexComp->GetSpriteHeight() / 2.f); pPlayerOne->SetParent(pPlayerOneRotationPointGo); pIntroScene.Add(pPlayerOneRotationPointGo); auto pPlayerTwo = new GameObject(); pAnimTexComp = pPlayerTwo->AddComponent(new AnimatedTextureComponent("player2.png", 64, 64, 8, 5)); pAnimTexComp->SetSpritesPerSecond(5); pAnimTexComp->Play(30, 31); pPlayerTwo->AddComponent(new RotatorComponent(16.f, 4.f, true)); auto pPlayerTwoRotationPointGo = new GameObject(); pPlayerTwoRotationPointGo->SetPosition(screenWidth - screenWidth / 4 - pAnimTexComp->GetSpriteWidth() / 2.f, screenHeight / 2 - pAnimTexComp->GetSpriteHeight() / 2.f); pPlayerTwo->SetParent(pPlayerTwoRotationPointGo); pIntroScene.Add(pPlayerTwoRotationPointGo); // Bubbles auto pBubblesGenerator = new GameObject(); auto pBubblesGeneratorComp = pBubblesGenerator->AddComponent(new BubblesGeneratorComponent(1 / 20.f, 17.5f, 200.f, 80)); pBubblesGenerator->SetPosition(screenWidth / 2, screenHeight / 2); pIntroScene.Add(pBubblesGenerator); // Next Scene Timer auto pNextSceneGo = new GameObject(); auto pTimedSceneSwitchComp = pNextSceneGo->AddComponent(new TimedSceneSwitchComponent(8.5f, "SinglePlayer", true)); pIntroScene.Add(pNextSceneGo); //Commands //Mute Music Command Command* pMuteMusicCommand = new MuteMusicCommand(soundSystem); input.AddKeyboardCommand(pIntroScene.GetId(), SDL_SCANCODE_M, PressType::DOWN, pMuteMusicCommand); pMuteMusicCommand = new MuteMusicCommand(soundSystem); input.AddControllerCommand(pIntroScene.GetId(), 0, ControllerButton::Back, PressType::DOWN, pMuteMusicCommand); // Next level command bool IS_INTRO{ true }; Command* pNextLevelCommand = new NextLevelCommand(pPlayerOne, IS_INTRO); input.AddKeyboardCommand(pIntroScene.GetId(), SDL_SCANCODE_F1, PressType::DOWN, pNextLevelCommand); pNextLevelCommand = new NextLevelCommand(pPlayerOne, IS_INTRO); input.AddKeyboardCommand(pIntroScene.GetId(), SDL_SCANCODE_RETURN, PressType::DOWN, pNextLevelCommand); pNextLevelCommand = new NextLevelCommand(pPlayerOne, IS_INTRO); input.AddControllerCommand(pIntroScene.GetId(), 0, ControllerButton::Start, PressType::DOWN, pNextLevelCommand); // Restart Function auto RestartIntro = [&soundSystem, pTextComp0, pTextComp1, pTextComp2, pTextComp3, pBubblesGeneratorComp, pTimedSceneSwitchComp]() { auto gameMode = GameState::GetInstance().GetGameMode(); soundSystem.PlayMusic(0, 1.f, 1); pTextComp0->SetColorOverTime(0, 0, 0, 255, 0, 0, 2.0f); pTextComp1->SetColorOverTime(0, 0, 0, 255, 0, 0, 2.0f); pTextComp2->SetColorOverTime(0, 0, 0, 255, 0, 0, 2.0f); pTextComp3->SetColorOverTime(0, 0, 0, 255, 0, 0, 2.0f); pTimedSceneSwitchComp->ResetTimer(); switch (gameMode) { case GameMode::SINGLEPLAYER: pTimedSceneSwitchComp->SetNextScene("SinglePlayer"); break; case GameMode::COOP: pTimedSceneSwitchComp->SetNextScene("MultiPlayer"); break; } pBubblesGeneratorComp->Restart(); //std::cout << "restarted intro\n"; }; pIntroScene.SetRestartFunction(RestartIntro); #pragma endregion IntroScene // ****************** // SinglePlayer Scene // ****************** #pragma region SinglePlayerScene { auto& pSinglePlayerScene = SceneManager::GetInstance().CreateScene("SinglePlayer"); // UI Text p1UpGo = new GameObject(); p1UpTextComp = p1UpGo->AddComponent(new TextComponent("1UP", arcadeFont, 0, 255, 0)); p1UpGo->SetPosition(88 - p1UpTextComp->GetWidth() / 2.f, -4.f); pSinglePlayerScene.Add(p1UpGo); p1ScoreGo = new GameObject(); p1ScoreGo->SetName("Player1ScoreGo"); p1ScoreTextComp = p1ScoreGo->AddComponent(new TextComponent(" 00", arcadeFont, 255, 255, 255)); p1ScoreGo->SetPosition(88 - p1ScoreTextComp->GetWidth() / 2.f, 12.f); auto pPlayerScoreComp = p1ScoreGo->AddComponent(new PlayerScoreComponent(1)); pSinglePlayerScene.Add(p1ScoreGo); pHighScoreTitleGo = new GameObject(); pHighScoreTitleTextComp = pHighScoreTitleGo->AddComponent(new TextComponent("HIGH SCORE", arcadeFont, 255, 0, 0)); pHighScoreTitleGo->SetPosition(screenWidth / 2.f - pHighScoreTitleTextComp->GetWidth() / 2.f, -4.f); pSinglePlayerScene.Add(pHighScoreTitleGo); pHighScoreGo = new GameObject(); pHighScoreGo->SetName("HighScoreText"); pHighScoreTextComp = pHighScoreGo->AddComponent(new TextComponent(" 30000", arcadeFont, 255, 255, 255)); pHighScoreGo->SetPosition(screenWidth / 2.f - pHighScoreTextComp->GetWidth() / 2.f, 12.f); pSinglePlayerScene.Add(pHighScoreGo); // Level1 auto pLevel1Go = new GameObject(); auto pLevel1Comp = pLevel1Go->AddComponent(new LevelComponent(1)); pSinglePlayerScene.Add(pLevel1Go); // Level2 auto pLevel2Go = new GameObject(); pLevel2Go->AddComponent(new LevelComponent(2)); pSinglePlayerScene.Add(pLevel2Go); // Level3 auto pLevel3Go = new GameObject(); pLevel3Go->AddComponent(new LevelComponent(3)); pSinglePlayerScene.Add(pLevel3Go); // Round# Text auto pRoundGo = new GameObject(); auto pRoundTextComp = pRoundGo->AddComponent(new TextComponent("ROUND 1", arcadeFont, 255, 255, 255)); auto pRoundTimedSetActiveComp = pRoundGo->AddComponent(new TimedSetActiveComponent(2.5f, false)); pRoundGo->SetPosition(screenWidth / 2.f - pRoundTextComp->GetWidth() / 2.f, 208.f); pSinglePlayerScene.Add(pRoundGo); auto pReadyGo = new GameObject(); auto pReadyTextComp = pReadyGo->AddComponent(new TextComponent("READY !", arcadeFont, 255, 255, 255)); auto pReadyTimedSetActiveComp = pReadyGo->AddComponent(new TimedSetActiveComponent(2.5f, false)); pReadyGo->SetPosition(screenWidth / 2.f - pReadyTextComp->GetWidth() / 2.f, 240.f); pSinglePlayerScene.Add(pReadyGo); // Player Lives auto pPlayerLives = new GameObject(); auto pPlayerLivesComp = pPlayerLives->AddComponent(new PlayerLivesComponent(0, screenHeight - 16.f)); pSinglePlayerScene.Add(pPlayerLives); // GameOver Observer auto pGameOverGo = new GameObject(); auto pGameOverComponent = pGameOverGo->AddComponent(new GameOverComponent()); pSinglePlayerScene.Add(pGameOverGo); // LevelWin Observer auto pLevelWinGo = new GameObject(); auto pLevelWinComponent = pLevelWinGo->AddComponent(new LevelWinComponent(3)); pSinglePlayerScene.Add(pLevelWinGo); // Player auto pPlayer = new GameObject(); pPlayer->SetName("Player1Go"); auto pPlayerComp = pPlayer->AddComponent(new PlayerComponent(48.f, screenHeight - 80.f, 1, GameState::GetInstance().GetPlayer1Lives())); pPlayerComp->RegisterLevel(pLevel1Comp); pPlayerComp->AddObserver(pPlayerLivesComp); pPlayerComp->AddObserver(pPlayerScoreComp); pPlayerComp->AddObserver(pGameOverComponent); pSinglePlayerScene.Add(pPlayer); pPlayerLivesComp->SetSpriteId(pPlayerComp->GetSpriteId()); pPlayerLivesComp->InitializeLives(pPlayerComp->GetLives()); // ZenChan Enemies auto pZenChan = new GameObject(); auto pZenChanComp = pZenChan->AddComponent(new ZenChanComponent(128.f, 64.f, EnemyFacingDirection::LEFT)); pZenChanComp->RegisterLevel(pLevel1Comp); pZenChanComp->AddObserver(pLevelWinComponent); pSinglePlayerScene.Add(pZenChan); auto pZenChan2 = new GameObject(); auto pZenChan2Comp = pZenChan2->AddComponent(new ZenChanComponent(192.f, 64.f, EnemyFacingDirection::RIGHT)); pZenChan2Comp->RegisterLevel(pLevel1Comp); pZenChan2Comp->AddObserver(pLevelWinComponent); pSinglePlayerScene.Add(pZenChan2); auto pZenChan3 = new GameObject(); auto pZenChan3Comp = pZenChan3->AddComponent(new ZenChanComponent(256.f, 64.f, EnemyFacingDirection::LEFT)); pZenChan3Comp->RegisterLevel(pLevel1Comp); pZenChan3Comp->AddObserver(pLevelWinComponent); pSinglePlayerScene.Add(pZenChan3); std::vector enemyColliders{}; enemyColliders.emplace_back(pZenChan->GetComponent()); enemyColliders.emplace_back(pZenChan2->GetComponent()); enemyColliders.emplace_back(pZenChan3->GetComponent()); pPlayerComp->RegisterEnemyColliders(enemyColliders); // Commands Command* pPlayerMoveLeft = new MovePlayerCommand(pPlayer, -1.f, 0); input.AddControllerCommand(pSinglePlayerScene.GetId(), 0, ControllerButton::DPadLeft, PressType::HELD, pPlayerMoveLeft); pPlayerMoveLeft = new MovePlayerCommand(pPlayer, -1.f, 0); input.AddKeyboardCommand(pSinglePlayerScene.GetId(), SDL_SCANCODE_LEFT, PressType::HELD, pPlayerMoveLeft); Command* pPlayerMoveRight = new MovePlayerCommand(pPlayer, 1.f, 0); input.AddControllerCommand(pSinglePlayerScene.GetId(), 0, ControllerButton::DPadRight, PressType::HELD, pPlayerMoveRight); pPlayerMoveRight = new MovePlayerCommand(pPlayer, 1.f, 0); input.AddKeyboardCommand(pSinglePlayerScene.GetId(), SDL_SCANCODE_RIGHT, PressType::HELD, pPlayerMoveRight); Command* pPlayerMoveUp = new MovePlayerCommand(pPlayer, 0, 1.f); input.AddControllerCommand(pSinglePlayerScene.GetId(), 0, ControllerButton::ButtonB, PressType::DOWN, pPlayerMoveUp); pPlayerMoveUp = new MovePlayerCommand(pPlayer, 0, 1.f); input.AddKeyboardCommand(pSinglePlayerScene.GetId(), SDL_SCANCODE_Z, PressType::DOWN, pPlayerMoveUp); Command* pPlayerShootBubble = new ShootBubblePlayerCommand(pPlayer); input.AddControllerCommand(pSinglePlayerScene.GetId(), 0, ControllerButton::ButtonA, PressType::DOWN, pPlayerShootBubble); pPlayerShootBubble = new ShootBubblePlayerCommand(pPlayer); input.AddKeyboardCommand(pSinglePlayerScene.GetId(), SDL_SCANCODE_X, PressType::DOWN, pPlayerShootBubble); //Mute Music Command pMuteMusicCommand = new MuteMusicCommand(soundSystem); input.AddKeyboardCommand(pSinglePlayerScene.GetId(), SDL_SCANCODE_M, PressType::DOWN, pMuteMusicCommand); pMuteMusicCommand = new MuteMusicCommand(soundSystem); input.AddControllerCommand(pSinglePlayerScene.GetId(), 0, ControllerButton::Back, PressType::DOWN, pMuteMusicCommand); // Next level command pNextLevelCommand = new NextLevelCommand(pPlayer); input.AddKeyboardCommand(pSinglePlayerScene.GetId(), SDL_SCANCODE_F1, PressType::DOWN, pNextLevelCommand); // Restart Function auto RestartSinglePlayer = [&pSinglePlayerScene, &soundSystem, pHighScoreTextComp, pRoundGo, pGameOverComponent, pLevelWinComponent, pReadyGo, pRoundTimedSetActiveComp, pReadyTimedSetActiveComp, pPlayerComp, screenHeight, pLevel1Go, pLevel2Go, pLevel3Go, pZenChanComp, pZenChan2Comp, pZenChan3Comp]() { pHighScoreTextComp->SetText(std::to_string(GameState::GetInstance().GetHighScore())); int levelId{ GameState::GetInstance().GetLevelId() }; soundSystem.PlayMusic(1, 1.f, -1); //soundSystem.StopMusic(); //todo: remove pRoundTimedSetActiveComp->ResetTimer(); pRoundGo->SetActive(true); pRoundGo->GetComponent()->SetText("ROUND " + std::to_string(levelId)); pReadyTimedSetActiveComp->ResetTimer(); pReadyGo->SetActive(true); pGameOverComponent->Reset(); pLevelWinComponent->Reset(); switch (levelId) { case 1: pLevel1Go->SetActive(true); pLevel2Go->SetActive(false); pLevel3Go->SetActive(false); pPlayerComp->RegisterLevel(pLevel1Go->GetComponent()); pZenChanComp->RegisterLevel(pLevel1Go->GetComponent()); pZenChan2Comp->RegisterLevel(pLevel1Go->GetComponent()); pZenChan3Comp->RegisterLevel(pLevel1Go->GetComponent()); break; case 2: pLevel1Go->SetActive(false); pLevel2Go->SetActive(true); pLevel3Go->SetActive(false); pPlayerComp->RegisterLevel(pLevel2Go->GetComponent()); pZenChanComp->RegisterLevel(pLevel2Go->GetComponent()); pZenChan2Comp->RegisterLevel(pLevel2Go->GetComponent()); pZenChan3Comp->RegisterLevel(pLevel2Go->GetComponent()); break; case 3: pLevel1Go->SetActive(false); pLevel2Go->SetActive(false); pLevel3Go->SetActive(true); pPlayerComp->RegisterLevel(pLevel3Go->GetComponent()); pZenChanComp->RegisterLevel(pLevel3Go->GetComponent()); pZenChan2Comp->RegisterLevel(pLevel3Go->GetComponent()); pZenChan3Comp->RegisterLevel(pLevel3Go->GetComponent()); break; } pPlayerComp->Reset(); pZenChanComp->Reset(); pZenChan2Comp->Reset(); pZenChan3Comp->Reset(); //std::cout << "restarted single player\n"; }; pSinglePlayerScene.SetRestartFunction(RestartSinglePlayer); } #pragma endregion SinglePlayerScene // ****************** // MultiPlayer Scene // ****************** #pragma region MultiPlayerScene { auto& pMultiPlayerScene = SceneManager::GetInstance().CreateScene("MultiPlayer"); // UI Text p1UpGo = new GameObject(); p1UpTextComp = p1UpGo->AddComponent(new TextComponent("1UP", arcadeFont, 0, 255, 0)); p1UpGo->SetPosition(88 - p1UpTextComp->GetWidth() / 2.f, -4.f); pMultiPlayerScene.Add(p1UpGo); p1ScoreGo = new GameObject(); p1ScoreGo->SetName("Player1ScoreGo"); p1ScoreTextComp = p1ScoreGo->AddComponent(new TextComponent(" 00", arcadeFont, 255, 255, 255)); p1ScoreGo->SetPosition(88 - p1ScoreTextComp->GetWidth() / 2.f, 12.f); auto pPlayer1ScoreComp = p1ScoreGo->AddComponent(new PlayerScoreComponent(1)); pMultiPlayerScene.Add(p1ScoreGo); p2UpGo = new GameObject(); p2UpTextComp = p2UpGo->AddComponent(new TextComponent("2UP", arcadeFont, 0, 187, 255)); p2UpGo->SetPosition(screenWidth - 88 - p2UpTextComp->GetWidth() / 2.f, -4.f); pMultiPlayerScene.Add(p2UpGo); p2ScoreGo = new GameObject(); p2ScoreGo->SetName("Player2ScoreGo"); p2ScoreTextComp = p2ScoreGo->AddComponent(new TextComponent(" 00", arcadeFont, 255, 255, 255)); p2ScoreGo->SetPosition(screenWidth - 88 - p2ScoreTextComp->GetWidth() / 2.f, 12.f); auto pPlayer2ScoreComp = p2ScoreGo->AddComponent(new PlayerScoreComponent(2)); pMultiPlayerScene.Add(p2ScoreGo); pHighScoreTitleGo = new GameObject(); pHighScoreTitleTextComp = pHighScoreTitleGo->AddComponent(new TextComponent("HIGH SCORE", arcadeFont, 255, 0, 0)); pHighScoreTitleGo->SetPosition(screenWidth / 2.f - pHighScoreTitleTextComp->GetWidth() / 2.f, -4.f); pMultiPlayerScene.Add(pHighScoreTitleGo); pHighScoreGo = new GameObject(); pHighScoreGo->SetName("HighScoreText"); pHighScoreTextComp = pHighScoreGo->AddComponent(new TextComponent(" 30000", arcadeFont, 255, 255, 255)); pHighScoreGo->SetPosition(screenWidth / 2.f - pHighScoreTextComp->GetWidth() / 2.f, 12.f); pMultiPlayerScene.Add(pHighScoreGo); // Level1 auto pLevel1Go = new GameObject(); auto pLevel1Comp = pLevel1Go->AddComponent(new LevelComponent(1)); pMultiPlayerScene.Add(pLevel1Go); // Level2 auto pLevel2Go = new GameObject(); pLevel2Go->AddComponent(new LevelComponent(2)); pMultiPlayerScene.Add(pLevel2Go); // Level3 auto pLevel3Go = new GameObject(); pLevel3Go->AddComponent(new LevelComponent(3)); pMultiPlayerScene.Add(pLevel3Go); // Round# Text auto pRoundGo = new GameObject(); auto pRoundTextComp = pRoundGo->AddComponent(new TextComponent("ROUND 1", arcadeFont, 255, 255, 255)); auto pRoundTimedSetActiveComp = pRoundGo->AddComponent(new TimedSetActiveComponent(2.5f, false)); pRoundGo->SetPosition(screenWidth / 2.f - pRoundTextComp->GetWidth() / 2.f, 208.f); pMultiPlayerScene.Add(pRoundGo); auto pReadyGo = new GameObject(); auto pReadyTextComp = pReadyGo->AddComponent(new TextComponent("READY !", arcadeFont, 255, 255, 255)); auto pReadyTimedSetActiveComp = pReadyGo->AddComponent(new TimedSetActiveComponent(2.5f, false)); pReadyGo->SetPosition(screenWidth / 2.f - pReadyTextComp->GetWidth() / 2.f, 240.f); pMultiPlayerScene.Add(pReadyGo); // Player Lives auto pPlayerLives = new GameObject(); auto pPlayerLivesComp = pPlayerLives->AddComponent(new PlayerLivesComponent(0, screenHeight - 16.f)); pMultiPlayerScene.Add(pPlayerLives); // Player2 Lives auto pPlayer2Lives = new GameObject(); auto pPlayer2LivesComp = pPlayerLives->AddComponent(new PlayerLivesComponent(screenWidth - 48.f, screenHeight - 16.f)); pMultiPlayerScene.Add(pPlayer2Lives); // GameOver Observer auto pGameOverGo = new GameObject(); auto pGameOverComponent = pGameOverGo->AddComponent(new GameOverComponent()); pMultiPlayerScene.Add(pGameOverGo); // LevelWin Observer auto pLevelWinGo = new GameObject(); auto pLevelWinComponent = pLevelWinGo->AddComponent(new LevelWinComponent(3)); pMultiPlayerScene.Add(pLevelWinGo); // Player auto pPlayer = new GameObject(); pPlayer->SetName("Player1Go"); auto pPlayerComp = pPlayer->AddComponent(new PlayerComponent(48.f, screenHeight - 80.f, 1, GameState::GetInstance().GetPlayer1Lives())); pPlayerComp->RegisterLevel(pLevel1Comp); pPlayerComp->AddObserver(pPlayerLivesComp); pPlayerComp->AddObserver(pPlayer1ScoreComp); pPlayerComp->AddObserver(pGameOverComponent); pMultiPlayerScene.Add(pPlayer); pPlayerLivesComp->SetSpriteId(pPlayerComp->GetSpriteId()); pPlayerLivesComp->InitializeLives(pPlayerComp->GetLives()); // Player2 auto pPlayer2 = new GameObject(); pPlayer2->SetName("Player2Go"); auto pPlayer2Comp = pPlayer2->AddComponent(new PlayerComponent(screenWidth - 96.f, screenHeight - 80.f, 2, GameState::GetInstance().GetPlayer2Lives())); pPlayer2Comp->RegisterLevel(pLevel1Comp); pPlayer2Comp->AddObserver(pPlayer2LivesComp); pPlayer2Comp->AddObserver(pPlayer2ScoreComp); pPlayer2Comp->AddObserver(pGameOverComponent); pMultiPlayerScene.Add(pPlayer2); pPlayer2LivesComp->SetSpriteId(pPlayer2Comp->GetSpriteId()); pPlayer2LivesComp->InitializeLives(pPlayer2Comp->GetLives()); // ZenChan Enemies auto pZenChan = new GameObject(); auto pZenChanComp = pZenChan->AddComponent(new ZenChanComponent(128.f, 64.f, EnemyFacingDirection::LEFT)); pZenChanComp->RegisterLevel(pLevel1Comp); pZenChanComp->AddObserver(pLevelWinComponent); pMultiPlayerScene.Add(pZenChan); auto pZenChan2 = new GameObject(); auto pZenChan2Comp = pZenChan2->AddComponent(new ZenChanComponent(192.f, 64.f, EnemyFacingDirection::RIGHT)); pZenChan2Comp->RegisterLevel(pLevel1Comp); pZenChan2Comp->AddObserver(pLevelWinComponent); pMultiPlayerScene.Add(pZenChan2); auto pZenChan3 = new GameObject(); auto pZenChan3Comp = pZenChan3->AddComponent(new ZenChanComponent(256.f, 64.f, EnemyFacingDirection::LEFT)); pZenChan3Comp->RegisterLevel(pLevel1Comp); pZenChan3Comp->AddObserver(pLevelWinComponent); pMultiPlayerScene.Add(pZenChan3); std::vector enemyColliders{}; enemyColliders.emplace_back(pZenChan->GetComponent()); enemyColliders.emplace_back(pZenChan2->GetComponent()); enemyColliders.emplace_back(pZenChan3->GetComponent()); pPlayerComp->RegisterEnemyColliders(enemyColliders); pPlayer2Comp->RegisterEnemyColliders(enemyColliders); // Player Commands Command* pPlayerMoveLeft = new MovePlayerCommand(pPlayer, -1.f, 0); input.AddControllerCommand(pMultiPlayerScene.GetId(), 1, ControllerButton::DPadLeft, PressType::HELD, pPlayerMoveLeft); pPlayerMoveLeft = new MovePlayerCommand(pPlayer, -1.f, 0); input.AddKeyboardCommand(pMultiPlayerScene.GetId(), SDL_SCANCODE_LEFT, PressType::HELD, pPlayerMoveLeft); Command* pPlayerMoveRight = new MovePlayerCommand(pPlayer, 1.f, 0); input.AddControllerCommand(pMultiPlayerScene.GetId(), 1, ControllerButton::DPadRight, PressType::HELD, pPlayerMoveRight); pPlayerMoveRight = new MovePlayerCommand(pPlayer, 1.f, 0); input.AddKeyboardCommand(pMultiPlayerScene.GetId(), SDL_SCANCODE_RIGHT, PressType::HELD, pPlayerMoveRight); Command* pPlayerMoveUp = new MovePlayerCommand(pPlayer, 0, 1.f); input.AddControllerCommand(pMultiPlayerScene.GetId(), 1, ControllerButton::ButtonB, PressType::DOWN, pPlayerMoveUp); pPlayerMoveUp = new MovePlayerCommand(pPlayer, 0, 1.f); input.AddKeyboardCommand(pMultiPlayerScene.GetId(), SDL_SCANCODE_Z, PressType::DOWN, pPlayerMoveUp); Command* pPlayerShootBubble = new ShootBubblePlayerCommand(pPlayer); input.AddControllerCommand(pMultiPlayerScene.GetId(), 1, ControllerButton::ButtonA, PressType::DOWN, pPlayerShootBubble); pPlayerShootBubble = new ShootBubblePlayerCommand(pPlayer); input.AddKeyboardCommand(pMultiPlayerScene.GetId(), SDL_SCANCODE_X, PressType::DOWN, pPlayerShootBubble); // Player 2 Commands Command* pPlayer2MoveLeft = new MovePlayerCommand(pPlayer2, -1.f, 0); input.AddControllerCommand(pMultiPlayerScene.GetId(), 0, ControllerButton::DPadLeft, PressType::HELD, pPlayer2MoveLeft); Command* pPlayer2MoveRight = new MovePlayerCommand(pPlayer2, 1.f, 0); input.AddControllerCommand(pMultiPlayerScene.GetId(), 0, ControllerButton::DPadRight, PressType::HELD, pPlayer2MoveRight); Command* pPlayer2MoveUp = new MovePlayerCommand(pPlayer2, 0, 1.f); input.AddControllerCommand(pMultiPlayerScene.GetId(), 0, ControllerButton::ButtonB, PressType::DOWN, pPlayer2MoveUp); Command* pPlayer2ShootBubble = new ShootBubblePlayerCommand(pPlayer2); input.AddControllerCommand(pMultiPlayerScene.GetId(), 0, ControllerButton::ButtonA, PressType::DOWN, pPlayer2ShootBubble); // Next level command pNextLevelCommand = new NextLevelCommand(pPlayer); input.AddKeyboardCommand(pMultiPlayerScene.GetId(), SDL_SCANCODE_F1, PressType::DOWN, pNextLevelCommand); // Mute Music Command pMuteMusicCommand = new MuteMusicCommand(soundSystem); input.AddKeyboardCommand(pMultiPlayerScene.GetId(), SDL_SCANCODE_M, PressType::DOWN, pMuteMusicCommand); pMuteMusicCommand = new MuteMusicCommand(soundSystem); input.AddControllerCommand(pMultiPlayerScene.GetId(), 0, ControllerButton::Back, PressType::DOWN, pMuteMusicCommand); // Restart Function auto RestartMultiPlayer = [&pMultiPlayerScene, &soundSystem, pHighScoreTextComp, pRoundGo, pGameOverComponent, pReadyGo, pRoundTimedSetActiveComp, pReadyTimedSetActiveComp, pPlayerComp, pPlayer2Comp, screenHeight, pLevel1Go, pLevel2Go, pLevel3Go, pZenChanComp, pZenChan2Comp, pZenChan3Comp]() { pHighScoreTextComp->SetText(std::to_string(GameState::GetInstance().GetHighScore())); int levelId{ GameState::GetInstance().GetLevelId() }; soundSystem.PlayMusic(1, 1.f, -1); //soundSystem.StopMusic(); //todo: remove pRoundTimedSetActiveComp->ResetTimer(); pRoundGo->SetActive(true); pRoundGo->GetComponent()->SetText("ROUND " + std::to_string(levelId)); pReadyTimedSetActiveComp->ResetTimer(); pReadyGo->SetActive(true); pGameOverComponent->Reset(); switch (levelId) { case 1: pLevel1Go->SetActive(true); pLevel2Go->SetActive(false); pLevel3Go->SetActive(false); pPlayerComp->RegisterLevel(pLevel1Go->GetComponent()); pPlayer2Comp->RegisterLevel(pLevel1Go->GetComponent()); pZenChanComp->RegisterLevel(pLevel1Go->GetComponent()); pZenChan2Comp->RegisterLevel(pLevel1Go->GetComponent()); pZenChan3Comp->RegisterLevel(pLevel1Go->GetComponent()); break; case 2: pLevel1Go->SetActive(false); pLevel2Go->SetActive(true); pLevel3Go->SetActive(false); pPlayerComp->RegisterLevel(pLevel2Go->GetComponent()); pPlayer2Comp->RegisterLevel(pLevel2Go->GetComponent()); pZenChanComp->RegisterLevel(pLevel2Go->GetComponent()); pZenChan2Comp->RegisterLevel(pLevel2Go->GetComponent()); pZenChan3Comp->RegisterLevel(pLevel2Go->GetComponent()); break; case 3: pLevel1Go->SetActive(false); pLevel2Go->SetActive(false); pLevel3Go->SetActive(true); pPlayerComp->RegisterLevel(pLevel3Go->GetComponent()); pPlayer2Comp->RegisterLevel(pLevel3Go->GetComponent()); pZenChanComp->RegisterLevel(pLevel3Go->GetComponent()); pZenChan2Comp->RegisterLevel(pLevel3Go->GetComponent()); pZenChan3Comp->RegisterLevel(pLevel3Go->GetComponent()); break; } pPlayerComp->Reset(); pPlayer2Comp->Reset(); pZenChanComp->Reset(); pZenChan2Comp->Reset(); pZenChan3Comp->Reset(); //std::cout << "restarted multi player\n"; }; pMultiPlayerScene.SetRestartFunction(RestartMultiPlayer); } #pragma endregion MultiPlayerScene // ************** // MainMenu Scene // ************** #pragma region GameOverScene { auto& pGameOverScene = SceneManager::GetInstance().CreateScene("GameOver"); // GameOver Text auto pGameOverGo = new GameObject(); auto pGameOverTextComp = pGameOverGo->AddComponent(new TextComponent("GAME OVER", arcadeFont, 255, 255, 255)); pGameOverGo->SetPosition(screenWidth / 2.f - pGameOverTextComp->GetWidth() / 2.f, screenHeight / 2.f - pGameOverTextComp->GetHeight() * 5.f); pGameOverTextComp->RecenterOnDraw(true, screenWidth); pGameOverScene.Add(pGameOverGo); pGameOverGo = new GameObject(); pGameOverTextComp = pGameOverGo->AddComponent(new TextComponent("HIGH SCORES", arcadeFont, 255, 0, 0)); pGameOverGo->SetPosition(screenWidth / 2.f - pGameOverTextComp->GetWidth() / 2.f, screenHeight / 2.f - pGameOverTextComp->GetHeight() * 2.f); pGameOverTextComp->RecenterOnDraw(true, screenWidth); pGameOverScene.Add(pGameOverGo); // Highscores float yPos{}; std::vector pSavedHighScoreTextComps{}; auto pSavedHighScoreGo = new GameObject(); auto pSavedHighScoreTextComp = pSavedHighScoreGo->AddComponent(new TextComponent("DAE 5000", arcadeFont, 255, 255, 0)); yPos = screenHeight / 2.f - pSavedHighScoreTextComp->GetHeight() / 2.f; pSavedHighScoreGo->SetPosition(screenWidth / 2.f - pSavedHighScoreTextComp->GetWidth() / 2.f, yPos); pSavedHighScoreTextComp->RecenterOnDraw(true, screenWidth); pGameOverScene.Add(pSavedHighScoreGo); pSavedHighScoreTextComps.emplace_back(pSavedHighScoreTextComp); pSavedHighScoreGo = new GameObject(); pSavedHighScoreTextComp = pSavedHighScoreGo->AddComponent(new TextComponent("DAE 5000", arcadeFont, 255, 255, 0)); yPos += pSavedHighScoreTextComp->GetHeight() * 1.5f; pSavedHighScoreGo->SetPosition(screenWidth / 2.f - pSavedHighScoreTextComp->GetWidth() / 2.f, yPos); pSavedHighScoreTextComp->RecenterOnDraw(true, screenWidth); pGameOverScene.Add(pSavedHighScoreGo); pSavedHighScoreTextComps.emplace_back(pSavedHighScoreTextComp); pSavedHighScoreGo = new GameObject(); pSavedHighScoreTextComp = pSavedHighScoreGo->AddComponent(new TextComponent("DAE 5000", arcadeFont, 255, 255, 0)); yPos += pSavedHighScoreTextComp->GetHeight() * 1.5f; pSavedHighScoreGo->SetPosition(screenWidth / 2.f - pSavedHighScoreTextComp->GetWidth() / 2.f, yPos); pSavedHighScoreTextComp->RecenterOnDraw(true, screenWidth); pGameOverScene.Add(pSavedHighScoreGo); pSavedHighScoreTextComps.emplace_back(pSavedHighScoreTextComp); pSavedHighScoreGo = new GameObject(); pSavedHighScoreTextComp = pSavedHighScoreGo->AddComponent(new TextComponent("DAE 5000", arcadeFont, 255, 255, 0)); yPos += pSavedHighScoreTextComp->GetHeight() * 1.5f; pSavedHighScoreGo->SetPosition(screenWidth / 2.f - pSavedHighScoreTextComp->GetWidth() / 2.f, yPos); pSavedHighScoreTextComp->RecenterOnDraw(true, screenWidth); pGameOverScene.Add(pSavedHighScoreGo); pSavedHighScoreTextComps.emplace_back(pSavedHighScoreTextComp); pSavedHighScoreGo = new GameObject(); pSavedHighScoreTextComp = pSavedHighScoreGo->AddComponent(new TextComponent("DAE 5000", arcadeFont, 255, 255, 0)); yPos += pSavedHighScoreTextComp->GetHeight() * 1.5f; pSavedHighScoreGo->SetPosition(screenWidth / 2.f - pSavedHighScoreTextComp->GetWidth() / 2.f, yPos); pSavedHighScoreTextComp->RecenterOnDraw(true, screenWidth); pGameOverScene.Add(pSavedHighScoreGo); pSavedHighScoreTextComps.emplace_back(pSavedHighScoreTextComp); // Selection Arrow pSelectionArrowGo = new GameObject(); pSelectionArrowTexComp = pSelectionArrowGo->AddComponent(new AnimatedTextureComponent("selection_arrow.png", 16, 16, 2, 1)); pSelectionArrowTexComp->SetSpritesPerSecond(2); pSelectionArrowTexComp->Play(0, 1, false); pGameOverScene.Add(pSelectionArrowGo); pSelectionArrowGo->SetActive(false); // UI Text p1UpGo = new GameObject(); p1UpTextComp = p1UpGo->AddComponent(new TextComponent("1UP", arcadeFont, 0, 255, 0)); p1UpGo->SetPosition(88 - p1UpTextComp->GetWidth() / 2.f, -4.f); pGameOverScene.Add(p1UpGo); p1ScoreGo = new GameObject(); p1ScoreTextComp = p1ScoreGo->AddComponent(new TextComponent(" 00", arcadeFont, 255, 255, 255)); p1ScoreGo->SetPosition(88 - p1ScoreTextComp->GetWidth() / 2.f, 12.f); auto pPlayer1ScoreComp = p1ScoreGo->AddComponent(new PlayerScoreComponent(1)); pGameOverScene.Add(p1ScoreGo); pHighScoreTitleGo = new GameObject(); pHighScoreTitleTextComp = pHighScoreTitleGo->AddComponent(new TextComponent("HIGH SCORE", arcadeFont, 255, 0, 0)); pHighScoreTitleGo->SetPosition(screenWidth / 2.f - pHighScoreTitleTextComp->GetWidth() / 2.f, -4.f); pGameOverScene.Add(pHighScoreTitleGo); pHighScoreGo = new GameObject(); pHighScoreGo->SetName("HighScoreText"); pHighScoreTextComp = pHighScoreGo->AddComponent(new TextComponent(" 30000", arcadeFont, 255, 255, 255)); pHighScoreGo->SetPosition(screenWidth / 2.f - pHighScoreTextComp->GetWidth() / 2.f, 12.f); pGameOverScene.Add(pHighScoreGo); p2UpGo = new GameObject(); p2UpTextComp = p2UpGo->AddComponent(new TextComponent("2UP", arcadeFont, 0, 187, 255)); p2UpGo->SetPosition(screenWidth - 88 - p2UpTextComp->GetWidth() / 2.f, -4.f); pGameOverScene.Add(p2UpGo); p2ScoreGo = new GameObject(); p2ScoreTextComp = p2ScoreGo->AddComponent(new TextComponent(" 00", arcadeFont, 255, 255, 255)); p2ScoreGo->SetPosition(screenWidth - 88 - p2ScoreTextComp->GetWidth() / 2.f, 12.f); auto pPlayer2ScoreComp = p2ScoreGo->AddComponent(new PlayerScoreComponent(2)); pGameOverScene.Add(p2ScoreGo); // Next level command pNextLevelCommand = new NextLevelCommand(pGameOverGo, false, true); input.AddKeyboardCommand(pGameOverScene.GetId(), SDL_SCANCODE_F1, PressType::DOWN, pNextLevelCommand); pNextLevelCommand = new NextLevelCommand(pGameOverGo, false, true); input.AddKeyboardCommand(pGameOverScene.GetId(), SDL_SCANCODE_RETURN, PressType::DOWN, pNextLevelCommand); pNextLevelCommand = new NextLevelCommand(pGameOverGo, false, true); input.AddControllerCommand(pGameOverScene.GetId(), 0, ControllerButton::Start, PressType::DOWN, pNextLevelCommand); pNextLevelCommand = new NextLevelCommand(pGameOverGo, false, true); input.AddControllerCommand(pGameOverScene.GetId(), 0, ControllerButton::ButtonA, PressType::DOWN, pNextLevelCommand); // Restart Function auto RestartGameOver = [&soundSystem, pSelectionArrowGo, pHighScoreTextComp, pSavedHighScoreTextComps, pPlayer1ScoreComp, pPlayer2ScoreComp/*, pMainMenuComp*/]() { soundSystem.StopMusic(); soundSystem.PlayMusic(3, 1.f, 1); pHighScoreTextComp->SetText(std::to_string(GameState::GetInstance().GetHighScore())); int index = GameState::GetInstance().AddHighScore("NEW", GameState::GetInstance().GetHighScore()); auto savedScores = GameState::GetInstance().GetSavedHighScores(); for (int i{}; i < 5; i++) { pSavedHighScoreTextComps[i]->SetText(savedScores[i].first + " " + std::to_string(savedScores[i].second)); if (i == index) { pSelectionArrowGo->SetActive(true); pSelectionArrowGo->SetPosition(pSavedHighScoreTextComps[i]->GetGameObject()->GetWorldPosition().x - 24.f, pSavedHighScoreTextComps[i]->GetGameObject()->GetWorldPosition().y + 2); pSavedHighScoreTextComps[i]->SetColor(255, 255, 0); } else { pSavedHighScoreTextComps[i]->SetColor(255, 255, 255); } } pPlayer1ScoreComp->RefreshScore(); pPlayer2ScoreComp->RefreshScore(); //pMainMenuComp->SetState(MainMenuState::LOGO); //pMainMenuComp->SetSelection(0); GameState::GetInstance().SetLevelId(1); //std::cout << "restarted game over\n"; }; pGameOverScene.SetRestartFunction(RestartGameOver); } #pragma endregion GameOverScene //******************************* // Set Starting Scene to MainMenu //******************************* SceneManager::GetInstance().SetScene("MainMenu", true); //SceneManager::GetInstance().SetScene("MultiPlayer", true); //SceneManager::GetInstance().SetScene("SinglePlayer", true); //SceneManager::GetInstance().SetScene("GameOver", true); } } int main(int, char* []) { ServiceLocator::RegisterSoundSystem(std::make_unique()); dae::DuvelEngine engine("../Data/"); engine.Run(dae::load); return 0; }