Skip to content

Commit

Permalink
win or failed
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Jun 14, 2024
1 parent b1ccea1 commit 782b1bd
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 56 deletions.
File renamed without changes
File renamed without changes
26 changes: 15 additions & 11 deletions include/Scene/MenuScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class MenuScene : public Scene {
m_BGM.Play();
}
if (Util::Input::IsKeyPressed(Util::Keycode::K)) {
m_BGM.LoadMedia("../assets/BGM/Jimmy_Scott-Sycamore_Trees.mp3");
m_BGM.Play();
}
if (Util::Input::IsKeyPressed(Util::Keycode::M)) {
m_CurrentMode = SceneMode::MAP;
Expand All @@ -47,22 +45,26 @@ class MenuScene : public Scene {
UIStatusType::UI_START) {
m_MenuUI.getUIStatus()->setUIStatusType(
UIStatusType::UI_DEFAULT);
m_BGM.Play();
m_CurrentMode = SceneMode::TUTORIAL;
}
if (Util::Input::IsKeyPressed(Util::Keycode::S)) {
m_CurrentMode = SceneMode::SANDBOX;
}
if (m_TutorialScene->getMissionAccomplishedUI()
}
if (m_CurrentMode == SceneMode::TUTORIAL &&
m_TutorialScene->getMissionAccomplishedUI()
->getUIStatus()
->getUIStatusType() == UIStatusType::UI_CONTINUE) {
m_CurrentMode = SceneMode::SKIRMISH;
}
m_MenuUI.getUIStatus()->setUIStatusType(UIStatusType::UI_DEFAULT);
m_SandBoxScene->setStage(true);
m_CurrentMode = SceneMode::SANDBOX;
}
if (m_CurrentMode==SceneMode::TUTORIAL&&m_TutorialScene->getMissionAccomplishedUI()
->getUIStatus()
->getUIStatusType() == UIStatusType::UI_CONTINUE) {
m_MenuUI.getUIStatus()->setUIStatusType(
UIStatusType::UI_DEFAULT);

if (m_CurrentMode == SceneMode::SANDBOX &&
m_SandBoxScene->getWonUI()->getUIStatus()->getUIStatusType() ==
UIStatusType::UI_RESTART) {
m_SandBoxScene->Start();
m_SandBoxScene->setStage(true);
m_CurrentMode = SceneMode::SANDBOX;
}
Expand Down Expand Up @@ -97,7 +99,9 @@ class MenuScene : public Scene {
UIStatusType::UI_EXIT ||
m_TutorialScene->getMissionAccomplishedUI()
->getUIStatus()
->getUIStatusType() == UIStatusType::UI_EXIT) {
->getUIStatusType() == UIStatusType::UI_EXIT ||
m_SandBoxScene->getWonUI()->getUIStatus()->getUIStatusType() ==
UIStatusType::UI_EXIT) {
return true;
}
return false;
Expand Down
24 changes: 21 additions & 3 deletions include/Scene/SandBoxScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@
#include "AI/AIScripts.hpp"
#include "Cursor.hpp"
#include "Scene.hpp"
#include "UI/WonUI.hpp"
#include "Util/Prop.hpp"
#include <glm/glm.hpp>

#define DEBUG_KEY P

class SandBoxScene : public Scene {
enum class Stages { STAGE1, STAGE2, STAGE3, STAGE4, START, END ,FORMAL_START ,FORMAL_UPDATE ,PLAYER_WON ,AI_WON};
enum class Stages {
STAGE1,
STAGE2,
STAGE3,
STAGE4,
START,
END,
FORMAL_START,
FORMAL_UPDATE,
PLAYER_WON,
AI_WON
};

public:
SandBoxScene(){};
Expand All @@ -22,12 +34,18 @@ class SandBoxScene : public Scene {
void Update() override;
void stageStart();
void stageUpdate();
void setStage(bool stage){
if(stage){
void setStage(bool stage) {
if (stage) {
m_stage = Stages::FORMAL_START;
}
}

Stages getStage() { return m_stage; }

std::shared_ptr<WonUI> getWonUI() { return m_WUI; }

private:
std::shared_ptr<WonUI> m_WUI = std::make_shared<WonUI>();
SpriteSheet m_SpriteSheet;
std::shared_ptr<CursorClass> m_Cursor = std::make_shared<CursorClass>();
Grid testGrid;
Expand Down
27 changes: 17 additions & 10 deletions include/UI/MissionFailedUI.hpp → include/UI/WonUI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
// Created by 盧威任 on 5/25/24.
//

#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_MISSIONACCOMPLISHED_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_MISSIONACCOMPLISHED_HPP
#ifndef PRACTICALTOOLSFORSIMPLEDESIGN_WUI_HPP
#define PRACTICALTOOLSFORSIMPLEDESIGN_WUI_HPP
#include "Button.hpp"
#include "UI/UI.hpp"
class MissionFailedUI : public UI {
class WonUI : public UI {
public:
MissionFailedUI() {}
~MissionFailedUI() {}
WonUI() {}
~WonUI() {}
void Update() override {
if (m_ContinueButton->ifClicked()) {
m_UIStatus->setUIStatusType(UIStatusType::UI_CONTINUE);
m_UIStatus->setUIStatusType(UIStatusType::UI_RESTART);
} else if (m_ExitButton->ifClicked()) {
m_UIStatus->setUIStatusType(UIStatusType::UI_EXIT);
}
Expand All @@ -20,21 +21,27 @@ class MissionFailedUI : public UI {

void Draw() override {
m_PausedImage->Draw(
Util::Transform({glm::vec2(0, 70), float(0), glm::vec2(1, 1)}), 1);
Util::Transform({glm::vec2(0, 70), float(0), glm::vec2(0.8, 0.8)}),
1);
m_ContinueButton->Draw();
m_ExitButton->Draw();
}

void setPausedImage(std::shared_ptr<Util::Image> image) {
m_PausedImage = image;
}

private:
std::shared_ptr<Util::Image> m_PausedImage =
std::make_shared<Util::Image>("../assets/images/paused.png");
std::make_shared<Util::Image>("../assets/images/PlayerWon.png");

std::shared_ptr<Button> m_ContinueButton = std::make_shared<Button>(
std::make_shared<Util::Image>("../assets/images/continue.png"), 1, true,
std::make_shared<Util::Image>("../assets/images/restart.png"), 1, true,
Util::Transform({glm::vec2(300, -100), float(0), glm::vec2(0.4, 0.4)}));

std::shared_ptr<Button> m_ExitButton = std::make_shared<Button>(
std::make_shared<Util::Image>("../assets/images/exit.png"), 1, true,
Util::Transform(
{glm::vec2(-300, -100), float(0), glm::vec2(0.4, 0.4)}));
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_MISSIONACCOMPLISHED_HPP
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_WUI_HPP
4 changes: 2 additions & 2 deletions include/Util/Prop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class Prop : public Structure {
void Start(glm::vec2 size) override {
m_Size = size;
this->SetAttachVisible(true);
SetZIndex(8);
m_HighLight.SetZIndex(10);
SetZIndex(0.7);
m_HighLight.SetZIndex(0.8);
}
void attachmentUpdate() override {
m_HighLight.SetObjectLocation(
Expand Down
61 changes: 32 additions & 29 deletions src/Scene/SandBoxScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ void SandBoxScene::Start() {
MapUtil::CellCoordToGlobal(glm::vec2(100, 100)));
}
void SandBoxScene::Update() {
if (m_stage == Stages::PLAYER_WON || m_stage == Stages::AI_WON) {
m_WUI->Update();
return;
}
m_GameObjectManager->Update();
m_EnemyObjectManager->Update();
if (m_stage != Stages::START && m_stage != Stages::FORMAL_START) {
Expand Down Expand Up @@ -54,28 +58,26 @@ void SandBoxScene::Update() {
m_GameObjectManager->spawnToWayPoint(
m_UI->getUnitTypeReadyToBeSpawned(), HouseType::MY);
}
if(m_stage==Stages::FORMAL_UPDATE){
if(m_GameObjectManager->getAvatarManager()->getAvatarArray().empty()&&m_GameObjectManager->getStructureManager()->getStructureArray()->getBuiltStructureArray().empty()){
m_stage=Stages::AI_WON;
m_Text->SetDrawable(
std::make_unique<Util::Image>("../assets/sprites/Task/AIWon.png"));
m_Text->SetVisible(true);
m_Text->setMovingRelativeToCamera(false);
Util::Transform trans;
trans.translation = {40, 5};
trans.scale = {0.7, 0.7};
m_Text->SetTransform(trans);
if (m_stage == Stages::FORMAL_UPDATE) {
if (m_GameObjectManager->getAvatarManager()->getAvatarArray().empty() &&
m_GameObjectManager->getStructureManager()
->getStructureArray()
->getBuiltStructureArray()
.empty()) {
m_stage = Stages::AI_WON;
m_WUI->setPausedImage(
std::make_shared<Util::Image>("assets/images/AIWon.png"));
}
if(m_EnemyObjectManager->getAvatarManager()->getAvatarArray().empty()&&m_EnemyObjectManager->getStructureManager()->getStructureArray()->getBuiltStructureArray().empty()){
m_stage=Stages::PLAYER_WON;
m_Text->SetDrawable(
std::make_unique<Util::Image>("../assets/sprites/Task/PlayerWon.png"));
m_Text->SetVisible(true);
m_Text->setMovingRelativeToCamera(false);
Util::Transform trans;
trans.translation = {40, 5};
trans.scale = {0.7, 0.7};
m_Text->SetTransform(trans);
if (m_EnemyObjectManager->getAvatarManager()
->getAvatarArray()
.empty() &&
m_EnemyObjectManager->getStructureManager()
->getStructureArray()
->getBuiltStructureArray()
.empty()) {
m_stage = Stages::PLAYER_WON;
m_WUI->setPausedImage(
std::make_shared<Util::Image>("assets/images/PlayerWon.png"));
}
}
}
Expand Down Expand Up @@ -125,15 +127,16 @@ void SandBoxScene::stageStart() {
break;
}
case Stages::STAGE4: {
m_GameObjectManager->spawn( UnitType::BARRACKS, HouseType::MY,{7,5});
m_GameObjectManager->spawn(UnitType::BARRACKS, HouseType::MY, {7, 5});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {7, 9});
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {7, 8});
m_stage = Stages::END;
break;
}
case Stages::FORMAL_START:{
case Stages::FORMAL_START: {
m_GameObjectManager->spawn(UnitType::INFANTRY, HouseType::MY, {7, 9});
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY, {36, 36});
m_EnemyObjectManager->spawn(UnitType::INFANTRY, HouseType::ENEMY,
{36, 36});
break;
}
}
Expand Down Expand Up @@ -166,17 +169,17 @@ void SandBoxScene::stageUpdate() {
m_EnemyObjectManager->setCheatMode(true);
stageStart();
}
}else if(m_stage == Stages::FORMAL_START){
m_EnemyScripts->Start(m_GameObjectManager, m_EnemyObjectManager,
m_Map, true);
} else if (m_stage == Stages::FORMAL_START) {
m_EnemyScripts->Start(m_GameObjectManager, m_EnemyObjectManager, m_Map,
true);
stageStart();
m_stage = Stages::FORMAL_UPDATE;
}

if(m_stage == Stages::PLAYER_WON || m_stage == Stages::AI_WON) {
if (m_stage == Stages::PLAYER_WON || m_stage == Stages::AI_WON) {
m_Text->Draw();
}
if (Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY )) {
if (Util::Input::IsKeyPressed(Util::Keycode::DEBUG_KEY)) {
m_EnemyObjectManager->setCheatMode(true);
}
}
4 changes: 3 additions & 1 deletion src/Scene/TutorialScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "Scene/TutorialScene.hpp"

void TutorialScene::Start() {

m_PlayerObjectivesText->SetZIndex(3);
LOG_TRACE("Start");
m_Map->Init(MapBinReader::readBin("../assets/map/ore-lord/map.bin", 64, 64),
64, 64);
Expand Down Expand Up @@ -122,6 +122,7 @@ void TutorialScene::initStage2() {
m_cellProp->setScale({6, 4});
m_cellProp->setObjectLocation({600, 1000}, 0);
m_cellProp->Start({12, 8});

m_stage = TutorialStages::STAGE2;
};

Expand Down Expand Up @@ -152,6 +153,7 @@ void TutorialScene::stage2Update() {
}

void TutorialScene::initStage3() {

m_PlayerObjectivesText->SetDrawable(
std::make_unique<Util::Image>("../assets/sprites/Task/Task3.png"));

Expand Down

0 comments on commit 782b1bd

Please sign in to comment.