Skip to content

Commit

Permalink
fix tutorial scene debug key
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed May 25, 2024
1 parent d97e124 commit 2d09d33
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 107 deletions.
Binary file modified assets/.DS_Store
Binary file not shown.
Binary file added assets/explosion/nuke.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 27 additions & 15 deletions include/Mechanics/BuiltStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,29 +77,32 @@ class BuiltStructure {
m_BuiltStructure.push_back(structure);
}

void updateAvatarSpawnLocation() {
public:
// glm::vec2 getEnemyBarrackCell() { return m_EnemyBarrackCell; }
// glm::vec2 getEnemyWayPointCell() { return m_EnemyWayPointCell; }
glm::vec2 getPlayerBarrackSpawnCell() {
for (auto i : m_BuiltStructure) {
if (std::dynamic_pointer_cast<Barracks>(i)) {
m_PlayerBarrackCell =
MapUtil::GlobalCoordToCellCoord(i->GetObjectLocation());
m_PlayerWayPointCell = MapUtil::GlobalCoordToCellCoord(
glm::vec2 ogSpawnPoint = i->GetObjectLocation();
while (!m_Map->getTileByCellPosition(ogSpawnPoint)
->getWalkable()) {
ogSpawnPoint.x -= 1;
}
return ogSpawnPoint;
}
}
}
glm::vec2 getPlayerBarrackWayPointCell() {
for (auto i : m_BuiltStructure) {
if (std::dynamic_pointer_cast<Barracks>(i)) {
return MapUtil::GlobalCoordToCellCoord(
std::dynamic_pointer_cast<Barracks>(i)
->GetWayPointLocation());
}
}
return m_PlayerWayPointCell;
}

glm::vec2 getPlayerBarrackCell() {
return {m_PlayerBarrackCell.x - 1, m_PlayerBarrackCell.y - 1};
}
// glm::vec2 getPlayerWayPointCell() { return m_PlayerWayPointCell; }

public:
// glm::vec2 getEnemyBarrackCell() { return m_EnemyBarrackCell; }
// glm::vec2 getEnemyWayPointCell() { return m_EnemyWayPointCell; }
glm::vec2 getPlayerBarrackSpawnCell() { return m_PlayerBarrackCell; }
glm::vec2 getPlayerBarrackWayPointCell() { return m_PlayerWayPointCell; }

bool ifBarrackBuilt() {
for (auto i : m_BuiltStructure) {
if (i->getID().getUnitType() == UnitType::BARRACKS) {
Expand All @@ -125,6 +128,15 @@ class BuiltStructure {
return false;
}

bool ifOreRefinaryBuilt() {
for (auto i : m_BuiltStructure) {
if (i->getID().getUnitType() == UnitType::ORE_REF) {
return true;
}
}
return false;
}

private:
std::shared_ptr<MapClass> m_Map = std::make_shared<MapClass>();
std::vector<std::shared_ptr<Structure>> m_BuiltStructure;
Expand Down
12 changes: 4 additions & 8 deletions include/Mechanics/UnitManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,19 @@ class UnitManager : public Player {
}
}

void spawnToWayPoint(std::shared_ptr<MapClass> m_Map, UnitType unit,
HouseType house) {
void spawnToWayPoint(UnitType unit, HouseType house) {

switch (unit) {
case UnitType::INFANTRY: {
auto avatar = std::make_shared<Infantry>(house);
m_StructureManager->getStructureArray()
->updateAvatarSpawnLocation();
if (m_StructureManager->getStructureArray()
->getPlayerBarrackCell()
->getPlayerBarrackSpawnCell()
.x == -1) {
return;
}

avatar->Start(m_StructureManager->getStructureArray()
->getPlayerBarrackCell());
->getPlayerBarrackSpawnCell());

m_AvatarManager->assignMoveOrderToAvatar(
avatar, {m_StructureManager->getStructureArray()
Expand All @@ -106,8 +103,7 @@ class UnitManager : public Player {
}
}
}
void spawn(std::shared_ptr<MapClass> m_Map, UnitType unit, HouseType house,
glm::vec2 cellPos) {
void spawn(UnitType unit, HouseType house, glm::vec2 cellPos) {
// 缺檢查敵方擁有建築的位置,並重生在該處
switch (unit) {
case UnitType::BARRACKS: {
Expand Down
6 changes: 5 additions & 1 deletion include/Scene/TutorialScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@

#define DEBUG_KEY P


enum class TutorialStages { STAGE1, STAGE2, STAGE3, STAGE4 };

class TutorialScene : public Scene {
enum class Stages { STAGE1, STAGE2, STAGE3, STAGE4 };

public:
TutorialScene(){};
~TutorialScene(){};
Expand All @@ -31,6 +31,10 @@ class TutorialScene : public Scene {
void stage2Update();
void stage3Update();
void stage4Update();
void initStage2();
void initStage3();
void initStage4();
void initFinalStage();

private:
SpriteSheet m_SpriteSheet;
Expand Down
4 changes: 2 additions & 2 deletions src/AI/EnemyScripts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void EnemyScripts::UpdateSpawnScript(SpawnMode spawnMode) {
return;
}
m_GameObjectManager->spawn(
m_Map, m_selectedBuildingType, HouseType::ENEMY,
m_selectedBuildingType, HouseType::ENEMY,
{m_baseCell.x + constructCountX, m_baseCell.y + constructCountY});
m_EnemyObjectManager->addUnitConstructCount(m_selectedBuildingType, 1);
setCost(0, SpawnMode::BUILDINGS);
Expand All @@ -193,7 +193,7 @@ void EnemyScripts::UpdateSpawnScript(SpawnMode spawnMode) {
return;
}
if (m_selectedAvatarType == UnitType::INFANTRY) {
m_GameObjectManager->spawnToWayPoint(m_Map, m_selectedAvatarType,
m_GameObjectManager->spawnToWayPoint(m_selectedAvatarType,
HouseType::ENEMY);
setCost(0, SpawnMode::AVATAR);
setCDTime(0.f, SpawnMode::AVATAR);
Expand Down
5 changes: 2 additions & 3 deletions src/Scene/DefaultScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ void DefaultScene::Update() {
->getStructureArray()
->getBuiltStructureArray());
if (m_UI->getIfUnitReadyToSpawn()) {
// what the fuck
m_GameObjectManager->getAvatarManager()->AppendAvatar(
m_UI->getUnitFromUI());
m_GameObjectManager->spawnToWayPoint(
m_UI->getUnitFromUI()->getID().getUnitType(), HouseType::MY);
}
}
50 changes: 20 additions & 30 deletions src/Scene/SandBoxScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,61 +58,51 @@ void SandBoxScene::Update() {
void SandBoxScene::stageStart() {
switch (m_stage) {
case Stages::STAGE1: {
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 5});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 6});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 7});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 8});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 9});
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 5});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 6});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 7});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 8});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 9});
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 5});
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 6});
m_stage = Stages::END;
break;
}
case Stages::STAGE2: {
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 5});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 6});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 5});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 6});

m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 5});
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 6});
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 7});
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 8});
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 9});
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 10});
m_stage = Stages::END;
break;
}
case Stages::STAGE3: {
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 5});
m_GameObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::MY,
{5, 6});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 5});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 6});

m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 5});
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{10, 6});
m_stage = Stages::END;
break;
}
case Stages::STAGE4: {
for (int i = 0; i < 50; i++) {
m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY,
HouseType::ENEMY,
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{30 + i / 5, 5 + i % 5});
}
m_stage = Stages::END;
Expand Down
Loading

0 comments on commit 2d09d33

Please sign in to comment.