diff --git a/.idea/.idea.Motherload/.idea/.name b/.idea/.idea.Motherload/.idea/.name
new file mode 100644
index 0000000..8add32b
--- /dev/null
+++ b/.idea/.idea.Motherload/.idea/.name
@@ -0,0 +1 @@
+Motherload
\ No newline at end of file
diff --git a/.idea/.idea.Motherload/.idea/copilot/chatSessions/blobs/version b/.idea/.idea.Motherload/.idea/copilot/chatSessions/blobs/version
deleted file mode 100644
index 720d64f..0000000
Binary files a/.idea/.idea.Motherload/.idea/copilot/chatSessions/blobs/version and /dev/null differ
diff --git a/.idea/.idea.Motherload/.idea/indexLayout.xml b/.idea/.idea.Motherload/.idea/indexLayout.xml
new file mode 100644
index 0000000..7b08163
--- /dev/null
+++ b/.idea/.idea.Motherload/.idea/indexLayout.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.Motherload/.idea/projectSettingsUpdater.xml b/.idea/.idea.Motherload/.idea/projectSettingsUpdater.xml
new file mode 100644
index 0000000..4bb9f4d
--- /dev/null
+++ b/.idea/.idea.Motherload/.idea/projectSettingsUpdater.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml
index 6827606..01eeafc 100644
--- a/.idea/.idea.Motherload/.idea/workspace.xml
+++ b/.idea/.idea.Motherload/.idea/workspace.xml
@@ -1,5 +1,8 @@
+
+
+
Game/Game.vcxproj
@@ -9,16 +12,33 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
+
+
-
-
-
+
+
+
+
+
@@ -62,6 +82,10 @@
+
+
+
+
{
"customColor": "",
"associatedIndex": 1
@@ -76,11 +100,13 @@
"C++ Project.Game.executor": "Run",
"RunOnceActivity.OpenProjectViewOnStart": "true",
"RunOnceActivity.ShowReadmeOnStart": "true",
+ "ignore.virus.scanning.warn.message": "true",
"node.js.detected.package.eslint": "true",
"node.js.detected.package.tslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"node.js.selected.package.tslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
+ "settings.editor.selected.configurable": "CppClangTidyOptionsId",
"vue.rearranger.settings.migration": "true"
},
"keyToStringList": {
@@ -156,14 +182,39 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+ 1711648418492
+
+
+
+ 1711648418492
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Assets/PlayerWalk.aseprite b/Assets/Player/PlayerWalk.aseprite
similarity index 100%
rename from Assets/PlayerWalk.aseprite
rename to Assets/Player/PlayerWalk.aseprite
diff --git a/Game/Animations/Animation.cpp b/Game/Animations/Animation.cpp
new file mode 100644
index 0000000..c5c6dd3
--- /dev/null
+++ b/Game/Animations/Animation.cpp
@@ -0,0 +1,25 @@
+#include "Animation.h"
+Animation::Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect): m_pTexture(pTexture), m_SrcRect(srcRect), m_Frames(frames) {
+
+}
+Animation::~Animation() {
+}
+void Animation::Update(float elapsedSec) {
+ if (m_isPlaying) {
+ m_FrameTimer -= elapsedSec;
+ if (m_FrameTimer <= 0.0f) {
+ m_FrameTimer = 0.1f;
+ ++m_CurrentFrame;
+ if (m_CurrentFrame >= m_Frames) {
+ m_CurrentFrame = 0;
+ }
+ }
+ }
+}
+void Animation::Draw(const Point2f& pos, float angle) const {
+ Rectf src = m_SrcRect;
+ src.left += m_CurrentFrame * src.width;
+ auto dst = Rectf { pos.x, pos.y, src.width, src.height };
+
+ m_pTexture->Draw(dst, src, m_isFlipped);
+}
diff --git a/Game/Animations/Animation.h b/Game/Animations/Animation.h
new file mode 100644
index 0000000..ef13932
--- /dev/null
+++ b/Game/Animations/Animation.h
@@ -0,0 +1,30 @@
+#pragma once
+#include "Texture.h"
+
+class Animation
+{
+public:
+ Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect);
+ ~Animation();
+
+ void Update(float elapsedSec);
+ void Draw(const Point2f& pos, float angle = 0.0f) const;
+
+ void SetPlaying(bool isPlaying) {
+ m_isPlaying = isPlaying;
+ }
+ void SetFlipped(bool isFlipped) {
+ m_isFlipped = isFlipped;
+ }
+
+private:
+ Texture* m_pTexture;
+ Rectf m_SrcRect;
+
+ int m_Frames { 0 };
+ int m_CurrentFrame { 0 };
+ float m_FrameTimer { 0.0f };
+
+ bool m_isPlaying { true };
+ bool m_isFlipped { false };
+};
diff --git a/Game/Camera.cpp b/Game/Camera.cpp
index 0624e98..1fedbcb 100644
--- a/Game/Camera.cpp
+++ b/Game/Camera.cpp
@@ -14,14 +14,14 @@ void Camera::BeginRendering() const {
glScalef(m_Scale, m_Scale, 1);
}
+// ReSharper disable once CppMemberFunctionMayBeStatic
void Camera::EndRendering() const {
glPopMatrix();
}
Point2f Camera::TransformMouse(const Point2f& mousePos) const {
- //Mousepos is in screen coords, we need to transform it to world coords
Point2f worldPos = mousePos;
- worldPos.x = (worldPos.x + m_Position.x) / m_Scale;
+ worldPos.x = ( worldPos.x + m_Position.x ) / m_Scale;
worldPos.y = Viewport.height - worldPos.y + m_Position.y / m_Scale;
return worldPos;
}
diff --git a/Game/Camera.h b/Game/Camera.h
index 979641e..17f4c44 100644
--- a/Game/Camera.h
+++ b/Game/Camera.h
@@ -5,28 +5,42 @@ class Player;
class Camera
{
public:
- Camera( );
- Camera( const Point2f& position, float scale = 1);
+ Camera();
+ Camera(const Point2f& position, float scale = 1);
~Camera() = default;
- void SetPosition( const Point2f& position ) { m_Position = position; }
- void SetScale( const float scale ) { m_Scale = scale; }
+ Camera(const Camera& other) = default;
+ Camera& operator=(const Camera& other) = default;
- const Point2f& GetPosition( ) const { return m_Position; }
- float GetScale( ) const { return m_Scale; }
+ void SetPosition(const Point2f& position) {
+ m_Position = position;
+ }
+ void SetScale(const float scale) {
+ m_Scale = scale;
+ }
+
+ const Point2f& GetPosition() const {
+ return m_Position;
+ }
+ float GetScale() const {
+ return m_Scale;
+ }
void BeginRendering() const;
void EndRendering() const;
- void SetTrackingPlayer(Player* player) { m_FollowingPlayer = player; }
+ void SetTrackingPlayer(Player* player) {
+ m_FollowingPlayer = player;
+ }
- Point2f TransformMouse (const Point2f& mousePos) const;
- Point2f TransformWorld (const Point2f& worldPos) const;
- Rectf Viewport = Rectf{ 0, 0, 846.f, 500.f };
+ Point2f TransformMouse(const Point2f& mousePos) const;
+ Point2f TransformWorld(const Point2f& worldPos) const;
+ Rectf Viewport = Rectf { 0, 0, 846.f, 500.f };
//TODO: Remove this and make it some static
-
+
private:
Point2f m_Position;
float m_Scale;
- Player* m_FollowingPlayer{ nullptr };
+ Player* m_FollowingPlayer { nullptr };
+ //TODO: Ask if the rule applies to the fact that the player is not managed by the camera
};
diff --git a/Game/Game.cpp b/Game/Game.cpp
index c53e23e..0290c97 100644
--- a/Game/Game.cpp
+++ b/Game/Game.cpp
@@ -2,7 +2,6 @@
#include "pch.h"
#include "Game.h"
-#include
#include
#include "colors.h"
@@ -10,11 +9,10 @@
#include "WorldLevel.h"
-Rectf Game::VIEWPORT{};
+Rectf Game::VIEWPORT {};
Game::Game(const Window& window)
- : BaseGame { window }, m_Camera(Camera()), m_WorldLevel(WorldLevel(&m_Camera, GetViewPort()))
-{
+ : BaseGame { window }, m_Camera(Camera()), m_WorldLevel(WorldLevel(&m_Camera, GetViewPort())) {
Initialize();
Game::VIEWPORT = GetViewPort(); //TODO: See if this can be removed
}
@@ -24,7 +22,7 @@ Game::~Game() {
}
void Game::Initialize() {
- m_Camera.SetPosition(Point2f{-GetViewPort().width / 2, -GetViewPort().height / 2});
+ m_Camera.SetPosition(Point2f { -GetViewPort().width / 2, -GetViewPort().height / 2 });
}
void Game::Cleanup() {
@@ -33,10 +31,11 @@ void Game::Cleanup() {
void Game::Update(float elapsedSec) {
const Uint8* pStates = SDL_GetKeyboardState(nullptr);
- if(m_IsRightMouseDown) {
- Point2f newCameraPos = Point2f{m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y};
- m_Camera.SetPosition(Point2f{-newCameraPos.x, -newCameraPos.y});
- } else {
+ if (m_IsRightMouseDown) {
+ const Point2f newCameraPos = Point2f { m_MousePos.x + m_MouseOffset.x, m_MousePos.y + m_MouseOffset.y };
+ m_Camera.SetPosition(Point2f { -newCameraPos.x, -newCameraPos.y });
+ }
+ else {
m_MouseOffset = m_Camera.GetPosition();
}
@@ -57,13 +56,13 @@ void Game::ProcessKeyUpEvent(const SDL_KeyboardEvent& e) {
}
void Game::ProcessMouseMotionEvent(const SDL_MouseMotionEvent& e) {
- m_MousePos = Point2f{float(e.x), float(e.y)};
+ m_MousePos = Point2f { float(e.x), float(e.y) };
m_WorldLevel.MouseMove(Point2f { float(e.x), float(e.y) });
}
void Game::ProcessMouseDownEvent(const SDL_MouseButtonEvent& e) {
m_IsRightMouseDown = e.button == SDL_BUTTON_RIGHT;
- m_MouseOffset = Point2f{-m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y};
+ m_MouseOffset = Point2f { -m_Camera.GetPosition().x - m_MousePos.x, -m_Camera.GetPosition().y - m_MousePos.y };
}
void Game::ProcessMouseUpEvent(const SDL_MouseButtonEvent& e) {
diff --git a/Game/Game.h b/Game/Game.h
index 51f853b..c1e15e7 100644
--- a/Game/Game.h
+++ b/Game/Game.h
@@ -1,10 +1,8 @@
#pragma once
-#include
#include "BaseGame.h"
#include "Camera.h"
#include "WorldLevel.h"
-#include "WorldTile.h"
class Game : public BaseGame
{
@@ -15,7 +13,7 @@ public:
Game(Game&& other) = delete;
Game& operator=(Game&& other) = delete;
// http://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rh-override
- ~Game();
+ ~Game() override;
void Update(float elapsedSec) override;
void Draw() const override;
@@ -40,8 +38,8 @@ private:
Camera m_Camera;
WorldLevel m_WorldLevel;
- Point2f m_MousePos{};
- Point2f m_MouseOffset{};
- bool m_IsRightMouseDown{};
+ Point2f m_MousePos {};
+ Point2f m_MouseOffset {};
+ bool m_IsRightMouseDown {};
};
diff --git a/Game/Game.vcxproj b/Game/Game.vcxproj
index 2540025..e76bcfa 100644
--- a/Game/Game.vcxproj
+++ b/Game/Game.vcxproj
@@ -1,327 +1,476 @@
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- 16.0
- Win32Proj
- {0f40114e-3e0c-4195-b425-91fd5ef586ad}
- Game
- 10.0
-
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 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)
- $(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)
- BuildCompile
-
-
-
- Level3
- true
- WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- Console
- true
- true
- true
-
-
-
-
- Level3
- true
- _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- NotUsing
- pch.h
-
-
- Console
- true
- Engine.lib;%(AdditionalDependencies)
-
-
-
-
- Copying dll files to executable
-
-
- xcopy "$(SolutionDir)Libraries\SDLMain\SDL2-2.26.3\lib\x64\*.dll" "$(TargetDir)" /y /d
-xcopy "$(SolutionDir)Libraries\SDLImage\SDL2_image-2.6.3\lib\x64\*.dll" "$(TargetDir)" /y /d
-xcopy "$(SolutionDir)Libraries\SDLMixer\SDL2_mixer-2.6.3\lib\x64\*.dll" "$(TargetDir)" /y /d
-xcopy "$(SolutionDir)Libraries\SDLTtf\SDL2_ttf-2.20.2\lib\x64\*.dll" "$(TargetDir)" /y /d
-xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s
-
-
-
-
- Level3
- true
- true
- true
- NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
-
-
- Console
- true
- true
- true
-
-
-
-
-
-
-
- MultiThreadedDebugDll
- EnableFastChecks
- Disabled
- true
- NoListing
- x64\Debug\
- false
- false
- x64\Debug\
- Default
- true
- Column
- false
- Prompt
- false
- Sync
- false
- false
- false
- NotSet
- Precise
- true
- false
- false
- false
- Default
- false
- false
- Default
- Default
- false
- x64\Debug\
- x64\Debug\
- false
- Neither
- false
- x64\Debug\
- Cdecl
- x64\Debug\vc143.pdb
- Create
- pch.h
- x64\Debug\Game.pch
- false
- false
- false
- true
- false
- false
- x64\Debug\
- true
- true
- false
- false
- Default
- x64\Debug\Game.tlog\
- false
- true
- false
- true
- true
- Level3
- x64\Debug\
- EditAndContinue
- false
- false
- false
- InheritWarningLevel
- true
- false
- _DEBUG;_CONSOLE;_UNICODE;UNICODE;
- true
- true
-
-
-
-
-
-
- MultiThreadedDebugDll
- EnableFastChecks
- Disabled
- true
- NoListing
- x64\Debug\
- false
- false
- x64\Debug\
- Default
- true
- Column
- false
- Prompt
- false
- Sync
- false
- false
- false
- NotSet
- Precise
- true
- false
- false
- false
- Default
- false
- false
- Default
- Default
- false
- x64\Debug\
- x64\Debug\
- false
- Neither
- false
- x64\Debug\
- Cdecl
- x64\Debug\vc143.pdb
- Create
- pch.h
- x64\Debug\Game.pch
- false
- false
- false
- true
- false
- false
- x64\Debug\
- true
- true
- false
- false
- Default
- x64\Debug\Game.tlog\
- false
- true
- false
- true
- true
- Level3
- x64\Debug\
- EditAndContinue
- false
- false
- false
- InheritWarningLevel
- true
- false
- _DEBUG;_CONSOLE;_UNICODE;UNICODE;
- true
- true
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- $(TargetDir)
-
-
- C:\Users\Bram\Desktop\Programming 2\Exam\dae16-VerhulstBram\Engine\imgui;$(VC_IncludePath);$(WindowsSDK_IncludePath);
-
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ Win32Proj
+ {0f40114e-3e0c-4195-b425-91fd5ef586ad}
+ Game
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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)
+ $(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)
+ BuildCompile
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ NotUsing
+ pch.h
+
+
+ Console
+ true
+ Engine.lib;%(AdditionalDependencies)
+
+
+
+
+ Copying dll files to executable
+
+
+ xcopy "$(SolutionDir)Libraries\SDLMain\SDL2-2.26.3\lib\x64\*.dll" "$(TargetDir)" /y /d
+ xcopy "$(SolutionDir)Libraries\SDLImage\SDL2_image-2.6.3\lib\x64\*.dll" "$(TargetDir)" /y /d
+ xcopy "$(SolutionDir)Libraries\SDLMixer\SDL2_mixer-2.6.3\lib\x64\*.dll" "$(TargetDir)" /y /d
+ xcopy "$(SolutionDir)Libraries\SDLTtf\SDL2_ttf-2.20.2\lib\x64\*.dll" "$(TargetDir)" /y /d
+ xcopy "$(SolutionDir)Resources\*.*" "$(TargetDir)" /y /d /s
+
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+ MultiThreadedDebugDll
+ EnableFastChecks
+ Disabled
+ true
+ NoListing
+ x64\Debug\
+ false
+ false
+ x64\Debug\
+ Default
+ true
+ Column
+ false
+ Prompt
+ false
+ Sync
+ false
+ false
+ false
+ NotSet
+ Precise
+ true
+ false
+ false
+ false
+ Default
+ false
+ false
+ Default
+ Default
+ false
+ x64\Debug\
+ x64\Debug\
+ false
+ Neither
+ false
+ x64\Debug\
+ Cdecl
+ x64\Debug\vc143.pdb
+ NotUsing
+ pch.h
+ x64\Debug\Game.pch
+ false
+ false
+ false
+ true
+ false
+ false
+ x64\Debug\
+ true
+ true
+ false
+ false
+ Default
+ x64\Debug\Game.tlog\
+ false
+ true
+ false
+ true
+ true
+ Level3
+ x64\Debug\
+ EditAndContinue
+ false
+ false
+ false
+ InheritWarningLevel
+ true
+ false
+ _DEBUG;_CONSOLE;_UNICODE;UNICODE;
+ true
+ true
+
+
+ MultiThreadedDebugDll
+ EnableFastChecks
+ Disabled
+ true
+ NoListing
+ x64\Debug\
+ false
+ false
+ x64\Debug\
+ Default
+ true
+ Column
+ false
+ Prompt
+ false
+ Sync
+ false
+ false
+ false
+ NotSet
+ Precise
+ true
+ false
+ false
+ false
+ Default
+ false
+ false
+ Default
+ Default
+ false
+ x64\Debug\
+ x64\Debug\
+ false
+ Neither
+ false
+ x64\Debug\
+ Cdecl
+ x64\Debug\vc143.pdb
+ NotUsing
+ pch.h
+ x64\Debug\Game.pch
+ false
+ false
+ false
+ true
+ false
+ false
+ x64\Debug\
+ true
+ true
+ false
+ false
+ Default
+ x64\Debug\Game.tlog\
+ false
+ true
+ false
+ true
+ true
+ Level3
+ x64\Debug\
+ EditAndContinue
+ false
+ false
+ false
+ InheritWarningLevel
+ true
+ false
+ _DEBUG;_CONSOLE;_UNICODE;UNICODE;
+ true
+ true
+
+
+ MultiThreadedDebugDll
+ EnableFastChecks
+ Disabled
+ true
+ NoListing
+ x64\Debug\
+ false
+ false
+ x64\Debug\
+ Default
+ true
+ Column
+ false
+ Prompt
+ false
+ Sync
+ false
+ false
+ false
+ NotSet
+ Precise
+ true
+ false
+ false
+ false
+ Default
+ false
+ false
+ Default
+ Default
+ false
+ x64\Debug\
+ x64\Debug\
+ false
+ Neither
+ false
+ x64\Debug\
+ Cdecl
+ x64\Debug\vc143.pdb
+ Create
+ pch.h
+ x64\Debug\Game.pch
+ false
+ false
+ false
+ true
+ false
+ false
+ x64\Debug\
+ true
+ true
+ false
+ false
+ Default
+ x64\Debug\Game.tlog\
+ false
+ true
+ false
+ true
+ true
+ Level3
+ x64\Debug\
+ EditAndContinue
+ false
+ false
+ false
+ InheritWarningLevel
+ true
+ false
+ _DEBUG;_CONSOLE;_UNICODE;UNICODE;
+ true
+ true
+
+
+
+
+
+
+ MultiThreadedDebugDll
+ EnableFastChecks
+ Disabled
+ true
+ NoListing
+ x64\Debug\
+ false
+ false
+ x64\Debug\
+ Default
+ true
+ Column
+ false
+ Prompt
+ false
+ Sync
+ false
+ false
+ false
+ NotSet
+ Precise
+ true
+ false
+ false
+ false
+ Default
+ false
+ false
+ Default
+ Default
+ false
+ x64\Debug\
+ x64\Debug\
+ false
+ Neither
+ false
+ x64\Debug\
+ Cdecl
+ x64\Debug\vc143.pdb
+ Create
+ pch.h
+ x64\Debug\Game.pch
+ false
+ false
+ false
+ true
+ false
+ false
+ x64\Debug\
+ true
+ true
+ false
+ false
+ Default
+ x64\Debug\Game.tlog\
+ false
+ true
+ false
+ true
+ true
+ Level3
+ x64\Debug\
+ EditAndContinue
+ false
+ false
+ false
+ InheritWarningLevel
+ true
+ false
+ _DEBUG;_CONSOLE;_UNICODE;UNICODE;
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ $(TargetDir)
+
+
+ C:\Users\Bram\Desktop\Programming 2\Exam\dae16-VerhulstBram\Engine\imgui;$(VC_IncludePath);$(WindowsSDK_IncludePath);
+
\ No newline at end of file
diff --git a/Game/WorldGridManager.cpp b/Game/GridSystem/WorldGridManager.cpp
similarity index 71%
rename from Game/WorldGridManager.cpp
rename to Game/GridSystem/WorldGridManager.cpp
index 61ddfa1..217aa34 100644
--- a/Game/WorldGridManager.cpp
+++ b/Game/GridSystem/WorldGridManager.cpp
@@ -1,22 +1,22 @@
#include "WorldGridManager.h"
WorldGridManager::WorldGridManager() {
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
- for(size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
- m_worldTiles[x][y] = nullptr;
+ for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
+ m_worldTiles[x][y] = nullptr;
}
}
}
WorldGridManager::~WorldGridManager() {
-
+
}
-WorldTile* WorldGridManager::GetTileAtIndex(const int x, const int y) const {
+WorldTile * WorldGridManager::GetTileAtIndex(const int x, const int y) const {
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
return nullptr;
}
return m_worldTiles[x][y];
}
-WorldTile* WorldGridManager::GetTileAtWorldPos(const Point2f& pos) const {
+WorldTile * WorldGridManager::GetTileAtWorldPos(const Point2f& pos) const {
int x = int(pos.x / TILE_WIDTH + WORLD_WIDTH / 2);
int y = int(-pos.y / TILE_HEIGHT);
if (x < 0 || x >= WORLD_WIDTH || y < 0 || y >= WORLD_HEIGHT) {
diff --git a/Game/WorldGridManager.h b/Game/GridSystem/WorldGridManager.h
similarity index 59%
rename from Game/WorldGridManager.h
rename to Game/GridSystem/WorldGridManager.h
index c513737..2fe331f 100644
--- a/Game/WorldGridManager.h
+++ b/Game/GridSystem/WorldGridManager.h
@@ -1,6 +1,5 @@
#pragma once
#include
-#include
#include "structs.h"
@@ -12,15 +11,16 @@ static const int TILE_HEIGHT = 50;
class WorldTile;
-struct surroundingTiles {
- std::array tiles;
+struct surroundingTiles
+{
+ std::array tiles;
//Center of the surrounding tiles is 0, 0
void SetTile(int x, int y, WorldTile* tile) {
tiles[x + y * 3] = tile;
}
- WorldTile* GetTile(int x, int y) {
+ WorldTile * GetTile(int x, int y) {
return tiles[x + y * 3];
}
};
@@ -30,15 +30,16 @@ class WorldGridManager
public:
WorldGridManager();
~WorldGridManager();
-
- WorldTile* GetTileAtIndex(const int x, const int y) const;
- WorldTile* GetTileAtWorldPos(const Point2f& pos) const;
+
+ WorldGridManager(const WorldGridManager& other) = default;
+
+ WorldTile * GetTileAtIndex(const int x, const int y) const;
+ WorldTile * GetTileAtWorldPos(const Point2f& pos) const;
void SetTileAtIndex(const int x, const int y, WorldTile* tile);
-
+
private:
+ std::array, WORLD_HEIGHT> m_worldTiles;
- std::array, WORLD_HEIGHT> m_worldTiles;
-
};
diff --git a/Game/WorldTile.cpp b/Game/GridSystem/WorldTile.cpp
similarity index 81%
rename from Game/WorldTile.cpp
rename to Game/GridSystem/WorldTile.cpp
index 3e8803d..21c1692 100644
--- a/Game/WorldTile.cpp
+++ b/Game/GridSystem/WorldTile.cpp
@@ -1,8 +1,7 @@
-#include "pch.h"
-#include "WorldTile.h"
+#include "WorldTile.h"
#include "colors.h"
-#include "TextureManager.h"
+#include "../TextureManager.h"
#include "utils.h"
@@ -17,12 +16,12 @@ WorldTile::~WorldTile() {
void WorldTile::Draw() const {
if (*m_GroundTileType != Tiles::AIR) {
m_pTexture->Draw(m_Position);
- if(m_Hightlight) {
+ if (m_Hightlight) {
utils::SetColor(Colors::GREEN);
utils::FillRect(m_Position, 50, 50);
}
}
}
Collision::TileCollisionRect WorldTile::GetCollisionRect() {
- return Collision::TileCollisionRect{ m_Position, GetSize(), (this)};
+ return Collision::TileCollisionRect { m_Position, GetSize(), ( this ) };
}
diff --git a/Game/WorldTile.h b/Game/GridSystem/WorldTile.h
similarity index 62%
rename from Game/WorldTile.h
rename to Game/GridSystem/WorldTile.h
index ea5836c..d9418a6 100644
--- a/Game/WorldTile.h
+++ b/Game/GridSystem/WorldTile.h
@@ -1,7 +1,7 @@
#pragma once
#include "Collision.h"
#include "Texture.h"
-#include "TextureManager.h"
+#include "../TextureManager.h"
@@ -13,21 +13,23 @@ enum class GroundTileTypes
Iron
};
-class GroundTileType {
+class GroundTileType
+{
public:
- GroundTileType(const std::string& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {}
+ GroundTileType(const std::string& filePath, GroundTileTypes type): m_filePath(filePath), m_type(type) {
+ }
virtual ~GroundTileType() = default;
- bool operator== ( const GroundTileType& rhs ) const {
+ bool operator==(const GroundTileType& rhs) const {
return m_type == rhs.m_type;
}
- bool operator!= ( const GroundTileType& rhs) const {
+ bool operator!=(const GroundTileType& rhs) const {
return m_type != rhs.m_type;
}
- virtual bool operator== (const GroundTileType* rhs) const {
+ virtual bool operator==(const GroundTileType* rhs) const {
return rhs->m_type == m_type;
}
- virtual bool operator!= (const GroundTileType* rhs) const {
+ virtual bool operator!=(const GroundTileType* rhs) const {
return rhs->m_type != m_type;
}
@@ -38,73 +40,87 @@ public:
virtual GroundTileTypes getType() const {
return m_type;
}
+
protected:
std::string m_filePath;
+
private:
GroundTileTypes m_type;
};
-class RandomGroundTile: public GroundTileType {
+class RandomGroundTile : public GroundTileType
+{
public:
RandomGroundTile(const std::string& filePath, GroundTileTypes type, int maxRandom): GroundTileType(filePath, type), m_maxRandom(maxRandom) {
}
~RandomGroundTile() override = default;
- bool operator== (const GroundTileType* rhs) const override{
+ bool operator==(const GroundTileType* rhs) const override {
return rhs->getType() == this->getType();
}
-
- bool operator!= (const GroundTileType* rhs) const override{
+
+ bool operator!=(const GroundTileType* rhs) const override {
return rhs->getType() != this->getType();
- }
-
+ }
+
std::string getPath() const override {
int variant = utils::randRange(1, m_maxRandom);
- std::string toReplace{ "[0]" };
+ std::string toReplace { "[0]" };
std::string replacement = std::to_string(utils::randRange(1, m_maxRandom));
size_t found = m_filePath.find(toReplace);
- std::string newFilePath{ m_filePath };
-
- if(found != std::string::npos) {
+ std::string newFilePath { m_filePath };
+
+ if (found != std::string::npos) {
newFilePath.replace(found, 3, replacement);
}
-
+
return newFilePath;
- }
+ }
+
private:
int m_maxRandom;
};
namespace Tiles
{
- static GroundTileType* AIR = new GroundTileType("", GroundTileTypes::Air);
+ static GroundTileType* AIR = new GroundTileType("", GroundTileTypes::Air);
static GroundTileType* DIRT = new RandomGroundTile("tiles/dirt/dirt[0].png", GroundTileTypes::Dirt, 5);
static GroundTileType* IRON = new GroundTileType("tiles/ores/Ore_Ironium.png", GroundTileTypes::Iron);
}
-class WorldTile {
+class WorldTile
+{
public:
WorldTile() = default;
WorldTile(const Point2f& position, GroundTileType* groundTileType, TextureManager* pTextureManager);
~WorldTile();
-
+
void Draw() const;
- Point2f GetPosition() const { return m_Position; }
- void SetPosition(const Point2f& position) { m_Position = position; }
+ Point2f GetPosition() const {
+ return m_Position;
+ }
+ void SetPosition(const Point2f& position) {
+ m_Position = position;
+ }
- Point2f GetSize() const { return Point2f{ 50, 50 }; }
+ Point2f GetSize() const {
+ return Point2f { 50, 50 };
+ }
- GroundTileType* GetTileType() const { return m_GroundTileType; }
- void SetTileType(GroundTileType* type) { m_GroundTileType = type; }
+ GroundTileType * GetTileType() const {
+ return m_GroundTileType;
+ }
+ void SetTileType(GroundTileType* type) {
+ m_GroundTileType = type;
+ }
Collision::TileCollisionRect GetCollisionRect();
- bool m_Hightlight{ false };
-
-
+ bool m_Hightlight { false };
+
private:
Point2f m_Position;
GroundTileType* m_GroundTileType;
@@ -113,6 +129,6 @@ private:
Collision::CollisionRect m_CollisionRect;
-
-
+
+
};
diff --git a/Game/Level.cpp b/Game/Level.cpp
index d0bd54a..f56365f 100644
--- a/Game/Level.cpp
+++ b/Game/Level.cpp
@@ -9,4 +9,4 @@ Level::Level(Camera* camera) {
m_pCamera = camera;
}
Level::~Level() {
-}
\ No newline at end of file
+}
diff --git a/Game/Level.h b/Game/Level.h
index 9f016b6..d536e45 100644
--- a/Game/Level.h
+++ b/Game/Level.h
@@ -6,8 +6,11 @@ class Level
public:
Level();
Level(Camera* camera);
- virtual ~Level();
-
+ virtual ~Level();
+
+ Level(const Level& other) = default;
+ Level(Level&& other) = default;
+
virtual void Update(float elapsedSec) = 0;
virtual void Draw() const = 0;
virtual void MouseMove(const Point2f& mousePos) = 0;
diff --git a/Game/Player.cpp b/Game/Player.cpp
index fdd46b4..9e3f4b5 100644
--- a/Game/Player.cpp
+++ b/Game/Player.cpp
@@ -6,21 +6,34 @@
#include "colors.h"
#include "utils.h"
#include "WorldLevel.h"
+#include "Animations/Animation.h"
-Player::Player(const Point2f& Position) : m_Position(Position), m_Size(Point2f{40, 40}), m_Vel(Point2f{0,0}), m_Acc(Point2f{0,0}) {
+Player::Player(const Point2f& Position, TextureManager* manager) : m_Position(Position), m_Size(Point2f { 40, 40 }), m_Vel(Point2f { 0, 0 }), m_Acc(Point2f { 0, 0 }) {
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_walkAnimation = new Animation(manager->GetTexture("animations/player/player_walk.png"), 8, 0.1f, Rectf { 0, 0, 70, 70 });
}
-Collision::CollisionRect Player::GetCollisionRect() {
- Collision::CollisionRect rect = {m_Position, m_Size, m_Vel};
+Collision::CollisionRect Player::GetCollisionRect() const {
+ Collision::CollisionRect rect = { m_Position, m_Size, m_Vel };
return rect;
}
void Player::Draw() const {
- utils::SetColor(Colors::PINK);
- utils::DrawRect(Rectf{m_Position.x, m_Position.y, m_Size.x, m_Size.y});
+ if (m_DrawCollisionRect) {
+ utils::SetColor(Colors::PINK);
+ utils::DrawRect(Rectf { m_Position.x, m_Position.y, m_Size.x, m_Size.y });
+ }
+ Point2f center = m_Position + m_Size / 2;
+
+ const int frameWidth = 70; //TODO: fix this
+ int halfFrameWidth = frameWidth / 2;
+
+ auto drawPos = Point2f { center.x - halfFrameWidth - 10, center.y - halfFrameWidth + 9 };
+
+ m_walkAnimation->Draw(drawPos, 0);
}
void Player::ProcessImGui() {
ImGui::Begin("Collision Info", nullptr, ImGuiWindowFlags_AlwaysAutoResize);
@@ -28,6 +41,7 @@ void Player::ProcessImGui() {
ImGui::Text("Did just dig right: %s", m_DidJustDigRight ? "true" : "false");
bool test = !utils::isKeyDown(SDL_SCANCODE_H);
ImGui::Text("Is Key Up H: %s", test ? "true" : "false");
+ ImGui::Checkbox("Draw Collision Rect", &m_DrawCollisionRect);
//ContactMap
ImGui::Text("ContactMap:");
@@ -39,112 +53,109 @@ void Player::ProcessImGui() {
}
void Player::Update(float elapsedTime, WorldLevel& level) {
- // m_Acc.y += m_Gravity.y;
- // m_Vel.y = std::min(m_Vel.y, m_MaxSpeed);
- //
- // Point2f nextPos = m_Position + m_Vel * elapsedTime;
- // //collision checking
-
- m_Vel = Point2f{0, -100};
-
+ m_Vel = Point2f { 0, -100 };
//check for keys
- if(utils::isKeyDown(SDL_SCANCODE_W)) {
+ if (utils::isKeyDown(SDL_SCANCODE_W)) {
m_Vel.y = 100;
m_Grounded = false;
}
- if(utils::isKeyPressed(SDL_SCANCODE_S)) {
+ if (utils::isKeyPressed(SDL_SCANCODE_S)) {
m_Vel.y = -100;
- if(m_Grounded) {
- if(m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
+ if (m_Grounded) {
+ if (m_ContactMap[Collision::CollisionDirection::Bottom] != nullptr) {
m_ContactMap[Collision::CollisionDirection::Bottom]->SetTileType(Tiles::AIR);
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Bottom];
//center of tile
Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
- m_Position = Point2f{tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5};
+ m_Position = Point2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
m_ContactMap[Collision::CollisionDirection::Bottom] = nullptr;
-
}
}
}
- if(utils::isKeyDown(SDL_SCANCODE_A)) {
+ if (utils::isKeyDown(SDL_SCANCODE_A)) {
+ m_walkAnimation->SetFlipped(false);
m_Vel.x = -100;
-
}
- if(utils::isKeyDown(SDL_SCANCODE_D)) {
+ if (utils::isKeyDown(SDL_SCANCODE_D)) {
m_Vel.x = 100;
- if(m_Grounded && !m_DidJustDigRight) {
+ m_walkAnimation->SetFlipped(true);
+ if (m_Grounded && !m_DidJustDigRight) {
//Check if the player doesnt come from digging a tile
- if(m_ContactMap[Collision::CollisionDirection::Right] != nullptr) {
+ if (m_ContactMap[Collision::CollisionDirection::Right] != nullptr) {
m_ContactMap[Collision::CollisionDirection::Right]->SetTileType(Tiles::AIR);
WorldTile* tile = m_ContactMap[Collision::CollisionDirection::Right];
//center of tile
- Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
- m_Position = Point2f{tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5};
+ const Point2f tileCenter = tile->GetCollisionRect().getCollisionRect().pos + tile->GetCollisionRect().getCollisionRect().size / 2;
+ m_Position = Point2f { tileCenter.x - m_Size.x / 2, tileCenter.y - m_Size.y / 2 + 5 };
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
m_DidJustDigRight = true;
}
}
}
- if(m_DidJustDigRight) {
- if(!utils::isKeyDown(SDL_SCANCODE_D)) {
+ if (m_DidJustDigRight) {
+ if (!utils::isKeyDown(SDL_SCANCODE_D)) {
m_DidJustDigRight = false;
- }
+ }
}
+ m_walkAnimation->Update(elapsedTime);
+
+
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;
Point2f intersectionPoint, normal;
-
- std::vector> contactTimes{};
- WorldGridManager& gridManager = level.GetGridManager();
-
+ std::vector> contactTimes {};
+
+ const WorldGridManager& gridManager = level.GetGridManager();
+
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) {
+ for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
+ WorldTile* tile = gridManager.GetTileAtIndex(x, y);
+ if (*tile->GetTileType() != Tiles::AIR) {
tile->m_Hightlight = false;
- if(Collision::DynamicRectVsRect(this->GetCollisionRect(), elapsedTime, tile->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) {
- contactTimes.push_back(std::pair{x + y * WORLD_WIDTH, t});
+ if (Collision::DynamicRectVsRect(this->GetCollisionRect(), elapsedTime, tile->GetCollisionRect().getCollisionRect(), intersectionPoint, normal, t)) {
+ contactTimes.emplace_back(std::pair { x + y * WORLD_WIDTH, t });
}
}
}
}
-
- std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair& a, const std::pair& b) {
+
+ std::sort(contactTimes.begin(), contactTimes.end(), [](const std::pair& a, const std::pair& b)
+ {
return a.second < b.second;
});
for (std::pair contact_time : contactTimes) {
int x = contact_time.first % WORLD_WIDTH;
int y = contact_time.first / WORLD_WIDTH;
- WorldTile* world_tile = gridManager.GetTileAtIndex(x,y);
+ WorldTile* world_tile = gridManager.GetTileAtIndex(x, y);
const Point2f WorldTilePos = world_tile->GetCollisionRect().getCollisionRect().pos;
const Point2f WorldTileSize = world_tile->GetCollisionRect().getCollisionRect().size;
- if(WorldTilePos.y + WorldTileSize.y > m_Position.y) {
- if(WorldTilePos.x + WorldTileSize.x > m_Position.x) {
- if(WorldTilePos.y + WorldTileSize.y / 2 > m_Position.y && m_Position.y + m_Size.y / 2 > WorldTilePos.y) {
+ if (WorldTilePos.y + WorldTileSize.y > m_Position.y) {
+ if (WorldTilePos.x + WorldTileSize.x > m_Position.x) {
+ if (WorldTilePos.y + WorldTileSize.y / 2 > m_Position.y && m_Position.y + m_Size.y / 2 > WorldTilePos.y) {
//Right of player
m_ContactMap[Collision::CollisionDirection::Right] = world_tile;
}
}
}
- if(WorldTilePos.y + WorldTileSize.y > m_Position.y) {
- if(WorldTilePos.x < m_Position.x + m_Size.x) {
- if(WorldTilePos.y + WorldTileSize.y / 2 > m_Position.y && m_Position.y + m_Size.y / 2 > WorldTilePos.y) {
+ if (WorldTilePos.y + WorldTileSize.y > m_Position.y) {
+ if (WorldTilePos.x < m_Position.x + m_Size.x) {
+ if (WorldTilePos.y + WorldTileSize.y / 2 > m_Position.y && m_Position.y + m_Size.y / 2 > WorldTilePos.y) {
//Left of player
m_ContactMap[Collision::CollisionDirection::Left] = world_tile;
}
@@ -152,8 +163,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
//Below the player
- if(WorldTilePos.y + WorldTileSize.y <= m_Position.y) {
- if(WorldTilePos.x + WorldTileSize.x / 2 > m_Position.x && m_Position.x + m_Size.x / 2 > WorldTilePos.x) {
+ if (WorldTilePos.y + WorldTileSize.y <= m_Position.y) {
+ if (WorldTilePos.x + WorldTileSize.x / 2 > m_Position.x && m_Position.x + m_Size.x / 2 > WorldTilePos.x) {
m_ContactMap[Collision::CollisionDirection::Bottom] = world_tile;
m_Grounded = true;
world_tile->m_Hightlight = true;
@@ -164,6 +175,24 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
}
- m_Position = m_Position + m_Vel * elapsedTime;
+ if (m_Vel.x != 0.0f) {
+ m_State = PlayerState::Walking;
+ }
+ else {
+ m_State = PlayerState::Idle;
+ }
+ switch (m_State) {
+ case PlayerState::Idle:
+ m_walkAnimation->SetPlaying(false);
+ break;
+ case PlayerState::Walking:
+ m_walkAnimation->SetPlaying(true);
+ break;
+ default:
+ break;
+
+ }
+
+ m_Position = m_Position + m_Vel * elapsedTime;
}
diff --git a/Game/Player.h b/Game/Player.h
index 1e95fe8..9801b3a 100644
--- a/Game/Player.h
+++ b/Game/Player.h
@@ -1,24 +1,60 @@
#pragma once
#include "Collision.h"
+#include "TextureManager.h"
+#include "Animations/Animation.h"
class WorldLevel;
+
+enum class PlayerState
+{
+ Idle,
+ Walking,
+ Digging,
+};
+
+enum class PlayerDirection
+{
+ Left,
+ Right,
+ Up,
+ Down,
+};
+
+enum class DigDirection
+{
+ Left,
+ Right,
+ Down
+};
+
class Player
{
public:
-
- Player(const Point2f& Position);
- Collision::CollisionRect GetCollisionRect();
+ Player(const Point2f& Position, TextureManager* pTextureManager);
+ Collision::CollisionRect GetCollisionRect() const;
void Update(float elapsedTime, WorldLevel& level);
void Draw() const;
-
- void SetPosition(Point2f pos) { m_Position = pos; }
- Point2f GetPosition() const { return m_Position; }
- void SetVelocity(Point2f vel) { m_Vel = vel; }
- Point2f GetVelocity() const { return m_Vel; }
+ void SetPosition(Point2f pos) {
+ m_Position = pos;
+ }
+ Point2f GetPosition() const {
+ return m_Position;
+ }
- auto GetContactMap(){ return m_ContactMap; }
- void SetContactMap(Collision::CollisionDirection dir, WorldTile* tile) { m_ContactMap[dir] = tile; }
+ void SetVelocity(Point2f vel) {
+ m_Vel = vel;
+ }
+ Point2f GetVelocity() const {
+ return m_Vel;
+ }
+
+ auto GetContactMap() {
+ return m_ContactMap;
+ }
+ void SetContactMap(Collision::CollisionDirection dir, WorldTile* tile) {
+ m_ContactMap[dir] = tile;
+ }
void ProcessImGui();
@@ -28,12 +64,20 @@ private:
Point2f m_Vel;
- std::map m_ContactMap;
+ std::map m_ContactMap;
Point2f m_Acc;
- Point2f m_Gravity{ 0, -9.81f };
+ Point2f m_Gravity { 0, -9.81f };
- bool m_Grounded{ false };
+ bool m_Grounded { false };
- bool m_DidJustDigRight{ false };
+ bool m_DidJustDigRight { false };
+ Animation* m_walkAnimation;
+
+ PlayerState m_State { PlayerState::Idle };
+ PlayerDirection m_Direction { PlayerDirection::Right };
+ DigDirection m_DigDirection { DigDirection::Right };
+
+ //Testing
+ bool m_DrawCollisionRect { true };
};
diff --git a/Game/TextureManager.cpp b/Game/TextureManager.cpp
index cd5c72b..52fb8c0 100644
--- a/Game/TextureManager.cpp
+++ b/Game/TextureManager.cpp
@@ -1,18 +1,21 @@
#include "pch.h"
#include "TextureManager.h"
-TextureManager* TextureManager::m_pInstance = NULL;
+TextureManager* TextureManager::m_pInstance = nullptr;
-TextureManager* TextureManager::GetInstance() {
+TextureManager * TextureManager::GetInstance() {
if (m_pInstance == nullptr) {
m_pInstance = new TextureManager();
}
return m_pInstance;
}
-Texture* TextureManager::GetTexture(const std::string& name) {
+Texture * TextureManager::GetTexture(const std::string& name) {
if (m_Textures.find(name) != m_Textures.end()) {
return m_Textures[name];
}
Texture* pTexture = new Texture(name);
m_Textures[name] = pTexture;
return pTexture;
-}
\ No newline at end of file
+}
+TextureManager::~TextureManager() {
+ //TODO: Loop over the m_Textures to delete them
+}
diff --git a/Game/TextureManager.h b/Game/TextureManager.h
index 6e35fea..9fd604d 100644
--- a/Game/TextureManager.h
+++ b/Game/TextureManager.h
@@ -6,15 +6,15 @@
class TextureManager
{
public:
- TextureManager() = default;
+ static TextureManager * GetInstance();
+ Texture * GetTexture(const std::string& name);
- static TextureManager* GetInstance();
-
- Texture* GetTexture(const std::string& name);
-
- static TextureManager* m_pInstance;
private:
- std::map m_Textures{};
-
-};
+ TextureManager() = default;
+ ~TextureManager();
+ static TextureManager* m_pInstance;
+private:
+ std::map m_Textures {};
+
+};
diff --git a/Game/WorldLevel.cpp b/Game/WorldLevel.cpp
index 0ff10ac..5553159 100644
--- a/Game/WorldLevel.cpp
+++ b/Game/WorldLevel.cpp
@@ -11,20 +11,18 @@
#include "utils.h"
-WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
- Level(camera),
- m_gridManager(WorldGridManager()),
- m_player(Player { Point2f { 0, 100 } }),
- m_mousePos { 0, 0 },
- m_viewport(viewport)
-{
+WorldLevel::WorldLevel(Camera* camera, Rectf viewport): Level(camera),
+ m_gridManager(WorldGridManager()),
+ m_player(Player { Point2f { 0, 100 }, TextureManager::GetInstance() }),
+ m_mousePos { 0, 0 },
+ m_viewport(viewport) {
// The grid is 34 x 50 big, the top center is 0,0 in world coords
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
int actualX = x - WORLD_WIDTH / 2;
- Point2f pos = Point2f{ float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT};
+ auto pos = Point2f { float(actualX * TILE_WIDTH), -float(y * TILE_HEIGHT) - TILE_HEIGHT };
GroundTileType* type = Tiles::AIR;
- switch(utils::randRange(0,2)) {
+ switch (utils::randRange(0, 2)) {
case 0:
type = Tiles::DIRT;
break;
@@ -38,8 +36,7 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
std::cout << "??" << std::endl;
}
-
- m_gridManager.SetTileAtIndex(x,y, new WorldTile{ pos, type, TextureManager::GetInstance() });
+ m_gridManager.SetTileAtIndex(x, y, new WorldTile { pos, type, TextureManager::GetInstance() });
}
}
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
@@ -48,27 +45,27 @@ WorldLevel::WorldLevel(Camera* camera, Rectf viewport):
}
WorldLevel::~WorldLevel() {
//delete m_pTextTexture;
-
+
}
void WorldLevel::Update(float elapsedSec) {
int mouseX, mouseY;
SDL_GetMouseState(&mouseX, &mouseY);
- m_mousePos = Point2f{ float(mouseX), float(mouseY) };
+ m_mousePos = Point2f { float(mouseX), float(mouseY) };
m_mousePos = m_pCamera->TransformMouse(m_mousePos);
//m_player.Update(elapsedSec, *this);
- WorldTile* selectedTile{ nullptr };
-
+ WorldTile* selectedTile { nullptr };
+
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
- if(m_gridManager.GetTileAtIndex(x,y)->GetCollisionRect().Contains(m_mousePos)) {
- selectedTile = m_gridManager.GetTileAtIndex(x,y);
+ if (m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().Contains(m_mousePos)) {
+ selectedTile = m_gridManager.GetTileAtIndex(x, y);
}
}
}
- if(selectedTile != nullptr) {
- if(utils::isMouseDown(SDL_BUTTON_LEFT)) {
+ if (selectedTile != nullptr) {
+ if (utils::isMouseDown(SDL_BUTTON_LEFT)) {
selectedTile->SetTileType(Tiles::AIR);
}
}
@@ -76,7 +73,7 @@ void WorldLevel::Update(float elapsedSec) {
m_player.Update(elapsedSec, *this);
WorldTile* t = m_gridManager.GetTileAtWorldPos(m_mousePos);
- if(t != nullptr) {
+ if (t != nullptr) {
t->SetTileType(Tiles::AIR);
}
@@ -100,15 +97,15 @@ void WorldLevel::Draw() const {
for (size_t x { 0 }; x < WORLD_WIDTH; ++x) {
for (size_t y { 0 }; y < WORLD_HEIGHT; ++y) {
- m_gridManager.GetTileAtIndex(x,y)->Draw();
+ m_gridManager.GetTileAtIndex(x, y)->Draw();
}
}
//loop over worldtiles
for (int x { 0 }; x < WORLD_WIDTH; ++x) {
for (int y { 0 }; y < WORLD_HEIGHT; ++y) {
- if(*m_gridManager.GetTileAtIndex(x,y)->GetTileType() != Tiles::AIR) {
- Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x,y)->GetCollisionRect().getCollisionRect();
+ if (*m_gridManager.GetTileAtIndex(x, y)->GetTileType() != Tiles::AIR) {
+ Collision::CollisionRect rect = m_gridManager.GetTileAtIndex(x, y)->GetCollisionRect().getCollisionRect();
utils::SetColor(Colors::GREEN);
utils::DrawRect(rect.pos, rect.size.x, rect.size.y);
}
@@ -134,16 +131,17 @@ void WorldLevel::ProcessImGui() {
if (ImGui::MenuItem("Camera Info")) {
m_ShowCameraWindow = !m_ShowCameraWindow;
}
- if(ImGui::MenuItem("Player Info")) {
+ if (ImGui::MenuItem("Player Info")) {
m_ShowPlayerInfo = !m_ShowPlayerInfo;
}
ImGui::EndMenu();
}
- if(ImGui::BeginMenu(std::to_string(utils::isKeyPressed(SDL_SCANCODE_S)).c_str())){}
+ if (ImGui::BeginMenu(std::to_string(utils::isKeyPressed(SDL_SCANCODE_S)).c_str())) {
+ }
ImGui::EndMainMenuBar();
}
- if(m_ShowTextureManagerWindow) {
+ if (m_ShowTextureManagerWindow) {
ImGui::Begin("Texture Manager", &m_ShowTextureManagerWindow, ImGuiWindowFlags_AlwaysAutoResize);
ImGui::Text("Texture loading Count:");
ImGui::SameLine();
@@ -151,17 +149,17 @@ void WorldLevel::ProcessImGui() {
ImGui::End();
}
- if(m_ShowCameraWindow) {
+ if (m_ShowCameraWindow) {
ImGui::Begin("Camera", &m_ShowCameraWindow, ImGuiWindowFlags_AlwaysAutoResize);
- ImGui::Text("Camera Position: (%f, %f)", m_pCamera->GetPosition().x, m_pCamera->GetPosition().y);
+ ImGui::Text("Camera Position: (%f, %f)", m_pCamera->GetPosition().x, m_pCamera->GetPosition().y);
ImGui::Text("Is Right Mouse Down: %s", utils::isMouseDown(0) ? "true" : "false");
- if(ImGui::Button("Reset Camera")) {
- m_pCamera->SetPosition(Point2f{-m_viewport.width / 2, -m_viewport.height / 2});
+ if (ImGui::Button("Reset Camera")) {
+ m_pCamera->SetPosition(Point2f { -m_viewport.width / 2, -m_viewport.height / 2 });
}
ImGui::End();
}
- if(m_ShowPlayerInfo) {
+ 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);
diff --git a/Game/WorldLevel.h b/Game/WorldLevel.h
index 979101b..694e4f0 100644
--- a/Game/WorldLevel.h
+++ b/Game/WorldLevel.h
@@ -1,43 +1,42 @@
#pragma once
-#include "Level.h"
-#include "Texture.h"
-#include "WorldLevel.h"
-#include "WorldTile.h"
-#include
-
#include "Collision.h"
+#include "Level.h"
#include "Player.h"
#include "utils.h"
-#include "WorldGridManager.h"
+#include "WorldLevel.h"
+#include "GridSystem/WorldGridManager.h"
-class WorldLevel : public Level {
+class WorldLevel : public Level
+{
public:
-
WorldLevel(Camera* camera, Rectf viewport);
~WorldLevel() override;
+ WorldLevel(const WorldLevel& other) = default;
+ WorldLevel(WorldLevel&& other) = default;
+
void Update(float elapsedSec) override;
void Draw() const override;
void MouseMove(const Point2f& mousePos) override;
void ProcessImGui() override;
- WorldGridManager& GetGridManager() { return m_gridManager; }
+ WorldGridManager& GetGridManager() {
+ return m_gridManager;
+ }
std::vector m_Rects;
private:
-
-
- WorldGridManager m_gridManager{};
+ WorldGridManager m_gridManager {};
Player m_player;
- Point2f m_mousePos{};
+ Point2f m_mousePos {};
Rectf m_viewport;
// ImGui Vars
- bool m_ShowTextureManagerWindow{ false };
- bool m_ShowCameraWindow{ false };
- bool m_ShowPlayerInfo{ true };
+ bool m_ShowTextureManagerWindow { false };
+ bool m_ShowCameraWindow { false };
+ bool m_ShowPlayerInfo { true };
};
diff --git a/Game/main.cpp b/Game/main.cpp
index 9538e63..0d06bc3 100644
--- a/Game/main.cpp
+++ b/Game/main.cpp
@@ -6,13 +6,12 @@
void StartHeapControl();
void DumpMemoryLeaks();
-int SDL_main(int argv, char** args)
-{
+int SDL_main(int argv, char** args) {
srand(static_cast(time(nullptr)));
StartHeapControl();
- Game* pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", 846.f, 500.f } } };
+ auto pGame { new Game { Window { "Motherload - Verhulst, Bram - 1DAEGD16E", 846.f, 500.f } } };
pGame->Run();
delete pGame;
diff --git a/Game/pch.cpp b/Game/pch.cpp
index 1730571..1d9f38c 100644
--- a/Game/pch.cpp
+++ b/Game/pch.cpp
@@ -1 +1 @@
-#include "pch.h"
\ No newline at end of file
+#include "pch.h"
diff --git a/Resources/animations/player/player_walk.png b/Resources/animations/player/player_walk.png
new file mode 100644
index 0000000..ff6cce1
Binary files /dev/null and b/Resources/animations/player/player_walk.png differ