diff --git a/include/AI/AIGroupCommander.hpp b/include/AI/AIGroupCommander.hpp new file mode 100644 index 00000000..149667a9 --- /dev/null +++ b/include/AI/AIGroupCommander.hpp @@ -0,0 +1,10 @@ +// +// Created by 盧威任 on 5/21/24. +// + +#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_AIGROUPCOMMANDER_HPP +#define PRACTICALTOOLSFORSIMPLEDESIGN_AIGROUPCOMMANDER_HPP + +class AIGroupCommander {}; + +#endif // PRACTICALTOOLSFORSIMPLEDESIGN_AIGROUPCOMMANDER_HPP diff --git a/include/Enemy/Enemy.hpp b/include/AI/Enemy.hpp similarity index 100% rename from include/Enemy/Enemy.hpp rename to include/AI/Enemy.hpp diff --git a/include/Enemy/EnemyScripts.hpp b/include/AI/EnemyScripts.hpp similarity index 100% rename from include/Enemy/EnemyScripts.hpp rename to include/AI/EnemyScripts.hpp diff --git a/include/Mechanics/AvatarManager.hpp b/include/Mechanics/AvatarManager.hpp index 518a7fbf..dd3cd4a9 100644 --- a/include/Mechanics/AvatarManager.hpp +++ b/include/Mechanics/AvatarManager.hpp @@ -29,18 +29,20 @@ class AvatarManager { std::vector> getAvatarArray() { return m_AvatarArray; } - void forceMove(std::shared_ptr unit, glm::vec2 cell); -protected: - void giveOrderToMyAvatar(std::shared_ptr unit); + void assignMoveOrderToAvatar(std::shared_ptr unit, + glm::vec2 destcell); - void updateTileWhileAvatarMoving(std::shared_ptr unit); + void assignAttackOrderToAvatar(std::shared_ptr unit, + glm::vec2 destcell); protected: - std::vector> m_AvatarArray; - std::unordered_map, glm::vec2> unitArrayAndLocation; + void assignOrderToMyAvatar(std::shared_ptr unit); + void updateTileWhileAvatarMoving(std::shared_ptr unit); private: + std::vector> m_AvatarArray; + std::unordered_map, glm::vec2> unitArrayAndLocation; std::shared_ptr m_NemesisManager = std::make_shared(); std::shared_ptr m_Navigator = diff --git a/include/Scene/TutorialScene.hpp b/include/Scene/TutorialScene.hpp index 801b0a76..99de2bf7 100644 --- a/include/Scene/TutorialScene.hpp +++ b/include/Scene/TutorialScene.hpp @@ -4,8 +4,8 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_TUTORIALSCENE_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_TUTORIALSCENE_HPP +#include "AI/EnemyScripts.hpp" #include "Cursor.hpp" -#include "Enemy/EnemyScripts.hpp" #include "Scene.hpp" // #include "Mechanics/GameObjectID.hpp" #include "Task.hpp" @@ -14,21 +14,24 @@ #define DEBUG_KEY P -enum class Stages{STAGE1,STAGE2,STAGE3,STAGE4}; -class TutorialScene : public Scene{ +enum class Stages { STAGE1, STAGE2, STAGE3, STAGE4 }; +class TutorialScene : public Scene { public: TutorialScene(){}; ~TutorialScene(){}; - void Start()override; - void Update()override; + void Start() override; + void Update() override; void stageStart(); void stageUpdate(); + private: SpriteSheet m_SpriteSheet; std::shared_ptr m_Cursor = std::make_shared(); Grid testGrid; - std::shared_ptr m_Enemy = std::make_shared(SceneMode::TUTORIAL); - std::shared_ptr m_EnemyScripts = std::make_shared(); + std::shared_ptr m_Enemy = + 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_cellProp = std::make_shared(); Stages m_stage; diff --git a/src/Enemy/Enemy.cpp b/src/Enemy/Enemy.cpp index 0d9b1227..dea69fb7 100644 --- a/src/Enemy/Enemy.cpp +++ b/src/Enemy/Enemy.cpp @@ -1,11 +1,7 @@ // // Created by nudle on 2024/4/28. // -#include "Enemy/Enemy.hpp" +#include "AI/Enemy.hpp" -void EnemyPlayer::Start(){ - -} -void EnemyPlayer::Update(){ - -} +void EnemyPlayer::Start() {} +void EnemyPlayer::Update() {} diff --git a/src/Mechanics/AvatarManager.cpp b/src/Mechanics/AvatarManager.cpp index cd1ec372..b22e2890 100644 --- a/src/Mechanics/AvatarManager.cpp +++ b/src/Mechanics/AvatarManager.cpp @@ -27,60 +27,47 @@ void AvatarManager::Update() { // give order to avatar if (m_AvatarArray[i]->getSelected()) { - giveOrderToMyAvatar(m_AvatarArray[i]); + assignOrderToMyAvatar(m_AvatarArray[i]); } } } } -void AvatarManager::giveOrderToMyAvatar(std::shared_ptr unit) { - if (unit->getID().getHouseType() == HouseType::MY) { +void AvatarManager::assignMoveOrderToAvatar(std::shared_ptr avatar, + glm::vec2 destcell) { + auto queue = + m_Navigator->findPath(avatar->getMoving()->getCurrentCell(), destcell); + avatar->getMoving()->setMovePath(queue); + avatar->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE); +} + +void AvatarManager::assignAttackOrderToAvatar(std::shared_ptr avatar, + glm::vec2 destcell) { + m_NemesisManager->removeNemesis(avatar); + if (m_Map->getTileByCellPosition(destcell)->ifEnemyAtTile()) { + if (m_Map->getTileByCellPosition(destcell)->ifStructureExists()) { + m_NemesisManager->addNemesis( + avatar, m_Map->getTileByCellPosition(destcell)->getStructure()); + } else { + m_NemesisManager->addNemesis( + avatar, + m_Map->getTileByCellPosition(destcell)->getAvatars()[0]); + } + } +} + +void AvatarManager::assignOrderToMyAvatar(std::shared_ptr avatar) { + if (avatar->getID().getHouseType() == HouseType::MY) { if (Util::Input::IsKeyDown(Util::Keycode::MOUSE_RB)) { - auto dest = Util::Input::GetCursorPosition(); - auto queue = - m_Navigator->findPath(unit->getMoving()->getCurrentCell(), - MapUtil::GlobalCoordToCellCoord( - MapUtil::ScreenToGlobalCoord(dest))); - // unit - unit->getMoving()->setMovePath(queue); - if (m_Map - ->getTileByCellPosition(MapUtil::GlobalCoordToCellCoord( - MapUtil::ScreenToGlobalCoord(dest))) - ->ifEnemyAtTile()) { - unit->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE); - if (m_Map - ->getTileByCellPosition(MapUtil::GlobalCoordToCellCoord( - MapUtil::ScreenToGlobalCoord(dest))) - ->ifStructureExists()) { - m_NemesisManager->addNemesis( - unit, m_Map - ->getTileByCellPosition( - MapUtil::GlobalCoordToCellCoord( - MapUtil::ScreenToGlobalCoord(dest))) - ->getStructure()); - } else { - m_NemesisManager->addNemesis( - unit, m_Map - ->getTileByCellPosition( - MapUtil::GlobalCoordToCellCoord( - MapUtil::ScreenToGlobalCoord(dest))) - ->getAvatars()[0]); - } + auto destcell = MapUtil::GlobalCoordToCellCoord( + MapUtil::ScreenToGlobalCoord(Util::Input::GetCursorPosition())); - } else { - m_NemesisManager->removeNemesis(unit); - unit->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE); - } + assignMoveOrderToAvatar(avatar, destcell); + assignAttackOrderToAvatar(avatar, destcell); } } } -void AvatarManager::forceMove(std::shared_ptr unit, glm::vec2 cell) { - unit->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE); - auto queue = - m_Navigator->findPath(unit->getMoving()->getCurrentCell(), cell); - unit->getMoving()->setMovePath(queue); -} void AvatarManager::updateTileWhileAvatarMoving( std::shared_ptr avatar) {