diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml
index d4c72e9..60db43f 100644
--- a/.idea/.idea.Motherload/.idea/workspace.xml
+++ b/.idea/.idea.Motherload/.idea/workspace.xml
@@ -11,23 +11,28 @@
-
-
-
-
+
+
-
+
+
+
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
-
-
+
+
@@ -37,7 +42,7 @@
@@ -45,210 +50,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
@@ -257,7 +59,6 @@
-
@@ -296,7 +97,7 @@
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
- "settings.editor.selected.configurable": "preferences.pluginManager",
+ "settings.editor.selected.configurable": "preferences.sourceCode.C++",
"vue.rearranger.settings.migration": "true"
},
"keyToStringList": {
@@ -446,7 +247,9 @@
-
+
+
+
@@ -568,7 +371,15 @@
1714654669410
-
+
+
+ 1715070920513
+
+
+
+ 1715070920513
+
+
@@ -586,14 +397,14 @@
-
-
+
+
diff --git a/Engine/BaseGame.cpp b/Engine/BaseGame.cpp
index ea85f7a..8ab91a8 100644
--- a/Engine/BaseGame.cpp
+++ b/Engine/BaseGame.cpp
@@ -169,6 +169,8 @@ void BaseGame::InitializeGameEngine()
SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
+ SDL_RendererInfo m_RendererInfo;
+ SDL_GetRendererInfo(SDL_GetRenderer(m_pWindow), &m_RendererInfo);
m_Initialized = true;
}
diff --git a/Game/Animations/Animation.cpp b/Game/Animations/Animation.cpp
index 4fdd482..dab1124 100644
--- a/Game/Animations/Animation.cpp
+++ b/Game/Animations/Animation.cpp
@@ -4,7 +4,8 @@
#include
#include "utils.h"
-Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames), m_isLooping(isLooping), m_FrameDuration(frameDuration) {
+Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames),
+ m_isLooping(isLooping), m_FrameDuration(frameDuration) {
}
void Animation::Update(float elapsedSec) {
@@ -15,7 +16,7 @@ void Animation::Update(float elapsedSec) {
++m_CurrentFrame;
if (m_CurrentFrame >= m_Frames) {
m_CurrentFrame = 0;
- if(!m_isLooping) {
+ if (!m_isLooping) {
m_hasPlayedOnce = true;
m_isPlaying = false;
}
@@ -24,12 +25,33 @@ void Animation::Update(float elapsedSec) {
}
}
void Animation::Draw(const Vector2f& pos) const {
- Draw(pos, Rectf{ pos.x, pos.y, m_SrcRect.width, m_SrcRect.height });
+ Draw(pos, Rectf { pos.x, pos.y, m_SrcRect.width, m_SrcRect.height });
}
void Animation::Draw(const Vector2f& pos, const Rectf& dst) const {
Rectf src = m_SrcRect;
src.left += static_cast(m_CurrentFrame) * src.width;
-
+
m_pTexture->Draw(dst, src, m_isFlipped);
}
+void Animation::SetPlaying(bool isPlaying) {
+ m_isPlaying = isPlaying;
+}
+void Animation::SetFlipped(bool isFlipped) {
+ m_isFlipped = isFlipped;
+}
+void Animation::Reset() {
+ m_CurrentFrame = 0;
+ m_hasPlayedOnce = false;
+ m_isPlaying = true;
+ m_FrameTimer = m_FrameDuration;
+}
+bool Animation::IsDone() const {
+ return m_hasPlayedOnce && !m_isLooping;
+}
+int Animation::GetFrameCount() const {
+ return m_Frames;
+}
+void Animation::SetFrame(int frame) {
+ m_CurrentFrame = frame;
+}
diff --git a/Game/Animations/Animation.h b/Game/Animations/Animation.h
index c9e89ea..0b2ab41 100644
--- a/Game/Animations/Animation.h
+++ b/Game/Animations/Animation.h
@@ -5,29 +5,20 @@ class Animation
{
public:
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping = true);
- ~Animation() = default;
void Update(float elapsedSec);
void Draw(const Vector2f& pos) const;
void Draw(const Vector2f& pos, const Rectf& dst) const;
-
- void SetPlaying(bool isPlaying) {
- m_isPlaying = isPlaying;
- }
- void SetFlipped(bool isFlipped) {
- m_isFlipped = isFlipped;
- }
- void Reset() {
- m_CurrentFrame = 0;
- m_hasPlayedOnce = false;
- m_isPlaying = true;
- m_FrameTimer = m_FrameDuration;
- }
- bool IsDone() const {
- return m_hasPlayedOnce && !m_isLooping;
- }
+ void SetPlaying(bool isPlaying);
+ void SetFlipped(bool isFlipped);
+
+ void Reset();
+ bool IsDone() const;
+
+ int GetFrameCount() const;
+ void SetFrame(int frame);
private:
Texture* m_pTexture;
diff --git a/Game/Game.cpp b/Game/Game.cpp
index cc7e302..5093645 100644
--- a/Game/Game.cpp
+++ b/Game/Game.cpp
@@ -30,7 +30,6 @@ void Game::Initialize() {
void Game::Cleanup() {
- //TODO: ask how 2 delete the TextureManager
ScreenManager::DestroyInstance();
GroundTileTypeManager::DestroyInstance();
TextureManager::DestroyInstance();
@@ -40,7 +39,7 @@ void Game::Update(float elapsedSec) {
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
if (m_IsRightMouseDown) {
- const Vector2f newCameraPos = Vector2f { m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y };
+ const Vector2f newCameraPos = Vector2f { m_MousePosition.x + m_MouseOffset.x, m_MousePosition.y + m_MouseOffset.y };
m_Camera.SetPosition(Vector2f { -newCameraPos.x, -newCameraPos.y });
}
else {
@@ -64,33 +63,17 @@ void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
}
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
- m_MousePos = Vector2f { float(e.x), float(e.y) };
+ m_MousePosition = Vector2f { float(e.x), float(e.y) };
m_pCurrentLevel->MouseMove(Vector2f { float(e.x), float(e.y) });
-
-
-
}
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT;
- m_MouseOffset = Vector2f { -m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y };
+ m_MouseOffset = Vector2f { -m_Camera.GetPosition().x - m_MousePosition.x, -m_Camera.GetPosition().y - m_MousePosition.y };
}
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT ? false : m_IsRightMouseDown;
- //std::cout << "MOUSEBUTTONUP event: ";
- //switch ( e.button )
- //{
- //case SDL_BUTTON_LEFT:
- // std::cout << " left button " << std::endl;
- // break;
- //case SDL_BUTTON_RIGHT:k
- // std::cout << " right button " << std::endl;
- // break;
- //case SDL_BUTTON_MIDDLE:
- // std::cout << " middle button " << std::endl;
- // break;
- //}
}
void Game::ProcessMouseWheelEvent(const SDL_MouseWheelEvent& e) {
float newScale = m_Camera.GetScale() - e.preciseY * 0.1f;
diff --git a/Game/Game.h b/Game/Game.h
index c0af4b9..ccd4cbb 100644
--- a/Game/Game.h
+++ b/Game/Game.h
@@ -32,7 +32,6 @@ public:
static Rectf VIEWPORT;
private:
- // FUNCTIONS
void Initialize();
void Cleanup();
@@ -43,7 +42,7 @@ private:
Level* m_pCurrentLevel;
- Vector2f m_MousePos {};
+ Vector2f m_MousePosition {};
Vector2f m_MouseOffset {};
bool m_IsRightMouseDown {};
diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj
index f8ad97a..4a62c04 100644
--- a/Game/Game.vcxproj
+++ b/Game/Game.vcxproj
@@ -467,6 +467,7 @@
true
+
@@ -489,6 +490,7 @@
+
diff --git a/Game/GridSystem/WorldGridManager.cpp b/Game/GridSystem/WorldGridManager.cpp
index 8f49d25..1168711 100644
--- a/Game/GridSystem/WorldGridManager.cpp
+++ b/Game/GridSystem/WorldGridManager.cpp
@@ -20,31 +20,15 @@ WorldGridManager::~WorldGridManager() {
delete m_worldTiles[x][y];
}
}
-
- std::cout << "Deleting static" << std::endl;
- // delete Tiles::AIR;
- // delete Tiles::DIRT;
- //
- // delete Tiles::Hazards::LAVA;
- // delete Tiles::Hazards::STONE;
- //
- // delete Tiles::Ores::BRONZE;
- // delete Tiles::Ores::GOLD;
- // delete Tiles::Ores::IRON;
- //
- // delete Tiles::Special::GRASS;
- // delete Tiles::Special::HARD_LEFT;
- // delete Tiles::Special::HARD_MIDDLE;
- // delete Tiles::Special::HARD_RIGHT;
}
surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_tile) {
surroundingTiles tiles;
Vector2f pos = world_tile->GetPosition();
Vector2f gridCoords = this->GetIndexFromPosition(pos);
- int x = gridCoords.x;
+ const int x = (int)gridCoords.x;
//TODO: Stupid fix, fix this
- int y = gridCoords.y - 1;
+ const int y = (int)gridCoords.y - 1;
tiles.SetTile(TileDirection::TopLeft, this->GetTileAtIndex(x - 1, y - 1));
tiles.SetTile(TileDirection::TopMiddle, this->GetTileAtIndex(x, y - 1));
@@ -58,12 +42,12 @@ surroundingTiles WorldGridManager::GetSurroundingTiles(const WorldTile* world_ti
tiles.SetTile(TileDirection::BottomRight, this->GetTileAtIndex(x + 1, y + 1));
return tiles;
-
+
}
Vector2f WorldGridManager::GetIndexFromPosition(Vector2f position) {
int x = int(position.x / TILE_WIDTH + WORLD_WIDTH / 2);
int y = int(-position.y / TILE_HEIGHT);
- return Vector2f{ float(x), float(y) };
+ return Vector2f { float(x), float(y) };
}
WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
diff --git a/Game/GridSystem/WorldGridManager.h b/Game/GridSystem/WorldGridManager.h
index 62a4dc8..c3cbdda 100644
--- a/Game/GridSystem/WorldGridManager.h
+++ b/Game/GridSystem/WorldGridManager.h
@@ -14,8 +14,7 @@ static const int TILE_HEIGHT = 50;
class WorldTile;
-enum TileDirection
-{
+enum TileDirection {
TopLeft,
TopMiddle,
TopRight,
@@ -29,41 +28,31 @@ enum TileDirection
BottomRight
};
-struct surroundingTiles
-{
+struct surroundingTiles {
- std::vector m_tiles{ 8, nullptr};
+ std::vector m_tiles { 8, nullptr };
void SetTile(TileDirection direction, WorldTile* tile) {
m_tiles[static_cast(direction)] = tile;
}
- WorldTile* GetTile(TileDirection direction) {
+ WorldTile * GetTile(TileDirection direction) {
return m_tiles[static_cast(direction)];
}
-
- // bool IsAllType(const GroundTileType& type) {
- // for (const auto& tile : m_tiles) {
- // if (tile.second == nullptr) {
- // return false;
- // }
- // if (tile.second->GetTileType() != &type) {
- // return false;
- // }
- // }
- // return true;
- // }
};
-class WorldGridManager
-{
+class WorldGridManager {
public:
WorldGridManager();
~WorldGridManager();
surroundingTiles GetSurroundingTiles(const WorldTile* world_tile);
- Vector2f GetIndexFromPosition(Vector2f position);
+ static Vector2f GetIndexFromPosition(Vector2f position);
- WorldGridManager(const WorldGridManager& other) = default;
+ WorldGridManager(const WorldGridManager& other) = delete;
+ WorldGridManager(WorldGridManager&& other) = default;
+ WorldGridManager& operator=(const WorldGridManager& other) = delete;
+ WorldGridManager& operator=(WorldGridManager&& other) = delete;
+
WorldTile * GetTileAtIndex(const int x, const int y) const;
WorldTile * GetTileAtWorldPos(const Vector2f& pos) const;
diff --git a/Game/GroundTileTypeManager.cpp b/Game/GroundTileTypeManager.cpp
index 456a1b9..c2a7a16 100644
--- a/Game/GroundTileTypeManager.cpp
+++ b/Game/GroundTileTypeManager.cpp
@@ -26,10 +26,6 @@ void GroundTileTypeManager::DestroyInstance() {
delete m_pInstance;
}
-GroundTileTypeManager::GroundTileTypeManager() {
-}
-// void GroundTileTypeManager::Initialize() {
- // AIR = new GroundTileType("", GroundTileTypes::Air);
-// }
-GroundTileTypeManager::~GroundTileTypeManager() {
-}
+GroundTileTypeManager::GroundTileTypeManager() = default;
+
+GroundTileTypeManager::~GroundTileTypeManager() = default;
diff --git a/Game/Gui/GuiMeter.cpp b/Game/Gui/GuiMeter.cpp
index 3abba58..f798ffb 100644
--- a/Game/Gui/GuiMeter.cpp
+++ b/Game/Gui/GuiMeter.cpp
@@ -2,6 +2,7 @@
#include "GuiMeter.h"
#include "TextureManager.h"
+#include "utils.h"
GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager): m_Position(pos), m_FrameCount(frameCount) {
m_Animation = new Animation(manager->GetTexture(filePath),frameCount, 0.0f, Rectf{0, 0, frameSize.x, frameSize.y}, false);
@@ -13,6 +14,6 @@ void GuiMeter::Draw() const {
m_Animation->Draw(m_Position);
}
void GuiMeter::Update(float elapsedSec) {
-
-
+ const int frame = static_cast(utils::map(m_Value, 0.0f, m_MaxValue, 0, (float)m_Animation->GetFrameCount()));
+ m_Animation->SetFrame(frame);
}
\ No newline at end of file
diff --git a/Game/Gui/GuiMeter.h b/Game/Gui/GuiMeter.h
index 221fa1b..0598228 100644
--- a/Game/Gui/GuiMeter.h
+++ b/Game/Gui/GuiMeter.h
@@ -15,11 +15,17 @@ public:
virtual void Draw() const override;
virtual void Update(float elapsedSec) override;
+ void SetValue(float value) {
+ m_Value = value;
+ }
+
private:
Animation* m_Animation{ nullptr };
Vector2f m_Position;
float m_Value{ 0.0f };
-
+ const float m_MaxValue{ 100.0f };
+
int m_FrameCount;
+
};
diff --git a/Game/Levels/Level.cpp b/Game/Levels/Level.cpp
index e5e4a81..426a06e 100644
--- a/Game/Levels/Level.cpp
+++ b/Game/Levels/Level.cpp
@@ -9,5 +9,4 @@ Level::Level() : m_pCamera(nullptr) {
Level::Level(Camera* camera) {
m_pCamera = camera;
}
-Level::~Level() {
-}
+Level::~Level() = default;
\ No newline at end of file
diff --git a/Game/Levels/Level.h b/Game/Levels/Level.h
index 6425e39..065ae46 100644
--- a/Game/Levels/Level.h
+++ b/Game/Levels/Level.h
@@ -6,7 +6,7 @@ class Level
{
public:
Level();
- Level(Camera* camera);
+ explicit Level(Camera* camera);
virtual ~Level();
Level(const Level& other) = default;
diff --git a/Game/Levels/World/Building.h b/Game/Levels/World/Building.h
index 3fb6819..28390b3 100644
--- a/Game/Levels/World/Building.h
+++ b/Game/Levels/World/Building.h
@@ -8,6 +8,8 @@ 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();
diff --git a/Game/Levels/World/WorldLevel.cpp b/Game/Levels/World/WorldLevel.cpp
index 7144913..db124de 100644
--- a/Game/Levels/World/WorldLevel.cpp
+++ b/Game/Levels/World/WorldLevel.cpp
@@ -16,11 +16,11 @@
class GroundTileType;
WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
- m_gridManager(WorldGridManager()),
- m_player(Player { Vector2f { 0, 100 }, TextureManager::GetInstance() }),
- m_mousePos { 0, 0 },
- m_viewport(viewport),
- m_screenManager(ScreenManager::GetInstance()) {
+ m_GridManager(WorldGridManager()),
+ m_Player(Player { Vector2f { 0, 100 }, TextureManager::GetInstance() }),
+ m_MousePos { 0, 0 },
+ m_Viewport(viewport),
+ m_ScreenManager(ScreenManager::GetInstance()) {
InitializeGroundTiles();
// The grid is 34 x 50 big, the top center is 0,0 in world coords
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
@@ -28,56 +28,57 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
const int actualX = x - WORLD_WIDTH / 2;
Vector2f pos = Vector2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
GroundTileType* type = getRandomGroundTile();
- m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_gridManager });
+ m_GridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_GridManager });
}
}
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
- m_gridManager.GetTileAtIndex(x, 0)->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
- m_gridManager.GetTileAtIndex(x, 1)->SetTileType(GroundTileTypeManager::GetInstance()->GRASS);
+ 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_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_RefeulBuilding = new Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, TextureManager::GetInstance() };
+ 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_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);
- m_gridManager.GetTileAtWorldPos(Vector2f {-250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
- 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_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);
- m_gridManager.GetTileAtWorldPos(Vector2f {350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
- 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_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_MineralBuilding = new 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);
+ m_GridManager.GetTileAtWorldPos(Vector2f {-250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
+ 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_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);
+ m_GridManager.GetTileAtWorldPos(Vector2f {350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
+ 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_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");
}
WorldLevel::~WorldLevel() {
- delete m_refeulBuilding;
- delete m_mineralBuilding;
- delete m_junkBuilding;
- delete m_repairBuilding;
+ delete m_RefeulBuilding;
+ delete m_MineralBuilding;
+ delete m_JunkBuilding;
+ delete m_RepairBuilding;
}
void WorldLevel::Update(float elapsedSec) {
- m_fps = 1 / elapsedSec;
+ m_Fps = 1 / elapsedSec;
+ m_Meter->Update(elapsedSec);
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
- m_mousePos = Vector2f { float(mouseX), float(mouseY) };
- m_mousePos = m_pCamera->TransformMouse(m_mousePos);
+ m_MousePos = Vector2f { float(mouseX), float(mouseY) };
+ m_MousePos = m_pCamera->TransformMouse(m_MousePos);
// for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
// for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
@@ -85,11 +86,11 @@ void WorldLevel::Update(float elapsedSec) {
// }
// }
- for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
- for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
- m_gridManager.GetTileAtIndex(x, y)->Update(m_pCamera);
- if (m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().Contains(m_mousePos)) {
- m_pSelectedTile = m_gridManager.GetTileAtIndex(x, y);
+ for (int x { 0 }; x < WORLD_WIDTH; ++x) {
+ for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
+ m_GridManager.GetTileAtIndex(x, y)->Update(m_pCamera);
+ if (m_GridManager.GetTileAtIndex(x, y)->GetCollisionRect().Contains(m_MousePos)) {
+ m_pSelectedTile = m_GridManager.GetTileAtIndex(x, y);
//selectedTile->m_Hightlight = true;
}
}
@@ -117,28 +118,28 @@ void WorldLevel::Update(float elapsedSec) {
// }
// }
- m_player.Update(elapsedSec, *this);
+ m_Player.Update(elapsedSec, *this);
//Move the camera when the player gets to the edge
if(m_FollowPlayer) {
- Vector2f playerPos = m_player.GetPosition();
+ Vector2f playerPos = m_Player.GetPosition();
Vector2f newCameraPos = m_pCamera->GetPosition();
if (playerPos.x < newCameraPos.x + 50) {
newCameraPos.x = playerPos.x - 50;
}
- if (playerPos.x > newCameraPos.x + m_viewport.width - 100) {
- newCameraPos.x = playerPos.x - m_viewport.width + 100;
+ if (playerPos.x > newCameraPos.x + m_Viewport.width - 100) {
+ newCameraPos.x = playerPos.x - m_Viewport.width + 100;
}
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 - 50) {
+ newCameraPos.y = playerPos.y - m_Viewport.height + 50;
}
m_pCamera->SetPosition(newCameraPos);
}
- Screen* screen = m_screenManager->GetCurrentScreen();
+ Screen* screen = m_ScreenManager->GetCurrentScreen();
if (screen != nullptr) {
screen->Update(elapsedSec);
}
@@ -158,11 +159,11 @@ void WorldLevel::Draw() const {
}
utils::SetColor(Colors::WHITE);
- utils::FillEllipse(m_mousePos, 2, 2);
+ utils::FillEllipse(m_MousePos, 2, 2);
- for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
- for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
- m_gridManager.GetTileAtIndex(x, y)->Draw();
+ for (int x { 0 }; x < WORLD_WIDTH; ++x) {
+ for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
+ m_GridManager.GetTileAtIndex(x, y)->Draw();
}
}
@@ -173,28 +174,30 @@ void WorldLevel::Draw() const {
m_pSelectedTile->Draw();
}
- m_refeulBuilding->Draw();
- m_mineralBuilding->Draw();
- m_junkBuilding->Draw();
- m_repairBuilding->Draw();
- m_player.Draw();
+ m_RefeulBuilding->Draw();
+ m_MineralBuilding->Draw();
+ m_JunkBuilding->Draw();
+ m_RepairBuilding->Draw();
+ m_Player.Draw();
utils::SetColor(Colors::GREEN);
- utils::DrawArrow(Vector2f{0, 0}, m_mousePos);
+ utils::DrawArrow(Vector2f{0, 0}, m_MousePos);
m_pCamera->EndRendering();
utils::FillRect(utils::GetMousePos(), 10, 10);
- utils::DrawRect(50, 50, m_viewport.width - 100, m_viewport.height - 100);
+ utils::DrawRect(50, 50, m_Viewport.width - 100, m_Viewport.height - 100);
- const Screen* screen = m_screenManager->GetCurrentScreen();
+ const Screen* screen = m_ScreenManager->GetCurrentScreen();
if (screen != nullptr) {
screen->Draw();
}
+
+ m_Meter->Draw();
}
void WorldLevel::MouseMove(const Vector2f& mousePos) {
- m_mousePos = mousePos;
+ m_MousePos = mousePos;
}
void WorldLevel::ProcessImGui() {
@@ -259,7 +262,7 @@ void WorldLevel::ProcessImGui() {
ImGui::EndMenu();
}
- if (ImGui::BeginMenu(std::to_string(m_fps).c_str())) {
+ if (ImGui::BeginMenu(std::to_string(m_Fps).c_str())) {
ImGui::EndMenu();
}
@@ -280,7 +283,7 @@ void WorldLevel::ProcessImGui() {
ImGui::Text("Camera Scale: %f", m_pCamera->GetScale());
ImGui::Text("Is Right Mouse Down: %s", utils::isMouseDown(0) ? "true" : "false");
if (ImGui::Button("Reset Camera")) {
- m_pCamera->SetPosition(Vector2f { -m_viewport.width / 2, -m_viewport.height / 2 });
+ m_pCamera->SetPosition(Vector2f { -m_Viewport.width / 2, -m_Viewport.height / 2 });
m_pCamera->SetScale(1.0f);
}
ImGui::Checkbox("Follow Player", &m_FollowPlayer);
@@ -289,9 +292,12 @@ void WorldLevel::ProcessImGui() {
if (m_ShowPlayerInfo) {
ImGui::Begin("Player Info", &m_ShowPlayerInfo, ImGuiWindowFlags_AlwaysAutoResize);
- ImGui::Text("Player Position: (%f, %f)", m_player.GetPosition().x, m_player.GetPosition().y);
- ImGui::Text("Player Velocity: (%f, %f)", m_player.GetVelocity().x, m_player.GetVelocity().y);
+ ImGui::Text("Player Position: (%f, %f)", m_Player.GetPosition().x, m_Player.GetPosition().y);
+ ImGui::Text("Player Velocity: (%f, %f)", m_Player.GetVelocity().x, m_Player.GetVelocity().y);
ImGui::End();
- m_player.ProcessImGui();
+ m_Player.ProcessImGui();
}
}
+WorldGridManager& WorldLevel::GetGridManager() {
+ return m_GridManager;
+}
diff --git a/Game/Levels/World/WorldLevel.h b/Game/Levels/World/WorldLevel.h
index ed55c7d..53796c8 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 "Gui/GuiMeter.h"
class WorldLevel : public Level
{
@@ -22,29 +23,29 @@ public:
void MouseMove(const Vector2f& mousePos) override;
void ProcessImGui() override;
- WorldGridManager& GetGridManager() {
- return m_gridManager;
- }
+ WorldGridManager& GetGridManager();
std::vector m_Rects;
private:
- double m_fps{ 0.0f };
+ double m_Fps{ 0.0f };
- WorldGridManager m_gridManager {};
- Player m_player;
- Vector2f m_mousePos {};
+ WorldGridManager m_GridManager;
+ Player m_Player;
+ Vector2f m_MousePos {};
- Rectf m_viewport;
+ Rectf m_Viewport;
- ScreenManager* m_screenManager;
+ ScreenManager* m_ScreenManager;
WorldTile* m_pSelectedTile { nullptr };
- Building* m_refeulBuilding;
- Building* m_mineralBuilding;
- Building* m_junkBuilding;
- Building* m_repairBuilding;
+ Building* m_RefeulBuilding;
+ Building* m_MineralBuilding;
+ Building* m_JunkBuilding;
+ Building* m_RepairBuilding;
+
+ GuiMeter* m_Meter{ nullptr };
// ImGui Vars
diff --git a/Game/Particle/Particle.cpp b/Game/Particle/Particle.cpp
new file mode 100644
index 0000000..a83b9f5
--- /dev/null
+++ b/Game/Particle/Particle.cpp
@@ -0,0 +1,10 @@
+#include "pch.h"
+#include "Particle.h"
+Particle::Particle(const Vector2f& pos, const Vector2f& velocity, Texture* pTexture): m_Position{ pos }, m_Velocity{ velocity }, m_pTexture{ pTexture }
+{}
+void Particle::Update(float elapsedSec) {
+
+}
+void Particle::Draw() const {
+
+}
diff --git a/Game/Particle/Particle.h b/Game/Particle/Particle.h
new file mode 100644
index 0000000..5c55b21
--- /dev/null
+++ b/Game/Particle/Particle.h
@@ -0,0 +1,16 @@
+#pragma once
+#include "Texture.h"
+
+class Particle {
+public:
+ Particle() = default;
+ Particle(const Vector2f& pos, const Vector2f& velocity, Texture* pTexture);
+ void Update(float elapsedSec);
+ void Draw() const;
+private:
+ Vector2f m_Position;
+ Vector2f m_Velocity;
+ Vector2f m_Acceleration;
+
+ Texture* m_pTexture;
+};
diff --git a/Game/Player.cpp b/Game/Player.cpp
index 73e69e0..51ff8db 100644
--- a/Game/Player.cpp
+++ b/Game/Player.cpp
@@ -57,7 +57,7 @@ void Player::Draw() const {
const int frameWidth = 70; //TODO: fix this
int halfFrameWidth = frameWidth / 2;
- float bobOffset = m_BobUp ? 1 : 0;
+ int bobOffset = m_BobUp ? 1 : 0;
float rotateOffset = std::abs(m_Vel.x) / 40;
Vector2f drawPos = Vector2f { center.x, center.y + 9 + bobOffset };
diff --git a/Game/TextureManager.cpp b/Game/TextureManager.cpp
index f5cf8f7..e0c247e 100644
--- a/Game/TextureManager.cpp
+++ b/Game/TextureManager.cpp
@@ -22,7 +22,6 @@ Texture * TextureManager::GetTexture(const std::string& name) {
return pTexture;
}
TextureManager::~TextureManager() {
- //TODO: Loop over the m_Textures to delete them
for (const auto& p : m_Textures) {
delete p.second;
}
diff --git a/Game/TextureManager.h b/Game/TextureManager.h
index 4084ca1..00e17ab 100644
--- a/Game/TextureManager.h
+++ b/Game/TextureManager.h
@@ -3,18 +3,21 @@
#include "Texture.h"
-class TextureManager
-{
+class TextureManager {
public:
static TextureManager * GetInstance();
static void DestroyInstance();
Texture* GetTexture(const std::string& name);
+ TextureManager(const TextureManager& other) = delete;
+ TextureManager& operator=(const TextureManager& other) = delete;
+ TextureManager(TextureManager&& other) = delete;
+ TextureManager& operator=(TextureManager&& other) = delete;
private:
TextureManager() = default;
~TextureManager();
+
static TextureManager* m_pInstance;
std::map m_Textures {};
-
};