Skip to content

Commit

Permalink
Merge pull request #67 from ntut-Tu/Update_Merge
Browse files Browse the repository at this point in the history
Update merge
  • Loading branch information
ntut-Tu authored May 10, 2024
2 parents bf0b316 + 5482fcf commit b283366
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 29 deletions.
2 changes: 1 addition & 1 deletion include/Mechanics/AvatarManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AvatarManager {
std::vector<std::shared_ptr<Avatar>> getAvatarArray() {
return m_AvatarArray;
}

void forceMove(std::shared_ptr<Avatar> unit,glm::vec2 cell);
protected:
void giveOrderToAvatar(std::shared_ptr<Avatar> unit);

Expand Down
8 changes: 7 additions & 1 deletion include/Mechanics/NemesisManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_NEMESISMANAGER_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_NEMESISMANAGER_HPP
#include "Map/MapUtility.hpp"
#define ATTACK_RANGE 5
class NemesisManager {
public:
NemesisManager() {}
Expand All @@ -31,10 +32,11 @@ class NemesisManager {
if (ifAvatarHasNemesis(hunter) == false) {
return false;
}
if (1 == 0) // check with in range
if (hunter.getDistance(m_Nemesis[hunter].getCurrentCell()) <= ATTACK_RANGE) // check with in range
{
return true;
} else {
forceMove(hunter,m_Nemesis[hunter].getCurrentCell());//向目標移動
return false;
}
}
Expand All @@ -47,6 +49,10 @@ 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() ==
Expand Down
23 changes: 4 additions & 19 deletions include/Mechanics/UnitManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "Avatar/Infantry.hpp"
#include "AvatarNavigator.hpp"
#include "Cursor.hpp"
#include "Enemy/Enemy.hpp"
#include "GameObjectID.hpp"
#include "Mechanics/AvatarManager.hpp"
#include "Mechanics/BuiltStructure.hpp"
Expand Down Expand Up @@ -68,36 +67,23 @@ class UnitManager : public Player {
for (auto i : *m_StructureManager->getStructureArray()
->getBuiltStructureArray()) {
if (std::dynamic_pointer_cast<OreRefinery>(i)) {
if (i->getHouseType() == HouseType::MY) {
addTotalCurrency(150);
} else {
m_Enemy->addTotalCurrency(150);
}
addTotalCurrency(150);
}
}
}

void importEnemy(std::shared_ptr<EnemyPlayer> enemy) { m_Enemy = enemy; }

void spawn(std::shared_ptr<MapClass> m_Map, UnitType unit,
HouseType house) {
if (house == HouseType::ENEMY) {
m_Enemy->addUnitConstructCount(unit, 1);
//m_Enemy->addUnitConstructCount(unit, 1);
} else {
// m_Player->setUnitConstructCount(unit, 1);
}
switch (unit) {
case UnitType::INFANTRY: {
auto avatar = std::make_shared<Infantry>(house);
if (house == HouseType::ENEMY) {
// if(m_EnemyBarrackCell.x==-1){
// return;
// }
// avatar ->Start(m_EnemyBarrackCell);
// avatar
// ->setNewDestination(m_EnemyWayPointCell);
} else {
if (m_StructureManager->getStructureArray()
if (m_StructureManager->getStructureArray()
->getPlayerBarrackCell()
.x == -1) {
return;
Expand All @@ -120,7 +106,7 @@ class UnitManager : public Player {
glm::vec2 cellPos) {
// 缺檢查敵方擁有建築的位置,並重生在該處
if (house == HouseType::ENEMY) {
m_Enemy->addUnitConstructCount(unit, 1);
//m_Enemy->addUnitConstructCount(unit, 1);
} else {
// m_Player->setUnitConstructCount(unit, 1);
}
Expand Down Expand Up @@ -229,6 +215,5 @@ class UnitManager : public Player {
std::chrono::high_resolution_clock::time_point m_StartTime;
double m_lastElapsed = 0.F;

std::shared_ptr<EnemyPlayer> m_Enemy;
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_UNITMANAGER_HPP
2 changes: 2 additions & 0 deletions include/Scene/Scene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Scene {
std::shared_ptr<CameraClass> m_SceneCamera = std::make_shared<CameraClass>();
std::shared_ptr<UnitManager> m_GameObjectManager =
std::make_shared<UnitManager>();
std::shared_ptr<UnitManager> m_EnemyObjectManager =
std::make_shared<UnitManager>();
Util::Renderer m_Renderer;
UIClass m_UI;
std::shared_ptr<Player> m_Player = std::make_shared<Player>();
Expand Down
2 changes: 1 addition & 1 deletion include/Scene/TutorialScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ class TutorialScene : public Scene{
std::shared_ptr<EnemyScripts> m_EnemyScripts = std::make_shared<EnemyScripts>();
std::shared_ptr<Task> m_Text = std::make_shared<Task>();
std::shared_ptr<Prop> m_cellProp = std::make_shared<Prop>();
Stages m_stage = Stages::STAGE1;
Stages m_stage;
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_TUTORIALSCENE_HPP
5 changes: 5 additions & 0 deletions src/Mechanics/AvatarManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ void AvatarManager::giveOrderToAvatar(std::shared_ptr<Avatar> unit) {
}
}
}
void AvatarManager::forceMove(std::shared_ptr<Avatar> unit,glm::vec2 cell){
unit->setAvatarOrder(AvatarOrderType::MOVE);
auto queue = m_Navigator->findPath(unit->getCurrentCell(), cell);
unit->setMovePath(queue);
}

void AvatarManager::updateTileWhileAvatarMoving(
std::shared_ptr<Avatar> avatar) {
Expand Down
28 changes: 21 additions & 7 deletions src/Scene/TutorialScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ void TutorialScene::Start() {
m_Enemy->setTotalCurrency(5000);
m_SceneCamera->Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)),
MapUtil::CellCoordToGlobal(glm::vec2(100, 100)));
m_GameObjectManager->importEnemy(m_Enemy);
m_EnemyScripts->Start(m_Enemy, m_GameObjectManager, m_Map);
m_EnemyScripts->Start(m_Enemy, m_EnemyObjectManager, m_Map);

/*
m_GameObjectManager->spawn(m_Map, UnitType::BARRACKS, HouseType::ENEMY,
m_EnemyObjectManager->spawn(m_Map, UnitType::BARRACKS, HouseType::ENEMY,
{20, 20});
m_GameObjectManager->spawn(m_Map, UnitType::POWER_PLANT,
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});

stageStart();
}
void TutorialScene::Update() {
m_GameObjectManager->Update();
m_EnemyObjectManager->Update();

stageUpdate();
Util::Transform trans;
Expand Down Expand Up @@ -60,6 +61,7 @@ void TutorialScene::Update() {
}
}
void TutorialScene::stageStart() {
m_stage = Stages::STAGE1;
m_Text->importCamera(m_SceneCamera);
m_Text->SetDrawable(
std::make_unique<Util::Image>("../assets/sprites/Task/Task1.png"));
Expand All @@ -75,6 +77,9 @@ void TutorialScene::stageStart() {
m_cellProp->setObjectLocation({750, 750}, 0);
}
void TutorialScene::stageUpdate() {
if(Util::Input::IsKeyPressed(Util::Keycode::R)){
stageStart();
}
switch (m_stage) {
case Stages::STAGE1: {
m_Text->Draw();
Expand Down Expand Up @@ -148,11 +153,11 @@ void TutorialScene::stageUpdate() {
m_cellProp->setScale({4, 3});
m_cellProp->setObjectLocation({1200, 850}, 0);
m_cellProp->Start({8, 6});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY,
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY,
HouseType::ENEMY, {24, 17});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY,
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY,
HouseType::ENEMY, {26, 18});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY,
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY,
HouseType::ENEMY, {25, 17});
m_stage = Stages::STAGE4;
}
Expand All @@ -161,6 +166,15 @@ void TutorialScene::stageUpdate() {
case Stages::STAGE4: {
m_Text->Draw();
m_cellProp->Update();
int enemy_count=0;
for(auto i:m_EnemyObjectManager->getAvatarManager()->getAvatarArray()){
if(i.getLivingStatus()==LivingStatus::DEAD){
enemy_count++;
}
}
if(enemy_count>=3){
//End?
}
break;
}
}
Expand Down

0 comments on commit b283366

Please sign in to comment.