mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-16 04:21:48 +01:00
Add basic controller Support
Fix more memory leaks (seeing a trend here)
This commit is contained in:
99
.idea/.idea.Motherload/.idea/workspace.xml
generated
99
.idea/.idea.Motherload/.idea/workspace.xml
generated
@@ -10,34 +10,20 @@
|
||||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="">
|
||||
<change afterPath="$PROJECT_DIR$/Game/GroundTileTypeManager.cpp" afterDir="false" />
|
||||
<change afterPath="$PROJECT_DIR$/Game/GroundTileTypeManager.h" afterDir="false" />
|
||||
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="Add alot of memory leak fixes">
|
||||
<change beforePath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Engine/Text.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/Text.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Animations/Animation.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Animations/Animation.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Animations/Animation.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Animations/Animation.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Engine/BaseGame.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/BaseGame.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Engine/BaseGame.h" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/BaseGame.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Game.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Game.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Game.vcxproj.filters" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj.filters" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GridSystem/WorldGridManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldGridManager.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GridSystem/WorldGridManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldGridManager.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GridSystem/WorldTile.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldTile.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GridSystem/WorldTile.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GridSystem/WorldTile.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Gui/Screen.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screen.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Gui/Screens/FuelScreen.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screens/FuelScreen.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Gui/Screens/FuelScreen.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screens/FuelScreen.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Gui/Screens/ScreenManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screens/ScreenManager.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Gui/Screens/ScreenManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screens/ScreenManager.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Levels/MainMenu/MainMenuLevel.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Levels/MainMenu/MainMenuLevel.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Levels/World/Building.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Levels/World/Building.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GroundTileTypeManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GroundTileTypeManager.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/GroundTileTypeManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GroundTileTypeManager.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Levels/World/WorldLevel.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Player.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/Player.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/TextureManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/TextureManager.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/TextureManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/TextureManager.h" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Game/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/main.cpp" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -47,19 +33,33 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_BRANCH_BY_REPOSITORY">
|
||||
<map>
|
||||
<entry key="$PROJECT_DIR$" value="ebda39f690147cf0dfe51c6e4e121c4f1e3606e8" />
|
||||
<entry key="$PROJECT_DIR$" value="b406c8ffccf41d69fdf385448c8d0c2d49b2f970" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="HighlightingSettingsPerFile">
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/algorithm" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/type_traits" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/vector" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/Animations/Animation.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Engine/BaseGame.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/Animations/Animation.h" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/Camera.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/Gui/Screens/FuelScreen.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/pch.cpp" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Game/pch.h" root0="FORCE_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Libraries/SDLMain/SDL2-2.26.3/include/SDL.h" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/Libraries/SDLMain/SDL2-2.26.3/include/SDL_gamecontroller.h" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../week6/Lab/Lab6/Game.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../week6/Lab/Lab6/main.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||
<setting file="file://$PROJECT_DIR$/../../week6/Lab/Lab6/pch.h" root0="SKIP_HIGHLIGHTING" />
|
||||
@@ -80,28 +80,28 @@
|
||||
<option name="hideEmptyMiddlePackages" value="true" />
|
||||
<option name="showLibraryContents" value="true" />
|
||||
</component>
|
||||
<component name="PropertiesComponent"><![CDATA[{
|
||||
"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"
|
||||
<component name="PropertiesComponent">{
|
||||
"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"
|
||||
]
|
||||
}
|
||||
}]]></component>
|
||||
}</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="Game" type="CppProject" factoryName="C++ Project">
|
||||
<configuration_1>
|
||||
@@ -226,7 +226,9 @@
|
||||
<workItem from="1713817523511" duration="347000" />
|
||||
<workItem from="1713853942608" duration="1816000" />
|
||||
<workItem from="1713855878621" duration="24000" />
|
||||
<workItem from="1713858589244" duration="4723000" />
|
||||
<workItem from="1713858589244" duration="8169000" />
|
||||
<workItem from="1713888717170" duration="3930000" />
|
||||
<workItem from="1713982171548" duration="3263000" />
|
||||
</task>
|
||||
<task id="LOCAL-00001" summary="Rework Tile detection system">
|
||||
<option name="closed" value="true" />
|
||||
@@ -308,7 +310,15 @@
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1713738730939</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="11" />
|
||||
<task id="LOCAL-00011" summary="Add alot of memory leak fixes">
|
||||
<option name="closed" value="true" />
|
||||
<created>1713863838768</created>
|
||||
<option name="number" value="00011" />
|
||||
<option name="presentableId" value="LOCAL-00011" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1713863838768</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="12" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
@@ -328,7 +338,8 @@
|
||||
<MESSAGE value="Remove Point2f, replace with Vector2f" />
|
||||
<MESSAGE value="Fix digging" />
|
||||
<MESSAGE value="Added Buildings Fixed rendering bugs with edges" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Added Buildings Fixed rendering bugs with edges" />
|
||||
<MESSAGE value="Add alot of memory leak fixes" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Add alot of memory leak fixes" />
|
||||
</component>
|
||||
<component name="XSLT-Support.FileAssociations.UIState">
|
||||
<expand />
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,8 @@ private:
|
||||
// Prevent timing jumps when debugging
|
||||
const float m_MaxElapsedSeconds;
|
||||
|
||||
SDL_GameController* m_pGameController;
|
||||
|
||||
// FUNCTIONS
|
||||
void InitializeGameEngine();
|
||||
void CleanupGameEngine();
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -112,6 +112,7 @@
|
||||
<PrecompiledHeader>Use</PrecompiledHeader>
|
||||
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
|
||||
<BrowseInformation>true</BrowseInformation>
|
||||
<LanguageStandard>Default</LanguageStandard>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -32,14 +32,14 @@ enum TileDirection
|
||||
struct surroundingTiles
|
||||
{
|
||||
|
||||
std::map<TileDirection, WorldTile *> m_tiles;
|
||||
std::vector<WorldTile *> m_tiles{ 8, nullptr};
|
||||
|
||||
void SetTile(TileDirection direction, WorldTile* tile) {
|
||||
m_tiles[direction] = tile;
|
||||
m_tiles[static_cast<int>(direction)] = tile;
|
||||
}
|
||||
|
||||
WorldTile* GetTile(TileDirection direction) {
|
||||
return m_tiles[direction];
|
||||
return m_tiles[static_cast<int>(direction)];
|
||||
}
|
||||
|
||||
// bool IsAllType(const GroundTileType& type) {
|
||||
|
||||
@@ -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<TileDirection>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<GroundTileType *, float> 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<GroundTileType *, float> 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<GroundTileType*, float> GroundTileWeights;
|
||||
|
||||
void InitializeGroundTiles();
|
||||
|
||||
class WorldTile
|
||||
|
||||
@@ -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() {
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include <map>
|
||||
|
||||
#include "GridSystem/WorldTile.h"
|
||||
|
||||
|
||||
class GroundTileType;
|
||||
|
||||
@@ -10,6 +12,23 @@ public:
|
||||
static GroundTileTypeManager* GetInstance();
|
||||
static void DestroyInstance();
|
||||
|
||||
GroundTileType* AIR;
|
||||
GroundTileType* DIRT;
|
||||
|
||||
GroundTileType* STONE;
|
||||
GroundTileType* LAVA;
|
||||
|
||||
GroundTileType* IRON;
|
||||
GroundTileType* BRONZE;
|
||||
GroundTileType* GOLD;
|
||||
|
||||
GroundTileType* HARD_LEFT;
|
||||
GroundTileType* HARD_RIGHT;
|
||||
GroundTileType* HARD_MIDDLE;
|
||||
|
||||
GroundTileType* GRASS;
|
||||
|
||||
|
||||
//
|
||||
// static GroundTileType* AIR{ nullptr };
|
||||
//
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "Collision.h"
|
||||
#include "colors.h"
|
||||
#include "GroundTileTypeManager.h"
|
||||
#include "utils.h"
|
||||
#include "GridSystem/WorldTile.h"
|
||||
#include "Gui/Screens/ScreenManager.h"
|
||||
@@ -20,6 +21,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
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) {
|
||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
@@ -30,35 +32,35 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
|
||||
}
|
||||
}
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
m_gridManager.GetTileAtIndex(x, 0)->SetTileType(Tiles::AIR);
|
||||
m_gridManager.GetTileAtIndex(x, 1)->SetTileType(Tiles::Special::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(Tiles::Special::HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(Tiles::Special::HARD_RIGHT);
|
||||
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(Tiles::Special::HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-350, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-300, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-250, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-200, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {-150, -50})->SetTileType(Tiles::Special::HARD_RIGHT);
|
||||
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(Tiles::Special::HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {250, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {300, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {350, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {400, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {450, -50})->SetTileType(Tiles::Special::HARD_RIGHT);
|
||||
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(Tiles::Special::HARD_LEFT);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {700, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {750, -50})->SetTileType(Tiles::Special::HARD_MIDDLE);
|
||||
m_gridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(Tiles::Special::HARD_RIGHT);
|
||||
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);
|
||||
|
||||
|
||||
}
|
||||
@@ -92,7 +94,7 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
}
|
||||
if (m_pSelectedTile != nullptr) {
|
||||
if (utils::isMouseDown(SDL_BUTTON_LEFT)) {
|
||||
m_pSelectedTile->SetTileType(Tiles::AIR);
|
||||
m_pSelectedTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,7 +108,7 @@ void WorldLevel::Update(float elapsedSec) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
direction = directions[i];
|
||||
if (surroundingTiles.GetTile(direction) != nullptr) {
|
||||
if (surroundingTiles.GetTile(direction)->GetTileType() != Tiles::AIR) {
|
||||
if (surroundingTiles.GetTile(direction)->GetTileType() != GroundTileTypeManager::GetInstance()->AIR) {
|
||||
//surroundingTiles.GetTile(direction)->m_Hightlight = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include "colors.h"
|
||||
#include "GroundTileTypeManager.h"
|
||||
#include "utils.h"
|
||||
#include "Levels/World/WorldLevel.h"
|
||||
#include "Animations/Animation.h"
|
||||
@@ -105,7 +106,7 @@ bool Player::CanDig(Collision::CollisionDirection dir, WorldLevel& level) {
|
||||
GroundTileType type = *tile->GetTileType();
|
||||
//TODO: Add a list of non diggable tiles
|
||||
|
||||
if (type == Tiles::Special::HARD_LEFT || type == Tiles::Special::HARD_MIDDLE || type == Tiles::Special::HARD_RIGHT) {
|
||||
if (type == GroundTileTypeManager::GetInstance()->HARD_LEFT || type == GroundTileTypeManager::GetInstance()->HARD_MIDDLE || type == GroundTileTypeManager::GetInstance()->HARD_RIGHT) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -191,7 +192,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
|
||||
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
|
||||
WorldTile* tile = gridManager.GetTileAtIndex(x, y);
|
||||
if (*tile->GetTileType() != Tiles::AIR) {
|
||||
if (*tile->GetTileType() != GroundTileTypeManager::GetInstance()->AIR) {
|
||||
tile->m_Hightlight = false;
|
||||
if (Collision::DynamicRectVsRect(this->GetCollisionRect(), elapsedTime, tile->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) {
|
||||
contactTimes.emplace_back(std::pair<int, float> { x + y * WORLD_WIDTH, t });
|
||||
@@ -273,7 +274,7 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
|
||||
std::cout << progress << '\n';
|
||||
m_Position = utils::lerp(m_DigStart, m_DigDestination, progress);
|
||||
if (progress >= 0.5f && !m_HasDeletedTile) {
|
||||
m_DigTile->SetTileType(Tiles::AIR);
|
||||
m_DigTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
|
||||
m_DigTile = nullptr;
|
||||
m_HasDeletedTile = true;
|
||||
}
|
||||
|
||||
2040
Resources/gamecontrollerdb.txt
Normal file
2040
Resources/gamecontrollerdb.txt
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user