Skip to content

Commit

Permalink
open fire and dead
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed May 17, 2024
1 parent f4d2a4c commit f795f9b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 21 deletions.
8 changes: 4 additions & 4 deletions include/Avatar/AttackAndDamage.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class AttackAndDamage {
void damageTargetWithWeapon(std::shared_ptr<IHealthable> target,
std::shared_ptr<Weapon> 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<IHealthable> target) {
Expand Down
2 changes: 1 addition & 1 deletion include/Avatar/Weapon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 2 additions & 4 deletions include/Mechanics/NemesisManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,22 @@ 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() ==
LivingStatus::DEAD) {
removeNemesis(hunter);
hunter->setAvatarOrder(AvatarOrderType::NO_ORDER);
prey->setAvatarOrder(AvatarOrderType::NO_ORDER);
break;
}

if (*pair.first->getHealth()->getLivingStatus() ==
LivingStatus::DEAD) {
removeNemesis(hunter);
hunter->setAvatarOrder(AvatarOrderType::NO_ORDER);
prey->setAvatarOrder(AvatarOrderType::NO_ORDER);
break;
}
}
}
Expand Down
31 changes: 19 additions & 12 deletions src/Avatar/Avatar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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>(LivingStatus::ALIVE));
Expand Down Expand Up @@ -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<Util::Image>(
"../assets/sprites/mech_open_fire.png"));
} else if (m_AvatarOrder == AvatarOrderType::TAKEN_DAMAGE) {
this->SetDrawable(std::make_shared<Util::Image>(
"../assets/sprites/mech_taken_damage.png"));
} else {
SetVisible(true);
if (getHealth()->getHP() < 50) {
this->SetDrawable(
std::make_shared<Util::Image>("../assets/sprites/mech_single.png"));
std::make_shared<Util::Image>("../assets/sprites/mech_dead.png"));
} else {

if (m_AvatarOrder == AvatarOrderType::OPEN_FIRE) {
this->SetDrawable(std::make_shared<Util::Image>(
"../assets/sprites/mech_open_fire.png"));
} else if (m_AvatarOrder == AvatarOrderType::TAKEN_DAMAGE) {
this->SetDrawable(std::make_shared<Util::Image>(
"../assets/sprites/mech_taken_damage.png"));
} else {
this->SetDrawable(std::make_shared<Util::Image>(
"../assets/sprites/mech_single.png"));
}
}
Draw();
}

0 comments on commit f795f9b

Please sign in to comment.