diff --git a/.idea/.idea.Motherload/.idea/workspace.xml b/.idea/.idea.Motherload/.idea/workspace.xml
index 164e542..22e23ff 100644
--- a/.idea/.idea.Motherload/.idea/workspace.xml
+++ b/.idea/.idea.Motherload/.idea/workspace.xml
@@ -10,16 +10,14 @@
-
+
-
-
-
-
-
-
-
-
+
+
+
+
+
+
@@ -29,11 +27,49 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -52,6 +88,11 @@
+
+
+
+
+
@@ -76,28 +117,28 @@
- {
- "keyToString": {
- "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": "preferences.pluginManager",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -229,6 +270,7 @@
+
@@ -318,7 +360,15 @@
1713863838768
-
+
+
+ 1714460546894
+
+
+
+ 1714460546894
+
+
@@ -339,7 +389,8 @@
-
+
+
diff --git a/Assets/Player/PlayerTurn.aseprite b/Assets/Player/PlayerTurn.aseprite
new file mode 100644
index 0000000..808dcb9
Binary files /dev/null and b/Assets/Player/PlayerTurn.aseprite differ
diff --git a/Assets/Player/PlayerWalk.aseprite b/Assets/Player/PlayerWalk.aseprite
index c2c0cc2..fbe8b19 100644
Binary files a/Assets/Player/PlayerWalk.aseprite and b/Assets/Player/PlayerWalk.aseprite differ
diff --git a/Game/Animations/Animation.cpp b/Game/Animations/Animation.cpp
index 084e7fa..eca8ebb 100644
--- a/Game/Animations/Animation.cpp
+++ b/Game/Animations/Animation.cpp
@@ -2,17 +2,21 @@
#include "Animation.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) {
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;
+ }
}
}
}
diff --git a/Game/Animations/Animation.h b/Game/Animations/Animation.h
index 62ed188..7c691d6 100644
--- a/Game/Animations/Animation.h
+++ b/Game/Animations/Animation.h
@@ -4,12 +4,13 @@
class Animation
{
public:
- Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect);
+ Animation(Texture* pTexture, int frames, float frameDuration, Rectf srcRect, bool isLooping = true);
~Animation() = default;
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;
@@ -18,6 +19,15 @@ public:
m_isFlipped = isFlipped;
}
+ void Reset() {
+ m_CurrentFrame = 0;
+ m_hasPlayedOnce = false;
+ m_isPlaying = true;
+ }
+ bool IsDone() const {
+ return m_hasPlayedOnce && !m_isLooping;
+ }
+
private:
Texture* m_pTexture;
Rectf m_SrcRect;
@@ -26,6 +36,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 };
};
diff --git a/Game/Player.cpp b/Game/Player.cpp
index e83441f..a937c68 100644
--- a/Game/Player.cpp
+++ b/Game/Player.cpp
@@ -20,8 +20,14 @@ 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 });
+ m_turnAnimation = new Animation(
+ manager->GetTexture("animations/player/player_turn.png"),
+ 5, 0.07f, Rectf{ 0, 0, 70, 70 }, false);
m_currentAnimation = m_walkAnimation;
}
+Player::Player(Player&& other) {
+
+}
Player::~Player() {
delete m_walkAnimation;
@@ -46,7 +52,7 @@ void Player::Draw() const {
float bobOffset = m_BobUp ? 1 : 0;
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_DigStart, 5, 5);
}
@@ -69,6 +75,22 @@ void Player::ProcessImGui() {
ImGui::Text("Player State %s", currentState.c_str());
ImGui::Text("Bob counter: %f", m_BobTimer);
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
@@ -138,8 +160,17 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
}
if (utils::isKeyDown(SDL_SCANCODE_A)) {
- m_walkAnimation->SetFlipped(false);
- m_Acc.x = -m_Speed;
+ 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)) {
@@ -155,8 +186,20 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
}
if (utils::isKeyDown(SDL_SCANCODE_D)) {
- m_Acc.x = m_Speed;
- m_walkAnimation->SetFlipped(true);
+
+ if(!m_IsTurning) {
+ m_Acc.x = m_Speed;
+ 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) {
//Check if the player doesnt come from digging a tile
if (this->CanDig(Collision::CollisionDirection::Right, level)) {
@@ -183,7 +226,12 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
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;
@@ -192,7 +240,6 @@ void Player::Update(float elapsedTime, WorldLevel& level) {
m_ContactMap[Collision::CollisionDirection::Right] = nullptr;
m_Grounded = false;
-
float t = 0, min_t = INFINITY;
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::ResolvePlayerVsRect(*this, elapsedTime, &rect);
}
+#pragma endregion
+
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;
diff --git a/Game/Player.h b/Game/Player.h
index 17ebec5..521e3ea 100644
--- a/Game/Player.h
+++ b/Game/Player.h
@@ -10,6 +10,7 @@ enum class PlayerState
Idle,
Walking,
Digging,
+ Turning
};
enum class PlayerDirection
@@ -32,7 +33,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();
@@ -92,6 +95,7 @@ private:
const float m_DigTime{ 0.5f };
bool m_Grounded { false };
+ bool m_IsTurning{ false };
bool m_DidJustDigRight { false };
bool m_DidJustDigLeft { false };
@@ -101,7 +105,7 @@ private:
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
diff --git a/Resources/animations/player/player_turn.png b/Resources/animations/player/player_turn.png
new file mode 100644
index 0000000..8b4b583
Binary files /dev/null and b/Resources/animations/player/player_turn.png differ
diff --git a/Resources/animations/player/player_walk.png b/Resources/animations/player/player_walk.png
index ff6cce1..efbf666 100644
Binary files a/Resources/animations/player/player_walk.png and b/Resources/animations/player/player_walk.png differ