Compare commits

...

2 Commits

Author SHA1 Message Date
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
10 changed files with 168 additions and 44 deletions

3
.gitignore vendored
View File

@@ -403,4 +403,5 @@ FodyWeavers.xsd
.idea/ .idea/
/.idea/ .idea/*
.idea/workspace.xml

View File

@@ -10,16 +10,14 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment=""> <list default="true" id="26a0623a-44d5-441c-8048-32ff1dab3479" name="Changes" comment="Add fps">
<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$/.idea/.idea.Motherload/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/.idea.Motherload/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Engine/BaseGame.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Engine/BaseGame.cpp" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Assets/Player/PlayerWalk.aseprite" beforeDir="false" afterPath="$PROJECT_DIR$/Assets/Player/PlayerWalk.aseprite" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/Game.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.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/Game.vcxproj" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj" 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.vcxproj.filters" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Game.vcxproj.filters" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Game/Player.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.cpp" afterDir="false" />
<change beforePath="$PROJECT_DIR$/Game/GroundTileTypeManager.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/GroundTileTypeManager.h" afterDir="false" /> <change beforePath="$PROJECT_DIR$/Game/Player.h" beforeDir="false" afterPath="$PROJECT_DIR$/Game/Player.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$/Resources/animations/player/player_walk.png" beforeDir="false" afterPath="$PROJECT_DIR$/Resources/animations/player/player_walk.png" 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/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/Game/main.cpp" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -29,11 +27,49 @@
<component name="Git.Settings"> <component name="Git.Settings">
<option name="RECENT_BRANCH_BY_REPOSITORY"> <option name="RECENT_BRANCH_BY_REPOSITORY">
<map> <map>
<entry key="$PROJECT_DIR$" value="b406c8ffccf41d69fdf385448c8d0c2d49b2f970" /> <entry key="$PROJECT_DIR$" value="da8377e7a09f06e92abfba75412dc49e0cdc6316" />
</map> </map>
</option> </option>
</component> </component>
<component name="HighlightingSettingsPerFile"> <component name="HighlightingSettingsPerFile">
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" /> <setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" /> <setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" /> <setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
@@ -52,6 +88,11 @@
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Engine/BaseGame.cpp" root0="SKIP_HIGHLIGHTING" /> <setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Engine/BaseGame.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Game/Animations/Animation.h" root0="FORCE_HIGHLIGHTING" /> <setting file="file://$PROJECT_DIR$/Game/Animations/Animation.h" root0="FORCE_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Game/Camera.cpp" 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/Game.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/GroundTileTypeManager.h" root0="SKIP_HIGHLIGHTING" />
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/Levels/World/WorldLevel.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/Levels/World/WorldLevel.h" root0="SKIP_HIGHLIGHTING" />
<setting file="mock://C:/Users/Bram/Desktop/Programming 2/Exam/dae16-VerhulstBram/Game/main.cpp" root0="SKIP_HIGHLIGHTING" />
<setting file="file://$PROJECT_DIR$/Game/pch.cpp" 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$/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.h" root0="SKIP_HIGHLIGHTING" />
@@ -76,28 +117,28 @@
<option name="hideEmptyMiddlePackages" value="true" /> <option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" /> <option name="showLibraryContents" value="true" />
</component> </component>
<component name="PropertiesComponent">{ <component name="PropertiesComponent"><![CDATA[{
&quot;keyToString&quot;: { "keyToString": {
&quot;C++ Project.Game.executor&quot;: &quot;Run&quot;, "C++ Project.Game.executor": "Debug",
&quot;RunOnceActivity.OpenProjectViewOnStart&quot;: &quot;true&quot;, "RunOnceActivity.OpenProjectViewOnStart": "true",
&quot;RunOnceActivity.ShowReadmeOnStart&quot;: &quot;true&quot;, "RunOnceActivity.ShowReadmeOnStart": "true",
&quot;ignore.virus.scanning.warn.message&quot;: &quot;true&quot;, "ignore.virus.scanning.warn.message": "true",
&quot;node.js.detected.package.eslint&quot;: &quot;true&quot;, "node.js.detected.package.eslint": "true",
&quot;node.js.detected.package.tslint&quot;: &quot;true&quot;, "node.js.detected.package.tslint": "true",
&quot;node.js.selected.package.eslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.eslint": "(autodetect)",
&quot;node.js.selected.package.tslint&quot;: &quot;(autodetect)&quot;, "node.js.selected.package.tslint": "(autodetect)",
&quot;nodejs_package_manager_path&quot;: &quot;npm&quot;, "nodejs_package_manager_path": "npm",
&quot;settings.editor.selected.configurable&quot;: &quot;preferences.pluginManager&quot;, "settings.editor.selected.configurable": "preferences.pluginManager",
&quot;vue.rearranger.settings.migration&quot;: &quot;true&quot; "vue.rearranger.settings.migration": "true"
}, },
&quot;keyToStringList&quot;: { "keyToStringList": {
&quot;rider.external.source.directories&quot;: [ "rider.external.source.directories": [
&quot;C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache&quot;, "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\DecompilerCache",
&quot;C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache&quot;, "C:\\Users\\Bram\\AppData\\Roaming\\JetBrains\\Rider2024.1\\resharper-host\\SourcesCache",
&quot;C:\\Users\\Bram\\AppData\\Local\\Symbols\\src&quot; "C:\\Users\\Bram\\AppData\\Local\\Symbols\\src"
] ]
} }
}</component> }]]></component>
<component name="RunManager"> <component name="RunManager">
<configuration name="Game" type="CppProject" factoryName="C++ Project"> <configuration name="Game" type="CppProject" factoryName="C++ Project">
<configuration_1> <configuration_1>
@@ -229,6 +270,7 @@
<workItem from="1714026889126" duration="4211000" /> <workItem from="1714026889126" duration="4211000" />
<workItem from="1714046400732" duration="2462000" /> <workItem from="1714046400732" duration="2462000" />
<workItem from="1714372163827" duration="2962000" /> <workItem from="1714372163827" duration="2962000" />
<workItem from="1714459066696" duration="11199000" />
</task> </task>
<task id="LOCAL-00001" summary="Rework Tile detection system"> <task id="LOCAL-00001" summary="Rework Tile detection system">
<option name="closed" value="true" /> <option name="closed" value="true" />
@@ -318,7 +360,15 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1713863838768</updated> <updated>1713863838768</updated>
</task> </task>
<option name="localTasksCounter" value="12" /> <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>
<option name="localTasksCounter" value="13" />
<servers /> <servers />
</component> </component>
<component name="TypeScriptGeneratedFilesManager"> <component name="TypeScriptGeneratedFilesManager">
@@ -339,7 +389,8 @@
<MESSAGE value="Fix digging" /> <MESSAGE value="Fix digging" />
<MESSAGE value="Added Buildings&#10;Fixed rendering bugs with edges" /> <MESSAGE value="Added Buildings&#10;Fixed rendering bugs with edges" />
<MESSAGE value="Add alot of memory leak fixes" /> <MESSAGE value="Add alot of memory leak fixes" />
<option name="LAST_COMMIT_MESSAGE" value="Add alot of memory leak fixes" /> <MESSAGE value="Add fps" />
<option name="LAST_COMMIT_MESSAGE" value="Add fps" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

Binary file not shown.

Binary file not shown.

View File

@@ -2,17 +2,21 @@
#include "Animation.h" #include "Animation.h"
#include "utils.h" #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) { void Animation::Update(float elapsedSec) {
if (m_isPlaying) { if (m_isPlaying) {
m_FrameTimer -= elapsedSec; m_FrameTimer -= elapsedSec;
if (m_FrameTimer <= 0.0f) { if (m_FrameTimer <= 0.0f) {
m_FrameTimer = 0.1f; m_FrameTimer = m_FrameDuration;
++m_CurrentFrame; ++m_CurrentFrame;
if (m_CurrentFrame >= m_Frames) { if (m_CurrentFrame >= m_Frames) {
m_CurrentFrame = 0; m_CurrentFrame = 0;
if(!m_isLooping) {
m_hasPlayedOnce = true;
m_isPlaying = false;
}
} }
} }
} }

View File

@@ -4,13 +4,14 @@
class Animation class Animation
{ {
public: public:
Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect); Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping = true);
~Animation() = default; ~Animation() = default;
void Update(float elapsedSec); void Update(float elapsedSec);
void Draw(const Vector2f& pos) const; void Draw(const Vector2f& pos) const;
void Draw(const Vector2f& pos, const Rectf& dst) const; void Draw(const Vector2f& pos, const Rectf& dst) const;
void SetPlaying(bool isPlaying) { void SetPlaying(bool isPlaying) {
m_isPlaying = isPlaying; m_isPlaying = isPlaying;
} }
@@ -18,6 +19,15 @@ public:
m_isFlipped = isFlipped; m_isFlipped = isFlipped;
} }
void Reset() {
m_CurrentFrame = 0;
m_hasPlayedOnce = false;
m_isPlaying = true;
}
bool IsDone() const {
return m_hasPlayedOnce && !m_isLooping;
}
private: private:
Texture* m_pTexture; Texture* m_pTexture;
Rectf m_SrcRect; Rectf m_SrcRect;
@@ -26,6 +36,11 @@ private:
int m_CurrentFrame { 0 }; int m_CurrentFrame { 0 };
float m_FrameTimer { 0.0f }; float m_FrameTimer { 0.0f };
float m_FrameDuration { 0.1f };
bool m_isPlaying { true }; bool m_isPlaying { true };
bool m_isFlipped { false }; bool m_isFlipped { false };
bool m_isLooping { true };
bool m_hasPlayedOnce { false };
}; };

View File

@@ -20,8 +20,14 @@ Player::Player(const Vector2f& Position, TextureManager* manager) : m_Position(P
m_walkAnimation = new Animation( m_walkAnimation = new Animation(
manager->GetTexture("animations/player/player_walk.png"), manager->GetTexture("animations/player/player_walk.png"),
8, 0.1f, Rectf { 0, 0, 70, 70 }); 8, 0.1f, Rectf { 0, 0, 70, 70 });
m_turnAnimation = new Animation(
manager->GetTexture("animations/player/player_turn.png"),
5, 0.07f, Rectf{ 0, 0, 70, 70 }, false);
m_currentAnimation = m_walkAnimation; m_currentAnimation = m_walkAnimation;
} }
Player::Player(Player&& other) {
}
Player::~Player() { Player::~Player() {
delete m_walkAnimation; delete m_walkAnimation;
@@ -46,7 +52,7 @@ void Player::Draw() const {
float bobOffset = m_BobUp ? 1 : 0; float bobOffset = m_BobUp ? 1 : 0;
Vector2f drawPos = Vector2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 + bobOffset }; Vector2f drawPos = Vector2f { center.x - halfFrameWidth, center.y - halfFrameWidth + 9 + bobOffset };
m_walkAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth }); m_currentAnimation->Draw(drawPos, Rectf { drawPos.x, drawPos.y, frameWidth, frameWidth });
utils::DrawEllipse(m_DigDestination, 5, 5); utils::DrawEllipse(m_DigDestination, 5, 5);
utils::DrawEllipse(m_DigStart, 5, 5); utils::DrawEllipse(m_DigStart, 5, 5);
} }
@@ -69,6 +75,22 @@ void Player::ProcessImGui() {
ImGui::Text("Player State %s", currentState.c_str()); ImGui::Text("Player State %s", currentState.c_str());
ImGui::Text("Bob counter: %f", m_BobTimer); ImGui::Text("Bob counter: %f", m_BobTimer);
ImGui::Text("Bob up: %s", m_BobUp ? "true" : "false"); ImGui::Text("Bob up: %s", m_BobUp ? "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 //ContactMap
@@ -138,8 +160,17 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
} }
} }
if (utils::isKeyDown(SDL_SCANCODE_A)) { if (utils::isKeyDown(SDL_SCANCODE_A)) {
if(!m_IsTurning) {
m_walkAnimation->SetFlipped(false); m_walkAnimation->SetFlipped(false);
m_Acc.x = -m_Speed; 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) { if (m_Grounded && !m_DidJustDigLeft) {
//Check if the player doesnt come from digging a tile //Check if the player doesnt come from digging a tile
if (this->CanDig(Collision::CollisionDirection::Left, level)) { if (this->CanDig(Collision::CollisionDirection::Left, level)) {
@@ -155,8 +186,20 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
} }
if (utils::isKeyDown(SDL_SCANCODE_D)) { if (utils::isKeyDown(SDL_SCANCODE_D)) {
if(!m_IsTurning) {
m_Acc.x = m_Speed; m_Acc.x = m_Speed;
m_walkAnimation->SetFlipped(true); m_walkAnimation->SetFlipped(true);
}
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) { if (m_Grounded && !m_DidJustDigRight) {
//Check if the player doesnt come from digging a tile //Check if the player doesnt come from digging a tile
if (this->CanDig(Collision::CollisionDirection::Right, level)) { if (this->CanDig(Collision::CollisionDirection::Right, level)) {
@@ -183,7 +226,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_Acc = Vector2f { 0, 0 }; m_Acc = Vector2f { 0, 0 };
m_walkAnimation->Update(elapsedTime); m_currentAnimation->Update(elapsedTime);
if(m_currentAnimation->IsDone()) {
m_currentAnimation = m_walkAnimation; //TODO: fix this hack
m_IsTurning = false;
}
#pragma region Collision
m_ContactMap[Collision::CollisionDirection::Top] = nullptr; m_ContactMap[Collision::CollisionDirection::Top] = nullptr;
@@ -192,7 +240,6 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_ContactMap[Collision::CollisionDirection::Right] = nullptr; m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
m_Grounded = false; m_Grounded = false;
float t = 0, min_t = INFINITY; float t = 0, min_t = INFINITY;
Vector2f intersectionPoint, normal; Vector2f intersectionPoint, normal;
@@ -254,6 +301,8 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
Collision::CollisionRect rect = world_tile->GetCollisionRect().getCollisionRect(); //TODO: fix this mess Collision::CollisionRect rect = world_tile->GetCollisionRect().getCollisionRect(); //TODO: fix this mess
Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect); Collision::ResolvePlayerVsRect(*this, elapsedTime, &rect);
} }
#pragma endregion
if (m_State != PlayerState::Digging) { //Fix for when the state is JUST set to digging if (m_State != PlayerState::Digging) { //Fix for when the state is JUST set to digging
if (m_Vel.x != 0.0f) { if (m_Vel.x != 0.0f) {
m_State = PlayerState::Walking; m_State = PlayerState::Walking;

View File

@@ -10,6 +10,7 @@ enum class PlayerState
Idle, Idle,
Walking, Walking,
Digging, Digging,
Turning
}; };
enum class PlayerDirection enum class PlayerDirection
@@ -32,7 +33,9 @@ class Player
public: public:
explicit Player(const Vector2f& Position, TextureManager* pTextureManager); explicit Player(const Vector2f& Position, TextureManager* pTextureManager);
Player( const Player& other ) = default; Player( const Player& other ) = default;
Player(Player&& other) = default; Player(Player&& other);
Player& operator=(const Player& other) = delete;
Player& operator=(Player&& other) = delete;
~Player(); ~Player();
@@ -92,6 +95,7 @@ private:
const float m_DigTime{ 0.5f }; const float m_DigTime{ 0.5f };
bool m_Grounded { false }; bool m_Grounded { false };
bool m_IsTurning{ false };
bool m_DidJustDigRight { false }; bool m_DidJustDigRight { false };
bool m_DidJustDigLeft { false }; bool m_DidJustDigLeft { false };
@@ -101,7 +105,7 @@ private:
Animation* m_digAnimation{ nullptr }; Animation* m_digAnimation{ nullptr };
PlayerState m_State { PlayerState::Idle }; PlayerState m_State { PlayerState::Idle };
PlayerDirection m_Direction { PlayerDirection::Right }; PlayerDirection m_Direction { PlayerDirection::Left };
DigDirection m_DigDirection { DigDirection::Right }; DigDirection m_DigDirection { DigDirection::Right };
//Testing //Testing

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