R-Type
Distributed multiplayer game engine in C++
Loading...
Searching...
No Matches
Sprite.hpp
Go to the documentation of this file.
1/*
2** EPITECH PROJECT, 2025
3** RTYPE
4** File description:
5** Sprite
6*/
7
8#pragma once
9
10#include <string>
11#include "IComponent.hpp"
12
13namespace ecs {
18 struct Rectangle {
19 int x;
20 int y;
21 int width;
22 int height;
23 };
24
32 class Sprite : public IComponent {
33 public:
44 Sprite(const std::string &textureKey, Rectangle sourceRect, float scale = 1.0f, float rotation = 0.0f,
45 bool flipX = false, bool flipY = false, int layer = 0)
46 : _textureKey(textureKey),
47 _sourceRect(sourceRect),
48 _scale(scale),
49 _rotation(rotation),
50 _flipX(flipX),
51 _flipY(flipY),
52 _layer(layer) {}
53
54 ~Sprite() override = default;
55
60 std::string getTextureKey() const { return _textureKey; }
61
67
72 float getScale() const { return _scale; }
73
78 float getRotation() const { return _rotation; }
79
84 bool isFlippedX() const { return _flipX; }
85
90 bool isFlippedY() const { return _flipY; }
91
96 int getLayer() const { return _layer; }
97
102 void setTextureKey(const std::string &textureKey) { _textureKey = textureKey; }
103
108 void setSourceRect(Rectangle sourceRect) { _sourceRect = sourceRect; }
109
114 void setScale(float scale) { _scale = scale; }
115
120 void setRotation(float rotation) { _rotation = rotation; }
121
126 void setFlipX(bool flipX) { _flipX = flipX; }
127
132 void setFlipY(bool flipY) { _flipY = flipY; }
133
138 void setLayer(int layer) { _layer = layer; }
139
144 ComponentType getType() const override { return getComponentType<Sprite>(); }
145
146 private:
147 std::string _textureKey;
149 float _scale;
150 float _rotation;
151 bool _flipX;
152 bool _flipY;
153 int _layer;
154 };
155} // namespace ecs
Base interface for all ECS components.
Component representing a visual sprite from a texture.
Definition Sprite.hpp:32
std::string _textureKey
Texture identifier (e.g., "r-typesheet1")
Definition Sprite.hpp:147
float _rotation
Rotation angle in degrees.
Definition Sprite.hpp:150
void setLayer(int layer)
Set the rendering layer.
Definition Sprite.hpp:138
void setFlipX(bool flipX)
Set horizontal flip state.
Definition Sprite.hpp:126
void setFlipY(bool flipY)
Set vertical flip state.
Definition Sprite.hpp:132
float getScale() const
Get the scale factor.
Definition Sprite.hpp:72
void setTextureKey(const std::string &textureKey)
Set the texture key.
Definition Sprite.hpp:102
float getRotation() const
Get the rotation angle.
Definition Sprite.hpp:78
int getLayer() const
Get the rendering layer.
Definition Sprite.hpp:96
int _layer
Rendering layer for Z-ordering.
Definition Sprite.hpp:153
Rectangle _sourceRect
Source rectangle in the texture.
Definition Sprite.hpp:148
ComponentType getType() const override
Get the component type ID.
Definition Sprite.hpp:144
void setRotation(float rotation)
Set the rotation angle.
Definition Sprite.hpp:120
void setSourceRect(Rectangle sourceRect)
Set the source rectangle.
Definition Sprite.hpp:108
bool _flipY
Vertical flip flag.
Definition Sprite.hpp:152
~Sprite() override=default
void setScale(float scale)
Set the scale factor.
Definition Sprite.hpp:114
bool _flipX
Horizontal flip flag.
Definition Sprite.hpp:151
float _scale
Scale factor (1.0 = original size)
Definition Sprite.hpp:149
bool isFlippedY() const
Check if vertically flipped.
Definition Sprite.hpp:90
std::string getTextureKey() const
Get the texture key.
Definition Sprite.hpp:60
bool isFlippedX() const
Check if horizontally flipped.
Definition Sprite.hpp:84
Rectangle getSourceRect() const
Get the source rectangle.
Definition Sprite.hpp:66
Sprite(const std::string &textureKey, Rectangle sourceRect, float scale=1.0f, float rotation=0.0f, bool flipX=false, bool flipY=false, int layer=0)
Constructor with all sprite parameters.
Definition Sprite.hpp:44
Maximum number of distinct component types supported by the Registry.
Definition GameLogic.hpp:26
std::size_t ComponentType
Type alias for component identification.
Rectangle structure defining a region in a texture.
Definition Sprite.hpp:18
int x
X coordinate of the top-left corner.
Definition Sprite.hpp:19
int height
Height of the rectangle.
Definition Sprite.hpp:22
int y
Y coordinate of the top-left corner.
Definition Sprite.hpp:20
int width
Width of the rectangle.
Definition Sprite.hpp:21