diff options
author | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-08 11:44:21 +0100 |
---|---|---|
committer | heavydemon21 <nielsstunnebrink1@gmail.com> | 2024-11-08 11:44:21 +0100 |
commit | 9432900158e6a31815345fcf0af8d28ae34c6da9 (patch) | |
tree | 36f799da46ba8f5e921349d0f004b08d6d2f29ea /src/crepe/api/Sprite.h | |
parent | 1c4156ee127b14760ed3b1a0cd16ad12180c7ac6 (diff) |
code style
Diffstat (limited to 'src/crepe/api/Sprite.h')
-rw-r--r-- | src/crepe/api/Sprite.h | 75 |
1 files changed, 72 insertions, 3 deletions
diff --git a/src/crepe/api/Sprite.h b/src/crepe/api/Sprite.h index 00dcb27..2e8b52a 100644 --- a/src/crepe/api/Sprite.h +++ b/src/crepe/api/Sprite.h @@ -1,6 +1,5 @@ #pragma once -#include <SDL2/SDL_rect.h> #include <cstdint> #include <memory> @@ -11,22 +10,92 @@ namespace crepe { +/** + * \struct Rect + * \brief Represents a rectangle area for rendering. + * + * Everything within the defined rectangle will be rendered. + * The SDLContext will translate this into the library's rectangle structure. + */ +struct Rect { + int w = 0; + int h = 0; + int x = 0; + int y = 0; +}; + +/** + * \struct FlipSettings + * \brief Flip settings for the sprite. + * + * Defines the horizontal and vertical flip settings for a sprite, which the + * SDLContext will translate into the corresponding settings for the library. + */ struct FlipSettings { - bool flip_x = true; - bool flip_y = true; + bool flip_x = false; + bool flip_y = false; }; +//! Forward declaration of the SDLContext facade. +class SDLContext; + +//! Forward declaration of the Animator class. +class Animator; + +//! Forward declaration of the AnimatorSystem class. +class AnimatorSystem; + +/** + * \class Sprite + * \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: + /** + * \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, std::shared_ptr<Texture> image, const Color & color, const FlipSettings & flip); + + /** + * \brief Destroys the Sprite instance. + */ ~Sprite(); + + + //! Texture used for the sprite std::shared_ptr<Texture> sprite_image; + //! Color tint of the sprite Color color; + //! Flip settings for the sprite FlipSettings flip; + //! Layer sorting level of the sprite uint8_t sorting_in_layer; + //! Order within the sorting layer uint8_t order_in_layer; + +public: + /** + * \brief Gets the maximum number of instances allowed for this sprite. + * \return Maximum instance count as an integer. + */ + virtual int get_instances_max() const { return 10; } + +private: + friend class SDLContext; + friend class Animator; + friend class AnimatorSystem; + + //! Render area of the sprite + Rect sprite_rect; }; } // namespace crepe |