38 Sprite(
char** text,
char*** ansi,
int z) {
41 Sprite(std::vector<std::string> text, std::vector<std::vector<std::string>> ansi,
int z) {
63 int getWidth()
const {
67 int getHeight()
const {
68 return sprite->height;
75 int draw(
int x,
int y) {
88 std::vector<std::string> text;
89 for (
int i = 0; i < sprite->height; i++) {
90 text.push_back(std::string(sprite->data[i]));
95 void setData(std::vector<std::string> text) {
100 void setData(
char** text) {
108 std::vector<std::vector<std::string>>
getAnsi() {
109 std::vector<std::vector<std::string>> ansi;
110 for (
int i = 0; i < sprite->height; i++) {
111 std::vector<std::string> row;
112 for (
int j = 0; j < sprite->width; j++) {
113 row.push_back(std::string(sprite->ansi[i][j]));
120 void setChar(
int x,
int y,
char c) {
124 int fillChar(
int x,
int y,
int width,
int height,
char c) {
128 int fillCharEmpty(
int x,
int y,
int width,
int height,
char c) {
132 int fillCharAll(
char c) {
136 int fillCharAllEmpty(
char c) {
140 int setAnsi(
int x,
int y,
char* ansi) {
144 int appendAnsi(
int x,
int y,
char* ansi) {
148 int fillAnsi(
int x,
int y,
char* ansi,
int width,
int height) {
152 int setAnsiAll(
char* ansi) {
156 int appendAnsiAll(
char* ansi) {
160 int resize(
int width,
int height) {
164 int resizeWithPadding(
int width,
int height,
char padding) {
172 int resizeAndCenter(
int width,
int height) {
176 void moveTo(
int x,
int y) {
180 void moveBy(
int dx,
int dy) {
184 std::vector<std::unique_ptr<Sprite>> getCollidingSprites() {
185 std::vector<std::unique_ptr<Sprite>> collisions;
187 for (
int i = 0; collisionSprites[i] !=
nullptr; i++) {
188 collisions.push_back(std::make_unique<Sprite>(collisionSprites[i]));
193 bool isCollidingWith(std::unique_ptr<Sprite> other) {
197 bool isOnTop(
int x,
int y) {
201 bool isOnBottom(
int x,
int y) {
205 int setForeground(
int x,
int y,
int rgb) {
209 int setForeground(
int rgb) {
213 int setForeground256(
int color) {
217 int setBackground(
int x,
int y,
int rgb) {
221 int rotate(
double radians) {
225 double getRotationAngle() {
237 int scale(
double scale) {
253 std::vector<std::unique_ptr<Sprite>> sprites;
256 sprites.push_back(std::make_unique<Sprite>(drawnSprites[i]));
271 return std::make_unique<Sprite>(sprite);
C++ Extensions for the Builder API.
CmdFX_Sprite * getSprite()
Get the Sprite object associated with this class.
Definition sprites.hpp:53
std::vector< std::string > getData()
Get the data of a sprite as a 1D vector of strings.
Definition sprites.hpp:87
std::vector< std::vector< std::string > > getAnsi()
Get the ANSI data of a sprite as a 2D vector of strings.
Definition sprites.hpp:108
C++ wrapper for the CmdFX canvas.
Definition canvas.hpp:23
std::vector< std::unique_ptr< Sprite > > getDrawnSprites()
Gets all of the drawn sprites.
Definition sprites.hpp:252
std::unique_ptr< Sprite > getSpriteAt(int x, int y)
Get the Sprite at a specific position.
Definition sprites.hpp:268
Primary namespace for CmdFX.
Definition cmdfx.hpp:22
char ** to2DArray(std::vector< std::string > string)
Converts a 1D vector of strings to a 2D array of characters.
Definition builder.hpp:39
char *** to3DArray(std::vector< std::vector< std::string > > string)
Converts a 2D vector of strings to a 3D array of characters.
Definition builder.hpp:55
CmdFX_Sprite ** Sprite_getCollidingSprites(CmdFX_Sprite *sprite)
Gets the sprites that are colliding with the given sprite.
void Sprite_remove(CmdFX_Sprite *sprite)
Removes a sprite from the terminal, making it no longer visble.
int Sprite_setAnsi(CmdFX_Sprite *sprite, int x, int y, char *ansi)
Sets the ANSI code at the given position in the sprite.
int Sprite_fillCharAllEmpty(CmdFX_Sprite *sprite, char c)
Sets the character at all positions in the sprite where there isn't a character.
int Sprite_setBackground(CmdFX_Sprite *sprite, int x, int y, int rgb)
Sets the background color of the sprite at the given position.
int Sprite_fillAnsi(CmdFX_Sprite *sprite, int x, int y, char *ansi, int width, int height)
Fills positions in the sprite with an ANSI code.
int Sprite_vFlip(CmdFX_Sprite *sprite)
Flips the sprite vertically.
int Sprite_rotate(CmdFX_Sprite *sprite, double radians)
Rotates the sprite by the given angle.
int Sprite_isOnBottom(CmdFX_Sprite *sprite, int x, int y)
Gets whether the sprite is the bottom-most sprite at the given position.
int Sprite_isColliding(CmdFX_Sprite *sprite1, CmdFX_Sprite *sprite2)
Checks if two sprites are colliding.
int Sprite_setAnsiAll(CmdFX_Sprite *sprite, char *ansi)
Sets the character at all positions in the sprite.
void Sprite_moveTo(CmdFX_Sprite *sprite, int x, int y)
Moves a sprite to the given position.
CmdFX_Sprite * Canvas_getSpriteAt(int x, int y)
Gets a sprite at the given position with the highest Z-index.
int Sprite_fillCharAll(CmdFX_Sprite *sprite, char c)
Sets the character at all positions in the sprite.
int Sprite_scale(CmdFX_Sprite *sprite, double scale)
Scales the sprite by the given factor.
CmdFX_Sprite ** Canvas_getDrawnSprites()
Gets the sprites that have been drawn to the terminal.
int Sprite_setData(CmdFX_Sprite *sprite, char **data)
Sets the text data for the sprite.
int Sprite_appendAnsiAll(CmdFX_Sprite *sprite, char *ansi)
Appends an ANSI code to all positions in the sprite.
void Sprite_free(CmdFX_Sprite *sprite)
Frees the memory allocated for a sprite.
double Sprite_getRotationAngle(CmdFX_Sprite *sprite)
Gets the rotation angle of the sprite.
void Sprite_moveBy(CmdFX_Sprite *sprite, int dx, int dy)
Moves a sprite by the given amount.
int Sprite_center(CmdFX_Sprite *sprite)
Centers the sprite on the terminal.
int Sprite_setForeground(CmdFX_Sprite *sprite, int x, int y, int rgb)
Sets the foreground color of the sprite at the given position.
int Sprite_transpose(CmdFX_Sprite *sprite)
Transposes the sprite.
int Sprite_fillCharEmpty(CmdFX_Sprite *sprite, int x, int y, int width, int height, char c)
Fills positions in the sprite where there isn't a character.
int Sprite_resizeAndCenter(CmdFX_Sprite *sprite, int width, int height)
Resizes and centers the sprite on the terminal.
int Sprite_setChar(CmdFX_Sprite *sprite, int x, int y, char c)
Sets the character at the given position in the sprite.
CmdFX_Sprite * Sprite_create(char **text, char ***ansi, int z)
Creates a new sprite.
int Sprite_draw(int x, int y, CmdFX_Sprite *sprite)
Draws a sprite to the terminal.
int Sprite_appendAnsi(CmdFX_Sprite *sprite, int x, int y, char *ansi)
Appends an ANSI code to the given position in the sprite.
int Sprite_fillChar(CmdFX_Sprite *sprite, int x, int y, int width, int height, char c)
Fills positions in the sprite.
struct CmdFX_Sprite CmdFX_Sprite
Represents a sprite that can be drawn to the terminal.
int Sprite_resize(CmdFX_Sprite *sprite, int width, int height)
Resizes the sprite to the given dimensions.
int Canvas_getDrawnSpritesCount()
Gets the number of sprites that have been drawn to the terminal.
int Sprite_setForegroundAll256(CmdFX_Sprite *sprite, int color)
Sets the foreground color of the sprite at the given position using 256-bit color codes.
int Sprite_hFlip(CmdFX_Sprite *sprite)
Flips the sprite horizontally.
int Sprite_isOnTop(CmdFX_Sprite *sprite, int x, int y)
Gets whether the sprite is the top-most sprite at the given position.
int Sprite_setForegroundAll(CmdFX_Sprite *sprite, int rgb)
Sets the foreground color of the sprite at the given position.
int Sprite_resizeWithPadding(CmdFX_Sprite *sprite, int width, int height, char padding)
Resizes the sprite to the given dimensions.
Represents a sprite that can be drawn to the terminal.
Definition sprites.h:30
int x
The X position of the sprite.
Definition sprites.h:34
int y
The Y position of the sprite.
Definition sprites.h:38