From 82d7fd045b93c275af732451149846171903629d Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sat, 30 Mar 2024 17:18:01 +0800 Subject: [PATCH] merge and run --- include/Unit/Avatar.hpp | 26 ++++++++++++++------------ include/Unit/PathfindingUnit.hpp | 3 --- src/Scene/DefaultScene.cpp | 8 ++++---- 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/Unit/Avatar.hpp b/include/Unit/Avatar.hpp index 07cbce67..7eeadceb 100644 --- a/include/Unit/Avatar.hpp +++ b/include/Unit/Avatar.hpp @@ -4,15 +4,12 @@ #ifndef PRACTICALTOOLSFORSIMPLEDESIGN_DUMMY_HPP #define PRACTICALTOOLSFORSIMPLEDESIGN_DUMMY_HPP +#include "Map/MapUtility.hpp" #include "Unit/AttackAndDamageUnit.hpp" -#include "Unit/FindValidPathToDest.hpp" #include "Unit/PathfindingUnit.hpp" - +enum class UnitMode { DEAD, MOVE, IDLE, MOVE_ATTACK, ALIVE }; class Avatar : public PathfindingUnit, public AttackAndDamageUnit { - enum class UnitMode { DEAD, MOVE, IDLE, MOVE_ATTACK }; - - protected: std::shared_ptr m_Image; @@ -28,8 +25,7 @@ class Avatar : public PathfindingUnit, public AttackAndDamageUnit { virtual void Start(glm::vec2 destination) { // destination = Barrack's // waypointLocation // setCurrentCell() //CurrentCell = Structure's Location - this->SetDrawable( - customizeImage()); + this->SetDrawable(customizeImage()); SetVisible(true); m_grid.SetActivate(true); setCurrentCell(destination); @@ -53,8 +49,10 @@ class Avatar : public PathfindingUnit, public AttackAndDamageUnit { cursorSetNewDest(); printf("-----------------------------\n"); } - virtual void customizeUpdate(){} - virtual std::shared_ptr customizeImage(){ return std::make_unique("../assets/sprites/capybara.png");} + virtual void customizeUpdate() {} + virtual std::shared_ptr customizeImage() { + return std::make_unique("../assets/sprites/capybara.png"); + } virtual void Update() override { switch (m_currentMode) { case (UnitMode::DEAD): { @@ -81,11 +79,15 @@ class Avatar : public PathfindingUnit, public AttackAndDamageUnit { Util::Input::GetCursorPosition()))); } } - float getDistance(glm::vec2 cell){ - return sqrt(pow(cell.x-getCurrentCell().x,2)+pow(cell.y-getCurrentCell().y,2)); + float getDistance(glm::vec2 cell) { + return sqrt(pow(cell.x - getCurrentCell().x, 2) + + pow(cell.y - getCurrentCell().y, 2)); } - void DEBUG_printCurrentMoveDirection(MoveDirection Dir){ + UnitMode getUnitMode() { return m_currentMode; } + void setUnitMode(UnitMode mode) { m_currentMode = mode; } + + void DEBUG_printCurrentMoveDirection(MoveDirection Dir) { switch (Dir) { case MoveDirection::RIGHT: { printf("(DEBUG)Avatar DIR:Right\n"); diff --git a/include/Unit/PathfindingUnit.hpp b/include/Unit/PathfindingUnit.hpp index ebede9cf..5ad87f8e 100644 --- a/include/Unit/PathfindingUnit.hpp +++ b/include/Unit/PathfindingUnit.hpp @@ -6,7 +6,6 @@ #define PRACTICALTOOLSFORSIMPLEDESIGN_PATHFINDINGUNIT_HPP #include "Grid.hpp" #include "Line.hpp" - #include "Map/Tile.hpp" #include "Util/GameObject.hpp" #include "Util/Transform.hpp" @@ -53,8 +52,6 @@ class PathfindingUnit : public Util::GameObject { }; virtual ~PathfindingUnit(){}; - // - UnitMode getUnitMode(){return m_currentMode;} void setDestinationCell(int x, int y) { this->m_destinationCell = {glm::vec2(x, y)}; } diff --git a/src/Scene/DefaultScene.cpp b/src/Scene/DefaultScene.cpp index 403670b6..41d366d1 100644 --- a/src/Scene/DefaultScene.cpp +++ b/src/Scene/DefaultScene.cpp @@ -32,10 +32,10 @@ void DefaultScene::Start() { m_Player->setTotalCurrency(5000); -// m_hunter->setCurrentCell({20,10}); -// m_runner->setCurrentCell({10,10}); - m_hunter->Start({20,9},m_Map); - m_runner->Start({9,10},m_Map); + // m_hunter->setCurrentCell({20,10}); + // m_runner->setCurrentCell({10,10}); + m_hunter->Start({20, 9}); + m_runner->Start({9, 10}); m_hunter->setTarget(m_runner); m_runner->setBeingChase(m_hunter); }