Skip to content

Commit

Permalink
currency
Browse files Browse the repository at this point in the history
  • Loading branch information
jonylu7 committed Apr 26, 2024
1 parent 4282161 commit e90a13b
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 22 deletions.
2 changes: 2 additions & 0 deletions include/Camera.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ class CameraClass {

void Start(glm::vec2 minPosition, glm::vec2 maxPosition);
void Update();

protected:
void UpdateWhenCursorAtBoarder();
void UpdateWhenCursorScroll();

Expand Down
5 changes: 2 additions & 3 deletions include/Mechanics/Player.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ class Player {
public:
Player() {}
~Player() {}

void setTotalCurrency(int value) { m_totalCurrency = value; };
void setTotalCurrency(int value) { m_totalCurrency = value; }
void addCurrency(int value) { m_totalCurrency += value; };

void setTotalPower(int value) { m_totalPower = value; }
Expand All @@ -32,6 +31,6 @@ class Player {
protected:
int m_maxTroopSize = 200;
int m_totalPower = 0;
int m_totalCurrency = 200;
int m_totalCurrency = 0;
};
#endif // PRACTICALTOOLSFORSIMPLEDESIGN_PLAYER_HPP
13 changes: 3 additions & 10 deletions include/UI/UI.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class UIClass {
public:
void Start(std::shared_ptr<MapClass> map, std::shared_ptr<Player> player,
void Start(std::shared_ptr<MapClass> map,
std::shared_ptr<GameObjectManager> gameobjectmanager);
void Update();

Expand All @@ -44,10 +44,6 @@ class UIClass {

protected:
void importMap(std::shared_ptr<MapClass> m_Map) { this->m_Map = m_Map; }
void importPlayer(std::shared_ptr<Player> m_Player) {
this->m_Player = m_Player;
ButtonScript.importPlayer(m_Player);
}
void
importGameObjManager(std::shared_ptr<GameObjectManager> gameObjectManager) {
m_gameObjectManager = gameObjectManager;
Expand Down Expand Up @@ -88,7 +84,7 @@ class UIClass {
glm::vec2 m_GridSize = {100, 100};

// 0318
void setSelectToBuild(unitType type){m_selectedStructureType = type;}
void setSelectToBuild(unitType type) { m_selectedStructureType = type; }

ImGuiIO &io = ImGui::GetIO();

Expand All @@ -99,7 +95,6 @@ class UIClass {
ImFont *sacker_light = io.Fonts->AddFontFromFileTTF(
"../assets/fonts/sackersgothicstd-light.otf", 11);


bool b_barackBuilt = false;
bool b_warfactoryBuilt = false;
bool b_orerefineryBuilt = false;
Expand All @@ -110,12 +105,10 @@ class UIClass {
glm::vec2 m_warfactoryTargetCell;
glm::vec2 m_orerefineryCell;
glm::vec2 m_orerefineryTargetCell;
unitType m_selectedStructureType=unitType::NONE;

unitType m_selectedStructureType = unitType::NONE;

// ptr import from scene
std::shared_ptr<MapClass> m_Map;
std::shared_ptr<Player> m_Player;
std::shared_ptr<GameObjectManager> m_gameObjectManager;
};

Expand Down
2 changes: 0 additions & 2 deletions include/UI/UIScriptProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

class UIScriptProcess {
private:
std::shared_ptr<Player> m_player;
std::shared_ptr<GameObjectManager> m_gameObjectManager;

// building
Expand Down Expand Up @@ -101,7 +100,6 @@ class UIScriptProcess {
void setIfReadytoSpawn(bool b) { b_isReadyToSpawn = b; }

// import from scene
void importPlayer(std::shared_ptr<Player> player) { m_player = player; }
void
importGameObjManager(std::shared_ptr<GameObjectManager> gameObjectManager) {
m_gameObjectManager = gameObjectManager;
Expand Down
4 changes: 2 additions & 2 deletions src/Scene/DefaultScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ void DefaultScene::Start() {
// m_dummy.Start({5, 5}, m_Map);
m_GameObjectManager->Start(m_Map);
// m_Cursor.Start(m_Map);
m_UI.Start(m_Map, m_Player, m_GameObjectManager);
m_Player->setTotalCurrency(5000);
m_UI.Start(m_Map, m_GameObjectManager);
m_GameObjectManager->setTotalCurrency(5000);
m_SceneCamera.Start(MapUtil::CellCoordToGlobal(glm::vec2(-10, -10)),
MapUtil::CellCoordToGlobal(glm::vec2(100, 100)));

Expand Down
3 changes: 0 additions & 3 deletions src/UI/UI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
std::unordered_map<unitType, unsigned int> UIClass::s_unitConstructCount;

void UIClass::Start(std::shared_ptr<MapClass> map,
std::shared_ptr<Player> player,
std::shared_ptr<GameObjectManager> gameobjectmanager) {
InitUnitQueue();
m_StructureIconSpriteSheet->Start(
Expand All @@ -18,7 +17,6 @@ void UIClass::Start(std::shared_ptr<MapClass> map,
m_VehiclesIconSpriteSheet->Start(
"../assets/sprites/ICON_Allied_Vehicles.png", 64, 48, 12, 0);
importMap(map);
importPlayer(player);
importGameObjManager(gameobjectmanager);
}

Expand Down Expand Up @@ -442,7 +440,6 @@ std::shared_ptr<Avatar> UIClass::getUnitFromUI() {
ButtonScript.setIfReadytoSpawn(false);
if (std::dynamic_pointer_cast<Infantry>(Avatar)) {


Avatar->Start({m_barrackCell.x + 1, m_barrackCell.y - 1});

Avatar->setNewDestination(m_barrackTargetCell);
Expand Down
4 changes: 2 additions & 2 deletions src/UI/UIScriptProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void UIScriptProcess::CountDown() {
}
if (m_currentBuildRemainingCost > 0) {
m_currentBuildRemainingCost -= buildCost;
m_player->addCurrency(-1 * buildCost);
m_gameObjectManager->addCurrency(-1 * buildCost);
}
}
// if finish building
Expand Down Expand Up @@ -108,7 +108,7 @@ void UIScriptProcess::CountDown() {
}
if (m_currentSpawnRemainingCost > 0) {
m_currentSpawnRemainingCost -= spawnCost;
m_player->addCurrency(-1 * spawnCost);
m_gameObjectManager->addCurrency(-1 * spawnCost);
}
}
// if finish spawning
Expand Down

0 comments on commit e90a13b

Please sign in to comment.