diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml
index b9d2954..38ce9ba 100644
--- a/.idea/.idea.Motherload/.idea/workspace.xml
+++ b/.idea/.idea.Motherload/.idea/workspace.xml
@@ -12,12 +12,23 @@
-
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
@@ -32,11 +43,12 @@
+
+
+
-
-
@@ -56,28 +68,28 @@
- {
- "keyToString": {
- "C++ Project.Game.executor": "Run",
- "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": "com.github.MitI_7.IDEOMApplicationPlugin",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -90,6 +102,7 @@
+
@@ -101,6 +114,7 @@
+
@@ -112,6 +126,7 @@
+
@@ -123,8 +138,10 @@
+
+
@@ -189,7 +206,12 @@
-
+
+
+
+
+
+
@@ -263,13 +285,22 @@
1713637256627
-
+
+
+ 1713738730939
+
+
+
+ 1713738730939
+
+
+
@@ -281,14 +312,8 @@
-
-
-
-
-
-
-
-
+
+
diff --git a/DevAssets/BuildingPlacement.psd b/DevAssets/BuildingPlacement.psd
new file mode 100644
index 0000000..cdc64e9
Binary files /dev/null and b/DevAssets/BuildingPlacement.psd differ
diff --git a/Engine/BaseGame.cpp b/Engine/BaseGame.cpp
index c45cd8e..bc84a73 100644
--- a/Engine/BaseGame.cpp
+++ b/Engine/BaseGame.cpp
@@ -197,6 +197,9 @@ void BaseGame::Run()
e.button.y = int(m_Window.height) - e.button.y;
this->ProcessMouseUpEvent(e.button);
break;
+ case SDL_MOUSEWHEEL:
+ this->ProcessMouseWheelEvent(e.wheel);
+ break;
}
}
diff --git a/Engine/BaseGame.h b/Engine/BaseGame.h
index 2dd5d20..ecb331f 100644
--- a/Engine/BaseGame.h
+++ b/Engine/BaseGame.h
@@ -7,49 +7,39 @@
class BaseGame
{
public:
- explicit BaseGame( const Window& window );
- BaseGame( const BaseGame& other ) = delete;
- BaseGame& operator=( const BaseGame& other ) = delete;
+ explicit BaseGame(const Window& window);
+ BaseGame(const BaseGame& other) = delete;
+ BaseGame& operator=(const BaseGame& other) = delete;
BaseGame(BaseGame&& other) = delete;
BaseGame& operator=(BaseGame&& other) = delete;
- virtual ~BaseGame( );
+ virtual ~BaseGame();
- void Run( );
+ void Run();
- virtual void Update(float elapsedSec)
- {
-
+ virtual void Update(float elapsedSec) {
}
- virtual void Draw() const
- {
-
+ virtual void Draw() const {
}
// Event handling
- virtual void ProcessKeyDownEvent(const SDL_KeyboardEvent& e)
- {
-
+ virtual void ProcessKeyDownEvent(const SDL_KeyboardEvent& e) {
}
- virtual void ProcessKeyUpEvent(const SDL_KeyboardEvent& e)
- {
-
+ virtual void ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
}
- virtual void ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e)
- {
-
+ virtual void ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
}
- virtual void ProcessMouseDownEvent(const SDL_MouseButtonEvent& e)
- {
-
+ virtual void ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
}
- virtual void ProcessMouseUpEvent(const SDL_MouseButtonEvent& e)
- {
-
+ virtual void ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
}
- virtual void ProcessImGui(){}
-
- const Rectf& GetViewPort() const
- {
+ virtual void ProcessMouseWheelEvent(const SDL_MouseWheelEvent& e) {
+ }
+
+
+ virtual void ProcessImGui() {
+ }
+
+ const Rectf& GetViewPort() const {
return m_Viewport;
}
@@ -66,8 +56,8 @@ private:
bool m_Initialized;
// Prevent timing jumps when debugging
const float m_MaxElapsedSeconds;
-
+
// FUNCTIONS
- void InitializeGameEngine( );
- void CleanupGameEngine( );
+ void InitializeGameEngine();
+ void CleanupGameEngine();
};
diff --git a/Game/Game.cpp b/Game/Game.cpp
index cfa9a48..b741b47 100644
--- a/Game/Game.cpp
+++ b/Game/Game.cpp
@@ -58,6 +58,7 @@ void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
m_MousePos = Vector2f { float(e.x), float(e.y) };
m_pCurrentLevel->MouseMove(Vector2f { float(e.x), float(e.y) });
+
}
@@ -83,6 +84,17 @@ void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
// break;
//}
}
+void Game::ProcessMouseWheelEvent(const SDL_MouseWheelEvent& e) {
+ Vector2f scroll = Vector2f { 0, 0 };
+ if (e.y > 0) {
+ scroll = Vector2f { 0, 1 };
+ }
+ else if (e.y < 0) {
+ scroll = Vector2f { 0, -1 };
+ }
+ //camera zoom
+ m_Camera.SetScale((m_Camera.GetScale() - e.preciseY * 0.1f));
+}
void Game::ProcessImGui() {
m_pCurrentLevel->ProcessImGui();
}
diff --git a/Game/Game.h b/Game/Game.h
index 1ffe6af..c0af4b9 100644
--- a/Game/Game.h
+++ b/Game/Game.h
@@ -25,6 +25,7 @@ public:
void ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) override;
void ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) override;
void ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) override;
+ void ProcessMouseWheelEvent(const SDL_MouseWheelEvent& e) override;
void ProcessImGui() override;
diff --git a/Game/GridSystem/WorldTile.cpp b/Game/GridSystem/WorldTile.cpp
index 1331879..7abba1b 100644
--- a/Game/GridSystem/WorldTile.cpp
+++ b/Game/GridSystem/WorldTile.cpp
@@ -10,6 +10,29 @@
#include "WorldGridManager.h"
+
+
+GroundTileType* getRandomGroundTile() {
+ // Generate a random weight between 0 and the sum of weights
+ float sumWeights = 0.0f;
+ for (const auto& pair : GroundTileWeights) {
+ sumWeights += pair.second;
+ }
+
+ float randomWeight = static_cast(rand()) / RAND_MAX * sumWeights;
+
+ // Find the corresponding ground tile type
+ float cumulativeWeight = 0.0f;
+ for (const auto& pair : GroundTileWeights) {
+ cumulativeWeight += pair.second;
+ if (randomWeight <= cumulativeWeight) {
+ return pair.first;
+ }
+ }
+
+ // This should never be reached if weights sum to 1.0
+ return Tiles::AIR; // Default value
+}
WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position }, m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
// const std::string dirtPath = + "tiles/dirt/dirt" + std::to_string(utils::randRange(1, 5)) + ".png";
// m_pTexture = new Texture(dirtPath);
diff --git a/Game/GridSystem/WorldTile.h b/Game/GridSystem/WorldTile.h
index 0e9d11d..1e278cc 100644
--- a/Game/GridSystem/WorldTile.h
+++ b/Game/GridSystem/WorldTile.h
@@ -11,11 +11,33 @@ enum class GroundTileTypes
Air,
Dirt,
Grass,
- Hard,
Stone,
- Iron
+ Lava,
+
+ //Special
+ Hard,
+
+ //Ores
+ Bronze,
+ Gold,
+ Iron,
};
+static std::map GroundTileTypeStrings {
+ { GroundTileTypes::Air, "Air" },
+ { GroundTileTypes::Dirt, "Dirt" },
+ { GroundTileTypes::Grass, "Grass" },
+ { GroundTileTypes::Stone, "Stone" },
+ { GroundTileTypes::Lava, "Lava" },
+ { GroundTileTypes::Hard, "Hard" },
+ { GroundTileTypes::Bronze, "Bronze" },
+ { GroundTileTypes::Gold, "Gold" },
+ { GroundTileTypes::Iron, "Iron" },
+};
+
+
+GroundTileType * getRandomGroundTile();
+
class GroundTileType
{
public:
@@ -90,8 +112,20 @@ namespace Tiles
{
static GroundTileType* AIR = new GroundTileType("", GroundTileTypes::Air);
static GroundTileType* DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5);
- static GroundTileType* IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
-
+
+ namespace Hazards
+ {
+ static GroundTileType* STONE = new RandomGroundTile("tiles/ores/Ore_Stone_[0].png", GroundTileTypes::Stone, 3);
+ static GroundTileType* LAVA = new RandomGroundTile("tiles/ores/Ore_Lava_[0].png", GroundTileTypes::Lava, 3);
+ }
+
+ namespace Ores
+ {
+ static GroundTileType* IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
+ static GroundTileType* BRONZE = new GroundTileType("tiles/ores/Ore_Bronzium.png", GroundTileTypes::Bronze);
+ static GroundTileType* GOLD = new GroundTileType("tiles/ores/Ore_Goldium.png", GroundTileTypes::Gold);
+ }
+
namespace Special
{
static GroundTileType* HARD_LEFT = new GroundTileType("tiles/dirt/special/hardLeft.png", GroundTileTypes::Hard);
@@ -102,6 +136,20 @@ namespace Tiles
}
}
+static std::map GroundTileWeights {
+ { Tiles::AIR, 0.2f },
+ { Tiles::DIRT, 0.5f },
+ { Tiles::Special::GRASS, 0.0f },
+ { Tiles::Hazards::STONE, 0.025f },
+ { Tiles::Hazards::LAVA, 0.01f },
+ { Tiles::Special::HARD_LEFT, 0.0f },
+ { Tiles::Special::HARD_MIDDLE, 0.0f },
+ { Tiles::Special::HARD_RIGHT, 0.0f },
+ { Tiles::Ores::BRONZE, 0.05f },
+ { Tiles::Ores::GOLD, 0.02f },
+ { Tiles::Ores::IRON, 0.1f },
+};
+
class WorldTile
{
public:
@@ -137,7 +185,7 @@ public:
private:
void DrawSide(const TileDirection& direction);
-
+
Vector2f m_Position;
GroundTileType* m_GroundTileType;
@@ -149,7 +197,7 @@ private:
surroundingTiles m_SurroundingTiles;
- std::vector m_SideTextures { 8, nullptr };
+ std::vector m_SideTextures { 8, nullptr };
Texture* m_pAllTexture;
};
diff --git a/Game/Levels/World/Building.h b/Game/Levels/World/Building.h
index e0b74d7..3fb6819 100644
--- a/Game/Levels/World/Building.h
+++ b/Game/Levels/World/Building.h
@@ -6,15 +6,19 @@ class Building
{
public:
Building(const std::string& filePath, const Vector2f& position, TextureManager* pTextureManager);
+ Building(const Building& other) = delete;
+ Building(Building&& other) = delete;
+
~Building();
void Draw() const;
void Update(float dt);
-
private:
Texture* m_Texture;
Vector2f m_Position;
Vector2f m_Size;
+
+ Rectf m_boundingBox;
};
diff --git a/Game/Levels/World/WorldLevel.cpp b/Game/Levels/World/WorldLevel.cpp
index d109c26..692814f 100644
--- a/Game/Levels/World/WorldLevel.cpp
+++ b/Game/Levels/World/WorldLevel.cpp
@@ -21,26 +21,12 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
m_viewport(viewport),
m_screenManager(ScreenManager::GetInstance()) {
// The grid is 34 x 50 big, the top center is 0,0 in world coords
- for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
- for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
+ for (int x { 0 }; x < WORLD_WIDTH; ++x) {
+ for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
const int actualX = x - WORLD_WIDTH / 2;
Vector2f pos = Vector2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
- GroundTileType* type = Tiles::AIR;
- switch (utils::randRange(0, 2)) {
- case 0:
- type = Tiles::DIRT;
- break;
- case 1:
- type = Tiles::IRON;
- break;
- case 2:
- //AIR
- break;
- default:
- std::cout << "??" << '\n';
- }
-
- m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, Tiles::DIRT, TextureManager::GetInstance(), &m_gridManager });
+ GroundTileType* type = getRandomGroundTile();
+ m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance(), &m_gridManager });
}
}
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
@@ -257,9 +243,11 @@ void WorldLevel::ProcessImGui() {
if (m_ShowCameraWindow) {
ImGui::Begin("Camera", &m_ShowCameraWindow, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("Camera Position: (%f, %f)", m_pCamera->GetPosition().x, m_pCamera->GetPosition().y);
+ 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->SetScale(1.0f);
}
ImGui::End();
}
diff --git a/Game/Player.cpp b/Game/Player.cpp
index 51dda10..68d927b 100644
--- a/Game/Player.cpp
+++ b/Game/Player.cpp
@@ -22,6 +22,12 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
m_currentAnimation = m_walkAnimation;
}
+Player::~Player() {
+ delete m_walkAnimation;
+ delete m_turnAnimation;
+ delete m_digAnimation;
+}
+
Collision::CollisionRect Player::GetCollisionRect() const {
Collision::CollisionRect rect = { m_Position, m_Size, m_Vel };
return rect;
diff --git a/Game/Player.h b/Game/Player.h
index 10a3346..53ea3d4 100644
--- a/Game/Player.h
+++ b/Game/Player.h
@@ -30,7 +30,12 @@ enum class DigDirection
class Player
{
public:
- Player(const Vector2f& Position, TextureManager* pTextureManager);
+ explicit Player(const Vector2f& Position, TextureManager* pTextureManager);
+ Player( const Player& other ) = default;
+ Player(Player&& other) = default;
+
+ ~Player();
+
Collision::CollisionRect GetCollisionRect() const;
void Update(float elapsedTime, WorldLevel& level);
void Draw() const;
diff --git a/Game/main.cpp b/Game/main.cpp
index 0046b01..c291ecf 100644
--- a/Game/main.cpp
+++ b/Game/main.cpp
@@ -2,7 +2,6 @@
#include
#include "Game.h"
-#define DEBUG
void StartHeapControl();
void DumpMemoryLeaks();
diff --git a/Resources/tiles/ores/Ore_Lava_1.jpg b/Resources/tiles/ores/Ore_Lava_1.jpg
deleted file mode 100644
index 59e145c..0000000
Binary files a/Resources/tiles/ores/Ore_Lava_1.jpg and /dev/null differ
diff --git a/Resources/tiles/ores/Ore_Lava_1.png b/Resources/tiles/ores/Ore_Lava_1.png
new file mode 100644
index 0000000..2f51258
Binary files /dev/null and b/Resources/tiles/ores/Ore_Lava_1.png differ
diff --git a/Resources/tiles/ores/Ore_Lava_2.jpg b/Resources/tiles/ores/Ore_Lava_2.jpg
deleted file mode 100644
index 4e6e0ca..0000000
Binary files a/Resources/tiles/ores/Ore_Lava_2.jpg and /dev/null differ
diff --git a/Resources/tiles/ores/Ore_Lava_2.png b/Resources/tiles/ores/Ore_Lava_2.png
new file mode 100644
index 0000000..716ebff
Binary files /dev/null and b/Resources/tiles/ores/Ore_Lava_2.png differ
diff --git a/Resources/tiles/ores/Ore_Lava_3.jpg b/Resources/tiles/ores/Ore_Lava_3.jpg
deleted file mode 100644
index a32df11..0000000
Binary files a/Resources/tiles/ores/Ore_Lava_3.jpg and /dev/null differ
diff --git a/Resources/tiles/ores/Ore_Lava_3.png b/Resources/tiles/ores/Ore_Lava_3.png
new file mode 100644
index 0000000..c31a622
Binary files /dev/null and b/Resources/tiles/ores/Ore_Lava_3.png differ
diff --git a/Resources/tiles/ores/Ore_Stone_1.jpg b/Resources/tiles/ores/Ore_Stone_1.jpg
deleted file mode 100644
index 2f6618d..0000000
Binary files a/Resources/tiles/ores/Ore_Stone_1.jpg and /dev/null differ
diff --git a/Resources/tiles/ores/Ore_Stone_1.png b/Resources/tiles/ores/Ore_Stone_1.png
new file mode 100644
index 0000000..36f7ed6
Binary files /dev/null and b/Resources/tiles/ores/Ore_Stone_1.png differ
diff --git a/Resources/tiles/ores/Ore_Stone_2.jpg b/Resources/tiles/ores/Ore_Stone_2.jpg
deleted file mode 100644
index 36cb22e..0000000
Binary files a/Resources/tiles/ores/Ore_Stone_2.jpg and /dev/null differ
diff --git a/Resources/tiles/ores/Ore_Stone_2.png b/Resources/tiles/ores/Ore_Stone_2.png
new file mode 100644
index 0000000..ba18626
Binary files /dev/null and b/Resources/tiles/ores/Ore_Stone_2.png differ
diff --git a/Resources/tiles/ores/Ore_Stone_3.jpg b/Resources/tiles/ores/Ore_Stone_3.jpg
deleted file mode 100644
index 9a7b083..0000000
Binary files a/Resources/tiles/ores/Ore_Stone_3.jpg and /dev/null differ
diff --git a/Resources/tiles/ores/Ore_Stone_3.png b/Resources/tiles/ores/Ore_Stone_3.png
new file mode 100644
index 0000000..d104672
Binary files /dev/null and b/Resources/tiles/ores/Ore_Stone_3.png differ