-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from jonylu7/buttonUpdate
Unit update
- Loading branch information
Showing
18 changed files
with
273 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// | ||
// Created by nudle on 2024/3/28. | ||
// | ||
|
||
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_HUNTER_HPP | ||
#define PRACTICALTOOLSFORSIMPLEDESIGN_HUNTER_HPP | ||
#include "Avatar.hpp" | ||
#include "Runner.hpp" | ||
|
||
#define ATTACK_RANGE 7 | ||
|
||
class Hunter:public Avatar{ | ||
private: | ||
std::shared_ptr<Runner> m_target; | ||
glm::vec2 lastTargetCell; | ||
|
||
public: | ||
void setTarget(std::shared_ptr<Runner> m_target){this->m_target=m_target;} | ||
std::shared_ptr<Util::Image> customizeImage()override{ return std::make_unique<Util::Image>("../assets/sprites/Hunter.png");} | ||
void customizeUpdate() override; | ||
void attack(std::shared_ptr<Avatar> attackTarget){}; | ||
}; | ||
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_HUNTER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// Created by nudle on 2024/3/28. | ||
// | ||
|
||
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_RUNNER_HPP | ||
#define PRACTICALTOOLSFORSIMPLEDESIGN_RUNNER_HPP | ||
#include "Avatar.hpp" | ||
#define ATTACK_RANGE 7 | ||
|
||
class Runner : public Avatar{ | ||
private: | ||
bool b_beingChase= false; | ||
|
||
std::shared_ptr<Avatar> m_hunter; | ||
glm::vec2 lastTargetCell; | ||
std::vector<MoveDirection> dictionary = { | ||
MoveDirection::UP, MoveDirection::UP_RIGHT, | ||
MoveDirection::RIGHT, MoveDirection::DOWN_RIGHT, | ||
MoveDirection::DOWN, MoveDirection::DOWN_LEFT, | ||
MoveDirection::LEFT, MoveDirection::UP_LEFT}; | ||
enum class runMode{REASONABLE,LIDL_RANDOM,FULL_RANDOM}; | ||
int edgeCount=0; | ||
public: | ||
void setBeingChase(std::shared_ptr<Avatar> hunter); | ||
std::shared_ptr<Util::Image> customizeImage()override{ return std::make_unique<Util::Image>("../assets/sprites/Runner.png");} | ||
void customizeUpdate()override; | ||
MoveDirection findNewDir(MoveDirection Dir,int edgeCount); | ||
MoveDirection oppositeDir(MoveDirection Dir,runMode mode); | ||
glm::vec2 getNextCellByCurrentPlus3(MoveDirection currentdir,glm::vec2 currentcell,int n,int m) ; | ||
}; | ||
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_RUNNER_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// | ||
// Created by nudle on 2024/3/29. | ||
// | ||
|
||
#include "Unit/Hunter.hpp" | ||
|
||
void Hunter::customizeUpdate(){ | ||
glm::vec2 targetCell = m_target->getCurrentCell(); | ||
if(getDistance(targetCell)>ATTACK_RANGE-1 && lastTargetCell!=m_target->getCurrentCell()){ | ||
// glm::vec2 nextCell = getNextCellByCurrent(getDirByRelativeCells(getCurrentCell(),targetCell),getCurrentCell()); | ||
setNewDestination(m_target->getCurrentCell()); | ||
lastTargetCell=m_target->getCurrentCell(); | ||
// setNewDestination(nextCell); | ||
} | ||
else if(getDistance(targetCell)<ATTACK_RANGE-1 ){ | ||
setNewDestination(getCurrentCell()); | ||
lastTargetCell=getCurrentCell(); | ||
attack(m_target); | ||
} | ||
} |
Oops, something went wrong.