diff --git a/include/AI/EnemyScripts.hpp b/include/AI/EnemyScripts.hpp index a419e7e4..2c4cbec3 100644 --- a/include/AI/EnemyScripts.hpp +++ b/include/AI/EnemyScripts.hpp @@ -9,17 +9,20 @@ #define SPACE 4 + enum class SpawnMode { BUILDINGS,AVATAR}; class EnemyScripts{ + private: std::shared_ptr m_GameObjectManager; std::shared_ptr m_EnemyObjectManager; std::shared_ptr m_Map; - glm::vec2 m_baseCell = {20,20}; + glm::vec2 m_baseCell = {20, 20}; int constructCountX = 0; int constructCountY = 0; + float m_buildingCDTime=0; float m_AvatarCDTime=0; float m_buildingCost = 0.F; diff --git a/include/Mechanics/BuiltStructure.hpp b/include/Mechanics/BuiltStructure.hpp index 6c39605e..4bb1771d 100644 --- a/include/Mechanics/BuiltStructure.hpp +++ b/include/Mechanics/BuiltStructure.hpp @@ -47,8 +47,8 @@ class BuiltStructure { return true; } - std::vector> *getBuiltStructureArray() { - return &m_BuiltStructure; + std::vector> getBuiltStructureArray() { + return m_BuiltStructure; } void StartBuiltStructure() { @@ -91,6 +91,38 @@ class BuiltStructure { 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 ifBarracksBuilt() { + for (auto i : m_BuiltStructure) { + if (i->getID().getUnitType() == UnitType::BARRACKS) { + return true; + } + } + return false; + } + bool ifPowerPlantsBuilt() { + for (auto i : m_BuiltStructure) { + if (i->getID().getUnitType() == UnitType::POWER_PLANT) { + return true; + } + } + return false; + } + bool ifWarFactoryBuilt() { + for (auto i : m_BuiltStructure) { + if (i->getID().getUnitType() == UnitType::WAR_FACT) { + return true; + } + } + return false; + } + + private: std::shared_ptr m_Map = std::make_shared(); std::vector> m_BuiltStructure; diff --git a/include/Mechanics/StructureManager.hpp b/include/Mechanics/StructureManager.hpp index 84b2c75d..5f43f57c 100644 --- a/include/Mechanics/StructureManager.hpp +++ b/include/Mechanics/StructureManager.hpp @@ -12,14 +12,14 @@ class StructureManager { virtual ~StructureManager() {} void Start(std::shared_ptr map) { - m_StructureArray.Start(map); + m_BuiltStructure->Start(map); m_Map = map; } void Update() { m_StructSelectingConstructionSite->Update(); - m_StructureArray.UpdateBuiltStructure(); + m_BuiltStructure->UpdateBuiltStructure(); } void AddStructSelectingBuiltSite(std::shared_ptr newstruct) { @@ -36,16 +36,19 @@ class StructureManager { if (m_StructSelectingConstructionSite->getStructureOrder() ->getStructureOrderType() == StructureOrderType::SELECTING_SITE) { - m_StructureArray.buildNewStructure( + m_BuiltStructure->buildNewStructure( m_StructSelectingConstructionSite); } } - BuiltStructure *getStructureArray() { return &m_StructureArray; } + std::shared_ptr getStructureArray() { + return m_BuiltStructure; + } protected: std::shared_ptr m_Map = std::make_shared(); - BuiltStructure m_StructureArray; + std::shared_ptr m_BuiltStructure = + std::make_shared(); std::shared_ptr m_StructSelectingConstructionSite = std::make_shared(); }; diff --git a/include/Mechanics/UnitManager.hpp b/include/Mechanics/UnitManager.hpp index cbcedc77..ee433bd1 100644 --- a/include/Mechanics/UnitManager.hpp +++ b/include/Mechanics/UnitManager.hpp @@ -54,7 +54,7 @@ class UnitManager : public Player { public: int getTotalPower() { return Player::getTotalPower( - *m_StructureManager->getStructureArray()->getBuiltStructureArray()); + m_StructureManager->getStructureArray()->getBuiltStructureArray()); } std::shared_ptr getAvatarManager() { return m_AvatarManager; @@ -64,22 +64,16 @@ class UnitManager : public Player { } int UpdateCurrency() { - for (auto i : *m_StructureManager->getStructureArray() - ->getBuiltStructureArray()) { + for (auto i : m_StructureManager->getStructureArray() + ->getBuiltStructureArray()) { if (std::dynamic_pointer_cast(i)) { addTotalCurrency(150); } } } - void spawn(std::shared_ptr m_Map, UnitType unit, - HouseType house) { - - if (house == HouseType::ENEMY) { - // m_Enemy->addUnitConstructCount(unit, 1); - } else { - // m_Player->setUnitConstructCount(unit, 1); - } + void spawnToWayPoint(std::shared_ptr m_Map, UnitType unit, + HouseType house) { switch (unit) { case UnitType::INFANTRY: { @@ -93,7 +87,12 @@ class UnitManager : public Player { avatar->Start(m_StructureManager->getStructureArray() ->getPlayerBarrackCell()); + m_AvatarManager->assignMoveOrderToAvatar(avatar,{m_StructureManager->getStructureArray()->getPlayerWayPointCell()}); + // assign order + m_AvatarManager->assignMoveOrderToAvatar( + avatar, m_StructureManager->getStructureArray() + ->getPlayerWayPointCell()); m_AvatarManager->AppendAvatar(avatar); m_troopSize+=1; } diff --git a/include/Scene/Scene.hpp b/include/Scene/Scene.hpp index ea611c67..b296f9c8 100644 --- a/include/Scene/Scene.hpp +++ b/include/Scene/Scene.hpp @@ -54,7 +54,7 @@ class Scene { std::shared_ptr m_EnemyObjectManager = std::make_shared(); Util::Renderer m_Renderer; - UIClass m_UI; + std::shared_ptr m_UI = std::make_shared(); std::shared_ptr m_Player = std::make_shared(); }; diff --git a/include/Scene/TutorialScene.hpp b/include/Scene/TutorialScene.hpp index 071f0fa9..1c706819 100644 --- a/include/Scene/TutorialScene.hpp +++ b/include/Scene/TutorialScene.hpp @@ -8,13 +8,14 @@ #include "Cursor.hpp" #include "Scene.hpp" // #include "Mechanics/GameObjectID.hpp" -#include "Task.hpp" #include "Util/Prop.hpp" -#include +#include "pch.hpp" #define DEBUG_KEY P +enum class TutorialStages { STAGE1, STAGE2, STAGE3, STAGE4 }; + class TutorialScene : public Scene { enum class Stages { STAGE1, STAGE2, STAGE3, STAGE4 }; public: @@ -22,8 +23,14 @@ class TutorialScene : public Scene { ~TutorialScene(){}; void Start() override; void Update() override; + +private: void stageStart(); void stageUpdate(); + void stage1Update(); + void stage2Update(); + void stage3Update(); + void stage4Update(); private: SpriteSheet m_SpriteSheet; @@ -33,8 +40,9 @@ class TutorialScene : public Scene { std::make_shared(SceneMode::TUTORIAL); std::shared_ptr m_EnemyScripts = std::make_shared(); - std::shared_ptr m_Text = std::make_shared(); + std::shared_ptr m_PlayerObjectivesText = + std::make_shared(); std::shared_ptr m_cellProp = std::make_shared(); - Stages m_stage; + TutorialStages m_stage; }; #endif // PRACTICALTOOLSFORSIMPLEDESIGN_TUTORIALSCENE_HPP diff --git a/include/Task.hpp b/include/Task.hpp deleted file mode 100644 index c2d8218d..00000000 --- a/include/Task.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// Created by nudle on 2024/5/9. -// - -#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_TASK_HPP -#define PRACTICALTOOLSFORSIMPLEDESIGN_TASK_HPP -#include "Util/GameObject.hpp" -#include "Camera.hpp" -#define CAM_OFFSET 0.05 -class Task:public Util::GameObject{ -public: - Task():Util::GameObject(){ SetZIndex(20);} - ~Task()override{} - void importCamera(std::shared_ptr camera){ - m_Camera=camera; - } - void setObjectScale(float scale){ - m_Transform.scale={scale,scale}; - } - void Draw()override{ - if (!m_Visible) { - return; - } - if (b_MovingRelativeToCamera) { - //m_Transform.translation = {m_Camera->getPosition().x*CAM_OFFSET,m_Camera->getPosition().y*CAM_OFFSET}; - //printf("(Task): pos = {%5f,%5f}",m_Transform.translation.x,m_Transform.translation.y); - m_Drawable->Draw(m_Transform, m_ZIndex); - } else { - m_Drawable->Draw(m_Transform, m_ZIndex); - } - } -private: - std::shared_ptr m_Camera; -}; -#endif // PRACTICALTOOLSFORSIMPLEDESIGN_TASK_HPP diff --git a/include/UI/Button.hpp b/include/UI/Button.hpp new file mode 100644 index 00000000..5c834177 --- /dev/null +++ b/include/UI/Button.hpp @@ -0,0 +1,15 @@ +// +// Created by 盧威任 on 5/21/24. +// + +#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_BUTTON_HPP +#define PRACTICALTOOLSFORSIMPLEDESIGN_BUTTON_HPP +#include "Util/GameObject.hpp" +class Button : public Util::GameObject { + + // setImage + // given cursor coord or cursor object +public: +private: +}; +#endif // PRACTICALTOOLSFORSIMPLEDESIGN_BUTTON_HPP diff --git a/include/Util/GameObject.hpp b/include/Util/GameObject.hpp index a445f689..16fc7a05 100644 --- a/include/Util/GameObject.hpp +++ b/include/Util/GameObject.hpp @@ -20,7 +20,7 @@ namespace Util { */ class GameObject { public: - Util::Transform m_Transform; // IDC if this should be here. + Util::Transform m_Transform; public: /** @@ -37,14 +37,17 @@ class GameObject { * @param children The children of the game object. * @param movingRelativeToCamera Whether the object can move relative to * camera position + * @param transfrom predefined transform */ GameObject(const std::shared_ptr &drawable, const float zIndex, const bool visible = true, - const bool movingRelativeToCamera = true) + const bool movingRelativeToCamera = true, + const Util::Transform transfrom = Util::Transform()) : m_Drawable(std::move(drawable)), m_ZIndex(zIndex), m_Visible(visible), - b_MovingRelativeToCamera(movingRelativeToCamera) {} + b_MovingRelativeToCamera(movingRelativeToCamera), + m_Transform(transfrom) {} /** * @brief Copy constructor. @@ -75,6 +78,8 @@ class GameObject { */ float GetZIndex() const { return m_ZIndex; } + void SetTransform(Util::Transform transform) { m_Transform = transform; } + /** * @brief Get the transform of the game object. * diff --git a/include/Util/Prop.hpp b/include/Util/Prop.hpp index 15ee652d..1c2100be 100644 --- a/include/Util/Prop.hpp +++ b/include/Util/Prop.hpp @@ -5,50 +5,53 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_PROP_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_PROP_HPP #include "Structure/Structure.hpp" -class Prop:public Structure{ +class Prop : public Structure { public: - Prop(bool selectable = false):Structure(selectable){} - ~Prop()override{} - void Start(glm::vec2 width)override{ - m_width=width; + Prop(bool selectable = false) + : Structure(selectable) {} + ~Prop() override {} + void Start(glm::vec2 width) override { + m_width = width; this->SetAttachVisible(true); SetZIndex(8); m_HighLight.SetZIndex(10); } - void attachmentUpdate()override{ - m_HighLight.SetObjectLocation({this->GetDrawLocation().x+m_highlightOffset.x,this->GetDrawLocation().y+m_highlightOffset.y}); + void attachmentUpdate() override { + m_HighLight.SetObjectLocation( + {this->GetDrawLocation().x + m_highlightOffset.x, + this->GetDrawLocation().y + m_highlightOffset.y}); m_HighLight.Draw(); } - void setScale(glm::vec2 scale){ - m_Transform.scale=scale; - } - void setHighLightImage(std::string path){ + void setScale(glm::vec2 scale) { m_Transform.scale = scale; } + void setHighLightImage(std::string path) { m_HighLight.SetDrawable(std::make_unique(path)); } - void setHighLightOffset(glm::vec2 globalDistance){ - m_highlightOffset=globalDistance; + void setHighLightOffset(glm::vec2 globalDistance) { + m_highlightOffset = globalDistance; } - void setObjectLocation(glm::vec2 location,float offsetCell){ + void setObjectLocation(glm::vec2 location, float offsetCell) { location = MapUtil::PositionStickToGrid(location); m_ObjectLocation = location; m_DrawLocation = {location.x + offsetCell * CELL_SIZE.x, location.y + offsetCell * CELL_SIZE.y}; m_Transform.translation = m_DrawLocation; } - bool isOverlaps(glm::vec2 cell){ - if(cell.x>m_ObjectLocation.x&&cell.xm_ObjectLocation.y&&cell.y getLocationCell().x - m_width.x && + cell.x < getLocationCell().x) && + (cell.y > getLocationCell().y - m_width.y && + cell.y < getLocationCell().y)) { + return true; } return false; } - void Update()override{ + void Update() override { Draw(); attachmentUpdate(); } + private: - glm::vec2 m_width={1,1}; - glm::vec2 m_highlightOffset={0,0}; + glm::vec2 m_width = {1, 1}; + glm::vec2 m_highlightOffset = {0, 0}; }; #endif // PRACTICALTOOLSFORSIMPLEDESIGN_PROP_HPP diff --git a/src/Scene/DefaultScene.cpp b/src/Scene/DefaultScene.cpp index d39fe918..3597b6ff 100644 --- a/src/Scene/DefaultScene.cpp +++ b/src/Scene/DefaultScene.cpp @@ -8,33 +8,22 @@ void DefaultScene::Start() { LOG_TRACE("Start"); + // create map m_Map->Init(98, 98); - // m_Map->Init( - // MapBinReader::readBin("../assets/map/green-belt/map.bin", 98, 98), 98, - // 98); - // m_Map->getTileByCellPosition(glm::vec2(5, 5))->setWalkable(0); + + /* m_Map->getTileByCellPosition(glm::vec2(6, 5))->setWalkable(0); m_Map->getTileByCellPosition(glm::vec2(7, 5))->setWalkable(0); m_Map->getTileByCellPosition(glm::vec2(8, 5))->setWalkable(0); m_Map->getTileByCellPosition(glm::vec2(9, 5))->setWalkable(0); + */ - // m_GameObjectManager.Start(); - - // m_dummy.Start({5, 5}, m_Map); + // start m_GameObjectManager->Start(m_Map); - // m_Cursor.Start(m_Map); - m_UI.Start(m_Map, m_GameObjectManager); + m_UI->Start(m_Map, m_GameObjectManager); m_GameObjectManager->setTotalCurrency(5000); m_SceneCamera->Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)), MapUtil::CellCoordToGlobal(glm::vec2(100, 100))); - - // m_hunter->setCurrentCell({20,10}); - // m_runner->setCurrentCell({10,10}); - - // m_hunter->Start({20, 9}); - // m_runner->Start({9, 10}); - // m_hunter->setTarget(m_runner); - // m_runner->setBeingChase(m_hunter); } void DefaultScene::Update() { @@ -47,7 +36,7 @@ void DefaultScene::Update() { m_Map->Draw(trans, 0); m_SceneCamera->Update(); m_Renderer.Update(); - m_UI.Update(); + m_UI->Update(); auto tileLocation = MapUtil::GlobalCoordToCellCoord( MapUtil::ScreenToGlobalCoord(Util::Input::GetCursorPosition())); @@ -55,20 +44,18 @@ void DefaultScene::Update() { m_Cursor->Update(m_Map->getTileByCellPosition(tileLocation)); } - auto tile = m_Map->getTileByCellPosition(MapUtil::GlobalCoordToCellCoord( - MapUtil::ScreenToGlobalCoord(Util::Input::GetCursorPosition()))); - - // m_GameObjectManager.Update(); + // build and spawn stuff - if (m_UI.getIfAnyBuildingReadyToBuild()) { + if (m_UI->getIfAnyBuildingReadyToBuild()) { m_GameObjectManager->getStructureManager()->AddStructSelectingBuiltSite( - m_UI.getSelectedBuilding()); + m_UI->getSelectedBuilding()); } - m_UI.checkExistBuilding(*m_GameObjectManager->getStructureManager() + m_UI->checkExistBuilding(m_GameObjectManager->getStructureManager() ->getStructureArray() ->getBuiltStructureArray()); - if (m_UI.getIfUnitReadyToSpawn()) { + if (m_UI->getIfUnitReadyToSpawn()) { + // what the fuck m_GameObjectManager->getAvatarManager()->AppendAvatar( - m_UI.getUnitFromUI()); + m_UI->getUnitFromUI()); } } diff --git a/src/Scene/TutorialScene.cpp b/src/Scene/TutorialScene.cpp index 12cd17f3..fca90702 100644 --- a/src/Scene/TutorialScene.cpp +++ b/src/Scene/TutorialScene.cpp @@ -9,7 +9,7 @@ void TutorialScene::Start() { m_Map->Init(100, 100); m_GameObjectManager->Start(m_Map); m_EnemyObjectManager->Start(m_Map); - m_UI.Start(m_Map, m_GameObjectManager); + m_UI->Start(m_Map, m_GameObjectManager); m_Player->setTotalCurrency(5000); m_Enemy->setTotalCurrency(5000); m_SceneCamera->Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)), @@ -17,20 +17,13 @@ void TutorialScene::Start() { // m_EnemyScripts->Start(m_Enemy,m_GameObjectManager, m_EnemyObjectManager, m_Map); - /* - m_EnemyObjectManager->spawn(m_Map, UnitType::BARRACKS, HouseType::ENEMY, - {20, 20}); - m_EnemyObjectManager->spawn(m_Map, UnitType::POWER_PLANT, - HouseType::ENEMY, {25, 25}); m_GameObjectManager->spawn(m_Map, - UnitType::ORE_REF, HouseType::ENEMY, {25, 20}); - */ m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, {5, 5}); // combat test - m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, - {6, 6}); - m_EnemyObjectManager->spawn(m_Map, UnitType::BARRACKS, HouseType::ENEMY, - {10, 10}); + // m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + // {6, 6}); + // m_EnemyObjectManager->spawn(m_Map, UnitType::BARRACKS, HouseType::ENEMY, + // {10, 10}); stageStart(); } @@ -43,7 +36,7 @@ void TutorialScene::Update() { m_Map->Draw(trans, 0); m_SceneCamera->Update(); m_Renderer.Update(); - m_UI.Update(); + m_UI->Update(); // temperarory place here auto tileLocation = MapUtil::GlobalCoordToCellCoord( @@ -55,26 +48,28 @@ void TutorialScene::Update() { auto tile = m_Map->getTileByCellPosition(MapUtil::GlobalCoordToCellCoord( MapUtil::ScreenToGlobalCoord(Util::Input::GetCursorPosition()))); - if (m_UI.getIfAnyBuildingReadyToBuild()) { + if (m_UI->getIfAnyBuildingReadyToBuild()) { m_GameObjectManager->getStructureManager()->AddStructSelectingBuiltSite( - m_UI.getSelectedBuilding()); + m_UI->getSelectedBuilding()); } - m_UI.checkExistBuilding(*m_GameObjectManager->getStructureManager() + m_UI->checkExistBuilding(m_GameObjectManager->getStructureManager() ->getStructureArray() ->getBuiltStructureArray()); - if (m_UI.getIfUnitReadyToSpawn()) { + if (m_UI->getIfUnitReadyToSpawn()) { m_GameObjectManager->getAvatarManager()->AppendAvatar( - m_UI.getUnitFromUI()); + m_UI->getUnitFromUI()); } } void TutorialScene::stageStart() { - m_stage = Stages::STAGE1; - m_Text->importCamera(m_SceneCamera); - m_Text->SetDrawable( + m_stage = TutorialStages::STAGE1; + m_PlayerObjectivesText->SetDrawable( std::make_unique("../assets/sprites/Task/Task1.png")); - m_Text->setObjectScale(0.6); - m_Text->SetVisible(true); - m_Text->setMovingRelativeToCamera(true); + m_PlayerObjectivesText->SetVisible(true); + m_PlayerObjectivesText->setMovingRelativeToCamera(false); + Util::Transform trans; + trans.translation = {40, 5}; + trans.scale = {0.7, 0.7}; + m_PlayerObjectivesText->SetTransform(trans); m_cellProp->SetDrawable( std::make_unique("../assets/sprites/Task/Task_Cell.png")); @@ -88,102 +83,114 @@ void TutorialScene::stageUpdate() { stageStart(); } switch (m_stage) { - case Stages::STAGE1: { - m_Text->Draw(); - m_cellProp->Update(); - for (auto i : - m_GameObjectManager->getAvatarManager()->getAvatarArray()) { - if (i->getHouseType() == HouseType::MY) { - if (m_cellProp->isOverlaps(i->getMoving()->getCurrentCell()) || - Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY)) { - // change next stage's text&prop here - m_Text->SetDrawable(std::make_unique( + case TutorialStages::STAGE1: { + stage1Update(); + } + case TutorialStages::STAGE2: { + stage2Update(); + break; + } + case TutorialStages::STAGE3: { + stage3Update(); + break; + } + case TutorialStages::STAGE4: { + stage4Update(); + break; + } + } +} + +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 = Stages::STAGE2; - } + 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; } } - break; } - case Stages::STAGE2: { - m_Text->Draw(); - m_cellProp->Update(); - int structCount = 0; - for (auto i : *(m_GameObjectManager->getStructureManager() - ->getStructureArray() - ->getBuiltStructureArray())) { - if (i->getHouseType() == HouseType::MY) { - structCount++; - } - } - if (structCount >= 3 || - Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY)) { - // change next stage's text&prop here - m_Text->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 = Stages::STAGE3; +void TutorialScene::stage2Update() { + m_PlayerObjectivesText->Draw(); + m_cellProp->Update(); + int structCount = 0; + for (auto i : (m_GameObjectManager->getStructureManager() + ->getStructureArray() + ->getBuiltStructureArray())) { + if (i->getHouseType() == HouseType::MY) { + structCount++; } - break; } - case Stages::STAGE3: { - m_Text->Draw(); - m_cellProp->Update(); - int avatarCount = 0; - for (auto i : - m_GameObjectManager->getAvatarManager()->getAvatarArray()) { - if (i->getHouseType() == HouseType::MY) { - if (m_cellProp->isOverlaps(i->getMoving()->getCurrentCell())) { - avatarCount++; - } - } - } - if (avatarCount >= 4 || - Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY)) { - // change next stage's text&prop here - m_Text->SetDrawable(std::make_unique( - "../assets/sprites/Task/Task4.png")); + if (structCount >= 3 || + Util::Input::IsKeyPressed(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_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 = Stages::STAGE4; - } - break; + 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; } - case Stages::STAGE4: { - m_Text->Draw(); - m_cellProp->Update(); - int enemy_count = 0; - for (auto i : - m_EnemyObjectManager->getAvatarManager()->getAvatarArray()) { - if (*i->getHealth()->getLivingStatus() == LivingStatus::DEAD) { - enemy_count++; +} +void TutorialScene::stage3Update() { + m_PlayerObjectivesText->Draw(); + m_cellProp->Update(); + int avatarCount = 0; + for (auto i : m_GameObjectManager->getAvatarManager()->getAvatarArray()) { + if (i->getHouseType() == HouseType::MY) { + if (m_cellProp->ifOverlaps(i->getMoving()->getCurrentCell())) { + avatarCount++; } } - if (enemy_count >= 3) { - // End? + } + if (avatarCount >= 4 || + Util::Input::IsKeyPressed(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; + } +} +void TutorialScene::stage4Update() { + m_PlayerObjectivesText->Draw(); + m_cellProp->Update(); + int enemy_count = 0; + for (auto i : m_EnemyObjectManager->getAvatarManager()->getAvatarArray()) { + if (*i->getHealth()->getLivingStatus() == LivingStatus::DEAD) { + enemy_count++; } - break; } + if (enemy_count >= 3) { + // End? } } diff --git a/src/UI/UI.cpp b/src/UI/UI.cpp index e9b837d6..294f8623 100644 --- a/src/UI/UI.cpp +++ b/src/UI/UI.cpp @@ -450,6 +450,7 @@ void UIClass::checkExistBuilding( } std::shared_ptr UIClass::getUnitFromUI() { + // what the fuck??? printf("(UI)return to GOM\n"); auto Avatar = m_UIScriptProcess->spawnAvatar(); m_UIScriptProcess->setIfReadytoSpawn(false); diff --git a/src/UI/UIScriptProcess.cpp b/src/UI/UIScriptProcess.cpp index ca33469d..26088564 100644 --- a/src/UI/UIScriptProcess.cpp +++ b/src/UI/UIScriptProcess.cpp @@ -206,8 +206,6 @@ void UIScriptProcess::SetIfFinished(UnitType type, bool value) { b_ADVPowerPlant = value; break; default: - // Handle the case when type doesn't match any of the options - // For example, you might throw an exception or set a default value break; } }