From 5b733e03e4e0842fb9527bb8587b377e417d86c4 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sun, 16 Jun 2024 12:25:20 +0800 Subject: [PATCH 1/7] fix map boundary --- include/Map/Map.hpp | 45 ++++++++++++++++++++------------- src/Mechanics/AvatarManager.cpp | 5 ++++ 2 files changed, 32 insertions(+), 18 deletions(-) diff --git a/include/Map/Map.hpp b/include/Map/Map.hpp index b6cff4b2..48a92851 100644 --- a/include/Map/Map.hpp +++ b/include/Map/Map.hpp @@ -55,35 +55,44 @@ class MapClass : public Core::Drawable { getTileByCellPosition(position)->removeStructure(); } - glm::vec2 findEnemyInRange(int attackRange,glm::vec2 myCell,HouseType myHouse){ - glm::vec2 NullPos={-1,-1}; - int x,y=1; - int r=1; - for(r=1;rifEnemyAtTile(myHouse)){ - return {myCell.x+x,myCell.y+y}; + glm::vec2 findEnemyInRange(int attackRange, glm::vec2 myCell, + HouseType myHouse) { + glm::vec2 NullPos = {-1, -1}; + int x, y = 1; + int r = 1; + for (r = 1; r < attackRange; r++) { + y = r; + for (x = -1 * r; x < r; x++) { + if (getTileByCellPosition({myCell.x + x, myCell.y + y}) + ->ifEnemyAtTile(myHouse)) { + return {myCell.x + x, myCell.y + y}; } } - for(y=r-1;y>=-1*r;y--){ - if(getTileByCellPosition({myCell.x+x,myCell.y+y})->ifEnemyAtTile(myHouse)){ - return {myCell.x+x,myCell.y+y}; + for (y = r - 1; y >= -1 * r; y--) { + if (getTileByCellPosition({myCell.x + x, myCell.y + y}) + ->ifEnemyAtTile(myHouse)) { + return {myCell.x + x, myCell.y + y}; } } - for(x=r-1;x>-1*r;x--){ - if(getTileByCellPosition({myCell.x+x,myCell.y+y})->ifEnemyAtTile(myHouse)){ - return {myCell.x+x,myCell.y+y}; + for (x = r - 1; x > -1 * r; x--) { + if (getTileByCellPosition({myCell.x + x, myCell.y + y}) + ->ifEnemyAtTile(myHouse)) { + return {myCell.x + x, myCell.y + y}; } } - for(y=-1*r+1;yifEnemyAtTile(myHouse)){ - return {myCell.x+x,myCell.y+y}; + for (y = -1 * r + 1; y < r; y++) { + if (getTileByCellPosition({myCell.x + x, myCell.y + y}) + ->ifEnemyAtTile(myHouse)) { + return {myCell.x + x, myCell.y + y}; } } } return NullPos; } + + int getWidth() { return m_MapWdith; } + int getHeight() { return m_MapHeight; } + protected: void InitGrid(); diff --git a/src/Mechanics/AvatarManager.cpp b/src/Mechanics/AvatarManager.cpp index 0c35811d..211c91f5 100644 --- a/src/Mechanics/AvatarManager.cpp +++ b/src/Mechanics/AvatarManager.cpp @@ -111,6 +111,11 @@ void AvatarManager::assignOrderToMyAvatar(std::shared_ptr avatar) { auto destcell = MapUtil::GlobalCoordToCellCoord( MapUtil::ScreenToGlobalCoord(Util::Input::GetCursorPosition())); + if (destcell.x < 0 || destcell.y < 0 || + destcell.x > m_Map->getWidth() / 2 - 1 || + destcell.y > m_Map->getHeight() / 2 - 1) { + return; + } assignMoveOrderToAvatar(avatar, destcell); assignAttackOrderToAvatar(avatar, destcell); From 2cba26bc6e29f1e1800966323007c9bf3f02567f Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sun, 16 Jun 2024 12:31:08 +0800 Subject: [PATCH 2/7] l --- include/Map/Tile.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/Map/Tile.hpp b/include/Map/Tile.hpp index ccb1c9ac..bacd7c85 100644 --- a/include/Map/Tile.hpp +++ b/include/Map/Tile.hpp @@ -74,7 +74,7 @@ class TileClass { auto it = m_Avatars.begin() + i; m_Avatars.erase(it); i--; - + // fix this if (m_Avatars.size() < 4) { setWalkable(true); } From 8500298cd48e174538e44c485bd50145bfa3002b Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sun, 16 Jun 2024 13:46:18 +0800 Subject: [PATCH 3/7] un --- src/Mechanics/UnitManager.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/Mechanics/UnitManager.cpp b/src/Mechanics/UnitManager.cpp index f67b7698..78d16429 100644 --- a/src/Mechanics/UnitManager.cpp +++ b/src/Mechanics/UnitManager.cpp @@ -4,7 +4,9 @@ #include "Mechanics/UnitManager.hpp" void UnitManager::spawnToWayPoint(UnitType unit, HouseType house) { - + if (!m_StructureManager->getStructureArray()->ifBarrackBuilt()) { + return; + } switch (unit) { case UnitType::INFANTRY: { auto avatar = std::make_shared(house); @@ -41,42 +43,44 @@ void UnitManager::spawn(UnitType unit, HouseType house, glm::vec2 cellPos) { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); - structure->setWaypointLocationByCellCoord({cellPos.x+2,cellPos.y+2}); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); + structure->setWaypointLocationByCellCoord( + {cellPos.x + 2, cellPos.y + 2}); break; } case UnitType::ORE_REF: { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); break; } case UnitType::POWER_PLANT: { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); break; } case UnitType::WAR_FACT: { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - structure->setWaypointLocationByCellCoord({cellPos.x+2,cellPos.y-2}); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); + structure->setWaypointLocationByCellCoord( + {cellPos.x + 2, cellPos.y - 2}); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); break; } case UnitType::ADV_POWER_PLANT: { auto structure = std::make_shared(house); auto globalPos = MapUtil::CellCoordToGlobal(cellPos); structure->Start(globalPos); - m_StructureManager->getStructureArray()->buildNewStructure( - structure, true); + m_StructureManager->getStructureArray()->buildNewStructure(structure, + true); break; } case UnitType::INFANTRY: { @@ -94,8 +98,8 @@ void UnitManager::spawn(UnitType unit, HouseType house, glm::vec2 cellPos) { break; } } - if(unit!=UnitType::NONE){ - addUnitConstructCount(unit,1); + if (unit != UnitType::NONE) { + addUnitConstructCount(unit, 1); } } From d1ae9ecd4479a7a781f59b69dfc7311df1970378 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sun, 16 Jun 2024 14:20:15 +0800 Subject: [PATCH 4/7] loop kina fix --- src/Mechanics/AvatarNavigator.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Mechanics/AvatarNavigator.cpp b/src/Mechanics/AvatarNavigator.cpp index 1ef2c01e..4e30cb0a 100644 --- a/src/Mechanics/AvatarNavigator.cpp +++ b/src/Mechanics/AvatarNavigator.cpp @@ -6,6 +6,7 @@ std::deque AvatarNavigator::findPath(glm::vec2 currentcell, glm::vec2 destinationcell) { + glm::vec2 ogcell = currentcell; std::deque dirQue; if (m_Map->getTileByCellPosition(destinationcell)->getWalkable() == false) { return dirQue; @@ -14,7 +15,7 @@ std::deque AvatarNavigator::findPath(glm::vec2 currentcell, Side whichSideToTouchObstacle = randomlyChooseSide(); int count = 0; - while (currentcell != destinationcell && count < 100) { + while (currentcell != destinationcell && count < 10) { printf("(findPath)\n"); count++; std::vector staightDirque; @@ -48,6 +49,9 @@ std::deque AvatarNavigator::findPath(glm::vec2 currentcell, for (auto i : movealong) { dirQue.push_back(i); currentcell = PathUtility::getNextCellByCurrent(i, currentcell); + if (ogcell == currentcell) { + return dirQue; + } } } } @@ -58,6 +62,7 @@ std::vector AvatarNavigator::moveAlongsideObstacle(Side side, glm::vec2 currentcell, MoveDirection currentdir, glm::vec2 destinationcell) { + glm::vec2 ogcell = currentcell; std::vector path; while (!canResumeWalkingStraight(currentcell, destinationcell)) { @@ -74,7 +79,7 @@ AvatarNavigator::moveAlongsideObstacle(Side side, glm::vec2 currentcell, path.push_back(currentdir); currentcell = PathUtility::getNextCellByCurrent(currentdir, currentcell); - if (path.size() > 30) { + if (path.size() > 30 || ogcell == currentcell) { return path; } } From 0cc00a3c3db96569e3456a3d82d04f89529d78d7 Mon Sep 17 00:00:00 2001 From: jonylu7 <60732316+jonylu7@users.noreply.github.com> Date: Sun, 16 Jun 2024 14:22:21 +0800 Subject: [PATCH 5/7] Update README.md --- README.md | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 99d43085..7f3ea339 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,6 @@ # Purpose - +讓我認識到....不要選一個系統太複雜的遊戲 # Goal # Methodology - -## Packages used -1. openGL version 4.1 -2. PTSD game Engine -3. SDL2 -4. Imgui \ No newline at end of file +肝、血和淚 From 47ca8d15f0791973246bc3ea64f72f98cce22602 Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Sun, 16 Jun 2024 21:50:33 +0800 Subject: [PATCH 6/7] fix trans location --- src/Scene/TutorialScene.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Scene/TutorialScene.cpp b/src/Scene/TutorialScene.cpp index aa0c348d..ba6fc3a5 100644 --- a/src/Scene/TutorialScene.cpp +++ b/src/Scene/TutorialScene.cpp @@ -71,7 +71,7 @@ void TutorialScene::stageStart() { m_PlayerObjectivesText->SetVisible(true); m_PlayerObjectivesText->setMovingRelativeToCamera(false); Util::Transform trans; - trans.translation = {40, 5}; + trans.translation = {840, 5}; trans.scale = {0.7, 0.7}; m_PlayerObjectivesText->SetTransform(trans); From 440a237a62a1ec8e38e52da251a7a5ad6cb495ca Mon Sep 17 00:00:00 2001 From: jonylu7 Date: Mon, 17 Jun 2024 15:49:55 +0800 Subject: [PATCH 7/7] t --- src/Scene/TutorialScene.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Scene/TutorialScene.cpp b/src/Scene/TutorialScene.cpp index ba6fc3a5..325a93ab 100644 --- a/src/Scene/TutorialScene.cpp +++ b/src/Scene/TutorialScene.cpp @@ -71,7 +71,8 @@ void TutorialScene::stageStart() { m_PlayerObjectivesText->SetVisible(true); m_PlayerObjectivesText->setMovingRelativeToCamera(false); Util::Transform trans; - trans.translation = {840, 5}; + + trans.translation = {540, 5}; trans.scale = {0.7, 0.7}; m_PlayerObjectivesText->SetTransform(trans);