Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Apr 13, 2024
1 parent 27d58ce commit 0bd9dff
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 20 deletions.
21 changes: 11 additions & 10 deletions include/Mechanics/FindValidPathToDest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,13 @@
#include <random>
class FindValidPathToDest {


private:
glm::vec2 m_destinationCell;
glm::vec2 m_nextCell;
glm::vec2 m_currentCell;
MoveDirection m_currentDir = MoveDirection::IDLE;

std::shared_ptr<MapClass> m_Map = std::make_shared<MapClass>();
std::deque<MoveDirection> m_dirQue;

public:
FindValidPathToDest(){};
Expand All @@ -42,7 +40,6 @@ class FindValidPathToDest {
MoveDirection getCurrentDir() { return m_currentDir; }
glm::vec2 getNextCell() { return m_nextCell; }


Side randomlyChooseSide() {
// Create a random number generator engine
std::random_device rd; // Obtain a random seed from the hardware
Expand All @@ -67,15 +64,19 @@ class FindValidPathToDest {

public:
std::deque<MoveDirection> findPath(glm::vec2 currentcell,
glm::vec2 destinationcell) ;
glm::vec2 destinationcell);
MoveDirection findNewDirWhenCrash(Side side, glm::vec2 currentcell,
MoveDirection currentdir) ;
bool isTouchedByObstacle(Side side,glm::vec2 currentcell,MoveDirection currentdir);

std::vector<MoveDirection> moveAlongsideObstacle(Side side, glm::vec2 currentcell,
MoveDirection currentdir,glm::vec2 destinationcell);
MoveDirection currentdir);
bool isTouchedByObstacle(Side side, glm::vec2 currentcell,
MoveDirection currentdir);

std::vector<MoveDirection> moveAlongsideObstacle(Side side,
glm::vec2 currentcell,
MoveDirection currentdir,
glm::vec2 destinationcell);
bool findStraightPath(glm::vec2 currentcell, glm::vec2 destinationcell,
std::vector<MoveDirection> *path);
bool canResumeWalkingStraight(glm::vec2 currentcell, glm::vec2 destinationcell);
bool canResumeWalkingStraight(glm::vec2 currentcell,
glm::vec2 destinationcell);
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_FINDVALIDPATHTODEST_HPP
10 changes: 6 additions & 4 deletions include/Unit/Avatar.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#define PRACTICALTOOLSFORSIMPLEDESIGN_DUMMY_HPP

#include "Map/MapUtility.hpp"
#include "Unit/PathfindingUnit.hpp"
#include "Unit/AttackAndDamageUnit.hpp"
#include "Unit/PathfindingUnit.hpp"

class Avatar : public PathfindingUnit,
public AttackAndDamageUnit,
Expand All @@ -28,8 +28,8 @@ class Avatar : public PathfindingUnit,
setNextCell(destination);

setMovementSpeed(4);
m_currentMode=UnitMode::MOVE;
m_Transform.scale={0.5,0.5};
m_currentMode = UnitMode::MOVE;
m_Transform.scale = {0.5, 0.5};
}
virtual void aliveUpdate() {
if (walkTowardNextCell() || b_justStarted) {
Expand All @@ -42,12 +42,14 @@ class Avatar : public PathfindingUnit,
printf("(aliveUpdate) getting new dir\n");
}
// m_wayPointUnit.Update();

SetVisible(true);
m_Transform.translation = getCurrentLocation();

Draw();

printf("Avatar cell={%d,%d}\n",getCurrentLocation().x,getCurrentLocation().y);
printf("Avatar cell={%d,%d}\n", getCurrentLocation().x,
getCurrentLocation().y);
printf("-----------avatar------------------\n");
}

Expand Down
13 changes: 7 additions & 6 deletions src/Scene/DefaultScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,16 @@ void DefaultScene::Start() {

// 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);

// m_hunter->Start({20, 9});
// m_runner->Start({9, 10});
// m_hunter->setTarget(m_runner);
// m_runner->setBeingChase(m_hunter);
}

void DefaultScene::Update() {
// m_hunter->Update();
// m_runner->Update();
// m_hunter->Update();
// m_runner->Update();

m_GameObjectManager->Update();

Expand Down

0 comments on commit 0bd9dff

Please sign in to comment.