mirror of
https://github.com/Nimac0/SDL_Minigame
synced 2026-01-12 09:03:42 +00:00
52 lines
1.0 KiB
C++
52 lines
1.0 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <SDL_render.h>
|
|
#include <memory>
|
|
#include <string>
|
|
|
|
#include "AnimationHandler.h"
|
|
#include "Component.h"
|
|
#include "Direction.h"
|
|
#include "RenderObject.h"
|
|
|
|
class TransformComponent;
|
|
|
|
class SpriteComponent : public Component, public RenderObject
|
|
{
|
|
public:
|
|
int animationIndex = 0;
|
|
|
|
std::map<std::string, std::unique_ptr<Animation>>* animations = nullptr;
|
|
|
|
private:
|
|
TransformComponent* transform;
|
|
SDL_Texture* texture;
|
|
SDL_Rect srcRect, destRect;
|
|
|
|
const char* texturePath;
|
|
|
|
bool animated = false;
|
|
uint8_t frames = 0;
|
|
uint8_t speed = 100;
|
|
bool flipped = false;
|
|
|
|
public:
|
|
SpriteComponent(const char* path, int zIndex);
|
|
SpriteComponent(
|
|
const char* path,
|
|
bool isAnimated,
|
|
std::map<std::string, std::unique_ptr<Animation>>* animationList,
|
|
std::string defaultAnimation,
|
|
int zIndex);
|
|
~SpriteComponent();
|
|
|
|
void setTexture(const char* path);
|
|
|
|
void init() override;
|
|
void update() override;
|
|
void draw() override;
|
|
void playAnimation(std::string type);
|
|
void setDirection(Direction direction);
|
|
};
|