From f795f9b78fe838bc9167b27496283f539d524065 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Fri, 17 May 2024 11:49:25 +0800 Subject: [PATCH] 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(); }