From a97d8414cbe606cc9ca8ba0685c50a532fa923bb Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Fri, 17 May 2024 01:45:57 +0800 Subject: [PATCH 1/7] combat init --- src/Scene/TutorialScene.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Scene/TutorialScene.cpp b/src/Scene/TutorialScene.cpp index 90ed8c98..1f7ebe72 100644 --- a/src/Scene/TutorialScene.cpp +++ b/src/Scene/TutorialScene.cpp @@ -8,6 +8,7 @@ void TutorialScene::Start() { LOG_TRACE("Start"); m_Map->Init(100, 100); m_GameObjectManager->Start(m_Map); + m_EnemyObjectManager->Start(m_Map); m_UI.Start(m_Map, m_GameObjectManager); m_Player->setTotalCurrency(5000); m_Enemy->setTotalCurrency(5000); From f4d2a4c1dd7d93c29aca2ce37bb17ed82a72c9f7 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Fri, 17 May 2024 11:05:29 +0800 Subject: [PATCH 2/7] composition avatar and combat --- assets/sprites/.DS_Store | Bin 8196 -> 8196 bytes assets/sprites/mech.png | Bin 22644 -> 0 bytes assets/sprites/mech_dead.png | Bin 0 -> 922 bytes assets/sprites/mech_open_fire.png | Bin 0 -> 536 bytes assets/sprites/mech_taken_damage.png | Bin 0 -> 862 bytes include/Avatar/Avatar.hpp | 20 ++++---- include/Avatar/Infantry.hpp | 6 +-- include/Avatar/Moving.hpp | 37 +++++++++++---- include/Avatar/Weapon.hpp | 10 +++- include/Mechanics/AvatarManager.hpp | 5 +- include/Mechanics/NemesisManager.hpp | 6 ++- include/Mechanics/UnitManager.hpp | 7 --- src/Avatar/Avatar.cpp | 66 ++++++++++++--------------- src/Avatar/Hunter.cpp | 11 ++--- src/Avatar/Runner.cpp | 22 ++++----- src/Mechanics/AvatarManager.cpp | 65 +++++++++++++++----------- src/Scene/TutorialScene.cpp | 7 ++- src/UI/UI.cpp | 2 +- 18 files changed, 148 insertions(+), 116 deletions(-) delete mode 100644 assets/sprites/mech.png create mode 100644 assets/sprites/mech_dead.png create mode 100644 assets/sprites/mech_open_fire.png create mode 100644 assets/sprites/mech_taken_damage.png diff --git a/assets/sprites/.DS_Store b/assets/sprites/.DS_Store index ea923d7749fe6f98a29e5ea54d5573c9772c2893..4cd0e8432987666a06e73fc8cbcd5e1da26f6155 100644 GIT binary patch delta 44 zcmZp1XmOa}&nUAoU^hRb%wz)rkXDY8Ipl89|-dpj3)aDiP{76SthLlBBGV+K8jEQSJxbkCgp}GU|v0FcuJn03srt90wIbRiuR~UAlAvDb8_#K}L`Op$Qok zL^>q&I!Y%%q#Ig92oVAV2qBP=Bs%DUECw+Z*m4UZf; zdq_-7>;u`!n6x*c|2m#pi!EDYR}d%lHO-#Glxa&fAT?Mq`_`y-eI42j!C!R)2r8|8ASv zssHIwDiH#M2H~sew`6dXJl-`M*AY*#Cp4w>>DNk;uU06p2Wr6G%Bg)cC6#*6Vc6QB z7+>d9(;QH~CnmOMF3CD!4<&ijP46EbLn!;7pU2`yd=Qua6mbV<^^#)6^rq3uPC6B47VAaz{FwR1yd6I5vh=TmK6i|X znPWxT4qAWGwteLczmYq5gFwj;t)cWMhGw?!_6b}bkNQBF zZk2LQ>iNFNoY3#Z{w!IB^sVL=eHNWt<}iI5wg;`guPIg8X!G0uVo`&lmPIUT2yc=u zKn{o~ew$}*IwiSWh~vHZ(tE)ZQCg?Ed`Wja)J|FF!=0uN6<#f72#8{{T}YJ24<_Pg zWJ7-a_q?@cecTZTaim+%=T2O#^jrenPTJ(?udxxa6O!{$#HEnE($gUwFWx809oG7A z+#u=n^(a-Zs+aP3-g!eix1M7L2NIcQyaBkz5?_55jk1V&}bH5m?H9<=sMs(&eC>?B)Pt zoMkU(yB!J>`^;Sry;m}SXST8GOK8zX%%R^3uyw};RYn9k(R!rvir-_XIU9xkt7lZhjnZIK(l2y%hF#7gfHCQif+!7}`O< zI!Oq%1%8BY#Mae7jS#wScVow4X;V56DkmyPO{KrL_9xala-cbFwIOY4BL03oe8SkH z`3buvyiTr89ABNlP3+N{i%Y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`oi4G+EH$4t5F-1-*u0Y?Ig@UXb!#dp_%6B8dMaA-f_1z@L!2 zC16blq6izT4UICF-&CjG`ZfRSfvpQ2*%AMn*xlRT&f*y3@4Wr--%tLw!2hcSsz#0T Yh@U=kdXHx%GTFd)``&Gp-iN>a4>ZV=D*ylh diff --git a/assets/sprites/mech_dead.png b/assets/sprites/mech_dead.png new file mode 100644 index 0000000000000000000000000000000000000000..fe0853cd0b150d59319877f40b5f036762eddc27 GIT binary patch literal 922 zcmeAS@N?(olHy`uVBq!ia0vp^hCnRG!3HE-)4u%&QjEnx?oJHr&dIz4aspB#JkxxA z8MJ_G4hAMhAqHlU5+Gz~&tzZ$vl$rFfHVUG^8!YM>;fjZtl+&|t5G3DA(p z%#etZ2wxwoh+i z#(Mch>H3D2mX`VkM*2oZx=P7{9O-#x! zEwNQn0$BtH5O0c3d|4@L;p!l8k%E4h-bUo-U3d5u9(QE(|*CAkg;TXsV!~ z;E9foE-n{WS5~G*2L&Yo(Gy;B3-|?3GKYXTQ#-o4fT-&Phl|TmPM7pUf2Ug}7+sbu zDp|(!rYomt=k43S-|e?`@ZsQKR8(MTX%P7Fm&IzGCf_ed(Kfrh(|1}V)<2LrZOU$a zF7we%fvNAAFEUlUyt;7PU5=A#U%J*a5L~eH6=kKy$ z>YQoc4T`kd3_s;IT13{)>2&_INl52VRjUrmaXqGbC%?62k5)&?Rj-)!#k2N7?WAqH zHw3WSoHsta+4p8*>FJP`2U-TXms6h3VQ2o6VK6ym>7vSAPcF@CUQu_^-%CA^(d~ob z%`1O5Df&oTYcBP<|MI7_Q|zkCXV&`2$GCJx{r?xiKA&;pH|w{Vv*t@4zpJsnH0;*3 z%FdE`(x<{cm;c_e>&^0K_U{F6z5aEm!Y3J5; zOFNjqOxtqn<7zXZdHTsVrI(wvHq;*FhK7{|TVweRm!?#$NGmw%5gWiFnV zKTG6H?B&@SGAinCf0uR_f2rswST;#p%Q^T>K=Xm!k;;p%bA3Cz@o>fOz->RXuevfW zZc5Ntd{|6y4L?ib_fqqaSq$%fo(ODmn4ROW=kW958DR_S>hfOA(%t%rop;-vgXver zcN+4hl)e1(I+$1XtESo2m-EkUW?U)LQ8BfFE60bAiIUbifGqQ0*g-y~F z)2%hHkM3T(^}!=yN3%yK&*X+FYzPUM^>4dN_T5#lexL5E+pkl!X`N?UM$d(_p8UEM xZ+KW2)CVgktDM{i3>FS%aOfbY1NxFbm=^hF&YYfd{Uaz=JYD@<);T3K0RUVv(f$Ac literal 0 HcmV?d00001 diff --git a/assets/sprites/mech_taken_damage.png b/assets/sprites/mech_taken_damage.png new file mode 100644 index 0000000000000000000000000000000000000000..96ffd13938ec65ac14951946bee85a3b3de51b17 GIT binary patch literal 862 zcmeAS@N?(olHy`uVBq!ia0vp^@<1%j!3HE->_hZ{6k~CayA#8@b22Z1oPg8_&op0O z1}z|)gMo=rh=CcT1PB@0GZ|RGYz783AkDzQynqoQyMPHUE5Cpl&Xxu#oPH}-187KO zW=KRygs+cPa(=E}VoH8es$NBI0Z0LZO@$SZnVVXYs8ErclUHn2VXFjIVFhG^g!Ppa zz)DK8ZIvQ?0~DO|i&7QL^bGV2l1AfjnEKjFOT9D}DX)@^Za$ zW4-*MbbUihOG|wNBYh(yU7!lx;>x^|#0uTKVr7USFmqf|i<65o3raHc^AtelCMM;V zme?vOfh>Xph&xL%(-1c06+^uR^q@XSM&D4+Kp$>4P^%3{)XKjoGZknv$b36P8?Z_g zF{nK@`XI}Z90TzwSQO}0J1!f2c(B=VNya^72L^Jur;B5V2XAtM1Zzsmfr%__|5GxW zvlE*(w+S)dysltoG(Vz#gTQKmCGY%s4*wUg<*3Yzs7Xz>kD9rB0e5+5BZNIosaR`ggp zh0W8BJ#&GYgZJ(oz1w~qK2YH7#_%S2g4Trf!F&Y_k@f}IN(#))wlHh*_|x_&{~k@*w; zEAR+8EKAJU;bg*gF_L#p|KWy*$C|Alh{y>EeY*dEFDscTgetCurrentCell().x, 2) + + pow(cell.y - m_Moving->getCurrentCell().y, 2)); } void setSpriteSheet() { @@ -70,9 +68,13 @@ class Avatar : public Moving, m_Health = health; } + void DrawAvatar(); + +public: std::shared_ptr getAttackAndDamager() { return m_AttackAndDamage; } + std::shared_ptr getMoving() { return m_Moving; } protected: std::shared_ptr m_AvatarSpriteSheet = @@ -80,6 +82,8 @@ class Avatar : public Moving, std::shared_ptr m_SpriteSheetAnimation = std::make_shared(); + // moving + std::shared_ptr m_Moving = std::make_shared(); // health std::shared_ptr m_Health = std::make_shared(); // attack and damage diff --git a/include/Avatar/Infantry.hpp b/include/Avatar/Infantry.hpp index bc84e8cb..c1b7bf7f 100644 --- a/include/Avatar/Infantry.hpp +++ b/include/Avatar/Infantry.hpp @@ -9,15 +9,15 @@ class Infantry : public Avatar { public: Infantry() : Avatar() { - setMovementSpeed(4), + getMoving()->setMovementSpeed(4), m_Health = std::make_shared( std::make_shared(LivingStatus::NOT_BORN_YET), 100, 0.5); } Infantry(HouseType house) - : Avatar(UnitType::INFANTRY,house){ + : Avatar(UnitType::INFANTRY, house) { // setHp(50); - setMovementSpeed(4); + getMoving()->setMovementSpeed(4); } private: diff --git a/include/Avatar/Moving.hpp b/include/Avatar/Moving.hpp index 8db0fd5e..2d731c68 100644 --- a/include/Avatar/Moving.hpp +++ b/include/Avatar/Moving.hpp @@ -20,7 +20,6 @@ class Moving { std::vector m_lineVector; glm::vec2 m_CurrentLocation; - glm::vec2 m_DestinationLocation; MoveDirection m_CurrentDir = MoveDirection::IDLE; @@ -37,7 +36,7 @@ class Moving { }; Moving(){}; - virtual ~Moving(){}; + ~Moving(){}; glm::vec2 getCurrentCell() { return MapUtil::GlobalCoordToCellCoord(getCurrentLocation()); @@ -47,6 +46,25 @@ class Moving { m_CurrentLocation = location; } MoveDirection getCurrentDir() { return m_CurrentDir; } + void setCurrentDir(MoveDirection dir) { m_CurrentDir = dir; } + + void moveUpdate() { + if (ifArrivedAtNextCell()) { + m_PrevCell = getCurrentCell(); + if (!m_MovePath.empty()) { + setCurrentDir(m_MovePath.front()); + m_MovePath.pop_front(); + } else { + finishedmovingUpdate(); + } + } + moveToNextCell(); + } + + void finishedmovingUpdate() { + moveToCellCorner(AvatarStandingCorner::CENTER); + setCurrentDir(MoveDirection::IDLE); + } void moveToNextCell(); void moveToCellCorner(AvatarStandingCorner corner); @@ -59,13 +77,14 @@ class Moving { m_PrevCell = getCurrentCell(); } - void setMovementSpeed(float speed) { m_MovementSpeed = speed; } - - glm::vec2 getDestinationCell() { - return MapUtil::CellCoordToGlobal(m_DestinationLocation); - } - void setDestinationCell(glm::vec2 destination) { - m_DestinationLocation = MapUtil::GlobalCoordToCellCoord(destination); + bool ifMovePathEmpty() { + if (m_MovePath.empty()) { + return true; + } else { + return false; + } } + + void setMovementSpeed(float speed) { m_MovementSpeed = speed; } }; #endif // PRACTICALTOOLSFORSIMPLEDESIGN_MOVING_HPP diff --git a/include/Avatar/Weapon.hpp b/include/Avatar/Weapon.hpp index c4081c4a..5c66f555 100644 --- a/include/Avatar/Weapon.hpp +++ b/include/Avatar/Weapon.hpp @@ -14,12 +14,18 @@ enum class WeaponType { Art_105mm, Art_120mm, Nuke, - Grenade + Grenade, + NONE }; class Weapon { public: - Weapon() {} + Weapon() + : m_FireRange(1), + m_SoftAttack(10), + m_HardAttack(10), + m_FireRateInMs(10), + m_Type(WeaponType::NONE) {} Weapon(float firerate, float firerange, float softattack, float hardattack, WeaponType weapontype) : m_FireRange(firerange), diff --git a/include/Mechanics/AvatarManager.hpp b/include/Mechanics/AvatarManager.hpp index 7b356d93..518a7fbf 100644 --- a/include/Mechanics/AvatarManager.hpp +++ b/include/Mechanics/AvatarManager.hpp @@ -29,9 +29,10 @@ class AvatarManager { std::vector> getAvatarArray() { return m_AvatarArray; } - void forceMove(std::shared_ptr unit,glm::vec2 cell); + void forceMove(std::shared_ptr unit, glm::vec2 cell); + protected: - void giveOrderToAvatar(std::shared_ptr unit); + void giveOrderToMyAvatar(std::shared_ptr unit); void updateTileWhileAvatarMoving(std::shared_ptr unit); diff --git a/include/Mechanics/NemesisManager.hpp b/include/Mechanics/NemesisManager.hpp index e554bcde..a6e3fab9 100644 --- a/include/Mechanics/NemesisManager.hpp +++ b/include/Mechanics/NemesisManager.hpp @@ -33,8 +33,10 @@ class NemesisManager { if (ifAvatarHasNemesis(hunter) == false) { return false; } - if (hunter->getDistance(m_Nemesis[hunter]->getCurrentCell()) <= - hunter->getWeapon()->getFireRange()) // check with in range + if (hunter->getDistance( + m_Nemesis[hunter]->getMoving()->getCurrentCell()) <= + hunter->getWeapon()->getFireRange() * + CELL_SIZE.x) // check with in range { return true; } else { diff --git a/include/Mechanics/UnitManager.hpp b/include/Mechanics/UnitManager.hpp index 2007280a..b945048f 100644 --- a/include/Mechanics/UnitManager.hpp +++ b/include/Mechanics/UnitManager.hpp @@ -91,8 +91,6 @@ class UnitManager : public Player { return; } - - avatar->Start(m_StructureManager->getStructureArray() ->getPlayerBarrackCell()); // avatar @@ -109,11 +107,6 @@ class UnitManager : public Player { void spawn(std::shared_ptr m_Map, UnitType unit, HouseType house, glm::vec2 cellPos) { // 缺檢查敵方擁有建築的位置,並重生在該處 - if (house == HouseType::ENEMY) { - // m_Enemy->addUnitConstructCount(unit, 1); - } else { - // m_Player->setUnitConstructCount(unit, 1); - } switch (unit) { case UnitType::BARRACKS: { auto structure = std::make_shared(house); diff --git a/src/Avatar/Avatar.cpp b/src/Avatar/Avatar.cpp index 30ea5564..ab73d129 100644 --- a/src/Avatar/Avatar.cpp +++ b/src/Avatar/Avatar.cpp @@ -9,7 +9,12 @@ void Avatar::whenSelected() { } void Avatar::Update() { + + if (getMoving()->ifMovePathEmpty()) { + m_AvatarOrder = AvatarOrderType::NO_ORDER; + } switch (*m_Health->getLivingStatus()) { + DrawAvatar(); case (LivingStatus::DEAD): SetVisible(false); break; @@ -18,12 +23,14 @@ void Avatar::Update() { whenSelected(); if (m_AvatarOrder == AvatarOrderType::OPEN_FIRE) { - + // open fire } else if (m_AvatarOrder == AvatarOrderType::MOVE) { - moveUpdate(); + m_Moving->moveUpdate(); } else if (m_AvatarOrder == AvatarOrderType::NO_ORDER) { - noOrderUpdate(); + noorderUpdate(); } else if (m_AvatarOrder == AvatarOrderType::TAKEN_DAMAGE) { + + // takendamage } else if (m_AvatarOrder == AvatarOrderType::SPAWNED) { spawnedUpdate(); } @@ -32,39 +39,15 @@ void Avatar::Update() { } } -void Avatar::noOrderUpdate() { - m_CurrentDir = MoveDirection::IDLE; +void Avatar::noorderUpdate() { + getMoving()->setCurrentDir(MoveDirection::IDLE); SetVisible(true); - m_Transform.translation = getCurrentLocation(); - - Draw(); + m_Transform.translation = getMoving()->getCurrentLocation(); } void Avatar::spawnedUpdate() { SetVisible(true); - m_Transform.translation = getCurrentLocation(); - - Draw(); -} -void Avatar::moveUpdate() { - - if (ifArrivedAtNextCell()) { - m_PrevCell = getCurrentCell(); - if (!m_MovePath.empty()) { - m_CurrentDir = m_MovePath.front(); - m_MovePath.pop_front(); - } else { - finishedmovingUpdate(); - m_CurrentDir = MoveDirection::IDLE; - m_AvatarOrder = AvatarOrderType::NO_ORDER; - } - } - moveToNextCell(); - - SetVisible(true); - m_Transform.translation = getCurrentLocation(); - - Draw(); + m_Transform.translation = getMoving()->getCurrentLocation(); } void Avatar::Start(glm::vec2 spawnlocationcell) { // destination = Barrack's @@ -73,9 +56,10 @@ void Avatar::Start(glm::vec2 spawnlocationcell) { // destination = Barrack's this->SetDrawable(customizeImage()); // setSpriteSheet(); SetVisible(true); - setMovementSpeed(4); + getMoving()->setMovementSpeed(4); m_AvatarOrder = AvatarOrderType::SPAWNED; - m_CurrentLocation = MapUtil::CellCoordToGlobal(spawnlocationcell); + getMoving()->getCurrentLocation() = + MapUtil::CellCoordToGlobal(spawnlocationcell); m_Transform.scale = {1, 1}; getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); @@ -124,9 +108,17 @@ void Avatar::DEBUG_printCurrentMoveDirection(MoveDirection Dir) { } } -void Avatar::finishedmovingUpdate() { - Moving::moveToCellCorner(AvatarStandingCorner::CENTER); - m_Transform.translation = getCurrentLocation(); - +void Avatar::DrawAvatar() { + m_Transform.translation = getMoving()->getCurrentLocation(); + if (m_AvatarOrder == AvatarOrderType::OPEN_FIRE) { + this->SetDrawable(std::make_shared( + "../assets/sprites/mech_open_fire.png")); + } else if (m_AvatarOrder == AvatarOrderType::TAKEN_DAMAGE) { + this->SetDrawable(std::make_shared( + "../assets/sprites/mech_taken_damage.png")); + } else { + this->SetDrawable( + std::make_shared("../assets/sprites/mech_single.png")); + } Draw(); } diff --git a/src/Avatar/Hunter.cpp b/src/Avatar/Hunter.cpp index bdc4af69..338bc324 100644 --- a/src/Avatar/Hunter.cpp +++ b/src/Avatar/Hunter.cpp @@ -5,17 +5,16 @@ #include "Avatar/Hunter.hpp" void Hunter::customizeUpdate() { - glm::vec2 targetCell = m_target->getCurrentCell(); + glm::vec2 targetCell = m_target->getMoving()->getCurrentCell(); if (getDistance(targetCell) > ATTACK_RANGE - 1 && - lastTargetCell != m_target->getCurrentCell()) { + lastTargetCell != m_target->getMoving()->getCurrentCell()) { // glm::vec2 nextCell = // getNextCellByCurrent(getDirByRelativeCells(getCurrentCell(),targetCell),getCurrentCell()); - setDestinationCell(m_target->getCurrentCell()); - lastTargetCell = m_target->getCurrentCell(); + + lastTargetCell = m_target->getMoving()->getCurrentCell(); // setNewDestination(nextCell); } else if (getDistance(targetCell) < ATTACK_RANGE - 1) { - setDestinationCell(getCurrentCell()); - lastTargetCell = getCurrentCell(); + lastTargetCell = getMoving()->getCurrentCell(); attack(m_target); } } diff --git a/src/Avatar/Runner.cpp b/src/Avatar/Runner.cpp index 3fd11c99..b2edb930 100644 --- a/src/Avatar/Runner.cpp +++ b/src/Avatar/Runner.cpp @@ -6,30 +6,30 @@ void Runner::setBeingChase(std::shared_ptr hunter) { b_beingChase = true; m_hunter = hunter; - lastTargetCell = getCurrentCell(); + lastTargetCell = m_Moving->getCurrentCell(); } void Runner::customizeUpdate() { if (b_beingChase && *m_hunter->getHealth()->getLivingStatus() == LivingStatus::ALIVE) { - glm::vec2 hunterCell = m_hunter->getCurrentCell(); + glm::vec2 hunterCell = m_hunter->getMoving()->getCurrentCell(); if (getDistance(hunterCell) <= ATTACK_RANGE - 1 && - lastTargetCell == getCurrentCell()) { + lastTargetCell == getMoving()->getCurrentCell()) { edgeCount = 0; - MoveDirection Dir = oppositeDir(PathUtility::getDirByRelativeCells( - getCurrentCell(), hunterCell), - runMode::LIDL_RANDOM); + MoveDirection Dir = + oppositeDir(PathUtility::getDirByRelativeCells( + getMoving()->getCurrentCell(), hunterCell), + runMode::LIDL_RANDOM); DEBUG_printCurrentMoveDirection(Dir); - glm::vec2 nextCell = - getNextCellByCurrentPlus3(Dir, getCurrentCell(), 3, 1); + glm::vec2 nextCell = getNextCellByCurrentPlus3( + Dir, getMoving()->getCurrentCell(), 3, 1); while (nextCell.x < 0 || nextCell.y < 0) { edgeCount += rand() % 2 + 1; Dir = findNewDir(Dir, edgeCount); DEBUG_printCurrentMoveDirection(Dir); - nextCell = - getNextCellByCurrentPlus3(Dir, getCurrentCell(), 1, 3); + nextCell = getNextCellByCurrentPlus3( + Dir, getMoving()->getCurrentCell(), 1, 3); } lastTargetCell = nextCell; - setDestinationCell(nextCell); } } else { b_beingChase = false; diff --git a/src/Mechanics/AvatarManager.cpp b/src/Mechanics/AvatarManager.cpp index a1cf3cdf..54cade30 100644 --- a/src/Mechanics/AvatarManager.cpp +++ b/src/Mechanics/AvatarManager.cpp @@ -5,54 +5,67 @@ #include "Mechanics/AvatarManager.hpp" void AvatarManager::Update() { + m_NemesisManager->Update(); for (auto unit : m_AvatarArray) { unit->Update(); if (unit->getAvatarOrder() == AvatarOrderType::MOVE) { updateTileWhileAvatarMoving(unit); } if (unit->getSelected()) { - giveOrderToAvatar(unit); + giveOrderToMyAvatar(unit); } } } -void AvatarManager::giveOrderToAvatar(std::shared_ptr unit) { - if (Util::Input::IsKeyDown(Util::Keycode::MOUSE_RB)) { - auto dest = Util::Input::GetCursorPosition(); - auto queue = m_Navigator->findPath( - unit->getCurrentCell(), MapUtil::GlobalCoordToCellCoord( - MapUtil::ScreenToGlobalCoord(dest))); - // unit - unit->setMovePath(queue); +void AvatarManager::giveOrderToMyAvatar(std::shared_ptr unit) { + if (unit->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(unit->getDestinationCell()) - ->ifEnemyAtTile()) { - m_NemesisManager->addNemesis( - unit, m_Map->getTileByCellPosition(unit->getDestinationCell()) - ->getAvatars()[0]); - } else { - unit->setAvatarOrder(AvatarOrderType::MOVE); + if (m_Map + ->getTileByCellPosition(MapUtil::GlobalCoordToCellCoord( + MapUtil::ScreenToGlobalCoord(dest))) + ->ifEnemyAtTile()) { + unit->setAvatarOrder(AvatarOrderType::MOVE); + m_NemesisManager->addNemesis( + unit, + m_Map + ->getTileByCellPosition(MapUtil::GlobalCoordToCellCoord( + MapUtil::ScreenToGlobalCoord(dest))) + ->getAvatars()[0]); + } else { + unit->setAvatarOrder(AvatarOrderType::MOVE); + } } } } -void AvatarManager::forceMove(std::shared_ptr unit,glm::vec2 cell){ - unit->setAvatarOrder(AvatarOrderType::MOVE); - auto queue = m_Navigator->findPath(unit->getCurrentCell(), cell); - unit->setMovePath(queue); - } +void AvatarManager::forceMove(std::shared_ptr unit, glm::vec2 cell) { + unit->setAvatarOrder(AvatarOrderType::MOVE); + auto queue = + m_Navigator->findPath(unit->getMoving()->getCurrentCell(), cell); + unit->getMoving()->setMovePath(queue); +} void AvatarManager::updateTileWhileAvatarMoving( std::shared_ptr avatar) { - if (avatar->ifArrivedAtNextCell()) { + if (avatar->getMoving()->ifArrivedAtNextCell()) { m_Map->removeAvatarsByCellPosition(avatar, unitArrayAndLocation[avatar]); - m_Map->setAvatarByCellPosition(avatar, avatar->getCurrentCell()); - unitArrayAndLocation[avatar] = avatar->getCurrentCell(); + m_Map->setAvatarByCellPosition(avatar, + avatar->getMoving()->getCurrentCell()); + unitArrayAndLocation[avatar] = avatar->getMoving()->getCurrentCell(); } } void AvatarManager::AppendAvatar(std::shared_ptr newAvatar) { m_AvatarArray.push_back(newAvatar); - unitArrayAndLocation[newAvatar] = newAvatar->getCurrentCell(); - m_Map->setAvatarByCellPosition(newAvatar, newAvatar->getCurrentCell()); + unitArrayAndLocation[newAvatar] = newAvatar->getMoving()->getCurrentCell(); + m_Map->setAvatarByCellPosition(newAvatar, + newAvatar->getMoving()->getCurrentCell()); } diff --git a/src/Scene/TutorialScene.cpp b/src/Scene/TutorialScene.cpp index 1f7ebe72..a8b55df6 100644 --- a/src/Scene/TutorialScene.cpp +++ b/src/Scene/TutorialScene.cpp @@ -26,6 +26,9 @@ void TutorialScene::Start() { */ m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY, {5, 5}); + // combat test + m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY, + {6, 6}); stageStart(); } @@ -89,7 +92,7 @@ void TutorialScene::stageUpdate() { for (auto i : m_GameObjectManager->getAvatarManager()->getAvatarArray()) { if (i->getHouseType() == HouseType::MY) { - if (m_cellProp->isOverlaps(i->getCurrentCell()) || + 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( @@ -139,7 +142,7 @@ void TutorialScene::stageUpdate() { for (auto i : m_GameObjectManager->getAvatarManager()->getAvatarArray()) { if (i->getHouseType() == HouseType::MY) { - if (m_cellProp->isOverlaps(i->getCurrentCell())) { + if (m_cellProp->isOverlaps(i->getMoving()->getCurrentCell())) { avatarCount++; } } diff --git a/src/UI/UI.cpp b/src/UI/UI.cpp index beb9538d..59654d8f 100644 --- a/src/UI/UI.cpp +++ b/src/UI/UI.cpp @@ -442,7 +442,7 @@ std::shared_ptr UIClass::getUnitFromUI() { Avatar->Start({m_barrackCell.x + 1, m_barrackCell.y - 1}); - Avatar->setDestinationCell(m_barrackTargetCell); + // Avatar->setDestinationCell(m_barrackTargetCell); } printf("(UI)return to GOM success\n"); return Avatar; From f795f9b78fe838bc9167b27496283f539d524065 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Fri, 17 May 2024 11:49:25 +0800 Subject: [PATCH 3/7] open fire and dead --- include/Avatar/AttackAndDamage.hpp | 8 +++---- include/Avatar/Weapon.hpp | 2 +- include/Mechanics/NemesisManager.hpp | 6 ++---- src/Avatar/Avatar.cpp | 31 +++++++++++++++++----------- 4 files changed, 26 insertions(+), 21 deletions(-) diff --git a/include/Avatar/AttackAndDamage.hpp b/include/Avatar/AttackAndDamage.hpp index cfb9dd9e..f98daba6 100644 --- a/include/Avatar/AttackAndDamage.hpp +++ b/include/Avatar/AttackAndDamage.hpp @@ -16,10 +16,10 @@ class AttackAndDamage { void damageTargetWithWeapon(std::shared_ptr target, std::shared_ptr weapon) { auto targethealth = target->getHealth(); - targethealth->addHP(-1 * (100 - targethealth->getArmorRate()) * - (1 / 100) * m_Weapon->getSoftAttack() + - targethealth->getArmorRate() * (1 / 100) * - m_Weapon->getHardAttack()); + auto damage = + ((1 - targethealth->getArmorRate()) * m_Weapon->getSoftAttack()) + + (targethealth->getArmorRate() * m_Weapon->getHardAttack()); + targethealth->addHP(-1 * damage); } void openFireToTarget(std::shared_ptr target) { diff --git a/include/Avatar/Weapon.hpp b/include/Avatar/Weapon.hpp index 5c66f555..36b32bab 100644 --- a/include/Avatar/Weapon.hpp +++ b/include/Avatar/Weapon.hpp @@ -24,7 +24,7 @@ class Weapon { : m_FireRange(1), m_SoftAttack(10), m_HardAttack(10), - m_FireRateInMs(10), + m_FireRateInMs(180), m_Type(WeaponType::NONE) {} Weapon(float firerate, float firerange, float softattack, float hardattack, WeaponType weapontype) diff --git a/include/Mechanics/NemesisManager.hpp b/include/Mechanics/NemesisManager.hpp index a6e3fab9..5e893f8a 100644 --- a/include/Mechanics/NemesisManager.hpp +++ b/include/Mechanics/NemesisManager.hpp @@ -53,10 +53,6 @@ class NemesisManager { hunter->setAvatarOrder(AvatarOrderType::OPEN_FIRE); prey->setAvatarOrder(AvatarOrderType::TAKEN_DAMAGE); hunter->getAttackAndDamager()->openFireToTarget(prey); - // 反擊 - prey->setAvatarOrder(AvatarOrderType::OPEN_FIRE); - hunter->setAvatarOrder(AvatarOrderType::TAKEN_DAMAGE); - prey->getAttackAndDamager()->openFireToTarget(prey); } if (*pair.second->getHealth()->getLivingStatus() == @@ -64,6 +60,7 @@ class NemesisManager { removeNemesis(hunter); hunter->setAvatarOrder(AvatarOrderType::NO_ORDER); prey->setAvatarOrder(AvatarOrderType::NO_ORDER); + break; } if (*pair.first->getHealth()->getLivingStatus() == @@ -71,6 +68,7 @@ class NemesisManager { removeNemesis(hunter); hunter->setAvatarOrder(AvatarOrderType::NO_ORDER); prey->setAvatarOrder(AvatarOrderType::NO_ORDER); + break; } } } diff --git a/src/Avatar/Avatar.cpp b/src/Avatar/Avatar.cpp index ab73d129..fa931b44 100644 --- a/src/Avatar/Avatar.cpp +++ b/src/Avatar/Avatar.cpp @@ -9,12 +9,12 @@ void Avatar::whenSelected() { } void Avatar::Update() { - + DrawAvatar(); if (getMoving()->ifMovePathEmpty()) { m_AvatarOrder = AvatarOrderType::NO_ORDER; } switch (*m_Health->getLivingStatus()) { - DrawAvatar(); + case (LivingStatus::DEAD): SetVisible(false); break; @@ -58,8 +58,8 @@ void Avatar::Start(glm::vec2 spawnlocationcell) { // destination = Barrack's SetVisible(true); getMoving()->setMovementSpeed(4); m_AvatarOrder = AvatarOrderType::SPAWNED; - getMoving()->getCurrentLocation() = - MapUtil::CellCoordToGlobal(spawnlocationcell); + getMoving()->setCurrentLocation( + MapUtil::CellCoordToGlobal(spawnlocationcell)); m_Transform.scale = {1, 1}; getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); @@ -110,15 +110,22 @@ void Avatar::DEBUG_printCurrentMoveDirection(MoveDirection Dir) { void Avatar::DrawAvatar() { m_Transform.translation = getMoving()->getCurrentLocation(); - if (m_AvatarOrder == AvatarOrderType::OPEN_FIRE) { - this->SetDrawable(std::make_shared( - "../assets/sprites/mech_open_fire.png")); - } else if (m_AvatarOrder == AvatarOrderType::TAKEN_DAMAGE) { - this->SetDrawable(std::make_shared( - "../assets/sprites/mech_taken_damage.png")); - } else { + SetVisible(true); + if (getHealth()->getHP() < 50) { this->SetDrawable( - std::make_shared("../assets/sprites/mech_single.png")); + std::make_shared("../assets/sprites/mech_dead.png")); + } else { + + if (m_AvatarOrder == AvatarOrderType::OPEN_FIRE) { + this->SetDrawable(std::make_shared( + "../assets/sprites/mech_open_fire.png")); + } else if (m_AvatarOrder == AvatarOrderType::TAKEN_DAMAGE) { + this->SetDrawable(std::make_shared( + "../assets/sprites/mech_taken_damage.png")); + } else { + this->SetDrawable(std::make_shared( + "../assets/sprites/mech_single.png")); + } } Draw(); } From cd6b3d07c33f124ee60c78c11b89e76a11e533fc Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Fri, 17 May 2024 12:16:54 +0800 Subject: [PATCH 4/7] struct and avatar comps --- include/Avatar/Avatar.hpp | 26 ++++++------ include/Mechanics/BuiltStructure.hpp | 53 ++++++++++++++----------- include/Mechanics/NemesisManager.hpp | 22 ++++++---- include/Mechanics/StructureManager.hpp | 9 +++-- include/Structure/Structure.hpp | 26 ++++++------ include/Structure/StructureOrder.hpp | 19 +++++---- include/Structure/WayPointStructure.hpp | 3 +- src/Avatar/Avatar.cpp | 25 +++++++----- src/Mechanics/AvatarManager.cpp | 8 ++-- src/Structure/Barracks.cpp | 6 +-- src/Structure/OreRefinery.cpp | 7 ++-- src/Structure/Structure.cpp | 19 +++++---- src/Structure/WarFactory.cpp | 4 +- src/Structure/WayPointStructure.cpp | 2 +- 14 files changed, 126 insertions(+), 103 deletions(-) diff --git a/include/Avatar/Avatar.hpp b/include/Avatar/Avatar.hpp index 525d6033..6c68c95c 100644 --- a/include/Avatar/Avatar.hpp +++ b/include/Avatar/Avatar.hpp @@ -15,11 +15,7 @@ #include "Selectable.hpp" #include "Util/Image.hpp" -class Avatar : public AttackAndDamage, - public AvatarOrder, - public Util::GameObject, - public Selectable, - public IHealthable { +class Avatar : public Util::GameObject, public Selectable, public IHealthable { public: Avatar(){}; @@ -59,22 +55,24 @@ class Avatar : public AttackAndDamage, "../assets/sprites/mech_single.png"); } - GameObjectID getID() { return m_ID; } - virtual void Update() override; - std::shared_ptr getHealth() override { return m_Health; } - void setHealth(std::shared_ptr health) override { - m_Health = health; - } - void DrawAvatar(); public: - std::shared_ptr getAttackAndDamager() { + GameObjectID getID() { return m_ID; } + + std::shared_ptr getAttackAndDamage() { return m_AttackAndDamage; } std::shared_ptr getMoving() { return m_Moving; } + std::shared_ptr getAvatarOrder() { return m_Order; } + + std::shared_ptr getHealth() override { return m_Health; } + + void setHealth(std::shared_ptr health) override { + m_Health = health; + } protected: std::shared_ptr m_AvatarSpriteSheet = @@ -82,6 +80,8 @@ class Avatar : public AttackAndDamage, std::shared_ptr m_SpriteSheetAnimation = std::make_shared(); + // order + std::shared_ptr m_Order = std::make_shared(); // moving std::shared_ptr m_Moving = std::make_shared(); // health diff --git a/include/Mechanics/BuiltStructure.hpp b/include/Mechanics/BuiltStructure.hpp index d6d38cf1..4d2b0a44 100644 --- a/include/Mechanics/BuiltStructure.hpp +++ b/include/Mechanics/BuiltStructure.hpp @@ -13,22 +13,23 @@ class BuiltStructure { virtual ~BuiltStructure() {} void buildNewStructure(std::shared_ptr m_Map, - std::shared_ptr newstruct,bool force=false) { + std::shared_ptr newstruct, + bool force = false) { std::vector coords = newstruct->GetAbsoluteOccupiedArea(); - if(!force){ + if (!force) { if (Util::Input::IsKeyPressed(Util::Keycode::MOUSE_LB)) { if (ifCanBuildStructureAtTile(m_Map, newstruct) == true) { m_BuiltStructure.push_back(newstruct); m_Map->builtStructureByCellPosition(newstruct, coords); - newstruct->setStructOrder( - StructureOrder::StructureOrderType::BUILT); + newstruct->getStructureOrder()->setStructOrder( + StructureOrderType::BUILT); } } - }else{ + } else { m_BuiltStructure.push_back(newstruct); m_Map->builtStructureByCellPosition(newstruct, coords); - newstruct->setStructOrder( - StructureOrder::StructureOrderType::BUILT); + newstruct->getStructureOrder()->setStructOrder( + StructureOrderType::BUILT); } } @@ -62,30 +63,34 @@ class BuiltStructure { m_BuiltStructure.push_back(structure); } - void updateAvatarSpawnLocation(std::vector> structure){ - for(auto i:structure){ - if(std::dynamic_pointer_cast(i)){ - if(i->getHouseType()==HouseType::ENEMY){ - m_EnemyBarrackCell=i->GetObjectLocation(); - m_EnemyWayPointCell=std::dynamic_pointer_cast(i)->GetWayPointLocation(); - } else{ - m_PlayerBarrackCell=i->GetObjectLocation(); - m_PlayerWayPointCell=std::dynamic_pointer_cast(i)->GetWayPointLocation(); + void updateAvatarSpawnLocation( + std::vector> structure) { + for (auto i : structure) { + if (std::dynamic_pointer_cast(i)) { + if (i->getHouseType() == HouseType::ENEMY) { + m_EnemyBarrackCell = i->GetObjectLocation(); + m_EnemyWayPointCell = std::dynamic_pointer_cast(i) + ->GetWayPointLocation(); + } else { + m_PlayerBarrackCell = i->GetObjectLocation(); + m_PlayerWayPointCell = + std::dynamic_pointer_cast(i) + ->GetWayPointLocation(); } } } } - glm::vec2 getEnemyBarrackCell(){return m_EnemyBarrackCell;} - glm::vec2 getEnemyWayPointCell(){return m_EnemyWayPointCell;} - glm::vec2 getPlayerBarrackCell(){return m_PlayerBarrackCell;} - glm::vec2 getPlayerWayPointCell(){return m_PlayerWayPointCell;} + glm::vec2 getEnemyBarrackCell() { return m_EnemyBarrackCell; } + glm::vec2 getEnemyWayPointCell() { return m_EnemyWayPointCell; } + glm::vec2 getPlayerBarrackCell() { return m_PlayerBarrackCell; } + glm::vec2 getPlayerWayPointCell() { return m_PlayerWayPointCell; } protected: std::vector> m_BuiltStructure; - glm::vec2 m_EnemyBarrackCell={-1,-1}; - glm::vec2 m_EnemyWayPointCell={-1,-1}; - glm::vec2 m_PlayerBarrackCell={-1,-1}; - glm::vec2 m_PlayerWayPointCell={-1,-1}; + glm::vec2 m_EnemyBarrackCell = {-1, -1}; + glm::vec2 m_EnemyWayPointCell = {-1, -1}; + glm::vec2 m_PlayerBarrackCell = {-1, -1}; + glm::vec2 m_PlayerWayPointCell = {-1, -1}; }; #endif // PRACTICALTOOLSFORSIMPLEDESIGN_BUILTSTRUCTURE_HPP diff --git a/include/Mechanics/NemesisManager.hpp b/include/Mechanics/NemesisManager.hpp index 5e893f8a..67cc0736 100644 --- a/include/Mechanics/NemesisManager.hpp +++ b/include/Mechanics/NemesisManager.hpp @@ -35,7 +35,7 @@ class NemesisManager { } if (hunter->getDistance( m_Nemesis[hunter]->getMoving()->getCurrentCell()) <= - hunter->getWeapon()->getFireRange() * + hunter->getAttackAndDamage()->getWeapon()->getFireRange() * CELL_SIZE.x) // check with in range { return true; @@ -50,24 +50,30 @@ class NemesisManager { auto hunter = pair.first; auto prey = pair.second; if (ifNemesisWithinWeaponRange(hunter)) { - hunter->setAvatarOrder(AvatarOrderType::OPEN_FIRE); - prey->setAvatarOrder(AvatarOrderType::TAKEN_DAMAGE); - hunter->getAttackAndDamager()->openFireToTarget(prey); + hunter->getAvatarOrder()->setAvatarOrder( + AvatarOrderType::OPEN_FIRE); + prey->getAvatarOrder()->setAvatarOrder( + AvatarOrderType::TAKEN_DAMAGE); + hunter->getAttackAndDamage()->openFireToTarget(prey); } if (*pair.second->getHealth()->getLivingStatus() == LivingStatus::DEAD) { removeNemesis(hunter); - hunter->setAvatarOrder(AvatarOrderType::NO_ORDER); - prey->setAvatarOrder(AvatarOrderType::NO_ORDER); + hunter->getAvatarOrder()->setAvatarOrder( + AvatarOrderType::NO_ORDER); + prey->getAvatarOrder()->setAvatarOrder( + AvatarOrderType::NO_ORDER); break; } if (*pair.first->getHealth()->getLivingStatus() == LivingStatus::DEAD) { removeNemesis(hunter); - hunter->setAvatarOrder(AvatarOrderType::NO_ORDER); - prey->setAvatarOrder(AvatarOrderType::NO_ORDER); + hunter->getAvatarOrder()->setAvatarOrder( + AvatarOrderType::NO_ORDER); + prey->getAvatarOrder()->setAvatarOrder( + AvatarOrderType::NO_ORDER); break; } } diff --git a/include/Mechanics/StructureManager.hpp b/include/Mechanics/StructureManager.hpp index 43bf4aee..f00a4e7c 100644 --- a/include/Mechanics/StructureManager.hpp +++ b/include/Mechanics/StructureManager.hpp @@ -27,14 +27,15 @@ class StructureManager { newstruct->Start(); m_StructSelectingConstructionSite = newstruct; - newstruct->setStructOrder( - StructureOrder::StructureOrderType::SELECTING_SITE); + newstruct->getStructureOrder()->setStructOrder( + StructureOrderType::SELECTING_SITE); } void SelectingBuildSite() { // bulit or not - if (m_StructSelectingConstructionSite->getStructOrder() == - StructureOrder::StructureOrderType::SELECTING_SITE) { + if (m_StructSelectingConstructionSite->getStructureOrder() + ->getStructureOrderType() == + StructureOrderType::SELECTING_SITE) { m_StructureArray.buildNewStructure( m_Map, m_StructSelectingConstructionSite); } diff --git a/include/Structure/Structure.hpp b/include/Structure/Structure.hpp index 004e1d62..bfde5aba 100644 --- a/include/Structure/Structure.hpp +++ b/include/Structure/Structure.hpp @@ -8,13 +8,13 @@ #include "Display/SpriteSheet.hpp" #include "Display/SpriteSheetAnimation.hpp" #include "HighLight.h" +#include "Map/MapUtility.hpp" #include "Mechanics/GameObjectID.hpp" #include "Selectable.hpp" #include "Structure/StructureOrder.hpp" -#include "Util/Image.hpp" - #include "Unit/Health.hpp" #include "Unit/IHealthable.hpp" +#include "Util/Image.hpp" #include "Util/GameObject.hpp" #include "Util/Input.hpp" @@ -26,7 +26,6 @@ class Structure : public Util::GameObject, public Selectable, - public StructureOrder, public IHealthable { public: @@ -79,34 +78,34 @@ class Structure : public Util::GameObject, glm::vec2 GetObjectLocation() { return this->m_ObjectLocation; } virtual void SetAttachVisible(bool visible); glm::vec2 GetDrawLocation() { return m_DrawLocation; }; - void SetID(GameObjectID id) { m_ID = id; }; virtual void attachmentUpdate(); float getElectricPower() { return this->m_ElectricPower; } float getBuildingTime() { return this->m_BuildingTime; } float getBuildingCost() { return this->m_BuildingCost; } - HouseType getHouseType() { return this->m_ID.getHouseType(); } - glm::vec2 GlobalCoordToCellCoord(glm::vec2 globalCoord) { - return glm::vec2(int(globalCoord[0] / CELL_SIZE.x), - int(globalCoord[1] / CELL_SIZE.y)); - } + HouseType getHouseType() { return this->m_ID.getHouseType(); } - glm::vec2 GetObjectCell() { - return GlobalCoordToCellCoord(m_ObjectLocation); + glm::vec2 getLocationCell() { + return MapUtil::GlobalCoordToCellCoord(m_ObjectLocation); } std::vector GetAbsoluteOccupiedArea(); void SetRelativeOccupiedArea(std::vector Area) { m_RelativeOccupiedArea = Area; } +public: GameObjectID getID() { return m_ID; } - std::shared_ptr getHealth() override { return m_Health; } void setHealth(std::shared_ptr health) override { m_Health = health; } + std::shared_ptr getStructureOrder() { return m_Order; } + + std::shared_ptr getAttackAndDamage() { + return m_AttackAndDamage; + } protected: float m_ElectricPower; @@ -127,6 +126,9 @@ class Structure : public Util::GameObject, glm::vec2 m_ObjectLocation = {100, 100}; std::vector m_RelativeOccupiedArea = {{0, 0}}; + // structure order + std::shared_ptr m_Order = + std::make_shared(); // health std::shared_ptr m_Health = std::make_shared(); // attack and damage diff --git a/include/Structure/StructureOrder.hpp b/include/Structure/StructureOrder.hpp index 7a9b4eb0..a8a58c02 100644 --- a/include/Structure/StructureOrder.hpp +++ b/include/Structure/StructureOrder.hpp @@ -4,20 +4,19 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTUREORDER_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_STRUCTUREORDER_HPP - +enum class StructureOrderType { + NOT_CONSTRUCTED_YET, + CONSTRUCTED, + SELECTING_SITE, + BUILT, + NO_ORDER +}; class StructureOrder { - public: StructureOrder() {} virtual ~StructureOrder() {} - enum class StructureOrderType { - NOT_CONSTRUCTED_YET, - CONSTRUCTED, - SELECTING_SITE, - BUILT, - NO_ORDER - }; - StructureOrderType getStructOrder() { return m_StructOrder; } + + StructureOrderType getStructureOrderType() { return m_StructOrder; } void setStructOrder(StructureOrderType structorder) { m_StructOrder = structorder; diff --git a/include/Structure/WayPointStructure.hpp b/include/Structure/WayPointStructure.hpp index aa02b718..54ac6044 100644 --- a/include/Structure/WayPointStructure.hpp +++ b/include/Structure/WayPointStructure.hpp @@ -47,7 +47,8 @@ class WayPointStructure : public Structure, public IWayPointStructure { break; } case LivingStatus::ALIVE: { - if (m_StructOrder == StructureOrderType::SELECTING_SITE) { + if (getStructureOrder()->getStructureOrderType() == + StructureOrderType::SELECTING_SITE) { this->updateMoveable(); } else { this->updateFixed(); diff --git a/src/Avatar/Avatar.cpp b/src/Avatar/Avatar.cpp index fa931b44..4659ec33 100644 --- a/src/Avatar/Avatar.cpp +++ b/src/Avatar/Avatar.cpp @@ -11,7 +11,7 @@ void Avatar::whenSelected() { void Avatar::Update() { DrawAvatar(); if (getMoving()->ifMovePathEmpty()) { - m_AvatarOrder = AvatarOrderType::NO_ORDER; + getAvatarOrder()->setAvatarOrder(AvatarOrderType::NO_ORDER); } switch (*m_Health->getLivingStatus()) { @@ -22,16 +22,20 @@ void Avatar::Update() { case (LivingStatus::ALIVE): whenSelected(); - if (m_AvatarOrder == AvatarOrderType::OPEN_FIRE) { + if (getAvatarOrder()->getAvatarOrder() == AvatarOrderType::OPEN_FIRE) { // open fire - } else if (m_AvatarOrder == AvatarOrderType::MOVE) { + } else if (getAvatarOrder()->getAvatarOrder() == + AvatarOrderType::MOVE) { m_Moving->moveUpdate(); - } else if (m_AvatarOrder == AvatarOrderType::NO_ORDER) { + } else if (getAvatarOrder()->getAvatarOrder() == + AvatarOrderType::NO_ORDER) { noorderUpdate(); - } else if (m_AvatarOrder == AvatarOrderType::TAKEN_DAMAGE) { + } else if (getAvatarOrder()->getAvatarOrder() == + AvatarOrderType::TAKEN_DAMAGE) { // takendamage - } else if (m_AvatarOrder == AvatarOrderType::SPAWNED) { + } else if (getAvatarOrder()->getAvatarOrder() == + AvatarOrderType::SPAWNED) { spawnedUpdate(); } @@ -57,7 +61,7 @@ void Avatar::Start(glm::vec2 spawnlocationcell) { // destination = Barrack's // setSpriteSheet(); SetVisible(true); getMoving()->setMovementSpeed(4); - m_AvatarOrder = AvatarOrderType::SPAWNED; + getAvatarOrder()->setAvatarOrder(AvatarOrderType::SPAWNED); getMoving()->setCurrentLocation( MapUtil::CellCoordToGlobal(spawnlocationcell)); m_Transform.scale = {1, 1}; @@ -115,11 +119,12 @@ void Avatar::DrawAvatar() { this->SetDrawable( std::make_shared("../assets/sprites/mech_dead.png")); } else { - - if (m_AvatarOrder == AvatarOrderType::OPEN_FIRE) { + + if (getAvatarOrder()->getAvatarOrder() == AvatarOrderType::OPEN_FIRE) { this->SetDrawable(std::make_shared( "../assets/sprites/mech_open_fire.png")); - } else if (m_AvatarOrder == AvatarOrderType::TAKEN_DAMAGE) { + } else if (getAvatarOrder()->getAvatarOrder() == + AvatarOrderType::TAKEN_DAMAGE) { this->SetDrawable(std::make_shared( "../assets/sprites/mech_taken_damage.png")); } else { diff --git a/src/Mechanics/AvatarManager.cpp b/src/Mechanics/AvatarManager.cpp index 54cade30..c8aaa4cd 100644 --- a/src/Mechanics/AvatarManager.cpp +++ b/src/Mechanics/AvatarManager.cpp @@ -8,7 +8,7 @@ void AvatarManager::Update() { m_NemesisManager->Update(); for (auto unit : m_AvatarArray) { unit->Update(); - if (unit->getAvatarOrder() == AvatarOrderType::MOVE) { + if (unit->getAvatarOrder()->getAvatarOrder() == AvatarOrderType::MOVE) { updateTileWhileAvatarMoving(unit); } if (unit->getSelected()) { @@ -32,7 +32,7 @@ void AvatarManager::giveOrderToMyAvatar(std::shared_ptr unit) { ->getTileByCellPosition(MapUtil::GlobalCoordToCellCoord( MapUtil::ScreenToGlobalCoord(dest))) ->ifEnemyAtTile()) { - unit->setAvatarOrder(AvatarOrderType::MOVE); + unit->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE); m_NemesisManager->addNemesis( unit, m_Map @@ -40,13 +40,13 @@ void AvatarManager::giveOrderToMyAvatar(std::shared_ptr unit) { MapUtil::ScreenToGlobalCoord(dest))) ->getAvatars()[0]); } else { - unit->setAvatarOrder(AvatarOrderType::MOVE); + unit->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE); } } } } void AvatarManager::forceMove(std::shared_ptr unit, glm::vec2 cell) { - unit->setAvatarOrder(AvatarOrderType::MOVE); + unit->getAvatarOrder()->setAvatarOrder(AvatarOrderType::MOVE); auto queue = m_Navigator->findPath(unit->getMoving()->getCurrentCell(), cell); unit->getMoving()->setMovePath(queue); diff --git a/src/Structure/Barracks.cpp b/src/Structure/Barracks.cpp index ca6b90af..95f28481 100644 --- a/src/Structure/Barracks.cpp +++ b/src/Structure/Barracks.cpp @@ -20,7 +20,7 @@ void Barracks::Start() { m_HighLight.SetHLScale(this->GetTransform().scale); whenSelected(); // State - setStructOrder(StructureOrderType::CONSTRUCTED); + getStructureOrder()->setStructOrder(StructureOrderType::CONSTRUCTED); // health Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); @@ -47,7 +47,7 @@ void Barracks::Start(glm::vec2 location) { SetVisible(true); m_SpriteSheetAnimation->initSpriteSheetAnimation(m_StructureSpriteSheet, false, INTERVAL, false); - setStructOrder(StructureOrderType::BUILT); + getStructureOrder()->setStructOrder(StructureOrderType::BUILT); Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); -} \ No newline at end of file +} diff --git a/src/Structure/OreRefinery.cpp b/src/Structure/OreRefinery.cpp index d489d820..b6bd1020 100644 --- a/src/Structure/OreRefinery.cpp +++ b/src/Structure/OreRefinery.cpp @@ -20,7 +20,8 @@ void OreRefinery::Start() { m_HighLight.SetHLScale(this->GetTransform().scale); whenSelected(); // State - setStructOrder(StructureOrderType::NOT_CONSTRUCTED_YET); + getStructureOrder()->setStructOrder( + StructureOrderType::NOT_CONSTRUCTED_YET); Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); } @@ -46,7 +47,7 @@ void OreRefinery::Start(glm::vec2 location) { SetVisible(true); m_SpriteSheetAnimation->initSpriteSheetAnimation(m_StructureSpriteSheet, false, INTERVAL, false); - setStructOrder(StructureOrderType::BUILT); + getStructureOrder()->setStructOrder(StructureOrderType::BUILT); Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); -} \ No newline at end of file +} diff --git a/src/Structure/Structure.cpp b/src/Structure/Structure.cpp index a286c992..50d67eaa 100644 --- a/src/Structure/Structure.cpp +++ b/src/Structure/Structure.cpp @@ -11,7 +11,7 @@ void Structure::Start() { if (this->m_ID.getUnitType() == UnitType::NONE) { Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::NOT_BORN_YET)); - m_StructOrder = StructureOrderType::NO_ORDER; + getStructureOrder()->setStructOrder(StructureOrderType::NO_ORDER); } else { m_Transform.scale = {2.f, 2.f}; m_HighLight.SetDrawable( @@ -23,7 +23,7 @@ void Structure::Start() { SetSpriteSheet(); Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); - m_StructOrder = StructureOrderType::SELECTING_SITE; + getStructureOrder()->setStructOrder(StructureOrderType::SELECTING_SITE); } } void Structure::Start(glm::vec2 location) { @@ -37,15 +37,15 @@ void Structure::Start(glm::vec2 location) { SetSpriteSheet(); Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); - m_StructOrder = StructureOrderType::SELECTING_SITE; + getStructureOrder()->setStructOrder(StructureOrderType::SELECTING_SITE); this->SetObjectLocation(location); SetVisible(true); m_SpriteSheetAnimation->initSpriteSheetAnimation(m_StructureSpriteSheet, false, INTERVAL, false); - setStructOrder(StructureOrderType::BUILT); + getStructureOrder()->setStructOrder(StructureOrderType::BUILT); Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); - } +} void Structure::Update() { switch (*getHealth()->getLivingStatus()) { @@ -54,9 +54,12 @@ void Structure::Update() { break; case LivingStatus::ALIVE: whenSelected(); - if (m_StructOrder == StructureOrderType::SELECTING_SITE) { + + if (getStructureOrder()->getStructureOrderType() == + StructureOrderType::SELECTING_SITE) { this->updateMoveable(); - } else if (m_StructOrder == StructureOrderType::BUILT) { + } else if (getStructureOrder()->getStructureOrderType() == + StructureOrderType::BUILT) { this->updateFixed(); } break; @@ -108,7 +111,7 @@ void Structure::attachmentUpdate() { std::vector Structure::GetAbsoluteOccupiedArea() { std::vector Area; for (auto i : m_RelativeOccupiedArea) { - Area.push_back({i.x + GetObjectCell().x, i.y + GetObjectCell().y}); + Area.push_back({i.x + getLocationCell().x, i.y + getLocationCell().y}); } return Area; } diff --git a/src/Structure/WarFactory.cpp b/src/Structure/WarFactory.cpp index 641fa3d4..32457ade 100644 --- a/src/Structure/WarFactory.cpp +++ b/src/Structure/WarFactory.cpp @@ -44,7 +44,7 @@ void WarFactory::Start(glm::vec2 location) { SetVisible(true); m_SpriteSheetAnimation->initSpriteSheetAnimation(m_StructureSpriteSheet, false, INTERVAL, false); - setStructOrder(StructureOrderType::BUILT); + getStructureOrder()->setStructOrder(StructureOrderType::BUILT); Structure::getHealth()->setLivingStatus( std::make_shared(LivingStatus::ALIVE)); -} \ No newline at end of file +} diff --git a/src/Structure/WayPointStructure.cpp b/src/Structure/WayPointStructure.cpp index 49461e1c..e13838bf 100644 --- a/src/Structure/WayPointStructure.cpp +++ b/src/Structure/WayPointStructure.cpp @@ -5,7 +5,7 @@ #include "Map/MapUtility.hpp" void WayPointStructure::whenSelected() { - if (this->getSelected() && this->getBuilt()) { + if (this->getSelected() && this->getStructureOrder()->getBuilt()) { if (Util::Input::IsKeyPressed(Util::Keycode(Util::Keycode::MOUSE_RB))) { this->SetWayPointLocationByCellCoord( MapUtil::GlobalCoordToCellCoord(MapUtil::ScreenToGlobalCoord( From 4ba8955e81136414e3d656de0e35042e0d3a3bac Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sat, 18 May 2024 16:24:44 +0800 Subject: [PATCH 5/7] remove when dead --- include/Map/Map.hpp | 9 ++++-- include/Mechanics/BuiltStructure.hpp | 41 ++++++++++++++++++-------- include/Mechanics/StructureManager.hpp | 4 +-- include/Mechanics/UnitManager.hpp | 10 +++---- include/Structure/Structure.hpp | 2 +- include/Unit/Health.hpp | 16 ++++++---- include/pch.hpp | 4 +-- src/Mechanics/AvatarManager.cpp | 33 +++++++++++++++------ src/Structure/Structure.cpp | 2 +- 9 files changed, 80 insertions(+), 41 deletions(-) diff --git a/include/Map/Map.hpp b/include/Map/Map.hpp index 0bb97b6a..036f9400 100644 --- a/include/Map/Map.hpp +++ b/include/Map/Map.hpp @@ -45,11 +45,16 @@ class MapClass : public Core::Drawable { getTileByCellPosition(position)->setBuildable(false); getTileByCellPosition(position)->pushAvatars(avatar); } - void removeAvatarsByCellPosition(std::shared_ptr avatar, - glm::vec2 position) { + + void removeAvatarByCellPosition(std::shared_ptr avatar, + glm::vec2 position) { getTileByCellPosition(position)->removeAvatar(avatar); } + void removeStrcutureByCellPosition(glm::vec2 position) { + getTileByCellPosition(position)->removeStructure(); + } + protected: void InitGrid(); diff --git a/include/Mechanics/BuiltStructure.hpp b/include/Mechanics/BuiltStructure.hpp index 4d2b0a44..2759c33f 100644 --- a/include/Mechanics/BuiltStructure.hpp +++ b/include/Mechanics/BuiltStructure.hpp @@ -7,18 +7,22 @@ #include "Structure/Barracks.hpp" #include "Structure/Structure.hpp" #include "pch.hpp" + class BuiltStructure { public: BuiltStructure() {} virtual ~BuiltStructure() {} - - void buildNewStructure(std::shared_ptr m_Map, - std::shared_ptr newstruct, + void Start(std::shared_ptr map) { + m_Map = map; + StartBuiltStructure(); + } + void buildNewStructure(std::shared_ptr newstruct, bool force = false) { - std::vector coords = newstruct->GetAbsoluteOccupiedArea(); + std::vector coords = newstruct->getAbsoluteOccupiedArea(); if (!force) { if (Util::Input::IsKeyPressed(Util::Keycode::MOUSE_LB)) { - if (ifCanBuildStructureAtTile(m_Map, newstruct) == true) { + // check whehter or not can built at tile + if (ifCanBuildStructureAtTile(newstruct) == true) { m_BuiltStructure.push_back(newstruct); m_Map->builtStructureByCellPosition(newstruct, coords); newstruct->getStructureOrder()->setStructOrder( @@ -33,9 +37,8 @@ class BuiltStructure { } } - bool ifCanBuildStructureAtTile(std::shared_ptr m_Map, - std::shared_ptr newstruct) { - std::vector coords = newstruct->GetAbsoluteOccupiedArea(); + bool ifCanBuildStructureAtTile(std::shared_ptr newstruct) { + std::vector coords = newstruct->getAbsoluteOccupiedArea(); for (auto i : coords) { if (m_Map->getTileByCellPosition(i)->getBuildable() == false) { return false; @@ -49,14 +52,25 @@ class BuiltStructure { } void StartBuiltStructure() { - for (auto pair : m_BuiltStructure) { - pair->Start(); + for (auto structure : m_BuiltStructure) { + structure->Start(); } } void UpdateBuiltStructure() { - for (auto pair : m_BuiltStructure) { - pair->Update(); + // check whether the structure is dead or update + for (int i = 0; i < m_BuiltStructure.size(); i++) { + if (m_BuiltStructure[i]->getHealth()->ifDead()) { + // remove from map + for (auto a : m_BuiltStructure[i]->getAbsoluteOccupiedArea()) { + m_Map->removeStrcutureByCellPosition(a); + } + // remove from builtstructure array + m_BuiltStructure.erase(m_BuiltStructure.begin() + i); + i--; + } else { + m_BuiltStructure[i]->Update(); + } } } void add(std::shared_ptr structure) { @@ -86,7 +100,8 @@ class BuiltStructure { glm::vec2 getPlayerBarrackCell() { return m_PlayerBarrackCell; } glm::vec2 getPlayerWayPointCell() { return m_PlayerWayPointCell; } -protected: +private: + std::shared_ptr m_Map = std::make_shared(); std::vector> m_BuiltStructure; glm::vec2 m_EnemyBarrackCell = {-1, -1}; glm::vec2 m_EnemyWayPointCell = {-1, -1}; diff --git a/include/Mechanics/StructureManager.hpp b/include/Mechanics/StructureManager.hpp index f00a4e7c..60921b2b 100644 --- a/include/Mechanics/StructureManager.hpp +++ b/include/Mechanics/StructureManager.hpp @@ -12,7 +12,7 @@ class StructureManager { virtual ~StructureManager() {} void Start(std::shared_ptr map) { - m_StructureArray.StartBuiltStructure(); + m_StructureArray.Start(map); m_Map = map; } void Update() { @@ -37,7 +37,7 @@ class StructureManager { ->getStructureOrderType() == StructureOrderType::SELECTING_SITE) { m_StructureArray.buildNewStructure( - m_Map, m_StructSelectingConstructionSite); + m_StructSelectingConstructionSite); } } diff --git a/include/Mechanics/UnitManager.hpp b/include/Mechanics/UnitManager.hpp index b945048f..eb871591 100644 --- a/include/Mechanics/UnitManager.hpp +++ b/include/Mechanics/UnitManager.hpp @@ -112,35 +112,35 @@ class UnitManager : public Player { auto structure = std::make_shared(house); structure->Start(cellPos); m_StructureManager->getStructureArray()->buildNewStructure( - m_Map, structure, true); + structure, true); break; } case UnitType::ORE_REF: { auto structure = std::make_shared(house); structure->Start(cellPos); m_StructureManager->getStructureArray()->buildNewStructure( - m_Map, structure, true); + structure, true); break; } case UnitType::POWER_PLANT: { auto structure = std::make_shared(house); structure->Start(cellPos); m_StructureManager->getStructureArray()->buildNewStructure( - m_Map, structure, true); + structure, true); break; } case UnitType::WAR_FACT: { auto structure = std::make_shared(house); structure->Start(cellPos); m_StructureManager->getStructureArray()->buildNewStructure( - m_Map, structure, true); + structure, true); break; } case UnitType::ADV_POWER_PLANT: { auto structure = std::make_shared(house); structure->Start(cellPos); m_StructureManager->getStructureArray()->buildNewStructure( - m_Map, structure, true); + structure, true); break; } case UnitType::INFANTRY: { diff --git a/include/Structure/Structure.hpp b/include/Structure/Structure.hpp index bfde5aba..47d94eb0 100644 --- a/include/Structure/Structure.hpp +++ b/include/Structure/Structure.hpp @@ -90,7 +90,7 @@ class Structure : public Util::GameObject, glm::vec2 getLocationCell() { return MapUtil::GlobalCoordToCellCoord(m_ObjectLocation); } - std::vector GetAbsoluteOccupiedArea(); + std::vector getAbsoluteOccupiedArea(); void SetRelativeOccupiedArea(std::vector Area) { m_RelativeOccupiedArea = Area; } diff --git a/include/Unit/Health.hpp b/include/Unit/Health.hpp index f52529bd..c96c0d6c 100644 --- a/include/Unit/Health.hpp +++ b/include/Unit/Health.hpp @@ -40,21 +40,25 @@ class Health { void setHP(int hp) { m_HP = hp; - if (m_HP <= 0) { - m_LivingStatus = std::make_shared(LivingStatus::DEAD); - } + ifDead(); } void addHP(int value) { m_HP += value; - if (m_HP <= 0) { - m_LivingStatus = std::make_shared(LivingStatus::DEAD); - } + ifDead(); } int getHP() { return m_HP; } void setArmorRate(float armorrate) { m_ArmorRate = armorrate; } float getArmorRate() { return m_ArmorRate; } + bool ifDead() { + if (m_HP <= 0) { + m_LivingStatus = std::make_shared(LivingStatus::DEAD); + return true; + } else { + return false; + } + } private: std::shared_ptr m_LivingStatus = diff --git a/include/pch.hpp b/include/pch.hpp index 194373d7..1d9e82aa 100644 --- a/include/pch.hpp +++ b/include/pch.hpp @@ -19,8 +19,8 @@ #include -//suppose to be "GL/glut", yet GLUT/glut on mac -//#include +// suppose to be "GL/glut", yet GLUT/glut on mac +// #include #include #include diff --git a/src/Mechanics/AvatarManager.cpp b/src/Mechanics/AvatarManager.cpp index c8aaa4cd..1a3db282 100644 --- a/src/Mechanics/AvatarManager.cpp +++ b/src/Mechanics/AvatarManager.cpp @@ -6,13 +6,29 @@ void AvatarManager::Update() { m_NemesisManager->Update(); - for (auto unit : m_AvatarArray) { - unit->Update(); - if (unit->getAvatarOrder()->getAvatarOrder() == AvatarOrderType::MOVE) { - updateTileWhileAvatarMoving(unit); - } - if (unit->getSelected()) { - giveOrderToMyAvatar(unit); + for (int i = 0; i < m_AvatarArray.size(); i++) { + // if dead remove, else update it + if (m_AvatarArray[i]->getHealth()->ifDead()) { + // remove from map + m_Map->removeAvatarByCellPosition( + m_AvatarArray[i], + m_AvatarArray[i]->getMoving()->getCurrentCell()); + // remove from array + m_AvatarArray.erase(m_AvatarArray.begin() + i); + i--; + } else { + m_AvatarArray[i]->Update(); + + // update tile while avatar is moving + if (m_AvatarArray[i]->getAvatarOrder()->getAvatarOrder() == + AvatarOrderType::MOVE) { + updateTileWhileAvatarMoving(m_AvatarArray[i]); + } + + // give order to avatar + if (m_AvatarArray[i]->getSelected()) { + giveOrderToMyAvatar(m_AvatarArray[i]); + } } } } @@ -55,8 +71,7 @@ void AvatarManager::forceMove(std::shared_ptr unit, glm::vec2 cell) { void AvatarManager::updateTileWhileAvatarMoving( std::shared_ptr avatar) { if (avatar->getMoving()->ifArrivedAtNextCell()) { - m_Map->removeAvatarsByCellPosition(avatar, - unitArrayAndLocation[avatar]); + m_Map->removeAvatarByCellPosition(avatar, unitArrayAndLocation[avatar]); m_Map->setAvatarByCellPosition(avatar, avatar->getMoving()->getCurrentCell()); unitArrayAndLocation[avatar] = avatar->getMoving()->getCurrentCell(); diff --git a/src/Structure/Structure.cpp b/src/Structure/Structure.cpp index 50d67eaa..df404de3 100644 --- a/src/Structure/Structure.cpp +++ b/src/Structure/Structure.cpp @@ -108,7 +108,7 @@ void Structure::attachmentUpdate() { m_HighLight.SetObjectLocation(this->GetDrawLocation()); m_HighLight.Draw(); } -std::vector Structure::GetAbsoluteOccupiedArea() { +std::vector Structure::getAbsoluteOccupiedArea() { std::vector Area; for (auto i : m_RelativeOccupiedArea) { Area.push_back({i.x + getLocationCell().x, i.y + getLocationCell().y}); From 0fb3adc94fbfa1feadbeee20ad8cd26149f65331 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sat, 18 May 2024 16:49:54 +0800 Subject: [PATCH 6/7] fix finished moving halfway --- src/Avatar/Avatar.cpp | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Avatar/Avatar.cpp b/src/Avatar/Avatar.cpp index 4659ec33..2106e901 100644 --- a/src/Avatar/Avatar.cpp +++ b/src/Avatar/Avatar.cpp @@ -20,6 +20,7 @@ void Avatar::Update() { break; case (LivingStatus::ALIVE): + SetVisible(true); whenSelected(); if (getAvatarOrder()->getAvatarOrder() == AvatarOrderType::OPEN_FIRE) { @@ -27,6 +28,9 @@ void Avatar::Update() { } else if (getAvatarOrder()->getAvatarOrder() == AvatarOrderType::MOVE) { m_Moving->moveUpdate(); + if (getMoving()->getCurrentDir() == MoveDirection::IDLE) { + getAvatarOrder()->setAvatarOrder(AvatarOrderType::NO_ORDER); + } } else if (getAvatarOrder()->getAvatarOrder() == AvatarOrderType::NO_ORDER) { noorderUpdate(); @@ -45,12 +49,10 @@ void Avatar::Update() { void Avatar::noorderUpdate() { getMoving()->setCurrentDir(MoveDirection::IDLE); - SetVisible(true); m_Transform.translation = getMoving()->getCurrentLocation(); } void Avatar::spawnedUpdate() { - SetVisible(true); m_Transform.translation = getMoving()->getCurrentLocation(); } @@ -59,7 +61,6 @@ void Avatar::Start(glm::vec2 spawnlocationcell) { // destination = Barrack's // setCurrentCell() //CurrentCell = Structure's Location this->SetDrawable(customizeImage()); // setSpriteSheet(); - SetVisible(true); getMoving()->setMovementSpeed(4); getAvatarOrder()->setAvatarOrder(AvatarOrderType::SPAWNED); getMoving()->setCurrentLocation( @@ -114,23 +115,23 @@ void Avatar::DEBUG_printCurrentMoveDirection(MoveDirection Dir) { void Avatar::DrawAvatar() { m_Transform.translation = getMoving()->getCurrentLocation(); - SetVisible(true); - if (getHealth()->getHP() < 50) { - this->SetDrawable( - std::make_shared("../assets/sprites/mech_dead.png")); - } else { - if (getAvatarOrder()->getAvatarOrder() == AvatarOrderType::OPEN_FIRE) { - this->SetDrawable(std::make_shared( - "../assets/sprites/mech_open_fire.png")); - } else if (getAvatarOrder()->getAvatarOrder() == - AvatarOrderType::TAKEN_DAMAGE) { + if (getAvatarOrder()->getAvatarOrder() == AvatarOrderType::OPEN_FIRE) { + this->SetDrawable(std::make_shared( + "../assets/sprites/mech_open_fire.png")); + } else if (getAvatarOrder()->getAvatarOrder() == + AvatarOrderType::TAKEN_DAMAGE) { + if (getHealth()->getHP() < 50) { this->SetDrawable(std::make_shared( - "../assets/sprites/mech_taken_damage.png")); + "../assets/sprites/mech_dead.png")); } else { this->SetDrawable(std::make_shared( - "../assets/sprites/mech_single.png")); + "../assets/sprites/mech_taken_damage.png")); } + } else { + this->SetDrawable( + std::make_shared("../assets/sprites/mech_single.png")); } + Draw(); } From 165e2e818c77f299e31236c6672064c4a1f21b98 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sat, 18 May 2024 17:14:55 +0800 Subject: [PATCH 7/7] success fully fix finished moving --- include/Avatar/Moving.hpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/include/Avatar/Moving.hpp b/include/Avatar/Moving.hpp index 2d731c68..e4585202 100644 --- a/include/Avatar/Moving.hpp +++ b/include/Avatar/Moving.hpp @@ -50,10 +50,10 @@ class Moving { void moveUpdate() { if (ifArrivedAtNextCell()) { + m_MovePath.pop_front(); m_PrevCell = getCurrentCell(); if (!m_MovePath.empty()) { setCurrentDir(m_MovePath.front()); - m_MovePath.pop_front(); } else { finishedmovingUpdate(); } @@ -73,7 +73,6 @@ class Moving { void setMovePath(std::deque movepath) { m_MovePath = movepath; m_CurrentDir = m_MovePath.front(); - m_MovePath.pop_front(); m_PrevCell = getCurrentCell(); }