Add Main UI, Fuel meter. Add particles to player digging

This commit is contained in:
Bram Verhulst
2024-05-14 12:28:37 +02:00
parent d5c002c2b2
commit 600050c198
39 changed files with 251 additions and 108 deletions

View File

@@ -6,10 +6,10 @@ class Building
{
public:
Building(const std::string& filePath, const Vector2f& position, TextureManager* pTextureManager);
Building(const Building& other) = delete;
Building(Building&& other) = delete;
Building& operator=(const Building& other) = delete;
Building& operator=(Building&& other) = delete;
Building(const Building& other) = default;
Building(Building&& other) = default;
Building& operator=(const Building& other) = default;
Building& operator=(Building&& other) = default;
~Building();

View File

@@ -35,12 +35,13 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
m_GridManager.GetTileAtIndex(x, 0)->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
m_GridManager.GetTileAtIndex(x, 1)->SetTileType(GroundTileTypeManager::GetInstance()->GRASS);
}
m_RefeulBuilding = new Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, TextureManager::GetInstance() };
m_Buildings.emplace_back(Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f { -750, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_MineralBuilding = new Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, TextureManager::GetInstance() };
m_Buildings.emplace_back(Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, TextureManager::GetInstance() });
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);
@@ -48,7 +49,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
m_GridManager.GetTileAtWorldPos(Vector2f {-200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-150, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_JunkBuilding = new Building { "buildings/junkStation.png", Vector2f { 250, -52 }, TextureManager::GetInstance() };
m_Buildings.emplace_back(Building { "buildings/junkStation.png", Vector2f { 250, -52 }, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
@@ -56,24 +57,22 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
m_GridManager.GetTileAtWorldPos(Vector2f {400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {450, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_RepairBuilding = new Building { "buildings/repairStation.png", Vector2f { 700, -52 }, TextureManager::GetInstance() };
m_Buildings.emplace_back(Building { "buildings/repairStation.png", Vector2f { 700, -52 }, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {650, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {700, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {750, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
// m_Meter = new GuiMeter("gui/main/fuel_guage.png", Vector2f{100, 100}, Vector2f{336, 146}, 100, TextureManager::GetInstance());
// Texture* test = new Texture("gui/main/fuel_guage.png");
m_topCover = TextureManager::GetInstance()->GetTexture("topBackground.png");
m_MainScreen = new MainScreen(TextureManager::GetInstance());
}
WorldLevel::~WorldLevel() {
delete m_RefeulBuilding;
delete m_MineralBuilding;
delete m_JunkBuilding;
delete m_RepairBuilding;
delete m_MainScreen;
}
void WorldLevel::Update(float elapsedSec) {
m_Fps = 1 / elapsedSec;
// m_Meter->Update(elapsedSec);
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
@@ -95,20 +94,9 @@ void WorldLevel::Update(float elapsedSec) {
}
}
}
testCounter++;
std::vector<Particle*> ToDelete{};
for(Particle* p : m_Particles) {
p->Update(elapsedSec);
if(p->IsDead()) {
ToDelete.emplace_back(p);
}
}
for (Particle* p : ToDelete) {
m_Particles.erase(std::remove(m_Particles.begin(), m_Particles.end(), p), m_Particles.end());
delete p;
}
if(testCounter % 100 == 0) {
m_Particles.emplace_back(new Particle(Vector2f{100, 100}, Vector2f{float(utils::randRange(-200, 200)), 10},100, TextureManager::GetInstance()->GetTexture("particles/dirt_" + std::to_string(utils::randRange(1, 8)) + ".png")));
for (Building building : m_Buildings) {
building.Update(elapsedSec);
}
@@ -118,23 +106,6 @@ void WorldLevel::Update(float elapsedSec) {
}
}
//Get the diogonal tiles of the selected tile
// if (m_pSelectedTile != nullptr) {
// surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
// TileDirection direction = TileDirection::TopMiddle;
// const std::array<TileDirection, 8> directions = { TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft,
// TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight };
//
// for (int i = 0; i < 8; i++) {
// direction = directions[i];
// if (surroundingTiles.GetTile(direction) != nullptr) {
// if (surroundingTiles.GetTile(direction)->GetTileType() != GroundTileTypeManager::GetInstance()->AIR) {
// //surroundingTiles.GetTile(direction)->m_Hightlight = true;
// }
// }
// }
// }
m_Player.Update(elapsedSec, *this);
//Move the camera when the player gets to the edge
@@ -150,8 +121,8 @@ void WorldLevel::Update(float elapsedSec) {
if (playerPos.y < newCameraPos.y + 50) {
newCameraPos.y = playerPos.y - 50;
}
if (playerPos.y > newCameraPos.y + m_Viewport.height - 50) {
newCameraPos.y = playerPos.y - m_Viewport.height + 50;
if (playerPos.y > newCameraPos.y + m_Viewport.height - 100) {
newCameraPos.y = playerPos.y - m_Viewport.height + 100;
}
m_pCamera->SetPosition(newCameraPos);
}
@@ -161,6 +132,8 @@ void WorldLevel::Update(float elapsedSec) {
screen->Update(elapsedSec);
}
m_MainScreen->Update(elapsedSec);
//Vector2f playerPos = m_player.GetPosition();
//Vector2f newCameraPos = playerPos;
//m_pCamera->SetPosition(newCameraPos);
@@ -169,7 +142,10 @@ void WorldLevel::Update(float elapsedSec) {
//m_pCamera->SetPosition(Vector2f{playerPos.x - m_viewport.width / 2, playerPos.y - m_viewport.height / 2});
}
void WorldLevel::Draw() const {
m_pCamera->BeginRendering();
// m_topCover->Draw(Vector2f{-850,-70} );
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);
@@ -191,16 +167,12 @@ void WorldLevel::Draw() const {
m_pSelectedTile->Draw();
}
m_RefeulBuilding->Draw();
m_MineralBuilding->Draw();
m_JunkBuilding->Draw();
m_RepairBuilding->Draw();
m_Player.Draw();
for(Particle* p : m_Particles) {
p->Draw();
for(Building building : m_Buildings) {
building.Draw();
}
m_Player.Draw();
utils::SetColor(Colors::GREEN);
utils::DrawArrow(Vector2f{0, 0}, m_MousePos);
@@ -214,8 +186,9 @@ void WorldLevel::Draw() const {
if (screen != nullptr) {
screen->Draw();
}
m_MainScreen->Draw();
// m_Meter->Draw();
}
void WorldLevel::MouseMove(const Vector2f& mousePos) {
m_MousePos = mousePos;

View File

@@ -7,6 +7,7 @@
#include "Gui/Screens/ScreenManager.h"
#include "Camera.h"
#include "Gui/GuiMeter.h"
#include "Gui/Screens/MainScreen.h"
#include "Particle/Particle.h"
class WorldLevel : public Level
@@ -28,8 +29,6 @@ public:
std::vector<Collision::CollisionRect> m_Rects;
std::vector<Particle*> m_Particles;
int testCounter{ 0 };
private:
double m_Fps{ 0.0f };
@@ -44,18 +43,17 @@ private:
WorldTile* m_pSelectedTile { nullptr };
Building* m_RefeulBuilding;
Building* m_MineralBuilding;
Building* m_JunkBuilding;
Building* m_RepairBuilding;
std::vector<Building> m_Buildings{};
GuiMeter* m_Meter{ nullptr };
MainScreen* m_MainScreen{};
Texture* m_topCover{ nullptr };
// ImGui Vars
bool m_ShowTextureManagerWindow { false };
bool m_ShowCameraWindow { false };
bool m_ShowPlayerInfo { true };
bool m_FollowPlayer { false };
bool m_FollowPlayer { true };
};