aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api/Sprite.h
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-14 11:10:31 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-14 11:10:31 +0100
commit6e13510f3c6d4155707f748d237bb1fa05243450 (patch)
treeb21ca972d14aac56b7c58c85c54d8a2fd1278a7e /src/crepe/api/Sprite.h
parent319d511135da1b58acb78ca939d7ee01fee4bbf3 (diff)
parentbe1e97bc7a494963ab1567492fafcda99e36f683 (diff)
merge `master` into `loek/audio`
Diffstat (limited to 'src/crepe/api/Sprite.h')
-rw-r--r--src/crepe/api/Sprite.h76
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