blob: 6f83ac884763d45d955f2ced8c3180c17ea5cf34 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
|
#pragma once
#include <cstdint>
#include <memory>
#include "api/Color.h"
#include "api/Texture.h"
#include "Component.h"
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 = 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, const std::shared_ptr<Texture> image,
const Color & color, const FlipSettings & flip);
/**
* \brief Destroys the Sprite instance.
*/
~Sprite();
//! 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;
//! 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
|