Skip to content

Commit

Permalink
Merge pull request #91 from ntut-Tu/main
Browse files Browse the repository at this point in the history
overlaps  fixed
  • Loading branch information
jonylu7 authored Jun 13, 2024
2 parents 0615b20 + d8864d0 commit 5da849c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
15 changes: 6 additions & 9 deletions include/AI/AIGroupCommander.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,19 @@ class AIGroupCommander {
glm::vec2 targetCell = {-1.f,-1.f};
//issue: empty group should delete before this
if(false&&static_cast<int>(m_offensiveGroup.size())>=static_cast<int>(m_PlayerUnitManager->getAvatarManager()->getAvatarArray().size())){
if(!m_PlayerUnitManager->getStructureManager()->getStructureArray()->getBuiltStructureArray().empty()){
targetCell=m_PlayerUnitManager->getStructureManager()->getStructureArray()->getBuiltStructureArray().front()->getCurrentLocationInCell();
}
for(auto i : m_PlayerUnitManager->getStructureManager()->getStructureArray()->getBuiltStructureArray()){
if(unit->getDistance(i->getCurrentLocationInCell())<unit->getDistance(targetCell)){
//attack
targetCell = i->getCurrentLocationInCell();
}
}
targetCell = m_Map->findEnemyInRange(200,unit->getCurrentLocationInCell(),HouseType::ENEMY);
//attack
m_AIAvatarManager->assignAttackOrderToAvatar(unit,targetCell,HouseType::ENEMY);
}else{
if(!m_PlayerUnitManager->getAvatarManager()->getAvatarArray().empty()){
targetCell=m_PlayerUnitManager->getAvatarManager()->getAvatarArray().front()->getCurrentLocationInCell();
}
for(auto i : m_PlayerUnitManager->getAvatarManager()->getAvatarArray()){
if(i->getDistance(unit->getCurrentLocationInCell())<unit->getDistance(targetCell)){
//attack
if(m_AIAvatarManager->ifAvatarHasNemesis(m_Map->getTileByCellPosition(targetCell)->getAvatars().front())){
continue;
}
targetCell = i->getCurrentLocationInCell();
}
}
Expand Down
5 changes: 0 additions & 5 deletions include/Map/MapUtility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,5 @@ class MapUtil {
int _y = location.y / CELL_SIZE.y;
return {_x * CELL_SIZE.x, _y * CELL_SIZE.y};
}
static float findDistance(glm::vec2 cell1, glm::vec2 cell2) {
float dx = cell2.x - cell1.x;
float dy = cell2.y - cell1.y;
return sqrt(dx * dx + dy * dy);
}
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_MAPUTILITY_HPP
3 changes: 3 additions & 0 deletions include/Mechanics/AvatarManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class AvatarManager {
bool ifAvatarHasNemesis(std::shared_ptr<Avatar> unit){
return m_NemesisManager->ifAvatarHasNemesis(unit);
}
bool ifAvatarHasHunter(std::shared_ptr<Avatar> unit){
return m_NemesisManager->ifAvatarHasNemesis(unit);
}
glm::vec2 getAvatarNemesisCell(std::shared_ptr<Avatar> unit){
return m_NemesisManager->getNemesisCell(unit);
}
Expand Down
4 changes: 3 additions & 1 deletion include/Structure/Structure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,9 @@ class Structure : public Util::GameObject, public Selectable, public Huntable {
glm::vec2 getCurrentLocationInCell() override {
return getAbsoluteOccupiedArea()[0];
};

glm::vec2 getTopRightCell(){
return getAbsoluteOccupiedArea()[-1];
};
protected:
float m_ElectricPower;
float m_BuildingTime;
Expand Down
8 changes: 4 additions & 4 deletions include/Util/Prop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class Prop : public Structure {
m_Transform.translation = m_DrawLocation;
}
bool ifOverlaps(glm::vec2 cell) {
if ((cell.x > getLocationCell().x - m_Size.x &&
cell.x < getLocationCell().x) &&
(cell.y > getLocationCell().y - m_Size.y &&
cell.y < getLocationCell().y)) {
if ((cell.x >= getLocationCell().x - m_Size.x &&
cell.x <= getLocationCell().x) &&
(cell.y >= getLocationCell().y - m_Size.y &&
cell.y <= getLocationCell().y)) {
return true;
}
return false;
Expand Down
2 changes: 1 addition & 1 deletion src/Scene/TutorialScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ void TutorialScene::initStage3() {
m_cellProp->setHighLightImage("../assets/sprites/Task/Task_Cell_Text3.png");
m_cellProp->setScale({1, 1});
m_cellProp->setObjectLocation({850, 850}, 0);
m_cellProp->Start({4, 4});
m_cellProp->Start({2, 2});
m_stage = TutorialStages::STAGE3;
}

Expand Down

0 comments on commit 5da849c

Please sign in to comment.