Compare commits

..

15 Commits

Author SHA1 Message Date
Bram Verhulst
3c83e566dd Add sun / moon, started on score / GameManager 2024-05-16 12:44:53 +02:00
Bram Verhulst
8866f33c09 Add Text rendering and Hull / Fuel Meters 2024-05-16 02:04:36 +02:00
Bram Verhulst
600050c198 Add Main UI, Fuel meter. Add particles to player digging 2024-05-14 12:28:37 +02:00
Bram Verhulst
d5c002c2b2 Add Particles (basic) 2024-05-09 13:50:52 +02:00
Bram Verhulst
8c3a485c2d Started on GuiIcon, General fixes 2024-05-09 00:46:05 +02:00
Bram Verhulst
d3b932df22 Fix digging 2024-05-07 10:35:18 +02:00
Bram Verhulst
77784a167e Remove All Memory leaks 2024-05-02 14:57:47 +02:00
Bram Verhulst
b6be73019f Add window icon,
Add digging animation (Non functional)
2024-05-02 12:28:12 +02:00
Bram Verhulst
64915567dc Update gitignore 2024-04-30 12:04:58 +02:00
Bram Verhulst
a1a2406084 Add player turning (Finally) 2024-04-30 11:57:24 +02:00
Bram Verhulst
8d56c747be Add fps 2024-04-30 09:01:59 +02:00
Bram Verhulst
da8377e7a0 Temp commit 2024-04-25 11:04:40 +02:00
Bram Verhulst
8a1506d42f Edit .gitignore 2024-04-24 21:44:11 +02:00
Bram Verhulst
b50a2d6fc0 Merge remote-tracking branch 'origin/main' 2024-04-24 21:39:09 +02:00
Bram Verhulst
f5d352239c Add basic controller Support
Fix more memory leaks (seeing a trend here)
2024-04-24 21:38:14 +02:00
102 changed files with 3376 additions and 493 deletions

5
.gitignore vendored
View File

@@ -400,3 +400,8 @@ FodyWeavers.xsd
# Game Project specifics -> do not ignore:
!**/Libraries/**/x86/
!**/Libraries/**/x64/
.idea/
.idea/*
.idea/workspace.xml

View File

@@ -11,33 +11,16 @@
</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" />
<change afterPath="$PROJECT_DIR$/Game/Levels/World/OrbitingObject.cpp" afterDir="false" />
<change afterPath="$PROJECT_DIR$/Game/Levels/World/OrbitingObject.h" afterDir="false" />
<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$/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/GameManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GameManager.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/GameManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GameManager.h" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Gui/Screens/MainScreen.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screens/MainScreen.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Gui/Screens/MainScreen.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Gui/Screens/MainScreen.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 +30,34 @@
<component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY">
<map>
<entry key="$PROJECT_DIR$" value="ebda39f690147cf0dfe51c6e4e121c4f1e3606e8" />
<entry key="$PROJECT_DIR$" value="d3b932df22970cf2f14e9dd79721ccae1d938a38" />
</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="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="file://$PROJECT_DIR$/Game/Animations/Animation.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/../../../../../../Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.37.32822/include/xstring" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Engine/BaseGame.cpp" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Engine/BaseGame.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Engine/Texture.cpp" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Engine/utils.cpp" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Engine/utils.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="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/Levels/World/Building.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Game/Player.cpp" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Game/Player.h" root0="FORCE_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 +78,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">{
&quot;keyToString&quot;: {
&quot;C++ Project.Game.executor&quot;: &quot;Debug&quot;,
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;,
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;,
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;,
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;,
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;,
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;,
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;,
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;,
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;,
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot;
},
"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"
&quot;keyToStringList&quot;: {
&quot;rider.external.source.directories&quot;: [
&quot;C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache&quot;,
&quot;C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache&quot;,
&quot;C:\\Users\\Bram\\AppData\\Local\\Symbols\\src&quot;
]
}
}]]></component>
}</component>
<component name="RunManager">
<configuration name="Game" type="CppProject" factoryName="C++ Project">
<configuration_1>
@@ -226,7 +224,33 @@
<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" />
<workItem from="1713995813246" duration="2567000" />
<workItem from="1714026889126" duration="4211000" />
<workItem from="1714046400732" duration="2462000" />
<workItem from="1714372163827" duration="2962000" />
<workItem from="1714459066696" duration="21789000" />
<workItem from="1714640485259" duration="321000" />
<workItem from="1714641751956" duration="3705000" />
<workItem from="1714652168988" duration="1613000" />
<workItem from="1714653831106" duration="2710000" />
<workItem from="1714763594789" duration="1983000" />
<workItem from="1714824060444" duration="811000" />
<workItem from="1715031948901" duration="46000" />
<workItem from="1715063584283" duration="11702000" />
<workItem from="1715170674144" duration="2320000" />
<workItem from="1715206284291" duration="5406000" />
<workItem from="1715254613428" duration="3973000" />
<workItem from="1715293126957" duration="547000" />
<workItem from="1715334251448" duration="4485000" />
<workItem from="1715360147026" duration="5634000" />
<workItem from="1715583954732" duration="5283000" />
<workItem from="1715669033601" duration="11720000" />
<workItem from="1715762731245" duration="3986000" />
<workItem from="1715773968873" duration="3580000" />
<workItem from="1715814533138" duration="12142000" />
</task>
<task id="LOCAL-00001" summary="Rework Tile detection system">
<option name="closed" value="true" />
@@ -308,7 +332,79 @@
<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>
<task id="LOCAL-00012" summary="Add fps">
<option name="closed" value="true" />
<created>1714460546894</created>
<option name="number" value="00012" />
<option name="presentableId" value="LOCAL-00012" />
<option name="project" value="LOCAL" />
<updated>1714460546894</updated>
</task>
<task id="LOCAL-00013" summary="Add player turning (Finally)">
<option name="closed" value="true" />
<created>1714471045905</created>
<option name="number" value="00013" />
<option name="presentableId" value="LOCAL-00013" />
<option name="project" value="LOCAL" />
<updated>1714471045905</updated>
</task>
<task id="LOCAL-00014" summary="Update gitignore">
<option name="closed" value="true" />
<created>1714471502013</created>
<option name="number" value="00014" />
<option name="presentableId" value="LOCAL-00014" />
<option name="project" value="LOCAL" />
<updated>1714471502013</updated>
</task>
<task id="LOCAL-00015" summary="Remove All Memory leaks">
<option name="closed" value="true" />
<created>1714654669410</created>
<option name="number" value="00015" />
<option name="presentableId" value="LOCAL-00015" />
<option name="project" value="LOCAL" />
<updated>1714654669410</updated>
</task>
<task id="LOCAL-00016" summary="Fix digging">
<option name="closed" value="true" />
<created>1715070920513</created>
<option name="number" value="00016" />
<option name="presentableId" value="LOCAL-00016" />
<option name="project" value="LOCAL" />
<updated>1715070920513</updated>
</task>
<task id="LOCAL-00017" summary="Started on GuiIcon, General fixes">
<option name="closed" value="true" />
<created>1715208368790</created>
<option name="number" value="00017" />
<option name="presentableId" value="LOCAL-00017" />
<option name="project" value="LOCAL" />
<updated>1715208368790</updated>
</task>
<task id="LOCAL-00018" summary="Add Particles (basic)">
<option name="closed" value="true" />
<created>1715255455692</created>
<option name="number" value="00018" />
<option name="presentableId" value="LOCAL-00018" />
<option name="project" value="LOCAL" />
<updated>1715255455692</updated>
</task>
<task id="LOCAL-00019" summary="Add Text rendering and Hull / Fuel Meters">
<option name="closed" value="true" />
<created>1715817878533</created>
<option name="number" value="00019" />
<option name="presentableId" value="LOCAL-00019" />
<option name="project" value="LOCAL" />
<updated>1715817878533</updated>
</task>
<option name="localTasksCounter" value="20" />
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
@@ -326,9 +422,17 @@
<MESSAGE value="Fixed sidePieces (Need to add more cases tho)" />
<MESSAGE value="Pre Point2f Nuke&#10;Fixed drawing,&#10;Added general optimisations" />
<MESSAGE value="Remove Point2f, replace with Vector2f" />
<MESSAGE value="Fix digging" />
<MESSAGE value="Added Buildings&#10;Fixed rendering bugs with edges" />
<option name="LAST_COMMIT_MESSAGE" value="Added Buildings&#10;Fixed rendering bugs with edges" />
<MESSAGE value="Add alot of memory leak fixes" />
<MESSAGE value="Add fps" />
<MESSAGE value="Add player turning (Finally)" />
<MESSAGE value="Update gitignore" />
<MESSAGE value="Remove All Memory leaks" />
<MESSAGE value="Fix digging" />
<MESSAGE value="Started on GuiIcon, General fixes" />
<MESSAGE value="Add Particles (basic)" />
<MESSAGE value="Add Text rendering and Hull / Fuel Meters" />
<option name="LAST_COMMIT_MESSAGE" value="Add Text rendering and Hull / Fuel Meters" />
</component>
<component name="XSLT-Support.FileAssociations.UIState">
<expand />

View File

@@ -1,15 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml
# Rider ignored files
/modules.xml
/projectSettingsUpdater.xml
/contentModel.xml
/.idea.Prog2Engine.iml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
# GitHub Copilot persisted chat sessions
/copilot/chatSessions

View File

@@ -1 +0,0 @@
Prog2Engine

View File

@@ -1,4 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
</project>

View File

@@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="UserContentModel">
<attachedFolders />
<explicitIncludes />
<explicitExcludes />
</component>
</project>

View File

@@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -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;
@@ -107,7 +107,7 @@ void BaseGame::InitializeGameEngine()
// Setup Dear ImGui style
ImGui::StyleColorsDark();
//ImGui::StyleColorsLight();
// ImGui::StyleColorsLight();
// Setup Platform/Renderer backends
ImGui_ImplSDL2_InitForOpenGL(m_pWindow, m_pContext);
@@ -145,8 +145,33 @@ void BaseGame::InitializeGameEngine()
std::cerr << "BaseGame::Initialize( ), error when calling Mix_OpenAudio: " << Mix_GetError() << std::endl;
return;
}
m_pIcon = IMG_Load("icon.png");
SDL_SetWindowIcon(m_pWindow, m_pIcon);
// delete icon;
//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");
SDL_RendererInfo m_RendererInfo;
SDL_GetRendererInfo(SDL_GetRenderer(m_pWindow), &m_RendererInfo);
m_Initialized = true;
}
@@ -200,6 +225,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;
}
}
@@ -245,6 +276,8 @@ void BaseGame::CleanupGameEngine()
ImGui_ImplSDL2_Shutdown();
ImGui::DestroyContext();
SDL_FreeSurface(m_pIcon);
SDL_GL_DeleteContext(m_pContext);
SDL_DestroyWindow(m_pWindow);

View File

@@ -57,6 +57,10 @@ private:
// Prevent timing jumps when debugging
const float m_MaxElapsedSeconds;
SDL_GameController* m_pGameController;
SDL_Surface* m_pIcon;
// FUNCTIONS
void InitializeGameEngine();
void CleanupGameEngine();

View File

@@ -1,7 +1,7 @@
#include "Text.h"
#include <iostream>
Text::Text(const std::string& text, const std::string& fontPath, int size, const Color4f& color): m_Text(text), m_FontPath(fontPath), m_Color(color) {
Text::Text(const std::string& text, const std::string& fontPath, int size, const Color4f& color): m_Text(text), m_FontPath(fontPath), m_Size(size), m_Color(color) {
m_Texture = new Texture(text, fontPath, size, color);
m_IsCreatedOk = m_Texture->IsCreationOk();
if(!m_IsCreatedOk) {
@@ -14,5 +14,17 @@ Text::~Text() {
}
}
void Text::Draw(const Vector2f& pos) const {
m_Texture->Draw(pos);
if(m_IsCreatedOk) {
m_Texture->Draw(pos);
} else {
std::cout << "Trying to render a Text that is not correctly made,\nText: " << m_Text << std::endl;
}
}
void Text::ChangeText(const std::string& text) {
if(m_IsCreatedOk && m_Texture->IsCreationOk()) {
delete m_Texture;
m_Texture = new Texture(text, m_FontPath, m_Size, m_Color);
} else {
std::cout << "This is wierd??: " << m_Text << std::endl;
}
}

View File

@@ -13,11 +13,14 @@ public:
void Draw(const Vector2f& pos) const;
void ChangeText(const std::string& text);
private:
std::string m_Text;
std::string m_FontPath;
int m_Size;
Color4f m_Color;
Texture* m_Texture;
bool m_IsCreatedOk{ false };

View File

@@ -692,6 +692,12 @@ float utils::map(float value, float start1, float stop1, float start2, float sto
float newVal = (value - start1) / (stop1 - start1) * (stop2 - start2) + start2;
return newVal;
}
float utils::clamp(float value, float min, float max) {
return std::max(min, std::min(value, max));
}
Vector2f utils::clamp(const Vector2f& value, const Vector2f& min, const Vector2f& max) {
return Vector2f { clamp(value.x, min.x, max.x), clamp(value.y, min.y, max.y) };
}
bool utils::isKeyDown(int keycode) {
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
if (pStates != nullptr) {

View File

@@ -111,6 +111,9 @@ namespace utils
Vector2f lerp(const Vector2f& a, const Vector2f& b, float t);
float map(float value, float start1, float stop1, float start2, float stop2);
float clamp(float value, float min, float max);
Vector2f clamp(const Vector2f& value, const Vector2f& min, const Vector2f& max);
#pragma endregion CollisionFunctionality
bool isKeyDown(SDL_Keycode keycode);

View File

@@ -1,29 +1,57 @@
#include "pch.h"
#include "Animation.h"
#include <iostream>
#include "utils.h"
Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames) {
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) {
if (m_isPlaying) {
m_FrameTimer -= elapsedSec;
if (m_FrameTimer <= 0.0f) {
m_FrameTimer = 0.1f;
m_FrameTimer = m_FrameDuration;
++m_CurrentFrame;
if (m_CurrentFrame >= m_Frames) {
m_CurrentFrame = 0;
if (!m_isLooping) {
m_hasPlayedOnce = true;
m_isPlaying = false;
}
}
}
}
}
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<float>(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;
}

View File

@@ -4,19 +4,21 @@
class Animation
{
public:
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect);
~Animation() = default;
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping = true);
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 SetPlaying(bool isPlaying);
void SetFlipped(bool isFlipped);
void Reset();
bool IsDone() const;
int GetFrameCount() const;
void SetFrame(int frame);
private:
Texture* m_pTexture;
@@ -26,6 +28,11 @@ private:
int m_CurrentFrame { 0 };
float m_FrameTimer { 0.0f };
float m_FrameDuration { 0.1f };
bool m_isPlaying { true };
bool m_isFlipped { false };
bool m_isLooping { true };
bool m_hasPlayedOnce { false };
};

View File

@@ -5,7 +5,9 @@
#include <algorithm>
#include "colors.h"
#include "GridSystem/GroundTileTypeManager.h"
#include "utils.h"
#include "GridSystem/WorldTile.h"
#include "Levels/World/WorldLevel.h"
@@ -28,8 +30,8 @@ void Game::Initialize() {
void Game::Cleanup() {
//TODO: ask how 2 delete the TextureManager
ScreenManager::DestroyInstance();
GroundTileTypeManager::DestroyInstance();
TextureManager::DestroyInstance();
}
@@ -37,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 {
@@ -55,49 +57,28 @@ void Game::Draw() const {
void Game::ProcessKeyDownEvent(const SDL_KeyboardEvent& e) {
//std::cout << "KEYDOWN event: " << e.keysym.sym << std::endl;
if(e.keysym.sym == SDLK_BACKQUOTE) {
m_imGui = !m_imGui;
}
}
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) {
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;
@@ -105,5 +86,7 @@ void Game::ProcessMouseWheelEvent(const SDL_MouseWheelEvent& e) {
m_Camera.SetScale(newScale);
}
void Game::ProcessImGui() {
m_pCurrentLevel->ProcessImGui();
if(m_imGui) {
m_pCurrentLevel->ProcessImGui();
}
}

View File

@@ -32,7 +32,6 @@ public:
static Rectf VIEWPORT;
private:
// FUNCTIONS
void Initialize();
void Cleanup();
@@ -43,8 +42,11 @@ private:
Level* m_pCurrentLevel;
Vector2f m_MousePos {};
Vector2f m_MousePosition {};
Vector2f m_MouseOffset {};
bool m_IsRightMouseDown {};
bool m_imGui{ true };
};

View File

@@ -71,7 +71,7 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<IncludePath>C:\Users\Bram\Desktop\Programming 2\Exam\dae16-VerhulstBram\Game;C:\Users\Bram\Desktop\Programming 2\Exam\dae16-VerhulstBram\Engine\imgui;$(SolutionDir)\Libraries\SDLTtf\SDL2_ttf-2.20.2\include;$(SolutionDir)\Libraries\SDLMixer\SDL2_mixer-2.6.3\include;$(SolutionDir)\Libraries\SDLImage\SDL2_image-2.6.3\include;$(SolutionDir)\Libraries\SDLMain\SDL2-2.26.3\include;$(SolutionDir)\Engine;$(IncludePath)</IncludePath>
<IncludePath>$(SolutionDir)Game;$(SolutionDir)Engine\imgui;$(SolutionDir)\Libraries\SDLTtf\SDL2_ttf-2.20.2\include;$(SolutionDir)\Libraries\SDLMixer\SDL2_mixer-2.6.3\include;$(SolutionDir)\Libraries\SDLImage\SDL2_image-2.6.3\include;$(SolutionDir)\Libraries\SDLMain\SDL2-2.26.3\include;$(SolutionDir)\Engine;$(IncludePath)</IncludePath>
<LibraryPath>$(SolutionDir)\x64\Debug;$(SolutionDir)\Libraries\SDLTtf\SDL2_ttf-2.20.2\lib\x64;$(SolutionDir)\Libraries\SDLMixer\SDL2_mixer-2.6.3\lib\x64;$(SolutionDir)\Libraries\SDLImage\SDL2_image-2.6.3\lib\x64;$(SolutionDir)\Libraries\SDLMain\SDL2-2.26.3\lib\x64;$(LibraryPath)</LibraryPath>
<CustomBuildAfterTargets>BuildCompile</CustomBuildAfterTargets>
</PropertyGroup>
@@ -112,6 +112,7 @@
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<BrowseInformation>true</BrowseInformation>
<LanguageStandard>Default</LanguageStandard>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -156,6 +157,80 @@
<ClCompile Include="Camera.cpp" />
<ClCompile Include="Game.cpp" />
<ClCompile Include="GameManager.cpp" />
<ClCompile Include="GridSystem\GroundTileTypeManager.cpp">
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<Optimization>Disabled</Optimization>
<SupportJustMyCode>true</SupportJustMyCode>
<AssemblerOutput>NoListing</AssemblerOutput>
<AssemblerListingLocation>x64\Debug\</AssemblerListingLocation>
<UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
<BrowseInformation>true</BrowseInformation>
<BrowseInformationFile>x64\Debug\</BrowseInformationFile>
<CompileAs>Default</CompileAs>
<ConformanceMode>true</ConformanceMode>
<DiagnosticsFormat>Column</DiagnosticsFormat>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
<ErrorReporting>Prompt</ErrorReporting>
<ExpandAttributedSource>false</ExpandAttributedSource>
<ExceptionHandling>Sync</ExceptionHandling>
<EnableASAN>false</EnableASAN>
<EnableFuzzer>false</EnableFuzzer>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<FloatingPointModel>Precise</FloatingPointModel>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<GenerateModuleDependencies>false</GenerateModuleDependencies>
<GenerateSourceDependencies>false</GenerateSourceDependencies>
<GenerateXMLDocumentationFiles>false</GenerateXMLDocumentationFiles>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<IntrinsicFunctions>false</IntrinsicFunctions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard_C>Default</LanguageStandard_C>
<MinimalRebuild>false</MinimalRebuild>
<ModuleDependenciesFile>x64\Debug\</ModuleDependenciesFile>
<ModuleOutputFile>x64\Debug\</ModuleOutputFile>
<OmitDefaultLibName>false</OmitDefaultLibName>
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<WholeProgramOptimization>false</WholeProgramOptimization>
<ObjectFileName>x64\Debug\</ObjectFileName>
<CallingConvention>Cdecl</CallingConvention>
<ProgramDataBaseFileName>x64\Debug\vc143.pdb</ProgramDataBaseFileName>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>x64\Debug\Game.pch</PrecompiledHeaderOutputFile>
<PreprocessToFile>false</PreprocessToFile>
<PreprocessKeepComments>false</PreprocessKeepComments>
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
<RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
<ScanSourceForModuleDependencies>false</ScanSourceForModuleDependencies>
<ShowIncludes>false</ShowIncludes>
<SourceDependenciesFile>x64\Debug\</SourceDependenciesFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<BufferSecurityCheck>true</BufferSecurityCheck>
<SmallerTypeCheck>false</SmallerTypeCheck>
<SpectreMitigation>false</SpectreMitigation>
<StructMemberAlignment>Default</StructMemberAlignment>
<TrackerLogDirectory>x64\Debug\Game.tlog\</TrackerLogDirectory>
<TranslateIncludes>false</TranslateIncludes>
<MinimalRebuildFromTracking>true</MinimalRebuildFromTracking>
<TreatWarningAsError>false</TreatWarningAsError>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<UseFullPaths>true</UseFullPaths>
<WarningLevel>Level3</WarningLevel>
<XMLDocumentationFileName>x64\Debug\</XMLDocumentationFileName>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<IntelJCCErratum>false</IntelJCCErratum>
<BuildStlModules>false</BuildStlModules>
<TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
<ExternalWarningLevel>InheritWarningLevel</ExternalWarningLevel>
<TreatExternalTemplatesAsInternal>true</TreatExternalTemplatesAsInternal>
<DisableAnalyzeExternal>false</DisableAnalyzeExternal>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_UNICODE;UNICODE;</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<LinkCompiled>true</LinkCompiled>
</ClCompile>
<ClCompile Include="GridSystem\WorldGridManager.cpp">
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -306,10 +381,86 @@
<LinkCompiled>true</LinkCompiled>
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</BrowseInformation>
</ClCompile>
<ClCompile Include="GroundTileTypeManager.cpp" />
<ClCompile Include="Gui\Button.cpp" />
<ClCompile Include="Gui\GuiButton.cpp" />
<ClCompile Include="Gui\GuiElement.cpp" />
<ClCompile Include="Gui\GuiMeter.cpp" />
<ClCompile Include="Gui\GuiText.cpp">
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<Optimization>Disabled</Optimization>
<SupportJustMyCode>true</SupportJustMyCode>
<AssemblerOutput>NoListing</AssemblerOutput>
<AssemblerListingLocation>x64\Debug\</AssemblerListingLocation>
<UndefineAllPreprocessorDefinitions>false</UndefineAllPreprocessorDefinitions>
<BrowseInformation>true</BrowseInformation>
<BrowseInformationFile>x64\Debug\</BrowseInformationFile>
<CompileAs>Default</CompileAs>
<ConformanceMode>true</ConformanceMode>
<DiagnosticsFormat>Column</DiagnosticsFormat>
<DisableLanguageExtensions>false</DisableLanguageExtensions>
<ErrorReporting>Prompt</ErrorReporting>
<ExpandAttributedSource>false</ExpandAttributedSource>
<ExceptionHandling>Sync</ExceptionHandling>
<EnableASAN>false</EnableASAN>
<EnableFuzzer>false</EnableFuzzer>
<EnableFiberSafeOptimizations>false</EnableFiberSafeOptimizations>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<FloatingPointModel>Precise</FloatingPointModel>
<ForceConformanceInForLoopScope>true</ForceConformanceInForLoopScope>
<GenerateModuleDependencies>false</GenerateModuleDependencies>
<GenerateSourceDependencies>false</GenerateSourceDependencies>
<GenerateXMLDocumentationFiles>false</GenerateXMLDocumentationFiles>
<InlineFunctionExpansion>Default</InlineFunctionExpansion>
<IntrinsicFunctions>false</IntrinsicFunctions>
<IgnoreStandardIncludePath>false</IgnoreStandardIncludePath>
<LanguageStandard>Default</LanguageStandard>
<LanguageStandard_C>Default</LanguageStandard_C>
<MinimalRebuild>false</MinimalRebuild>
<ModuleDependenciesFile>x64\Debug\</ModuleDependenciesFile>
<ModuleOutputFile>x64\Debug\</ModuleOutputFile>
<OmitDefaultLibName>false</OmitDefaultLibName>
<FavorSizeOrSpeed>Neither</FavorSizeOrSpeed>
<WholeProgramOptimization>false</WholeProgramOptimization>
<ObjectFileName>x64\Debug\</ObjectFileName>
<CallingConvention>Cdecl</CallingConvention>
<ProgramDataBaseFileName>x64\Debug\vc143.pdb</ProgramDataBaseFileName>
<PrecompiledHeader>Use</PrecompiledHeader>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<PrecompiledHeaderOutputFile>x64\Debug\Game.pch</PrecompiledHeaderOutputFile>
<PreprocessToFile>false</PreprocessToFile>
<PreprocessKeepComments>false</PreprocessKeepComments>
<PreprocessSuppressLineNumbers>false</PreprocessSuppressLineNumbers>
<RemoveUnreferencedCodeData>true</RemoveUnreferencedCodeData>
<ScanSourceForModuleDependencies>false</ScanSourceForModuleDependencies>
<ShowIncludes>false</ShowIncludes>
<SourceDependenciesFile>x64\Debug\</SourceDependenciesFile>
<SuppressStartupBanner>true</SuppressStartupBanner>
<BufferSecurityCheck>true</BufferSecurityCheck>
<SmallerTypeCheck>false</SmallerTypeCheck>
<SpectreMitigation>false</SpectreMitigation>
<StructMemberAlignment>Default</StructMemberAlignment>
<TrackerLogDirectory>x64\Debug\Game.tlog\</TrackerLogDirectory>
<TranslateIncludes>false</TranslateIncludes>
<MinimalRebuildFromTracking>true</MinimalRebuildFromTracking>
<TreatWarningAsError>false</TreatWarningAsError>
<TreatWChar_tAsBuiltInType>true</TreatWChar_tAsBuiltInType>
<UseFullPaths>true</UseFullPaths>
<WarningLevel>Level3</WarningLevel>
<XMLDocumentationFileName>x64\Debug\</XMLDocumentationFileName>
<DebugInformationFormat>EditAndContinue</DebugInformationFormat>
<IntelJCCErratum>false</IntelJCCErratum>
<BuildStlModules>false</BuildStlModules>
<TreatAngleIncludeAsExternal>false</TreatAngleIncludeAsExternal>
<ExternalWarningLevel>InheritWarningLevel</ExternalWarningLevel>
<TreatExternalTemplatesAsInternal>true</TreatExternalTemplatesAsInternal>
<DisableAnalyzeExternal>false</DisableAnalyzeExternal>
<PreprocessorDefinitions>_DEBUG;_CONSOLE;_UNICODE;UNICODE;</PreprocessorDefinitions>
<SDLCheck>true</SDLCheck>
<LinkCompiled>true</LinkCompiled>
</ClCompile>
<ClCompile Include="Gui\Screen.cpp" />
<ClCompile Include="Gui\Screens\FuelScreen.cpp" />
<ClCompile Include="Gui\Screens\MainScreen.cpp" />
<ClCompile Include="Gui\Screens\ScreenManager.cpp" />
<ClCompile Include="Levels\Level.cpp">
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
@@ -388,6 +539,7 @@
</ClCompile>
<ClCompile Include="Levels\MainMenu\MainMenuLevel.cpp" />
<ClCompile Include="Levels\World\Building.cpp" />
<ClCompile Include="Levels\World\OrbitingObject.cpp" />
<ClCompile Include="Levels\World\WorldLevel.cpp">
<RuntimeLibrary>MultiThreadedDebugDll</RuntimeLibrary>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -464,6 +616,7 @@
<BrowseInformation Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</BrowseInformation>
</ClCompile>
<ClCompile Include="main.cpp" />
<ClCompile Include="Particle\Particle.cpp" />
<ClCompile Include="pch.cpp" />
<ClCompile Include="Player.cpp" />
<ClCompile Include="TextureManager.cpp" />
@@ -473,17 +626,23 @@
<ClInclude Include="Camera.h" />
<ClInclude Include="Game.h" />
<ClInclude Include="GameManager.h" />
<ClInclude Include="GridSystem\GroundTileTypeManager.h" />
<ClInclude Include="GridSystem\WorldGridManager.h" />
<ClInclude Include="GridSystem\WorldTile.h" />
<ClInclude Include="GroundTileTypeManager.h" />
<ClInclude Include="Gui\Button.h" />
<ClInclude Include="Gui\GuiButton.h" />
<ClInclude Include="Gui\GuiElement.h" />
<ClInclude Include="Gui\GuiMeter.h" />
<ClInclude Include="Gui\GuiText.h" />
<ClInclude Include="Gui\Screen.h" />
<ClInclude Include="Gui\Screens\FuelScreen.h" />
<ClInclude Include="Gui\Screens\MainScreen.h" />
<ClInclude Include="Gui\Screens\ScreenManager.h" />
<ClInclude Include="Levels\Level.h" />
<ClInclude Include="Levels\MainMenu\MainMenuLevel.h" />
<ClInclude Include="Levels\World\Building.h" />
<ClInclude Include="Levels\World\OrbitingObject.h" />
<ClInclude Include="Levels\World\WorldLevel.h" />
<ClInclude Include="Particle\Particle.h" />
<ClInclude Include="pch.h" />
<ClInclude Include="Player.h" />
<ClInclude Include="TextureManager.h" />
@@ -495,6 +654,6 @@
<LocalDebuggerWorkingDirectory>$(TargetDir)</LocalDebuggerWorkingDirectory>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<IncludePath>C:\Users\Bram\Desktop\Programming 2\Exam\dae16-VerhulstBram\Game;C:\Users\Bram\Desktop\Programming 2\Exam\dae16-VerhulstBram\Engine\imgui;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
<IncludePath>$(SolutionDir)Game;$(SolutionDir)Engine\imgui;$(VC_IncludePath);$(WindowsSDK_IncludePath);</IncludePath>
</PropertyGroup>
</Project>

View File

@@ -69,6 +69,9 @@
<ClCompile Include="Levels\World\WorldLevel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="GroundTileTypeManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Game.h">
@@ -122,5 +125,8 @@
<ClInclude Include="Levels\World\WorldLevel.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="GroundTileTypeManager.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
</Project>

View File

@@ -1,2 +1,50 @@
#include "pch.h"
#include "GameManager.h"
GameManager* GameManager::m_pInstance = nullptr;
GameManager& GameManager::GetInstance() {
if (m_pInstance == nullptr) {
m_pInstance = new GameManager();
}
return *m_pInstance;
}
void GameManager::SetMainScreen(MainScreen* pMainScreen) {
m_pMainScreen = pMainScreen;
//TODO: not the best but ¯\_(ツ)_/¯
}
void GameManager::SetFuel(int fuel) {
m_Fuel = fuel;
}
int GameManager::GetFuel() const {
return m_Fuel;
}
void GameManager::DecreaseFuel(int fuel) {
m_Fuel -= fuel;
}
void GameManager::AddFuel(int fuel) {
m_Fuel += fuel;
}
void GameManager::SetHullIntegrity(int hullIntegrity) {
m_HullIntegrity = hullIntegrity;
}
int GameManager::GetHullIntegrity() const {
return m_HullIntegrity;
}
void GameManager::DamageHull(int damage) {
m_HullIntegrity -= damage;
}
void GameManager::SetScore(int score) {
m_Score = score;
}
int GameManager::GetScore() const {
return m_Score;
}
void GameManager::IncreaseScore(int score) {
m_Score += score;
}
void GameManager::Update(float elapsedSecs) {
m_pMainScreen->SetFuelMeterValue(m_Fuel);
m_pMainScreen->SetHullMeterValue(m_HullIntegrity);
m_pMainScreen->SetScore(std::to_string(m_Score));
}

View File

@@ -1,12 +1,38 @@
#pragma once
#include "Player.h"
#include "Gui/Screens/MainScreen.h"
class GameManager
{
class GameManager {
public:
float balance{ 0.0f };
float fuel{ 0.0f };
static GameManager& GetInstance();
static GameManager* m_pInstance;
void SetMainScreen(MainScreen* pMainScreen);
void SetFuel(int fuel);
int GetFuel() const;
void DecreaseFuel(int fuel);
void AddFuel(int fuel);
void SetHullIntegrity(int hullIntegrity);
int GetHullIntegrity() const;
void DamageHull(int damage);
void SetScore(int score);
int GetScore() const;
void IncreaseScore(int score);
void Update(float elapsedSecs);
private:
GameManager() = default;
float m_Balance{ 0.0f };
int m_HullIntegrity{ 100 };
int m_Fuel{ 100 };
int m_Score{ 0 };
MainScreen* m_pMainScreen{ nullptr };
};

View File

@@ -0,0 +1,31 @@
#include "pch.h"
#include "GroundTileTypeManager.h"
#include "GridSystem/WorldTile.h"
GroundTileTypeManager* GroundTileTypeManager::m_pInstance = nullptr;
GroundTileTypeManager* GroundTileTypeManager::GetInstance() {
if (m_pInstance == nullptr) {
m_pInstance = new GroundTileTypeManager();
}
return m_pInstance;
}
void GroundTileTypeManager::DestroyInstance() {
delete m_pInstance->AIR;
delete m_pInstance->DIRT;
delete m_pInstance->STONE;
delete m_pInstance->LAVA;
delete m_pInstance->IRON;
delete m_pInstance->BRONZE;
delete m_pInstance->GOLD;
delete m_pInstance->HARD_LEFT;
delete m_pInstance->HARD_RIGHT;
delete m_pInstance->HARD_MIDDLE;
delete m_pInstance->GRASS;
delete m_pInstance;
}
GroundTileTypeManager::GroundTileTypeManager() = default;
GroundTileTypeManager::~GroundTileTypeManager() = default;

View File

@@ -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 };
//
@@ -35,4 +54,3 @@ private:
static GroundTileTypeManager* m_pInstance;
};

View File

@@ -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) {

View File

@@ -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::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];
WorldTile * GetTile(TileDirection direction) {
return m_tiles[static_cast<int>(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;

View File

@@ -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,42 @@ 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 +81,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");
}
@@ -63,22 +93,23 @@ void WorldTile::Draw() {
switch (m_GroundTileType->getType()) {
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
const GroundTileTypes type = tile->GetTileType()->getType();
if(type != Tiles::DIRT->getType()) {
allDirt = false;
break;
}
}
}
if(allDirt) {
m_pAllTexture->Draw(m_Position);
return;
}
if(*m_GroundTileType == Tiles::AIR) {
// bool allDirt = true;
// 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 != GroundTileTypeManager::GetInstance()->DIRT->getType()) {
// allDirt = false;
// break;
// }
// }
// }
// if (allDirt) {
// m_pAllTexture->Draw(m_Position);
// return;
// }
// else {
this->DrawSide(TileDirection::TopLeft);
this->DrawSide(TileDirection::TopRight);
this->DrawSide(TileDirection::BottomLeft);
@@ -88,9 +119,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 +131,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 +141,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 +156,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);
}
}
}
}

View File

@@ -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

View File

@@ -1,22 +0,0 @@
#include "pch.h"
#include "GroundTileTypeManager.h"
#include "GridSystem/WorldTile.h"
GroundTileTypeManager* GroundTileTypeManager::m_pInstance = nullptr;
GroundTileTypeManager* GroundTileTypeManager::GetInstance() {
if (m_pInstance == nullptr) {
m_pInstance = new GroundTileTypeManager();
}
return m_pInstance;
}
void GroundTileTypeManager::DestroyInstance() {
}
// void GroundTileTypeManager::Initialize() {
// AIR = new GroundTileType("", GroundTileTypes::Air);
// }
GroundTileTypeManager::GroundTileTypeManager() {
}
GroundTileTypeManager::~GroundTileTypeManager() {
}

View File

@@ -1,28 +1,28 @@
#include "pch.h"
#include "Button.h"
#include "GuiButton.h"
#include <iostream>
#include "colors.h"
#include "utils.h"
Button::Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
GuiButton::GuiButton(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
m_Texture = manager->GetTexture(filePath);
if(size.x == 0 && size.y == 0) {
m_Size = Vector2f{float(m_Texture->GetWidth()), float(m_Texture->GetHeight())};
}
std::cout << "Button created" << '\n';
}
Button::~Button() {
GuiButton::~GuiButton() {
std::cout << "Button destroyed" << '\n';
}
void Button::Draw() const {
void GuiButton::Draw() const {
Rectf dest = Rectf(m_Position, m_Size);
Rectf src = Rectf(0, 0, m_Texture->GetWidth(), m_Texture->GetHeight());
if(m_IsHovered) {
m_Texture->Draw(dest, src, false);
}
}
void Button::Update(float elapsedSec) {
void GuiButton::Update(float elapsedSec) {
Vector2f mousePos = utils::GetMousePos();
Rectf buttonRect = Rectf(m_Position, m_Size);

View File

@@ -2,17 +2,18 @@
#include <functional>
#include <iostream>
#include "GuiElement.h"
#include "Texture.h"
#include "../TextureManager.h"
class Button
class GuiButton : public GuiElement
{
public:
Button() = default;
Button(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
~Button();
void Draw() const;
void Update(float elapsedSec);
GuiButton() = default;
GuiButton(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager);
~GuiButton() override;
virtual void Draw() const override;
virtual void Update(float elapsedSec) override;
void SetOnClick(std::function<void(void)> onClick) {
m_OnClick = onClick;

2
Game/Gui/GuiElement.cpp Normal file
View File

@@ -0,0 +1,2 @@
#include "pch.h"
#include "GuiElement.h"

14
Game/Gui/GuiElement.h Normal file
View File

@@ -0,0 +1,14 @@
#pragma once
class GuiElement
{
public:
GuiElement() = default;
virtual ~GuiElement() = default;
virtual void Draw() const = 0;
virtual void Update(float elapsedSec) = 0;
private:
};

27
Game/Gui/GuiMeter.cpp Normal file
View File

@@ -0,0 +1,27 @@
#include "pch.h"
#include "GuiMeter.h"
#include "TextureManager.h"
#include "utils.h"
GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager): GuiMeter(
filePath, pos, frameSize, frameSize, frameCount, manager) {
}
GuiMeter::GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, Vector2f drawSize, int frameCount, TextureManager* manager): m_Position(pos),
m_DrawSize(drawSize), m_FrameCount(frameCount) {
m_Animation = new Animation(manager->GetTexture(filePath), frameCount, 0.0f, Rectf { 0, 0, frameSize.x, frameSize.y }, false);
}
GuiMeter::~GuiMeter() {
delete m_Animation;
}
void GuiMeter::Draw() const {
m_Animation->Draw(m_Position, Rectf{m_Position, m_DrawSize});
utils::DrawRect(Rectf { m_Position, m_DrawSize});
}
void GuiMeter::Update(float elapsedSec) {
m_Value += 1;
const int frame = static_cast<int>(utils::map(m_Value, 0.0f, m_MaxValue, 0, (float)m_Animation->GetFrameCount()));
m_Animation->SetFrame(frame);
}
void GuiMeter::SetValue(float value) {
m_Value = value;
}

34
Game/Gui/GuiMeter.h Normal file
View File

@@ -0,0 +1,34 @@
#pragma once
#include "GuiElement.h"
#include "Texture.h"
#include "Animations/Animation.h"
class TextureManager;
class GuiMeter final : public GuiElement
{
public:
GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, int frameCount, TextureManager* manager);
GuiMeter(const std::string& filePath, Vector2f pos, Vector2f frameSize, Vector2f drawSize, int frameCount, TextureManager* manager);
GuiMeter(GuiMeter& other) = delete;
GuiMeter& operator=(const GuiMeter& other) = delete;
GuiMeter(GuiMeter&& other) = delete;
GuiMeter& operator=(GuiMeter&& other) = delete;
virtual ~GuiMeter() override;
virtual void Draw() const override;
virtual void Update(float elapsedSec) override;
void SetValue(float value);
private:
Animation* m_Animation{ nullptr };
Vector2f m_Position;
Vector2f m_DrawSize;
float m_Value{ 0.0f };
const float m_MaxValue{ 100.0f };
int m_FrameCount;
};

26
Game/Gui/GuiText.cpp Normal file
View File

@@ -0,0 +1,26 @@
#include "pch.h"
#include "GuiText.h"
#include "colors.h"
GuiText::GuiText(const Vector2f& position, const std::string& text, const std::string& fontPath, int size, const Color4f& color): m_Position(position), m_Text(new Text(text, fontPath, size, color)) {
}
GuiText::GuiText(): m_Position(100,100), m_Text(new Text("Undefined", "fonts/verdana.ttf", 10, Colors::WHITE)) {
}
void GuiText::Draw() const {
m_Text->Draw(m_Position);
}
void GuiText::Update(float elapsedSec) {
}
void GuiText::ChangeText(const std::string& text) const {
m_Text->ChangeText(text);
}
GuiText::~GuiText() {
delete m_Text;
}

20
Game/Gui/GuiText.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include "GuiElement.h"
#include "Text.h"
#include "Texture.h"
class GuiText : public GuiElement {
public:
GuiText(const Vector2f& position, const std::string& text, const std::string& fontPath, int size, const Color4f& color);
GuiText();
void Draw() const override;
void Update(float elapsedSec) override;
void ChangeText(const std::string& text) const;
~GuiText() override;
private:
Vector2f m_Position;
Text* m_Text;
};

View File

@@ -2,24 +2,30 @@
#include "Screen.h"
Screen::Screen(const std::string& filePath, Vector2f pos, Vector2f size, TextureManager* manager): m_Position(pos), m_Size(size) {
m_Background = manager->GetTexture(filePath);
if(!filePath.empty()) {
m_Background = manager->GetTexture(filePath);
} else {
m_Background = nullptr;
}
}
Screen::~Screen() {
for (Button* b : m_Buttons) {
for (GuiElement* b : m_Elements) {
delete b;
}
}
void Screen::Update(float elapsedSecs) {
for (Button* b : m_Buttons) {
for (GuiElement* b : m_Elements) {
b->Update(elapsedSecs);
}
}
void Screen::Draw() const {
Rectf dest = Rectf(m_Position, m_Size);
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
m_Background->Draw(dest, src, false);
if(m_Background != nullptr) { //Incase there is no background
Rectf dest = Rectf(m_Position, m_Size);
Rectf src = Rectf(0, 0, m_Background->GetWidth(), m_Background->GetHeight());
m_Background->Draw(dest, src, false);
}
for (Button* b : m_Buttons) {
b->Draw();
for (GuiElement* GuiElement : m_Elements) {
GuiElement->Draw();
}
}

View File

@@ -1,7 +1,7 @@
#pragma once
#include <vector>
#include "Button.h"
#include "GuiButton.h"
#include "structs.h"
#include "Texture.h"
#include "../TextureManager.h"
@@ -14,7 +14,7 @@ public:
virtual ~Screen();
void AddButton(Button* button) { m_Buttons.push_back(button); }
void AddElement(GuiElement* element) { m_Elements.push_back(element); }
virtual void Update(float elapsedSecs);
virtual void Draw() const;
@@ -24,5 +24,5 @@ private:
Texture* m_Background{ nullptr };
std::vector<Button*> m_Buttons;
std::vector<GuiElement*> m_Elements;
};

View File

@@ -15,34 +15,33 @@ FuelScreen::FuelScreen(const std::string& filePath, Vector2f pos, Vector2f size,
const Vector2f closeButtonOffset = Vector2f { 460, 396 - 14 };
Vector2f closeButtonPos = fuelScreenCenter + closeButtonOffset;
closeButtonPos.y -= 18;
Button* closeFuelButton = new Button { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
GuiButton* closeFuelButton = new GuiButton { "gui/close.png", closeButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
closeFuelButton->SetOnClick([this]() { ScreenManager::GetInstance()->CloseScreen(); });
this->AddButton(closeFuelButton);
this->AddElement(closeFuelButton);
const Vector2f oneDollarButtonPos = Vector2f { 451, 287 };
Button* fiveDollarButton = new Button { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fiveDollarButton);
GuiButton* fiveDollarButton = new GuiButton { "gui/fuel/5dollars.png", oneDollarButtonPos , Vector2f{0,0}, TextureManager::GetInstance() };
this->AddElement(fiveDollarButton);
const Vector2f tenDollarButtonPos = oneDollarButtonPos + Vector2f { 113, -1 };
Button* tenDollarButton = new Button { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(tenDollarButton);
GuiButton* tenDollarButton = new GuiButton { "gui/fuel/10dollars.png", tenDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddElement(tenDollarButton);
const Vector2f twentyFiveDollarButtonPos = oneDollarButtonPos + Vector2f { 0, -89 };
Button* twentyFiveDollarButton = new Button { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(twentyFiveDollarButton);
GuiButton* twentyFiveDollarButton = new GuiButton { "gui/fuel/25dollars.png", twentyFiveDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddElement(twentyFiveDollarButton);
const Vector2f fiftyDollarButtonPos = twentyFiveDollarButtonPos + Vector2f { 114, 0 };
Button* fiftyDollarButton = new Button { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fiftyDollarButton);
GuiButton* fiftyDollarButton = new GuiButton { "gui/fuel/50dollars.png", fiftyDollarButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddElement(fiftyDollarButton);
const Vector2f fillTankButtonPos = Vector2f { 450, 108 };
Button* fillTankButton = new Button { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddButton(fillTankButton);
GuiButton* fillTankButton = new GuiButton { "gui/fuel/fillTank.png", fillTankButtonPos, Vector2f{0,0}, TextureManager::GetInstance() };
this->AddElement(fillTankButton);
}
FuelScreen::~FuelScreen() {
}
FuelScreen::~FuelScreen() = default;
void FuelScreen::Draw() const {
Screen::Draw();

View File

@@ -0,0 +1,45 @@
#include "pch.h"
#include "MainScreen.h"
#include "colors.h"
#include "utils.h"
#include "Gui/GuiText.h"
MainScreen::MainScreen(TextureManager* manager) : Screen("", Vector2f{0, 0}, Vector2f{900.f, 500.f}, manager) {
Vector2f ScreenSize = utils::GetViewport();
Vector2f FuelFrameSize{ 336, 77 };
Vector2f HullFrameSize{ 61, 76 };
m_FuelMeter = new GuiMeter("gui/main/fuel/fuel.png", Vector2f{HullFrameSize.x + 10, ScreenSize.y - FuelFrameSize.y }, FuelFrameSize,FuelFrameSize / 1.3, 21, manager);
this->AddElement(m_FuelMeter);
m_HullMeter = new GuiMeter("gui/main/hull/hull.png", Vector2f{5, ScreenSize.y - HullFrameSize.y - 10 }, HullFrameSize, HullFrameSize, 50, manager);
this->AddElement(m_HullMeter);
Vector2f DepthMeterPosition{10, ScreenSize.y - 120};
m_DepthText = new GuiText(DepthMeterPosition, "Depth: 20", "fonts/Arial.ttf", 20, Colors::YELLOW);
this->AddElement(m_DepthText);
Vector2f ScoreMeterPosition{10, ScreenSize.y - 150};
m_ScoreText = new GuiText(ScoreMeterPosition, "Score: 0", "fonts/Arial.ttf", 20, Colors::YELLOW);
this->AddElement(m_ScoreText);
}
MainScreen::~MainScreen() = default;
void MainScreen::Draw() const {
Screen::Draw();
}
void MainScreen::Update(float elapsedSecs) {
Screen::Update(elapsedSecs);
}
void MainScreen::SetFuelMeterValue(float value) const {
m_FuelMeter->SetValue(value);
}
void MainScreen::SetHullMeterValue(float value) const {
m_HullMeter->SetValue(value);
}
void MainScreen::SetDepth(const std::string& text) const {
m_DepthText->ChangeText(text);
}
void MainScreen::SetScore(const std::string& text) const {
m_ScoreText->ChangeText(text);
}

View File

@@ -0,0 +1,27 @@
#pragma once
#include "Gui/GuiMeter.h"
#include "Gui/GuiText.h"
#include "Gui/Screen.h"
class MainScreen: public Screen {
public:
explicit MainScreen(TextureManager* manager);
virtual ~MainScreen() override;
virtual void Draw() const override;
virtual void Update(float elapsedSecs) override;
void SetFuelMeterValue(float value) const;
void SetHullMeterValue(float value) const;
void SetDepth(const std::string& text) const;
void SetScore(const std::string& text) const;
private:
GuiMeter* m_FuelMeter;
GuiMeter* m_HullMeter;
GuiText* m_DepthText;
GuiText* m_ScoreText;
};

View File

@@ -9,5 +9,4 @@ Level::Level() : m_pCamera(nullptr) {
Level::Level(Camera* camera) {
m_pCamera = camera;
}
Level::~Level() {
}
Level::~Level() = default;

View File

@@ -6,7 +6,7 @@ class Level
{
public:
Level();
Level(Camera* camera);
explicit Level(Camera* camera);
virtual ~Level();
Level(const Level& other) = default;

View File

@@ -6,8 +6,8 @@ Building::Building(const std::string& filePath, const Vector2f& position, Textur
m_Texture = pTextureManager->GetTexture(filePath);
m_Size = Vector2f(m_Texture->GetWidth(), m_Texture->GetHeight());
}
Building::~Building() {
}
Building::~Building() = default;
void Building::Draw() const {
m_Texture->Draw(m_Position);
}

View File

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

View File

@@ -0,0 +1,14 @@
#include "pch.h"
#include "OrbitingObject.h"
#include <iostream>
OrbitingObject::OrbitingObject(const Vector2f& orbit, float distance, float speed, Texture* texture, float offset): m_Texture(texture), m_Orbit(orbit), m_Speed(speed), m_Distance(distance), m_currentCycle(offset) {
}
void OrbitingObject::Update(float elapsedSecs) {
m_Position = Vector2f(m_Orbit.x + cosf(m_currentCycle) * m_Distance, m_Orbit.y + sinf(m_currentCycle) * m_Distance);
m_currentCycle += m_Speed * elapsedSecs;
}
void OrbitingObject::Draw() const {
m_Texture->Draw(m_Position);
}

View File

@@ -0,0 +1,21 @@
#pragma once
#include "Texture.h"
class OrbitingObject {
public:
OrbitingObject(const Vector2f& orbit, float distance, float speed, Texture* texture, float offset = 0);
void Update(float elapsedSecs);
void Draw() const;
private:
Texture* m_Texture;
Vector2f m_Position;
Vector2f m_Orbit;
float m_Distance;
float m_Speed;
float m_currentCycle{ 0 };
};

View File

@@ -8,6 +8,7 @@
#include "Collision.h"
#include "colors.h"
#include "../../GridSystem/GroundTileTypeManager.h"
#include "utils.h"
#include "GridSystem/WorldTile.h"
#include "Gui/Screens/ScreenManager.h"
@@ -15,130 +16,132 @@
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) {
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 = 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(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_Buildings.emplace_back(Building { "buildings/fuelStation.png", Vector2f { -700, -52 }, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f { -750, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f { -700, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f { -650, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f { -600, -50 })->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
m_mineralBuilding = new Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, TextureManager::GetInstance() };
m_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_Buildings.emplace_back(Building { "buildings/mineralStation.png", Vector2f { -350, -52 }, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {-400, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {-350, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {-300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
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_Buildings.emplace_back(Building { "buildings/junkStation.png", Vector2f { 250, -52 }, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {200, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {250, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {300, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
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_Buildings.emplace_back(Building { "buildings/repairStation.png", Vector2f { 700, -52 }, TextureManager::GetInstance() });
m_GridManager.GetTileAtWorldPos(Vector2f {650, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_LEFT);
m_GridManager.GetTileAtWorldPos(Vector2f {700, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {750, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_MIDDLE);
m_GridManager.GetTileAtWorldPos(Vector2f {800, -50})->SetTileType(GroundTileTypeManager::GetInstance()->HARD_RIGHT);
// Texture* test = new Texture("gui/main/fuel_guage.png");
m_topCover = TextureManager::GetInstance()->GetTexture("topBackground.png");
m_MainScreen = new MainScreen(TextureManager::GetInstance());
m_Sun = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("sun.png"));
m_Moon = new OrbitingObject(Vector2f{0, -1000}, 1200, 0.5f, TextureManager::GetInstance()->GetTexture("moon.png"), M_PI);
}
WorldLevel::~WorldLevel() {
delete m_refeulBuilding;
delete m_mineralBuilding;
delete m_junkBuilding;
delete m_repairBuilding;
//delete m_pTextTexture;
delete m_MainScreen;
}
void WorldLevel::Update(float elapsedSec) {
m_Fps = 1 / 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) {
m_gridManager.GetTileAtIndex(x, y)->m_Hightlight = false;
}
}
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 (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
// for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
// m_gridManager.GetTileAtIndex(x, y)->m_Hightlight = false;
// }
// }
m_Sun->Update(elapsedSec);
m_Moon->Update(elapsedSec);
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;
}
}
}
for (Building building : m_Buildings) {
building.Update(elapsedSec);
}
if (m_pSelectedTile != nullptr) {
if (utils::isMouseDown(SDL_BUTTON_LEFT)) {
m_pSelectedTile->SetTileType(Tiles::AIR);
m_pSelectedTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
}
}
//Get the diogonal tiles of the selected tile
if (m_pSelectedTile != nullptr) {
surroundingTiles surroundingTiles = m_gridManager.GetSurroundingTiles(m_pSelectedTile);
TileDirection direction = TileDirection::TopMiddle;
const std::array<TileDirection, 8> directions = { TileDirection::TopLeft, TileDirection::TopMiddle, TileDirection::TopRight, TileDirection::MiddleLeft,
TileDirection::MiddleRight, TileDirection::BottomLeft, TileDirection::BottomMiddle, TileDirection::BottomRight };
for (int i = 0; i < 8; i++) {
direction = directions[i];
if (surroundingTiles.GetTile(direction) != nullptr) {
if (surroundingTiles.GetTile(direction)->GetTileType() != Tiles::AIR) {
//surroundingTiles.GetTile(direction)->m_Hightlight = true;
}
}
}
}
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 - 100) {
newCameraPos.y = playerPos.y - m_Viewport.height + 100;
}
m_pCamera->SetPosition(newCameraPos);
}
Screen* screen = m_screenManager->GetCurrentScreen();
Screen* screen = m_ScreenManager->GetCurrentScreen();
if (screen != nullptr) {
screen->Update(elapsedSec);
}
m_MainScreen->Update(elapsedSec);
m_MainScreen->SetDepth(std::to_string((int)-m_Player.GetPosition().y - 50) + " ft.");
//Vector2f playerPos = m_player.GetPosition();
//Vector2f newCameraPos = playerPos;
//m_pCamera->SetPosition(newCameraPos);
@@ -147,18 +150,21 @@ void WorldLevel::Update(float elapsedSec) {
//m_pCamera->SetPosition(Vector2f{playerPos.x - m_viewport.width / 2, playerPos.y - m_viewport.height / 2});
}
void WorldLevel::Draw() const {
m_pCamera->BeginRendering();
// m_topCover->Draw(Vector2f{-850,-70} );
m_topCover->Draw(Rectf{-850, -70, 850, -70 + 32}, Rectf{0, 0, WORLD_WIDTH * 50, 32});
for (Collision::CollisionRect rect : m_Rects) {
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
}
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();
}
}
@@ -169,28 +175,34 @@ void WorldLevel::Draw() const {
m_pSelectedTile->Draw();
}
m_refeulBuilding->Draw();
m_mineralBuilding->Draw();
m_junkBuilding->Draw();
m_repairBuilding->Draw();
m_player.Draw();
for(Building building : m_Buildings) {
building.Draw();
}
m_Player.Draw();
utils::SetColor(Colors::GREEN);
utils::DrawArrow(Vector2f{0, 0}, m_mousePos);
utils::DrawArrow(Vector2f{0, 0}, m_MousePos);
m_Sun->Draw();
m_Moon->Draw();
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_MainScreen->Draw();
}
void WorldLevel::MouseMove(const Vector2f& mousePos) {
m_mousePos = mousePos;
m_MousePos = mousePos;
}
void WorldLevel::ProcessImGui() {
@@ -255,6 +267,10 @@ void WorldLevel::ProcessImGui() {
ImGui::EndMenu();
}
if (ImGui::BeginMenu(std::to_string(m_Fps).c_str())) {
ImGui::EndMenu();
}
ImGui::EndMainMenuBar();
}
@@ -272,7 +288,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);
@@ -281,9 +297,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;
}

View File

@@ -6,6 +6,11 @@
#include "GridSystem/WorldGridManager.h"
#include "Gui/Screens/ScreenManager.h"
#include "Camera.h"
#include "OrbitingObject.h"
#include "Text.h"
#include "Gui/GuiMeter.h"
#include "Gui/Screens/MainScreen.h"
#include "Particle/Particle.h"
class WorldLevel : public Level
{
@@ -22,33 +27,38 @@ public:
void MouseMove(const Vector2f& mousePos) override;
void ProcessImGui() override;
WorldGridManager& GetGridManager() {
return m_gridManager;
}
WorldGridManager& GetGridManager();
std::vector<Collision::CollisionRect> m_Rects;
private:
WorldGridManager m_gridManager {};
Player m_player;
Vector2f m_mousePos {};
double m_Fps{ 0.0f };
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;
std::vector<Building> m_Buildings{};
MainScreen* m_MainScreen{};
OrbitingObject* m_Sun{ nullptr };
OrbitingObject* m_Moon{ nullptr };
Texture* m_topCover{ nullptr };
// ImGui Vars
bool m_ShowTextureManagerWindow { false };
bool m_ShowCameraWindow { false };
bool m_ShowPlayerInfo { true };
bool m_FollowPlayer { false };
bool m_FollowPlayer { true };
};

View File

@@ -0,0 +1,19 @@
#include "pch.h"
#include "Particle.h"
Particle::Particle(const Vector2f& pos, const Vector2f& velocity, float lifetime, Texture* pTexture): m_Position { pos }, m_Velocity { velocity }, m_LifeTime { lifetime },
m_pTexture { pTexture } {
}
void Particle::Update(float elapsedSec) {
m_Acceleration = Vector2f { 0.0f, -9.81f * 20};
m_Velocity += m_Acceleration * elapsedSec;
m_Position += m_Velocity * elapsedSec;
m_LifeTime -= elapsedSec;
m_Acceleration = Vector2f { 0.0f, 0.0f };
}
void Particle::Draw() const {
m_pTexture->Draw(m_Position);
}
bool Particle::IsDead() const {
return m_LifeTime <= 0.0f;
}

20
Game/Particle/Particle.h Normal file
View File

@@ -0,0 +1,20 @@
#pragma once
#include "Texture.h"
class Particle {
public:
Particle() = default;
Particle(const Vector2f& pos, const Vector2f& velocity,float lifetime, Texture* pTexture);
void Update(float elapsedSec);
void Draw() const;
bool IsDead() const;
private:
Vector2f m_Position;
Vector2f m_Velocity;
Vector2f m_Acceleration;
float m_LifeTime;
Texture* m_pTexture;
};

View File

@@ -5,6 +5,7 @@
#include <algorithm>
#include "colors.h"
#include "GridSystem/GroundTileTypeManager.h"
#include "utils.h"
#include "Levels/World/WorldLevel.h"
#include "Animations/Animation.h"
@@ -18,14 +19,28 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
m_walkAnimation = new Animation(
manager->GetTexture("animations/player/player_walk.png"),
8, 0.1f, Rectf { 0, 0, 70, 70 });
8, 0.1f, Rectf { 0, 0, 70, 70 }, true);
m_turnAnimation = new Animation(
manager->GetTexture("animations/player/player_turn.png"),
5, 0.07f, Rectf { 0, 0, 70, 70 }, false);
m_digStartAnimation = new Animation(
manager->GetTexture("animations/player/player_dig_start.png"),
7, 0.07f, Rectf { 0, 0, 70, 70 }, false);
m_digAnimation = new Animation(
manager->GetTexture("animations/player/player_dig.png"),
7, 0.05f, Rectf { 0, 0, 70, 70 }, true);
m_currentAnimation = m_walkAnimation;
}
Player::Player(Player&& other) {
}
Player::~Player() {
delete m_walkAnimation;
// delete m_turnAnimation;
// delete m_digAnimation;
delete m_turnAnimation;
delete m_digAnimation;
delete m_digStartAnimation;
}
Collision::CollisionRect Player::GetCollisionRect() const {
@@ -42,18 +57,29 @@ void Player::Draw() const {
const int frameWidth = 70; //TODO: fix this
int halfFrameWidth = frameWidth / 2;
float bobOffset = m_BobUp ? 1 : 0;
Vector2f drawPos = Vector2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 + bobOffset };
int bobOffset = m_BobUp ? 1 : 0;
m_walkAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
utils::DrawEllipse(m_DigDestination, 5, 5);
utils::DrawEllipse(m_DigStart, 5, 5);
float rotateOffset = std::abs(m_Vel.x) / 40;
Vector2f drawPos = Vector2f { center.x, center.y + 9 + bobOffset };
glPushMatrix();
glTranslatef(drawPos.x - halfFrameWidth, drawPos.y - halfFrameWidth, 0);
if (!m_Grounded && std::abs(m_Vel.y) > 0.1f) {
glRotatef(m_Direction == PlayerDirection::Left ? rotateOffset : -rotateOffset, 0, 0, 1);
}
{
m_currentAnimation->Draw(Vector2f { 0, 0 }, Rectf { 0, 0, frameWidth, frameWidth });
}
glPopMatrix();
for (Particle* particle : m_DigParticles) {
particle->Draw();
}
}
void Player::ProcessImGui() {
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("is Grounded: %s", m_Grounded ? "true" : "false");
ImGui::Checkbox("Draw Collision Rect", &m_DrawCollisionRect);
std::string currentState {};
std::string currentState { "No idea" };
switch (m_State) {
case PlayerState::Idle:
currentState = "Idle";
@@ -64,10 +90,31 @@ void Player::ProcessImGui() {
case PlayerState::Walking:
currentState = "Walking";
break;
case PlayerState::Flying:
currentState = "Flying";
break;
}
ImGui::Text("Player State %s", currentState.c_str());
ImGui::Text("Is digging Primed: %s", m_IsDiggingPrimed ? "true" : "false");
ImGui::Text("Bob counter: %f", m_BobTimer);
ImGui::Text("Bob up: %s", m_BobUp ? "true" : "false");
ImGui::Text("Is Grounded: %s", m_Grounded ? "true" : "false");
std::string direction {};
switch (m_Direction) {
case PlayerDirection::Down:
direction = "Down";
break;
case PlayerDirection::Left:
direction = "Left";
break;
case PlayerDirection::Right:
direction = "Right";
break;
case PlayerDirection::Up:
direction = "Up";
break;
}
ImGui::Text("Direction: %s", direction.c_str());
//ContactMap
@@ -91,8 +138,8 @@ void Player::Dig(Collision::CollisionDirection dir, WorldLevel& level) {
//Center
m_DigDestination.x += tile->GetSize().x / 2 - m_Size.x / 2;
}
if(dir == Collision::Left) {
m_DigDestination += Vector2f{ 2, 0};
if (dir == Collision::Left) {
m_DigDestination += Vector2f { 2, 0 };
}
m_ContactMap[dir] = nullptr;
}
@@ -105,7 +152,8 @@ 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;
}
@@ -119,29 +167,52 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_BobTimer = 0.0f;
}
std::vector<Particle *> particlesToDelete {};
for (Particle* particle : m_DigParticles) {
particle->Update(elapsedTime);
if (particle->IsDead()) {
particlesToDelete.push_back(particle);
}
}
for (Particle* particle : particlesToDelete) {
m_DigParticles.erase(std::remove(m_DigParticles.begin(), m_DigParticles.end(), particle), m_DigParticles.end());
delete particle;
}
//check for keys
if (m_State != PlayerState::Digging) {
m_Vel = Vector2f { 0, -100 };
if (utils::isKeyDown(SDL_SCANCODE_W)) {
m_Vel.y = 100;
m_State = PlayerState::Flying;
m_Vel.y = m_Speed;
m_Grounded = false;
}
if (utils::isKeyPressed(SDL_SCANCODE_S)) {
if (m_Grounded) {
if (this->CanDig(Collision::Bottom, level)) {
m_DigDirection = DigDirection::Down;
m_currentAnimation = m_digStartAnimation;
m_currentAnimation->Reset();
m_IsDiggingPrimed = false;
this->Dig(Collision::CollisionDirection::Bottom, level);
}
}
else {
m_Vel.y = -100;
}
}
if (utils::isKeyDown(SDL_SCANCODE_A)) {
m_walkAnimation->SetFlipped(false);
m_Vel.x = -100;
if (!m_IsTurning) {
m_walkAnimation->SetFlipped(false);
}
m_Acc.x = -m_Speed;
if (m_Direction == PlayerDirection::Right) {
m_IsTurning = true;
m_currentAnimation = m_turnAnimation;
m_currentAnimation->SetFlipped(true);
m_currentAnimation->Reset();
}
m_Direction = PlayerDirection::Left;
if (m_Grounded && !m_DidJustDigLeft) {
//Check if the player doesnt come from digging a tile
if (this->CanDig(Collision::CollisionDirection::Left, level)) {
m_DigDirection = DigDirection::Left;
this->Dig(Collision::CollisionDirection::Left, level);
m_DidJustDigLeft = true;
}
@@ -154,11 +225,23 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
if (utils::isKeyDown(SDL_SCANCODE_D)) {
m_Vel.x = 100;
m_walkAnimation->SetFlipped(true);
if (!m_IsTurning) {
m_walkAnimation->SetFlipped(true);
}
m_Acc.x = m_Speed;
if (m_Direction == PlayerDirection::Left) {
m_IsTurning = true;
m_currentAnimation = m_turnAnimation;
m_currentAnimation->SetFlipped(false);
m_currentAnimation->Reset();
}
m_Direction = PlayerDirection::Right;
if (m_Grounded && !m_DidJustDigRight) {
//Check if the player doesnt come from digging a tile
if (this->CanDig(Collision::CollisionDirection::Right, level)) {
m_DigDirection = DigDirection::Right;
this->Dig(Collision::CollisionDirection::Right, level);
m_DidJustDigRight = true;
}
@@ -170,17 +253,38 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
}
m_walkAnimation->Update(elapsedTime);
m_Vel = m_Vel + m_Gravity * elapsedTime;
m_Vel = m_Vel + m_Acc * elapsedTime;
m_Vel = utils::clamp(m_Vel, Vector2f { -m_Speed, -m_Speed }, Vector2f { m_Speed, m_Speed });
//air resistance
//only if not moving
if (abs(m_Acc.x) < 0.1f) {
m_Vel.x = m_Vel.x * 0.90f;
}
m_Acc = Vector2f { 0, 0 };
m_currentAnimation->Update(elapsedTime);
if (m_currentAnimation->IsDone() && m_IsTurning) {
m_currentAnimation = m_walkAnimation;
m_IsTurning = false;
}
if (m_currentAnimation == m_digStartAnimation) {
}
#pragma region Collision
m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
m_ContactMap[Collision::CollisionDirection::Left] = nullptr;
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
m_Grounded = false;
float t = 0, min_t = INFINITY;
Vector2f intersectionPoint, normal;
@@ -191,7 +295,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 });
@@ -200,7 +304,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
}
std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair<int, float>& a, const std::pair<int, float>& b) {
std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair<int, float>& a, const std::pair<int, float>& b)
{
return a.second < b.second;
});
@@ -242,12 +347,14 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
Collision::CollisionRect rect = world_tile->GetCollisionRect().getCollisionRect(); //TODO: fix this mess
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
}
if (m_State != PlayerState::Digging) { //Fix for when the state is JUST set to digging
if (m_Vel.x != 0.0f) {
m_State = PlayerState::Walking;
#pragma endregion
if (m_State == PlayerState::Walking || m_State == PlayerState::Idle) { //Fix for when the state is JUST set to digging
if (std::abs(m_Vel.x) < 0.1f) {
m_State = PlayerState::Idle;
}
else {
m_State = PlayerState::Idle;
m_State = PlayerState::Walking;
}
}
}
@@ -259,29 +366,44 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_walkAnimation->SetPlaying(true);
break;
case PlayerState::Digging: {
m_walkAnimation->SetPlaying(false);
// m_walkAnimation->SetPlaying(false);
//Diganimation
if (!m_Digging) { //TODO: fix for setting the start position
m_Digging = true;
m_DigStart = m_Position;
m_currentAnimation->Update(elapsedTime);
if (m_currentAnimation->IsDone() && m_State == PlayerState::Digging && !m_IsDiggingPrimed) {
m_IsDiggingPrimed = true;
m_currentAnimation = m_digAnimation;
}
m_DigProgress += elapsedTime;
//lerp to the destination
float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f);
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 = nullptr;
m_HasDeletedTile = true;
}
if (progress >= 1.0f) {
m_State = PlayerState::Idle;
m_HasDeletedTile = false;
m_Digging = false;
if (m_IsDiggingPrimed) {
if (!m_Digging) { //TODO: fix for setting the start position
m_Digging = true;
m_DigStart = m_Position;
m_Vel = Vector2f { 0, 0 };
}
m_DigProgress += elapsedTime;
//lerp to the destination
float progress = utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 1.0f);
int particleProgress = (int)utils::map(m_DigProgress, 0.0f, m_DigTime, 0.0f, 100.0f);
std::cout << progress << '\n';
if (particleProgress % 25 == 0) {
m_DigParticles.push_back(new Particle(m_Position, Vector2f { (float)utils::randRange(-200, 200), (float)utils::randRange(-100, -300) }, 5.f,
TextureManager::GetInstance()->GetTexture("particles/dirt_" + std::to_string(utils::randRange(1, 8)) + ".png")));
}
m_Position = utils::lerp(m_DigStart, m_DigDestination, progress);
if (progress >= 0.5f && !m_HasDeletedTile) {
m_DigTile->SetTileType(GroundTileTypeManager::GetInstance()->AIR);
m_DigTile = nullptr;
m_HasDeletedTile = true;
}
if (progress >= 1.0f) {
m_State = PlayerState::Idle;
m_currentAnimation = m_walkAnimation;
m_HasDeletedTile = false;
m_Digging = false;
}
}
break;
}
default:

View File

@@ -2,6 +2,7 @@
#include "Collision.h"
#include "TextureManager.h"
#include "Animations/Animation.h"
#include "Particle/Particle.h"
class WorldLevel;
@@ -10,6 +11,8 @@ enum class PlayerState
Idle,
Walking,
Digging,
Turning,
Flying
};
enum class PlayerDirection
@@ -32,7 +35,9 @@ class Player
public:
explicit Player(const Vector2f& Position, TextureManager* pTextureManager);
Player( const Player& other ) = default;
Player(Player&& other) = default;
Player(Player&& other);
Player& operator=(const Player& other) = delete;
Player& operator=(Player&& other) = delete;
~Player();
@@ -72,10 +77,12 @@ private:
Vector2f m_Vel;
const float m_Speed{ 400.0f };
std::map<Collision::CollisionDirection, WorldTile *> m_ContactMap;
Vector2f m_Acc;
Vector2f m_Gravity { 0, -9.81f };
Vector2f m_Gravity { 0, -1000.0f };
float m_BobTimer{ 0.0f };
const float m_BobTime{ 0.1f };
bool m_BobUp{ true };
@@ -87,19 +94,25 @@ private:
bool m_HasDeletedTile{ false };
WorldTile* m_DigTile{ nullptr };
bool m_IsDiggingPrimed{ false };
std::vector<Particle*> m_DigParticles{};
const float m_DigTime{ 0.5f };
bool m_Grounded { false };
bool m_IsTurning{ false };
bool m_DidJustDigRight { false };
bool m_DidJustDigLeft { false };
Animation* m_currentAnimation{ nullptr };
Animation* m_walkAnimation;
Animation* m_turnAnimation{ nullptr };
Animation* m_digStartAnimation{ nullptr };
Animation* m_digAnimation{ nullptr };
PlayerState m_State { PlayerState::Idle };
PlayerDirection m_Direction { PlayerDirection::Right };
PlayerDirection m_Direction { PlayerDirection::Left };
DigDirection m_DigDirection { DigDirection::Right };
//Testing

View File

@@ -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;
}

View File

@@ -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<std::string, Texture *> m_Textures {};
};

View File

@@ -12,13 +12,10 @@ int SDL_main(int argv, char** args) {
StartHeapControl();
new Button();
auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", Viewport.x, Viewport.y } } };
auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", Viewport.x, Viewport.y, true} } };
pGame->Run();
delete pGame;
//DumpMemoryLeaks();
return 0;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

BIN
Resources/fonts/Arial.ttf Normal file

Binary file not shown.

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

BIN
Resources/moon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 419 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 368 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 430 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 426 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 402 B

Some files were not shown because too many files have changed in this diff Show More