diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml
index e87ac59..47ff246 100644
--- a/.idea/.idea.Motherload/.idea/workspace.xml
+++ b/.idea/.idea.Motherload/.idea/workspace.xml
@@ -10,34 +10,20 @@
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
+
+
-
-
-
-
-
@@ -47,19 +33,33 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
-
+
+
@@ -80,28 +80,28 @@
- {
+ "keyToString": {
+ "C++ Project.Game.executor": "Debug",
+ "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": "preferences.pluginManager",
+ "vue.rearranger.settings.migration": "true"
},
- "keyToStringList": {
- "rider.external.source.directories": [
- "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache",
- "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache",
- "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
+ "keyToStringList": {
+ "rider.external.source.directories": [
+ "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache",
+ "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache",
+ "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
]
}
-}]]>
+}
@@ -226,7 +226,9 @@
-
+
+
+
@@ -308,7 +310,15 @@
1713738730939
-
+
+
+ 1713863838768
+
+
+
+ 1713863838768
+
+
@@ -328,7 +338,8 @@
-
+
+
diff --git a/Engine/BaseGame.cpp b/Engine/BaseGame.cpp
index bc84a73..9611a59 100644
--- a/Engine/BaseGame.cpp
+++ b/Engine/BaseGame.cpp
@@ -40,7 +40,7 @@ void BaseGame::InitializeGameEngine()
#endif
// Initialize SDL
- if (SDL_Init(SDL_INIT_VIDEO /*| SDL_INIT_AUDIO*/) < 0)
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_GAMECONTROLLER | SDL_INIT_JOYSTICK | SDL_INIT_HAPTIC/*| SDL_INIT_AUDIO*/) < 0)
{
std::cerr << "BaseGame::Initialize( ), error when calling SDL_Init: " << SDL_GetError() << std::endl;
return;
@@ -145,8 +145,27 @@ void BaseGame::InitializeGameEngine()
std::cerr << "BaseGame::Initialize( ), error when calling Mix_OpenAudio: " << Mix_GetError() << std::endl;
return;
}
-
+
+ //Initialize controller
+ m_pGameController = nullptr;
+ if (SDL_NumJoysticks() < 1)
+ {
+ std::cout << "Warning: No controller connected!" << std::endl;
+ }
+ else
+ {
+ //Load joystick
+ m_pGameController = SDL_GameControllerOpen(0);
+ if (m_pGameController == nullptr)
+ {
+ std::cout << "Warning: Unable to open game controller! SDL Error: " << SDL_GetError() << std::endl;
+ }
+ }
+
+ SDL_GameControllerAddMappingsFromFile("gamecontrollerdb.txt");
+
+
m_Initialized = true;
}
@@ -200,6 +219,12 @@ void BaseGame::Run()
case SDL_MOUSEWHEEL:
this->ProcessMouseWheelEvent(e.wheel);
break;
+ case SDL_CONTROLLERBUTTONDOWN:
+ std::cout << "Button " << int(e.jbutton.button) << " down on controller " << int(e.jbutton.which) << std::endl;
+ if(e.cbutton.button == SDL_GameControllerButton::SDL_CONTROLLER_BUTTON_X) {
+ std::cout << "X button pressed" << std::endl;
+ }
+ break;
}
}
diff --git a/Engine/BaseGame.h b/Engine/BaseGame.h
index ecb331f..b80a0f7 100644
--- a/Engine/BaseGame.h
+++ b/Engine/BaseGame.h
@@ -57,6 +57,8 @@ private:
// Prevent timing jumps when debugging
const float m_MaxElapsedSeconds;
+ SDL_GameController* m_pGameController;
+
// FUNCTIONS
void InitializeGameEngine();
void CleanupGameEngine();
diff --git a/Game/Game.cpp b/Game/Game.cpp
index ffd07be..70811cf 100644
--- a/Game/Game.cpp
+++ b/Game/Game.cpp
@@ -90,14 +90,6 @@ void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
//}
}
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
float newScale = m_Camera.GetScale() - e.preciseY * 0.1f;
if(newScale < 0.0f) {
newScale = 0.0f;
diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj
index fa9d262..a8fdbbb 100644
--- a/Game/Game.vcxproj
+++ b/Game/Game.vcxproj
@@ -112,6 +112,7 @@
Use
pch.h
true
+ Default
Console
diff --git a/Game/GridSystem/WorldGridManager.cpp b/Game/GridSystem/WorldGridManager.cpp
index 067c3c9..8f49d25 100644
--- a/Game/GridSystem/WorldGridManager.cpp
+++ b/Game/GridSystem/WorldGridManager.cpp
@@ -22,20 +22,20 @@ WorldGridManager::~WorldGridManager() {
}
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;
+ // 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) {
diff --git a/Game/GridSystem/WorldGridManager.h b/Game/GridSystem/WorldGridManager.h
index 40e2728..62a4dc8 100644
--- a/Game/GridSystem/WorldGridManager.h
+++ b/Game/GridSystem/WorldGridManager.h
@@ -32,14 +32,14 @@ enum TileDirection
struct surroundingTiles
{
- std::map m_tiles;
+ std::vector m_tiles{ 8, nullptr};
void SetTile(TileDirection direction, WorldTile* tile) {
- m_tiles[direction] = tile;
+ m_tiles[static_cast(direction)] = tile;
}
WorldTile* GetTile(TileDirection direction) {
- return m_tiles[direction];
+ return m_tiles[static_cast(direction)];
}
// bool IsAllType(const GroundTileType& type) {
diff --git a/Game/GridSystem/WorldTile.cpp b/Game/GridSystem/WorldTile.cpp
index 0b74c6c..d54c4ac 100644
--- a/Game/GridSystem/WorldTile.cpp
+++ b/Game/GridSystem/WorldTile.cpp
@@ -5,6 +5,7 @@
#include "Camera.h"
#include "colors.h"
+#include "GroundTileTypeManager.h"
#include "../TextureManager.h"
#include "utils.h"
#include "WorldGridManager.h"
@@ -12,7 +13,7 @@
-GroundTileType* getRandomGroundTile() {
+GroundTileType * getRandomGroundTile() {
// Generate a random weight between 0 and the sum of weights
float sumWeights = 0.0f;
for (const auto& pair : GroundTileWeights) {
@@ -31,13 +32,41 @@ GroundTileType* getRandomGroundTile() {
}
// This should never be reached if weights sum to 1.0
- return Tiles::AIR; // Default value
+ return GroundTileTypeManager::GetInstance()->AIR; // Default value
}
-// void InitializeGroundTiles() {
-//
-// Tiles::AIR = new GroundTileType("", GroundTileTypes::Air);
-// }
-WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager, WorldGridManager* pGridManager) : m_Position { position }, m_GroundTileType { groundTileType }, m_pGridManager { pGridManager } {
+void InitializeGroundTiles() {
+ Tiles tiles {};
+ GroundTileTypeManager::GetInstance()->AIR = new GroundTileType("", GroundTileTypes::Air);
+ GroundTileTypeManager::GetInstance()->DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5);
+
+ GroundTileTypeManager::GetInstance()->STONE = new RandomGroundTile("tiles/ores/Ore_Stone_[0].png", GroundTileTypes::Stone, 3);
+ GroundTileTypeManager::GetInstance()->LAVA = new RandomGroundTile("tiles/ores/Ore_Lava_[0].png", GroundTileTypes::Lava, 3);
+
+ GroundTileTypeManager::GetInstance()->IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
+ GroundTileTypeManager::GetInstance()->BRONZE = new GroundTileType("tiles/ores/Ore_Bronzium.png", GroundTileTypes::Bronze);
+ GroundTileTypeManager::GetInstance()->GOLD = new GroundTileType("tiles/ores/Ore_Goldium.png", GroundTileTypes::Gold);
+
+ GroundTileTypeManager::GetInstance()->GRASS = new RandomGroundTile("tiles/dirt/special/grass[0].png", GroundTileTypes::Grass, 2);
+ GroundTileTypeManager::GetInstance()->HARD_LEFT = new GroundTileType("tiles/dirt/special/hardLeft.png", GroundTileTypes::Hard);
+ GroundTileTypeManager::GetInstance()->HARD_RIGHT = new GroundTileType("tiles/dirt/special/hardRight.png", GroundTileTypes::Hard);
+ GroundTileTypeManager::GetInstance()->HARD_MIDDLE = new GroundTileType("tiles/dirt/special/hardMiddle.png", GroundTileTypes::Hard);
+
+ GroundTileWeights = {
+ { GroundTileTypeManager::GetInstance()->AIR, 0.2f },
+ { GroundTileTypeManager::GetInstance()->DIRT, 0.5f },
+ { GroundTileTypeManager::GetInstance()->GRASS, 0.0f },
+ { GroundTileTypeManager::GetInstance()->STONE, 0.025f },
+ { GroundTileTypeManager::GetInstance()->LAVA, 0.01f },
+ { GroundTileTypeManager::GetInstance()->HARD_LEFT, 0.0f },
+ { GroundTileTypeManager::GetInstance()->HARD_MIDDLE, 0.0f },
+ { GroundTileTypeManager::GetInstance()->HARD_RIGHT, 0.0f },
+ { GroundTileTypeManager::GetInstance()->BRONZE, 0.05f },
+ { GroundTileTypeManager::GetInstance()->GOLD, 0.02f },
+ { GroundTileTypeManager::GetInstance()->IRON, 0.1f },
+ };
+}
+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);
m_pTexture = pTextureManager->GetTexture(groundTileType->getPath());
@@ -51,7 +80,7 @@ WorldTile::WorldTile(const Vector2f& position, GroundTileType* groundTileType, T
m_SideTextures[TileDirection::BottomMiddle] = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleBottom.png");
m_SideTextures[TileDirection::MiddleLeft] = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleLeft.png");
m_SideTextures[TileDirection::MiddleRight] = pTextureManager->GetTexture("tiles/dirt/sidepieces/middleRight.png");
-
+
m_pAllTexture = pTextureManager->GetTexture("tiles/dirt/sidepieces/all.png");
}
@@ -64,21 +93,22 @@ void WorldTile::Draw() {
case GroundTileTypes::Air: {
//check if it's all around dirt
bool allDirt = true;
- for (int i = 0; i < 8; i++) {
- const WorldTile* tile = m_SurroundingTiles.GetTile(static_cast(i));
- if(tile != nullptr) { //Tile exists
+ TileDirection allDirtDirections[] { TileDirection::BottomMiddle, TileDirection::MiddleLeft, TileDirection::MiddleRight, TileDirection::TopMiddle };
+ for (int i = 0; i < 3; i++) {
+ const WorldTile* tile = m_SurroundingTiles.GetTile(allDirtDirections[i]);
+ if (tile != nullptr) { //Tile exists
const GroundTileTypes type = tile->GetTileType()->getType();
- if(type != Tiles::DIRT->getType()) {
+ if (type != GroundTileTypeManager::GetInstance()->DIRT->getType()) {
allDirt = false;
break;
}
}
}
- if(allDirt) {
+ if (allDirt) {
m_pAllTexture->Draw(m_Position);
return;
}
- if(*m_GroundTileType == Tiles::AIR) {
+ else {
this->DrawSide(TileDirection::TopLeft);
this->DrawSide(TileDirection::TopRight);
this->DrawSide(TileDirection::BottomLeft);
@@ -88,9 +118,8 @@ void WorldTile::Draw() {
this->DrawSide(TileDirection::BottomMiddle);
this->DrawSide(TileDirection::MiddleLeft);
this->DrawSide(TileDirection::MiddleRight);
- break;
}
-
+ break;
}
case GroundTileTypes::Dirt:
case GroundTileTypes::Hard:
@@ -101,9 +130,9 @@ void WorldTile::Draw() {
default:
break;
}
-
-
- if (*m_GroundTileType != Tiles::AIR) {
+
+
+ if (*m_GroundTileType != GroundTileTypeManager::GetInstance()->AIR) {
m_pTexture->Draw(m_Position);
if (m_Hightlight) {
utils::SetColor(Colors::GREEN);
@@ -111,16 +140,14 @@ void WorldTile::Draw() {
}
}
-
-
}
void WorldTile::Update(const Camera* camera) {
m_pGridManager->GetIndexFromPosition(m_Position);
m_SurroundingTiles = m_pGridManager->GetSurroundingTiles(this);
- const Vector2f mouse_pos = camera->TransformMouse(Vector2f{utils::GetMousePos().x, 500 - utils::GetMousePos().y});
- m_Hightlight = utils::IsPointInRect(mouse_pos, Rectf{GetCollisionRect().pos, GetCollisionRect().size});
+ const Vector2f mouse_pos = camera->TransformMouse(Vector2f { utils::GetMousePos().x, 500 - utils::GetMousePos().y });
+ m_Hightlight = utils::IsPointInRect(mouse_pos, Rectf { GetCollisionRect().pos, GetCollisionRect().size });
}
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
return Collision::TileCollisionRect { m_Position, GetSize(), ( this ) };
@@ -128,18 +155,19 @@ Collision::TileCollisionRect WorldTile::GetCollisionRect() {
void WorldTile::DrawSide(const TileDirection& direction) {
const WorldTile* tile = m_SurroundingTiles.GetTile(direction);
- if(tile != nullptr) {
+ if (tile != nullptr) {
const GroundTileTypes type = tile->GetTileType()->getType();
- if(direction == TileDirection::BottomMiddle || direction == TileDirection::BottomLeft || direction == TileDirection::BottomRight) {
- if(type == Tiles::Special::GRASS->getType() || type == Tiles::Special::HARD_LEFT->getType() || type == Tiles::Special::HARD_MIDDLE->getType() || type == Tiles::Special::HARD_RIGHT->getType()) {
+ if (direction == TileDirection::BottomMiddle || direction == TileDirection::BottomLeft || direction == TileDirection::BottomRight) {
+ if (type == GroundTileTypeManager::GetInstance()->GRASS->getType() || type == GroundTileTypeManager::GetInstance()->HARD_LEFT->getType() || type ==
+ GroundTileTypeManager::GetInstance()->HARD_MIDDLE->getType() || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT->getType()) {
//Fix for edges being renderd on grass / hard tiles
//TODO: Possible fix if i have time
return;
}
}
- if(type != Tiles::AIR->getType()) {
+ if (type != GroundTileTypeManager::GetInstance()->AIR->getType()) {
m_SideTextures[direction]->Draw(m_Position);
}
}
-}
\ No newline at end of file
+}
diff --git a/Game/GridSystem/WorldTile.h b/Game/GridSystem/WorldTile.h
index 1649dd3..7a97f70 100644
--- a/Game/GridSystem/WorldTile.h
+++ b/Game/GridSystem/WorldTile.h
@@ -108,48 +108,28 @@ private:
int m_maxRandom;
};
-namespace Tiles
+class Tiles
{
- static GroundTileType* AIR = new GroundTileType("", GroundTileTypes::Air);
- static GroundTileType* DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5);
-
- 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);
- static GroundTileType* HARD_RIGHT = new GroundTileType("tiles/dirt/special/hardRight.png", GroundTileTypes::Hard);
- static GroundTileType* HARD_MIDDLE = new GroundTileType("tiles/dirt/special/hardMiddle.png", GroundTileTypes::Hard);
-
- static GroundTileType* GRASS = new RandomGroundTile("tiles/dirt/special/grass[0].png", GroundTileTypes::Grass, 2);
- }
-}
-
-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 },
+public:
+
};
+// 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 },
+// };
+
+static std::map GroundTileWeights;
+
void InitializeGroundTiles();
class WorldTile
diff --git a/Game/GroundTileTypeManager.cpp b/Game/GroundTileTypeManager.cpp
index a5c9c31..9b055c8 100644
--- a/Game/GroundTileTypeManager.cpp
+++ b/Game/GroundTileTypeManager.cpp
@@ -13,10 +13,10 @@ GroundTileTypeManager* GroundTileTypeManager::GetInstance() {
}
void GroundTileTypeManager::DestroyInstance() {
}
+GroundTileTypeManager::GroundTileTypeManager(): AIR(new GroundTileType("", GroundTileTypes::Air)), DIRT(new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5)){
+}
// void GroundTileTypeManager::Initialize() {
// AIR = new GroundTileType("", GroundTileTypes::Air);
// }
-GroundTileTypeManager::GroundTileTypeManager() {
-}
GroundTileTypeManager::~GroundTileTypeManager() {
}
diff --git a/Game/GroundTileTypeManager.h b/Game/GroundTileTypeManager.h
index cbf1581..817b200 100644
--- a/Game/GroundTileTypeManager.h
+++ b/Game/GroundTileTypeManager.h
@@ -1,6 +1,8 @@
#pragma once
#include