This commit is contained in:
Bram Verhulst
2024-06-09 22:03:29 +02:00
parent d7389411f5
commit 5f1dcd5788
76 changed files with 1532 additions and 385 deletions

View File

@@ -11,6 +11,8 @@ public:
Level(const Level& other) = default;
Level(Level&& other) = default;
Level& operator=(const Level& other) = default;
Level& operator=(Level&& other) = default;
virtual void Update(float elapsedSec) = 0;
virtual void Draw() const = 0;

View File

@@ -5,16 +5,16 @@
#include <utility>
#include "colors.h"
#include "GameManager.h"
#include "Player.h"
#include "utils.h"
Building::Building(const std::string& filePath, const Vector2f& position, const Rectf& boundingBox, TextureManager* pTextureManager): m_Position(position),
m_BoundingBox(boundingBox) {
m_Texture = pTextureManager->GetTexture(filePath);
m_Size = Vector2f(m_Texture->GetWidth(), m_Texture->GetHeight());
std::cout << "i like kids" << std::endl;
}
Building::~Building() = default;
void Building::Draw() const {
utils::SetColor(Colors::WHITE);
m_Texture->Draw(m_Position);
utils::SetColor(Colors::GREEN);
Rectf temp = m_BoundingBox;
@@ -24,15 +24,20 @@ void Building::Draw() const {
}
void Building::Update(float dt, const Rectf& objectBoundingBox) {
if (IsObjectInHitbox(objectBoundingBox)) {
if (!m_IsPlayerInHitbox) { //TODO: what
m_IsPlayerInHitbox = true;
if (m_OnEnterHitbox != nullptr) {
m_OnEnterHitbox();
}
else {
std::cout << "No function set for onEnterHitbox" << std::endl;
Player* player = GameManager::GetInstance().GetPlayer();
float speed = player->GetVelocity().Length();
if (speed < 100.0f) {
if (!m_IsPlayerInHitbox) {
m_IsPlayerInHitbox = true;
if (m_OnEnterHitbox != nullptr) {
m_OnEnterHitbox();
}
else {
std::cout << "No function set for onEnterHitbox" << std::endl;
}
}
}
}
else {
m_IsPlayerInHitbox = false;

View File

@@ -8,12 +8,8 @@ class Building
{
public:
Building(const std::string& filePath, const Vector2f& position, const Rectf& boundingBox, TextureManager* pTextureManager);
// Building(const Building& other) = default;
// Building(Building&& other) = default;
// Building& operator=(const Building& other) = default;
// Building& operator=(Building&& other) = default;
~Building();
~Building() = default;
void Draw() const;
void Update(float dt, const Rectf& objectBoundingBox);

View File

@@ -46,8 +46,11 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
m_GridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_Buildings.emplace_back(new Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, Rectf{0 ,0, 100, 100}, TextureManager::GetInstance() });
Building* mineralBuilding = new Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, Rectf{0 ,0, 100, 100}, TextureManager::GetInstance() };
mineralBuilding->SetOnEnterHitbox([]() {
ScreenManager::GetInstance()->OpenScreen(ScreenManager::m_SellScreen);
});
m_Buildings.emplace_back(mineralBuilding);
m_GridManager.GetTileAtWorldPos(Vector2f {-400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {-350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
@@ -70,7 +73,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
m_GridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_topCover = TextureManager::GetInstance()->GetTexture("topBackground.png");
m_TopCover = TextureManager::GetInstance()->GetTexture("topBackground.png");
m_MainScreen = new MainScreen(TextureManager::GetInstance());
GameManager::GetInstance().SetMainScreen(m_MainScreen);
@@ -80,13 +83,28 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
GameManager::GetInstance().SetFuel(100);
GameManager::GetInstance().SetHullIntegrity(100);
GameManager::GetInstance().SetPlayer(&m_Player);
m_BackgroundMusic = new SoundStream("sound/bgm.wav");
m_BackgroundMusic->Play(0);
}
WorldLevel::~WorldLevel() {
delete m_MainScreen;
delete m_Sun;
delete m_Moon;
delete m_BackgroundMusic;
for (Building* building : m_Buildings) {
delete building;
}
GameManager::DestroyInstance();
}
void WorldLevel::Update(float elapsedSec) {
m_Fps = 1 / elapsedSec;
@@ -156,7 +174,7 @@ void WorldLevel::Update(float elapsedSec) {
GameManager::GetInstance().Update(elapsedSec);
m_MainScreen->SetDepth(std::to_string((int)-m_Player.GetPosition().y - 50) + " ft.");
m_MainScreen->SetScore("Score: " + std::to_string(GameManager::GetInstance().GetScore()));
m_MainScreen->SetScore(std::to_string(GameManager::GetInstance().GetScore()));
// m_MainScreen->SetFuelMeterValue(GameManager::GetInstance().GetFuel());
// m_MainScreen->SetHullMeterValue(GameManager::GetInstance().GetHullIntegrity());
m_MainScreen->Update(elapsedSec);
@@ -178,7 +196,7 @@ void WorldLevel::Draw() const {
m_Moon->Draw();
// m_topCover->Draw(Vector2f{-850,-70} );
m_topCover->Draw(Rectf{-850, -70, 850, -70 + 32}, Rectf{0, 0, WORLD_WIDTH * 50, 32});
m_TopCover->Draw(Rectf{-850, -70, 850, -70 + 32}, Rectf{0, 0, WORLD_WIDTH * 50, 32});
for (Collision::CollisionRect rect : m_Rects) {
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);

View File

@@ -8,6 +8,7 @@
#include "Camera.h"
#include "OrbitingObject.h"
#include "SoundEffect.h"
#include "SoundStream.h"
#include "Text.h"
#include "Gui/GuiMeter.h"
#include "Gui/Screens/MainScreen.h"
@@ -19,8 +20,12 @@ public:
WorldLevel(Camera* camera, Rectf viewport);
virtual ~WorldLevel() override;
WorldLevel(const WorldLevel& other) = default;
WorldLevel(WorldLevel&& other) = default;
WorldLevel(const WorldLevel& other) = delete;
WorldLevel& operator=(const WorldLevel& other) = delete;
WorldLevel(WorldLevel&& other) = delete;
WorldLevel& operator=(WorldLevel&& other) = delete;
void Update(float elapsedSec) override;
void Draw() const override;
@@ -40,6 +45,8 @@ private:
Player m_Player;
Vector2f m_MousePos {};
SoundStream* m_BackgroundMusic;
Rectf m_Viewport;
ScreenManager* m_ScreenManager;
@@ -54,7 +61,7 @@ private:
OrbitingObject* m_Sun{ nullptr };
OrbitingObject* m_Moon{ nullptr };
Texture* m_topCover{ nullptr };
Texture* m_TopCover{ nullptr };
// ImGui Vars