mirror of
https://github.com/HowestDAE/dae16-VerhulstBram.git
synced 2025-12-17 03:41:48 +01:00
Reformat + Basic animation system
General fixes
This commit is contained in:
25
Game/Animations/Animation.cpp
Normal file
25
Game/Animations/Animation.cpp
Normal file
@@ -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);
|
||||
}
|
||||
30
Game/Animations/Animation.h
Normal file
30
Game/Animations/Animation.h
Normal file
@@ -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 };
|
||||
};
|
||||
Reference in New Issue
Block a user