mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 10:13:42 +00:00
48 lines
828 B
C++
48 lines
828 B
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <SDL_render.h>
|
|
|
|
#include "AnimationHandler.h"
|
|
#include "Component.h"
|
|
|
|
class TransformComponent;
|
|
|
|
enum SpriteDirection
|
|
{
|
|
LEFT,
|
|
RIGHT
|
|
};
|
|
|
|
class SpriteComponent : public Component
|
|
{
|
|
public:
|
|
int animationIndex = 0;
|
|
|
|
std::map<AnimationType, Animation*> animations;
|
|
|
|
private:
|
|
TransformComponent* transform;
|
|
SDL_Texture* texture;
|
|
SDL_Rect srcRect, destRect;
|
|
|
|
bool animated = false;
|
|
uint8_t frames = 0;
|
|
uint8_t speed = 100;
|
|
bool flipped;
|
|
|
|
public:
|
|
SpriteComponent() = default;
|
|
SpriteComponent(const char* path);
|
|
SpriteComponent(const char* path, bool isAnimated);
|
|
~SpriteComponent();
|
|
|
|
void setTexture(const char* path);
|
|
|
|
void init() override;
|
|
void update() override;
|
|
void draw() override;
|
|
void playAnimation(AnimationType type);
|
|
void setDirection(SpriteDirection direction);
|
|
};
|