diff --git a/assets/.DS_Store b/assets/.DS_Store index 92effa15..9b6eec75 100644 Binary files a/assets/.DS_Store and b/assets/.DS_Store differ diff --git a/assets/explosion/nuke.png b/assets/explosion/nuke.png new file mode 100644 index 00000000..6c968156 Binary files /dev/null and b/assets/explosion/nuke.png differ diff --git a/include/Mechanics/BuiltStructure.hpp b/include/Mechanics/BuiltStructure.hpp index ef748413..280c2398 100644 --- a/include/Mechanics/BuiltStructure.hpp +++ b/include/Mechanics/BuiltStructure.hpp @@ -77,29 +77,32 @@ class BuiltStructure { m_BuiltStructure.push_back(structure); } - void updateAvatarSpawnLocation() { +public: + // glm::vec2 getEnemyBarrackCell() { return m_EnemyBarrackCell; } + // glm::vec2 getEnemyWayPointCell() { return m_EnemyWayPointCell; } + glm::vec2 getPlayerBarrackSpawnCell() { for (auto i : m_BuiltStructure) { if (std::dynamic_pointer_cast(i)) { - m_PlayerBarrackCell = - MapUtil::GlobalCoordToCellCoord(i->GetObjectLocation()); - m_PlayerWayPointCell = MapUtil::GlobalCoordToCellCoord( + glm::vec2 ogSpawnPoint = i->GetObjectLocation(); + while (!m_Map->getTileByCellPosition(ogSpawnPoint) + ->getWalkable()) { + ogSpawnPoint.x -= 1; + } + return ogSpawnPoint; + } + } + } + glm::vec2 getPlayerBarrackWayPointCell() { + for (auto i : m_BuiltStructure) { + if (std::dynamic_pointer_cast(i)) { + return MapUtil::GlobalCoordToCellCoord( std::dynamic_pointer_cast(i) ->GetWayPointLocation()); } } + return m_PlayerWayPointCell; } - glm::vec2 getPlayerBarrackCell() { - return {m_PlayerBarrackCell.x - 1, m_PlayerBarrackCell.y - 1}; - } - // glm::vec2 getPlayerWayPointCell() { return m_PlayerWayPointCell; } - -public: - // glm::vec2 getEnemyBarrackCell() { return m_EnemyBarrackCell; } - // glm::vec2 getEnemyWayPointCell() { return m_EnemyWayPointCell; } - glm::vec2 getPlayerBarrackSpawnCell() { return m_PlayerBarrackCell; } - glm::vec2 getPlayerBarrackWayPointCell() { return m_PlayerWayPointCell; } - bool ifBarrackBuilt() { for (auto i : m_BuiltStructure) { if (i->getID().getUnitType() == UnitType::BARRACKS) { @@ -125,6 +128,15 @@ class BuiltStructure { return false; } + bool ifOreRefinaryBuilt() { + for (auto i : m_BuiltStructure) { + if (i->getID().getUnitType() == UnitType::ORE_REF) { + return true; + } + } + return false; + } + private: std::shared_ptr m_Map = std::make_shared(); std::vector> m_BuiltStructure; diff --git a/include/Mechanics/UnitManager.hpp b/include/Mechanics/UnitManager.hpp index 37b0438b..ccee9b8e 100644 --- a/include/Mechanics/UnitManager.hpp +++ b/include/Mechanics/UnitManager.hpp @@ -72,22 +72,19 @@ class UnitManager : public Player { } } - void spawnToWayPoint(std::shared_ptr m_Map, UnitType unit, - HouseType house) { + void spawnToWayPoint(UnitType unit, HouseType house) { switch (unit) { case UnitType::INFANTRY: { auto avatar = std::make_shared(house); - m_StructureManager->getStructureArray() - ->updateAvatarSpawnLocation(); if (m_StructureManager->getStructureArray() - ->getPlayerBarrackCell() + ->getPlayerBarrackSpawnCell() .x == -1) { return; } avatar->Start(m_StructureManager->getStructureArray() - ->getPlayerBarrackCell()); + ->getPlayerBarrackSpawnCell()); m_AvatarManager->assignMoveOrderToAvatar( avatar, {m_StructureManager->getStructureArray() @@ -106,8 +103,7 @@ class UnitManager : public Player { } } } - void spawn(std::shared_ptr m_Map, UnitType unit, HouseType house, - glm::vec2 cellPos) { + void spawn(UnitType unit, HouseType house, glm::vec2 cellPos) { // 缺檢查敵方擁有建築的位置,並重生在該處 switch (unit) { case UnitType::BARRACKS: { diff --git a/include/Scene/TutorialScene.hpp b/include/Scene/TutorialScene.hpp index 1c706819..8c3f59f7 100644 --- a/include/Scene/TutorialScene.hpp +++ b/include/Scene/TutorialScene.hpp @@ -13,11 +13,11 @@ #define DEBUG_KEY P - enum class TutorialStages { STAGE1, STAGE2, STAGE3, STAGE4 }; class TutorialScene : public Scene { enum class Stages { STAGE1, STAGE2, STAGE3, STAGE4 }; + public: TutorialScene(){}; ~TutorialScene(){}; @@ -31,6 +31,10 @@ class TutorialScene : public Scene { void stage2Update(); void stage3Update(); void stage4Update(); + void initStage2(); + void initStage3(); + void initStage4(); + void initFinalStage(); private: SpriteSheet m_SpriteSheet; diff --git a/src/AI/EnemyScripts.cpp b/src/AI/EnemyScripts.cpp index c265bead..655e05ae 100644 --- a/src/AI/EnemyScripts.cpp +++ b/src/AI/EnemyScripts.cpp @@ -174,7 +174,7 @@ void EnemyScripts::UpdateSpawnScript(SpawnMode spawnMode) { return; } m_GameObjectManager->spawn( - m_Map, m_selectedBuildingType, HouseType::ENEMY, + m_selectedBuildingType, HouseType::ENEMY, {m_baseCell.x + constructCountX, m_baseCell.y + constructCountY}); m_EnemyObjectManager->addUnitConstructCount(m_selectedBuildingType, 1); setCost(0, SpawnMode::BUILDINGS); @@ -193,7 +193,7 @@ void EnemyScripts::UpdateSpawnScript(SpawnMode spawnMode) { return; } if (m_selectedAvatarType == UnitType::INFANTRY) { - m_GameObjectManager->spawnToWayPoint(m_Map, m_selectedAvatarType, + m_GameObjectManager->spawnToWayPoint(m_selectedAvatarType, HouseType::ENEMY); setCost(0, SpawnMode::AVATAR); setCDTime(0.f, SpawnMode::AVATAR); diff --git a/src/Scene/DefaultScene.cpp b/src/Scene/DefaultScene.cpp index c19e067c..846df143 100644 --- a/src/Scene/DefaultScene.cpp +++ b/src/Scene/DefaultScene.cpp @@ -52,8 +52,7 @@ void DefaultScene::Update() { ->getStructureArray() ->getBuiltStructureArray()); if (m_UI->getIfUnitReadyToSpawn()) { - // what the fuck - m_GameObjectManager->getAvatarManager()->AppendAvatar( - m_UI->getUnitFromUI()); + m_GameObjectManager->spawnToWayPoint( + m_UI->getUnitFromUI()->getID().getUnitType(), HouseType::MY); } } diff --git a/src/Scene/SandBoxScene.cpp b/src/Scene/SandBoxScene.cpp index 8a33b8b1..18763119 100644 --- a/src/Scene/SandBoxScene.cpp +++ b/src/Scene/SandBoxScene.cpp @@ -58,61 +58,51 @@ void SandBoxScene::Update() { void SandBoxScene::stageStart() { switch (m_stage) { case Stages::STAGE1: { - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 5}); - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 6}); - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 7}); - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 8}); - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 9}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 5}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 6}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 7}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 8}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 9}); + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 5}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 6}); m_stage = Stages::END; break; } case Stages::STAGE2: { - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 5}); - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 6}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 5}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 6}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 5}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 6}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 7}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 8}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 9}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 10}); m_stage = Stages::END; break; } case Stages::STAGE3: { - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 5}); - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 6}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 5}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 6}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 5}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {10, 6}); m_stage = Stages::END; break; } case Stages::STAGE4: { for (int i = 0; i < 50; i++) { - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, - HouseType::ENEMY, + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {30 + i / 5, 5 + i % 5}); } m_stage = Stages::END; diff --git a/src/Scene/TutorialScene.cpp b/src/Scene/TutorialScene.cpp index b343977c..8061cefe 100644 --- a/src/Scene/TutorialScene.cpp +++ b/src/Scene/TutorialScene.cpp @@ -18,8 +18,7 @@ void TutorialScene::Start() { // m_EnemyScripts->Start(m_Enemy,m_GameObjectManager, // m_EnemyObjectManager, m_Map); - m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, - {5, 5}); + m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 5}); // combat test // m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, // {6, 6}); @@ -62,7 +61,6 @@ void TutorialScene::Update() { } } void TutorialScene::stageStart() { - m_stage = TutorialStages::STAGE1; m_PlayerObjectivesText->SetDrawable( std::make_unique("../assets/sprites/Task/Task1.png")); m_PlayerObjectivesText->SetVisible(true); @@ -78,14 +76,16 @@ void TutorialScene::stageStart() { m_cellProp->setHighLightOffset({-100, 0}); m_cellProp->Start({2, 2}); m_cellProp->setObjectLocation({750, 750}, 0); + m_stage = TutorialStages::STAGE1; } void TutorialScene::stageUpdate() { - if (Util::Input::IsKeyPressed(Util::Keycode::R)) { + if (Util::Input::IsKeyDown(Util::Keycode::R)) { stageStart(); } switch (m_stage) { case TutorialStages::STAGE1: { stage1Update(); + break; } case TutorialStages::STAGE2: { stage2Update(); @@ -106,26 +106,27 @@ void TutorialScene::stage1Update() { m_PlayerObjectivesText->Draw(); m_cellProp->Update(); for (auto i : m_GameObjectManager->getAvatarManager()->getAvatarArray()) { - if (i->getSelected()) { - if (m_cellProp->ifOverlaps(i->getMoving()->getCurrentCell()) || - Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY)) { - // change next stage's text&prop here - m_PlayerObjectivesText->SetDrawable( - std::make_unique( - "../assets/sprites/Task/Task2.png")); - - m_cellProp->setHighLightImage( - "../assets/sprites/Task/Task_Cell_Text2.png"); - m_cellProp->setScale({6, 4}); - m_cellProp->setObjectLocation({600, 1000}, 0); - m_cellProp->Start({12, 8}); - m_stage = TutorialStages::STAGE2; - break; - } + + if ((i->getSelected() && + m_cellProp->ifOverlaps(i->getMoving()->getCurrentCell())) || + Util::Input::IsKeyDown(Util::Keycode::DEBUG_KEY)) { + initStage2(); + break; } } } +void TutorialScene::initStage2() { + m_PlayerObjectivesText->SetDrawable( + std::make_unique("../assets/sprites/Task/Task2.png")); + + m_cellProp->setHighLightImage("../assets/sprites/Task/Task_Cell_Text2.png"); + m_cellProp->setScale({6, 4}); + m_cellProp->setObjectLocation({600, 1000}, 0); + m_cellProp->Start({12, 8}); + m_stage = TutorialStages::STAGE2; +}; + void TutorialScene::stage2Update() { m_PlayerObjectivesText->Draw(); m_cellProp->Update(); @@ -145,20 +146,24 @@ void TutorialScene::stage2Update() { ->ifPowerPlantBuilt() && m_GameObjectManager->getStructureManager() ->getStructureArray() - ->ifWarFactoryBuilt() || - Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY)) { + ->ifOreRefinaryBuilt() || + Util::Input::IsKeyDown(Util::Keycode::DEBUG_KEY)) { // change next stage's text&prop here - m_PlayerObjectivesText->SetDrawable( - std::make_unique("../assets/sprites/Task/Task3.png")); - - m_cellProp->setHighLightImage( - "../assets/sprites/Task/Task_Cell_Text3.png"); - m_cellProp->setScale({2, 2}); - m_cellProp->setObjectLocation({850, 850}, 0); - m_cellProp->Start({4, 4}); - m_stage = TutorialStages::STAGE3; + initStage3(); } } + +void TutorialScene::initStage3() { + m_PlayerObjectivesText->SetDrawable( + std::make_unique("../assets/sprites/Task/Task3.png")); + + m_cellProp->setHighLightImage("../assets/sprites/Task/Task_Cell_Text3.png"); + m_cellProp->setScale({2, 2}); + m_cellProp->setObjectLocation({850, 850}, 0); + m_cellProp->Start({4, 4}); + m_stage = TutorialStages::STAGE3; +} + void TutorialScene::stage3Update() { m_PlayerObjectivesText->Draw(); m_cellProp->Update(); @@ -170,26 +175,25 @@ void TutorialScene::stage3Update() { } } } - if (avatarCount >= 4 || - Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY)) { + if (avatarCount >= 4 || Util::Input::IsKeyDown(Util::Keycode::DEBUG_KEY)) { // change next stage's text&prop here - m_PlayerObjectivesText->SetDrawable( - std::make_unique("../assets/sprites/Task/Task4.png")); - - m_cellProp->setHighLightImage( - "../assets/sprites/Task/Task_Cell_Text4.png"); - m_cellProp->setScale({4, 3}); - m_cellProp->setObjectLocation({1200, 850}, 0); - m_cellProp->Start({8, 6}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, - {24, 17}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, - {26, 18}); - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, - {25, 17}); - m_stage = TutorialStages::STAGE4; + initStage4(); } } +void TutorialScene::initStage4() { + m_PlayerObjectivesText->SetDrawable( + std::make_unique("../assets/sprites/Task/Task4.png")); + + m_cellProp->setHighLightImage("../assets/sprites/Task/Task_Cell_Text4.png"); + m_cellProp->setScale({4, 3}); + m_cellProp->setObjectLocation({1200, 850}, 0); + m_cellProp->Start({8, 6}); + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {24, 17}); + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {26, 18}); + m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {25, 17}); + m_stage = TutorialStages::STAGE4; +} + void TutorialScene::stage4Update() { m_PlayerObjectivesText->Draw(); m_cellProp->Update(); @@ -201,5 +205,8 @@ void TutorialScene::stage4Update() { } if (enemy_count >= 3) { // End? + initFinalStage(); } } + +void TutorialScene::initFinalStage() {}