mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-18 20:59:20 +01:00
Add player turning (Finally)
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user