Motor de sprites/animacions/surfaces i jugador centrat (v0.2.0)
This commit is contained in:
1 parent
7bb1edd08a
commit
de5a670fdb
34 files changed
+16137
-81
No files matched your search
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#include "core/rendering/sprite/moving_sprite.hpp"
|
||||
#include "core/resources/resource_types.hpp"
|
||||
|
||||
class AnimatedSprite : public MovingSprite {
|
||||
public:
|
||||
struct AnimationData {
|
||||
std::string name;
|
||||
std::vector<SDL_FRect> frames;
|
||||
std::vector<float> speeds;
|
||||
int loop_from{-1};
|
||||
bool completed{false};
|
||||
int current_frame{0};
|
||||
float accumulated_time{0.0F};
|
||||
};
|
||||
|
||||
explicit AnimatedSprite(const AnimationResource& cached_data);
|
||||
~AnimatedSprite() override = default;
|
||||
|
||||
void update(float delta_time) override;
|
||||
|
||||
auto animationIsCompleted() -> bool;
|
||||
auto getCurrentAnimationSize() -> int { return static_cast<int>(animations_[current_animation_].frames.size()); }
|
||||
|
||||
void setCurrentAnimation(const std::string& name = "default");
|
||||
void setCurrentAnimation(int index = 0);
|
||||
void resetAnimation();
|
||||
void setCurrentAnimationFrame(int num);
|
||||
void animate(float delta_time);
|
||||
|
||||
private:
|
||||
void buildNameIndex();
|
||||
|
||||
std::vector<AnimationData> animations_;
|
||||
std::unordered_map<std::string, int> animation_index_;
|
||||
int current_animation_{0};
|
||||
};
|
||||
Reference in new issue
Block a user