Skip to content

Commit

Permalink
overlaps
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed May 31, 2024
1 parent ac99a1c commit 319a91c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
4 changes: 2 additions & 2 deletions include/Scene/TutorialScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ class TutorialScene : public Scene {
private:
void stageStart();
void stageUpdate();
// update
// update stage
void stage1Update();
void stage2Update();
void stage3Update();
void stage4Update();
void stageFinalUpdate();
// init
// init stage
void initStage2();
void initStage3();
void initStage4();
Expand Down
10 changes: 5 additions & 5 deletions include/Util/Prop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ class Prop : public Structure {
Prop(bool selectable = false)
: Structure(selectable) {}
~Prop() override {}
void Start(glm::vec2 width) override {
m_width = width;
void Start(glm::vec2 size) override {
m_Size = size;
this->SetAttachVisible(true);
SetZIndex(8);
m_HighLight.SetZIndex(10);
Expand All @@ -37,9 +37,9 @@ class Prop : public Structure {
m_Transform.translation = m_DrawLocation;
}
bool ifOverlaps(glm::vec2 cell) {
if ((cell.x > getLocationCell().x - m_width.x &&
if ((cell.x > getLocationCell().x - m_Size.x &&
cell.x < getLocationCell().x) &&
(cell.y > getLocationCell().y - m_width.y &&
(cell.y > getLocationCell().y - m_Size.y &&
cell.y < getLocationCell().y)) {
return true;
}
Expand All @@ -51,7 +51,7 @@ class Prop : public Structure {
}

private:
glm::vec2 m_width = {1, 1};
glm::vec2 m_Size = {1, 1};
glm::vec2 m_highlightOffset = {0, 0};
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_PROP_HPP
30 changes: 9 additions & 21 deletions src/Scene/TutorialScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
void TutorialScene::Start() {

LOG_TRACE("Start");
m_Map->Init(100, 100);
m_Map->Init(MapBinReader::readBin("../assets/map/ore-lord/map.bin", 64, 64),
64, 64);
m_GameObjectManager->Start(m_Map);
m_EnemyObjectManager->Start(m_Map);
m_UI->Start(m_Map, m_GameObjectManager);
Expand All @@ -15,16 +16,7 @@ void TutorialScene::Start() {
m_SceneCamera->Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)),
MapUtil::CellCoordToGlobal(glm::vec2(100, 100)));

// m_EnemyScripts->Start(m_Enemy,m_GameObjectManager,
// m_EnemyObjectManager, m_Map);

m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {5, 5});
// combat test
// m_EnemyObjectManager->spawn(m_Map, UnitType::INFANTRY, HouseType::ENEMY,
// {6, 6});
// m_EnemyObjectManager->spawn(m_Map, UnitType::BARRACKS, HouseType::ENEMY,
// {10, 10});

stageStart();
}
void TutorialScene::Update() {
Expand Down Expand Up @@ -165,7 +157,7 @@ void TutorialScene::initStage3() {
std::make_unique<Util::Image>("../assets/sprites/Task/Task3.png"));

m_cellProp->setHighLightImage("../assets/sprites/Task/Task_Cell_Text3.png");
m_cellProp->setScale({2, 2});
m_cellProp->setScale({1, 1});
m_cellProp->setObjectLocation({850, 850}, 0);
m_cellProp->Start({4, 4});
m_stage = TutorialStages::STAGE3;
Expand All @@ -174,15 +166,16 @@ void TutorialScene::initStage3() {
void TutorialScene::stage3Update() {
m_PlayerObjectivesText->Draw();
m_cellProp->Update();
int avatarCount = 0;
int avataroverlapscount = 0;
for (auto i : m_GameObjectManager->getAvatarManager()->getAvatarArray()) {
if (i->getHouseType() == HouseType::MY) {
if (m_cellProp->ifOverlaps(i->getMoving()->getCurrentCell())) {
avatarCount++;
avataroverlapscount++;
}
}
}
if (avatarCount >= 4 || Util::Input::IsKeyDown(Util::Keycode::DEBUG_KEY)) {
if (avataroverlapscount >= 4 ||
Util::Input::IsKeyDown(Util::Keycode::DEBUG_KEY)) {
// change next stage's text&prop here
initStage4();
}
Expand All @@ -204,13 +197,8 @@ void TutorialScene::initStage4() {
void TutorialScene::stage4Update() {
m_PlayerObjectivesText->Draw();
m_cellProp->Update();
int enemy_deadcount = 0;
for (auto i : m_EnemyObjectManager->getAvatarManager()->getAvatarArray()) {
if (*i->getHealth()->getLivingStatus() == LivingStatus::DEAD) {
enemy_deadcount++;
}
}
if (enemy_deadcount >= 3 ||
if (m_EnemyObjectManager->getAvatarManager()->getAvatarArray().size() ==
0 ||
Util::Input::IsKeyDown(Util::Keycode::DEBUG_KEY)) {
initFinalStage();
}
Expand Down

0 comments on commit 319a91c

Please sign in to comment.