cmdfx 0.2.0
Lightweight game engine for your terminal
Loading...
Searching...
No Matches
sprites.h
Go to the documentation of this file.
1
11
12#pragma once
13
14#include "cmdfx/core/builder.h"
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
20// Core Functions
21
30typedef struct CmdFX_Sprite {
34 int x;
38 int y;
42 int width;
46 int height;
56 char** data;
57
67 char*** ansi;
76 int z;
85 int id;
92 int uid;
94
104
110
123
140CmdFX_Sprite* Sprite_create(char** text, char*** ansi, int z);
141
149
165int Sprite_draw(int x, int y, CmdFX_Sprite* sprite);
166
172
173// Utility Methods - Sprite Builder
174
191int Sprite_setData(CmdFX_Sprite* sprite, char** data);
192
208int Sprite_setChar(CmdFX_Sprite* sprite, int x, int y, char c);
209
227int Sprite_fillChar(CmdFX_Sprite* sprite, int x, int y, int width, int height, char c);
228
249int Sprite_fillCharEmpty(CmdFX_Sprite* sprite, int x, int y, int width, int height, char c);
250
264int Sprite_fillCharAll(CmdFX_Sprite* sprite, char c);
265
283
298int Sprite_setAnsi(CmdFX_Sprite* sprite, int x, int y, char* ansi);
299
314int Sprite_appendAnsi(CmdFX_Sprite* sprite, int x, int y, char* ansi);
315
333int Sprite_fillAnsi(CmdFX_Sprite* sprite, int x, int y, char* ansi, int width, int height);
334
348int Sprite_setAnsiAll(CmdFX_Sprite* sprite, char* ansi);
349
364int Sprite_appendAnsiAll(CmdFX_Sprite* sprite, char* ansi);
365
366// Utility Methods - Sprite Creation
367
385CmdFX_Sprite* Sprite_createFilled(int width, int height, char c, char* ansi, int z);
386
403CmdFX_Sprite* Sprite_loadFromFile(const char* path, int z);
404
405// Utility Methods - Sizing
406
419int Sprite_resize(CmdFX_Sprite* sprite, int width, int height);
420
436int Sprite_resizeWithPadding(CmdFX_Sprite* sprite, int width, int height, char padding);
437
450
465int Sprite_resizeAndCenter(CmdFX_Sprite* sprite, int width, int height);
466
467// Utility Methods - Movement
468
475void Sprite_moveTo(CmdFX_Sprite* sprite, int x, int y);
476
483void Sprite_moveBy(CmdFX_Sprite* sprite, int dx, int dy);
484
485// Utility Methods - Collisions
486
499
507
521int Sprite_isOnTop(CmdFX_Sprite* sprite, int x, int y);
522
536int Sprite_isOnBottom(CmdFX_Sprite* sprite, int x, int y);
537
538// Utility Methods - Color
539
555int Sprite_setForeground(CmdFX_Sprite* sprite, int x, int y, int rgb);
556
571
586
602int Sprite_setBackground(CmdFX_Sprite* sprite, int x, int y, int rgb);
603
618
633
634// Utility Methods - Color Gradient
635
655int Sprite_setForegroundGradient(CmdFX_Sprite* sprite, int x, int y, int width, int height, enum CmdFX_GradientDirection direction, int numColors, ...);
656
671int Sprite_setForegroundGradientAll(CmdFX_Sprite* sprite, enum CmdFX_GradientDirection direction, int numColors, ...);
672
692int Sprite_setBackgroundGradient(CmdFX_Sprite* sprite, int x, int y, int width, int height, enum CmdFX_GradientDirection direction, int numColors, ...);
693
708int Sprite_setBackgroundGradientAll(CmdFX_Sprite* sprite, enum CmdFX_GradientDirection direction, int numColors, ...);
709
710// Utility Methods - Transformations
711
724int Sprite_rotate(CmdFX_Sprite* sprite, double radians);
725
739
752
765
778int Sprite_scale(CmdFX_Sprite* sprite, double scale);
779
792
793#ifdef __cplusplus
794}
795#endif
Builder API for building 2D Character Arrays.
CmdFX_GradientDirection
Represents a color gradient that can be applied .
Definition builder.h:464
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_setForegroundGradient(CmdFX_Sprite *sprite, int x, int y, int width, int height, enum CmdFX_GradientDirection direction, int numColors,...)
Sets a foreground gradient using RGB colors for a specified section of the sprite.
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_setBackgroundGradient(CmdFX_Sprite *sprite, int x, int y, int width, int height, enum CmdFX_GradientDirection direction, int numColors,...)
Sets a background gradient using RGB colors for a specified section of 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_setForegroundGradientAll(CmdFX_Sprite *sprite, enum CmdFX_GradientDirection direction, int numColors,...)
Sets a foreground gradient using RGB colors.
CmdFX_Sprite * Sprite_loadFromFile(const char *path, int z)
Creates a new sprite from a file.
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.
int Sprite_resize(CmdFX_Sprite *sprite, int width, int height)
Resizes the sprite to the given dimensions.
CmdFX_Sprite * Sprite_createFilled(int width, int height, char c, char *ansi, int z)
Creates a new sprite with the given dimensions.
int Sprite_setBackgroundAll(CmdFX_Sprite *sprite, int rgb)
Sets the background color of the sprite at the given position.
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_setBackgroundGradientAll(CmdFX_Sprite *sprite, enum CmdFX_GradientDirection direction, int numColors,...)
Sets a background gradient using RGB colors.
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_setBackgroundAll256(CmdFX_Sprite *sprite, int color)
Sets the background color of the sprite at the given position using 256-bit color codes.
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 z
The Z-index of the sprite.
Definition sprites.h:76
int width
The width of the sprite.
Definition sprites.h:42
char ** data
The text data for the sprite.
Definition sprites.h:56
int height
The height of the sprite.
Definition sprites.h:46
int id
The drawing ID of the sprite.
Definition sprites.h:85
int x
The X position of the sprite.
Definition sprites.h:34
int y
The Y position of the sprite.
Definition sprites.h:38
char *** ansi
The ANSI data for the sprite.
Definition sprites.h:67
int uid
The unique ID of the sprite.
Definition sprites.h:92