Skip to content

Commit

Permalink
assign order
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed May 21, 2024
1 parent 1cf31e5 commit da219e9
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 63 deletions.
10 changes: 10 additions & 0 deletions include/AI/AIGroupCommander.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Created by 盧威任 on 5/21/24.
//

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_AIGROUPCOMMANDER_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_AIGROUPCOMMANDER_HPP

class AIGroupCommander {};

#endif // PRACTICALTOOLSFORSIMPLEDESIGN_AIGROUPCOMMANDER_HPP
File renamed without changes.
File renamed without changes.
14 changes: 8 additions & 6 deletions include/Mechanics/AvatarManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,20 @@ class AvatarManager {
std::vector<std::shared_ptr<Avatar>> getAvatarArray() {
return m_AvatarArray;
}
void forceMove(std::shared_ptr<Avatar> unit, glm::vec2 cell);

protected:
void giveOrderToMyAvatar(std::shared_ptr<Avatar> unit);
void assignMoveOrderToAvatar(std::shared_ptr<Avatar> unit,
glm::vec2 destcell);

void updateTileWhileAvatarMoving(std::shared_ptr<Avatar> unit);
void assignAttackOrderToAvatar(std::shared_ptr<Avatar> unit,
glm::vec2 destcell);

protected:
std::vector<std::shared_ptr<Avatar>> m_AvatarArray;
std::unordered_map<std::shared_ptr<Avatar>, glm::vec2> unitArrayAndLocation;
void assignOrderToMyAvatar(std::shared_ptr<Avatar> unit);
void updateTileWhileAvatarMoving(std::shared_ptr<Avatar> unit);

private:
std::vector<std::shared_ptr<Avatar>> m_AvatarArray;
std::unordered_map<std::shared_ptr<Avatar>, glm::vec2> unitArrayAndLocation;
std::shared_ptr<NemesisManager> m_NemesisManager =
std::make_shared<NemesisManager>();
std::shared_ptr<AvatarNavigator> m_Navigator =
Expand Down
17 changes: 10 additions & 7 deletions include/Scene/TutorialScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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<CursorClass> m_Cursor = std::make_shared<CursorClass>();
Grid testGrid;
std::shared_ptr<EnemyPlayer> m_Enemy = std::make_shared<EnemyPlayer>(SceneMode::TUTORIAL);
std::shared_ptr<EnemyScripts> m_EnemyScripts = std::make_shared<EnemyScripts>();
std::shared_ptr<EnemyPlayer> m_Enemy =
std::make_shared<EnemyPlayer>(SceneMode::TUTORIAL);
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;
Expand Down
10 changes: 3 additions & 7 deletions src/Enemy/Enemy.cpp
Original file line number Diff line number Diff line change
@@ -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() {}
73 changes: 30 additions & 43 deletions src/Mechanics/AvatarManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Avatar> unit) {
if (unit->getID().getHouseType() == HouseType::MY) {
void AvatarManager::assignMoveOrderToAvatar(std::shared_ptr<Avatar> 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> 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> 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<Avatar> 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> avatar) {
Expand Down

0 comments on commit da219e9

Please sign in to comment.