diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-12 15:11:51 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-12 15:11:51 +0100 |
commit | 33454c2c8d8c0abdfd405608af4e6cd53a25e7c4 (patch) | |
tree | ef5131afc629815e993775423602a6e8af5fcb5f /src/crepe/api/Sprite.h | |
parent | 067247360d68042ad5466b802399338c14d7dc58 (diff) | |
parent | 656df6ddd6b5231705798540c347efeebf8ac8a9 (diff) |
merge `master` into `loek/cleanup`
Diffstat (limited to 'src/crepe/api/Sprite.h')
-rw-r--r-- | src/crepe/api/Sprite.h | 76 |
1 files changed, 66 insertions, 10 deletions
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 00dcb27..deb3f93 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -1,32 +1,88 @@ #pragma once -#include <SDL2/SDL_rect.h> #include <cstdint> #include <memory> -#include "api/Color.h" -#include "api/Texture.h" - +#include "Color.h" #include "Component.h" +#include "Texture.h" namespace crepe { +struct Rect { + int w = 0; + int h = 0; + int x = 0; + int y = 0; +}; + struct FlipSettings { - bool flip_x = true; - bool flip_y = true; + bool flip_x = false; + bool flip_y = false; }; +class SDLContext; +class Animator; +class AnimatorSystem; + +/** + * \brief Represents a renderable sprite component. + * + * A renderable sprite that can be displayed in the game. It includes a texture, + * color, and flip settings, and is managed in layers with defined sorting orders. + */ class Sprite : public Component { public: - Sprite(game_object_id_t id, std::shared_ptr<Texture> image, + // TODO: Loek comment in github #27 will be looked another time + // about shared_ptr Texture + /** + * \brief Constructs a Sprite with specified parameters. + * \param game_id Unique identifier for the game object this sprite belongs to. + * \param image Shared pointer to the texture for this sprite. + * \param color Color tint applied to the sprite. + * \param flip Flip settings for horizontal and vertical orientation. + */ + Sprite(game_object_id_t id, const std::shared_ptr<Texture> image, const Color & color, const FlipSettings & flip); + + /** + * \brief Destroys the Sprite instance. + */ ~Sprite(); - std::shared_ptr<Texture> sprite_image; + + //! Texture used for the sprite + const std::shared_ptr<Texture> sprite_image; + //! Color tint of the sprite Color color; + //! Flip settings for the sprite FlipSettings flip; - uint8_t sorting_in_layer; - uint8_t order_in_layer; + //! Layer sorting level of the sprite + uint8_t sorting_in_layer = 0; + //! Order within the sorting layer + uint8_t order_in_layer = 0; + +public: + /** + * \brief Gets the maximum number of instances allowed for this sprite. + * \return Maximum instance count as an integer. + * + * For now is this number randomly picked. I think it will eventually be 1. + */ + virtual int get_instances_max() const { return 10; } + +private: + //! Reads the sprite_rect of sprite + friend class SDLContext; + + //! Reads the all the variables plus the sprite_rect + friend class Animator; + + //! Reads the all the variables plus the sprite_rect + friend class AnimatorSystem; + + //! Render area of the sprite this will also be adjusted by the AnimatorSystem if an Animator object is present in GameObject + Rect sprite_rect; }; } // namespace crepe |