Add sun / moon, started on score / GameManager

This commit is contained in:
Bram Verhulst
2024-05-16 12:44:53 +02:00
parent 8866f33c09
commit 3c83e566dd
12 changed files with 176 additions and 35 deletions

View File

@@ -539,6 +539,7 @@
</ClCompile>
<ClCompile Include="Levels\MainMenu\MainMenuLevel.cpp" />
<ClCompile Include="Levels\World\Building.cpp" />
<ClCompile Include="Levels\World\OrbitingObject.cpp" />
<ClCompile Include="Levels\World\WorldLevel.cpp">
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -639,6 +640,7 @@
<ClInclude Include="Levels\Level.h" />
<ClInclude Include="Levels\MainMenu\MainMenuLevel.h" />
<ClInclude Include="Levels\World\Building.h" />
<ClInclude Include="Levels\World\OrbitingObject.h" />
<ClInclude Include="Levels\World\WorldLevel.h" />
<ClInclude Include="Particle\Particle.h" />
<ClInclude Include="pch.h" />

View File

@@ -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));
}

View File

@@ -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 };
};

View File

@@ -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);
}

View File

@@ -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;
};

View File

@@ -0,0 +1,14 @@
#include "pch.h"
#include "OrbitingObject.h"
#include <iostream>
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);
}

View File

@@ -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 };
};

View File

@@ -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);

View File

@@ -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