diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml index 562475c..d241815 100644 --- a/.idea/.idea.Motherload/.idea/workspace.xml +++ b/.idea/.idea.Motherload/.idea/workspace.xml @@ -11,21 +11,16 @@ - - + + - - - - - + + - - + + + + @@ -52,6 +51,7 @@ + @@ -78,28 +78,28 @@ - { + "keyToString": { + "C++ Project.Game.executor": "Debug", + "RunOnceActivity.OpenProjectViewOnStart": "true", + "RunOnceActivity.ShowReadmeOnStart": "true", + "ignore.virus.scanning.warn.message": "true", + "node.js.detected.package.eslint": "true", + "node.js.detected.package.tslint": "true", + "node.js.selected.package.eslint": "(autodetect)", + "node.js.selected.package.tslint": "(autodetect)", + "nodejs_package_manager_path": "npm", + "settings.editor.selected.configurable": "preferences.pluginManager", + "vue.rearranger.settings.migration": "true" }, - "keyToStringList": { - "rider.external.source.directories": [ - "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache", - "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache", - "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src" + "keyToStringList": { + "rider.external.source.directories": [ + "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache", + "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache", + "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src" ] } -}]]> +} @@ -250,7 +250,7 @@ - + - @@ -423,7 +431,8 @@ - diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj index 035089c..4724b62 100644 --- a/Game/Game.vcxproj +++ b/Game/Game.vcxproj @@ -539,6 +539,7 @@ + MultiThreadedDebugDll EnableFastChecks @@ -639,6 +640,7 @@ + diff --git a/Game/GameManager.cpp b/Game/GameManager.cpp index a41cc3b..276cd67 100644 --- a/Game/GameManager.cpp +++ b/Game/GameManager.cpp @@ -1,2 +1,50 @@ #include "pch.h" #include "GameManager.h" + +GameManager* GameManager::m_pInstance = nullptr; + +GameManager& GameManager::GetInstance() { + if (m_pInstance == nullptr) { + m_pInstance = new GameManager(); + } + return *m_pInstance; +} +void GameManager::SetMainScreen(MainScreen* pMainScreen) { + m_pMainScreen = pMainScreen; + //TODO: not the best but ¯\_(ツ)_/¯ +} +void GameManager::SetFuel(int fuel) { + m_Fuel = fuel; +} +int GameManager::GetFuel() const { + return m_Fuel; +} +void GameManager::DecreaseFuel(int fuel) { + m_Fuel -= fuel; +} +void GameManager::AddFuel(int fuel) { + m_Fuel += fuel; +} +void GameManager::SetHullIntegrity(int hullIntegrity) { + m_HullIntegrity = hullIntegrity; +} +int GameManager::GetHullIntegrity() const { + return m_HullIntegrity; +} +void GameManager::DamageHull(int damage) { + m_HullIntegrity -= damage; +} +void GameManager::SetScore(int score) { + m_Score = score; +} +int GameManager::GetScore() const { + return m_Score; +} +void GameManager::IncreaseScore(int score) { + m_Score += score; +} +void GameManager::Update(float elapsedSecs) { + m_pMainScreen->SetFuelMeterValue(m_Fuel); + m_pMainScreen->SetHullMeterValue(m_HullIntegrity); + m_pMainScreen->SetScore(std::to_string(m_Score)); +} diff --git a/Game/GameManager.h b/Game/GameManager.h index 0a34524..c67fedb 100644 --- a/Game/GameManager.h +++ b/Game/GameManager.h @@ -1,12 +1,38 @@ #pragma once #include "Player.h" +#include "Gui/Screens/MainScreen.h" -class GameManager -{ +class GameManager { public: - float balance{ 0.0f }; - float fuel{ 0.0f }; + static GameManager& GetInstance(); + static GameManager* m_pInstance; + + + void SetMainScreen(MainScreen* pMainScreen); + + void SetFuel(int fuel); + int GetFuel() const; + void DecreaseFuel(int fuel); + void AddFuel(int fuel); + + void SetHullIntegrity(int hullIntegrity); + int GetHullIntegrity() const; + void DamageHull(int damage); + + void SetScore(int score); + int GetScore() const; + void IncreaseScore(int score); + + void Update(float elapsedSecs); private: GameManager() = default; + + + float m_Balance{ 0.0f }; + int m_HullIntegrity{ 100 }; + int m_Fuel{ 100 }; + int m_Score{ 0 }; + MainScreen* m_pMainScreen{ nullptr }; }; + diff --git a/Game/Gui/Screens/MainScreen.cpp b/Game/Gui/Screens/MainScreen.cpp index 9e84d42..166fab5 100644 --- a/Game/Gui/Screens/MainScreen.cpp +++ b/Game/Gui/Screens/MainScreen.cpp @@ -18,6 +18,10 @@ MainScreen::MainScreen(TextureManager* manager) : Screen("", Vector2f{0, 0}, Vec Vector2f DepthMeterPosition{10, ScreenSize.y - 120}; m_DepthText = new GuiText(DepthMeterPosition, "Depth: 20", "fonts/Arial.ttf", 20, Colors::YELLOW); this->AddElement(m_DepthText); + + Vector2f ScoreMeterPosition{10, ScreenSize.y - 150}; + m_ScoreText = new GuiText(ScoreMeterPosition, "Score: 0", "fonts/Arial.ttf", 20, Colors::YELLOW); + this->AddElement(m_ScoreText); } MainScreen::~MainScreen() = default; void MainScreen::Draw() const { @@ -35,4 +39,7 @@ void MainScreen::SetHullMeterValue(float value) const { void MainScreen::SetDepth(const std::string& text) const { m_DepthText->ChangeText(text); } +void MainScreen::SetScore(const std::string& text) const { + m_ScoreText->ChangeText(text); +} diff --git a/Game/Gui/Screens/MainScreen.h b/Game/Gui/Screens/MainScreen.h index a9aa2fc..9141fa8 100644 --- a/Game/Gui/Screens/MainScreen.h +++ b/Game/Gui/Screens/MainScreen.h @@ -15,11 +15,13 @@ public: void SetHullMeterValue(float value) const; void SetDepth(const std::string& text) const; + void SetScore(const std::string& text) const; private: GuiMeter* m_FuelMeter; GuiMeter* m_HullMeter; GuiText* m_DepthText; + GuiText* m_ScoreText; }; diff --git a/Game/Levels/World/OrbitingObject.cpp b/Game/Levels/World/OrbitingObject.cpp new file mode 100644 index 0000000..bc9d364 --- /dev/null +++ b/Game/Levels/World/OrbitingObject.cpp @@ -0,0 +1,14 @@ +#include "pch.h" +#include "OrbitingObject.h" + +#include +OrbitingObject::OrbitingObject(const Vector2f& orbit, float distance, float speed, Texture* texture, float offset): m_Texture(texture), m_Orbit(orbit), m_Speed(speed), m_Distance(distance), m_currentCycle(offset) { +} +void OrbitingObject::Update(float elapsedSecs) { + m_Position = Vector2f(m_Orbit.x + cosf(m_currentCycle) * m_Distance, m_Orbit.y + sinf(m_currentCycle) * m_Distance); + m_currentCycle += m_Speed * elapsedSecs; +} +void OrbitingObject::Draw() const { + m_Texture->Draw(m_Position); + +} diff --git a/Game/Levels/World/OrbitingObject.h b/Game/Levels/World/OrbitingObject.h new file mode 100644 index 0000000..6d11ff1 --- /dev/null +++ b/Game/Levels/World/OrbitingObject.h @@ -0,0 +1,21 @@ +#pragma once +#include "Texture.h" + +class OrbitingObject { +public: + OrbitingObject(const Vector2f& orbit, float distance, float speed, Texture* texture, float offset = 0); + + void Update(float elapsedSecs); + void Draw() const; + + +private: + Texture* m_Texture; + Vector2f m_Position; + Vector2f m_Orbit; + float m_Distance; + float m_Speed; + + float m_currentCycle{ 0 }; + +}; diff --git a/Game/Levels/World/WorldLevel.cpp b/Game/Levels/World/WorldLevel.cpp index 3051072..fa169c1 100644 --- a/Game/Levels/World/WorldLevel.cpp +++ b/Game/Levels/World/WorldLevel.cpp @@ -67,6 +67,8 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera), m_MainScreen = new MainScreen(TextureManager::GetInstance()); + m_Sun = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("sun.png")); + m_Moon = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("moon.png"), M_PI); } WorldLevel::~WorldLevel() { @@ -86,6 +88,9 @@ void WorldLevel::Update(float elapsedSec) { // m_gridManager.GetTileAtIndex(x, y)->m_Hightlight = false; // } // } + + m_Sun->Update(elapsedSec); + m_Moon->Update(elapsedSec); for (int x { 0 }; x < WORLD_WIDTH; ++x) { for (int y { 0 }; y < WORLD_HEIGHT; ++y) { @@ -179,6 +184,9 @@ void WorldLevel::Draw() const { utils::SetColor(Colors::GREEN); utils::DrawArrow(Vector2f{0, 0}, m_MousePos); + m_Sun->Draw(); + m_Moon->Draw(); + m_pCamera->EndRendering(); utils::FillRect(utils::GetMousePos(), 10, 10); diff --git a/Game/Levels/World/WorldLevel.h b/Game/Levels/World/WorldLevel.h index 4c1ba9b..3b2eb55 100644 --- a/Game/Levels/World/WorldLevel.h +++ b/Game/Levels/World/WorldLevel.h @@ -6,6 +6,7 @@ #include "GridSystem/WorldGridManager.h" #include "Gui/Screens/ScreenManager.h" #include "Camera.h" +#include "OrbitingObject.h" #include "Text.h" #include "Gui/GuiMeter.h" #include "Gui/Screens/MainScreen.h" @@ -49,6 +50,9 @@ private: MainScreen* m_MainScreen{}; + OrbitingObject* m_Sun{ nullptr }; + OrbitingObject* m_Moon{ nullptr }; + Texture* m_topCover{ nullptr }; // ImGui Vars diff --git a/Resources/moon.png b/Resources/moon.png new file mode 100644 index 0000000..50b814e Binary files /dev/null and b/Resources/moon.png differ diff --git a/Resources/sun.png b/Resources/sun.png new file mode 100644 index 0000000..5a93903 Binary files /dev/null and b/Resources/sun.png differ