cmdfx 0.1.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#ifdef __cplusplus
15extern "C" {
16#endif
17
18// Core Functions
19
28typedef struct CmdFX_Sprite {
32 int x;
36 int y;
40 int width;
44 int height;
54 char** data;
55
65 char*** ansi;
74 int z;
82 int id;
84
94
107
124CmdFX_Sprite* Sprite_create(char** text, char*** ansi, int z);
125
133
149int Sprite_draw(int x, int y, CmdFX_Sprite* sprite);
150
156
157// Utility Methods - Sprite Builder
158
175int Sprite_setData(CmdFX_Sprite* sprite, char** data);
176
192int Sprite_setChar(CmdFX_Sprite* sprite, int x, int y, char c);
193
211int Sprite_fillChar(CmdFX_Sprite* sprite, int x, int y, char c, int width, int height);
212
233int Sprite_fillCharEmpty(CmdFX_Sprite* sprite, int x, int y, char c, int width, int height);
234
248int Sprite_fillCharAll(CmdFX_Sprite* sprite, char c);
249
267
282int Sprite_setAnsi(CmdFX_Sprite* sprite, int x, int y, char* ansi);
283
298int Sprite_appendAnsi(CmdFX_Sprite* sprite, int x, int y, char* ansi);
299
317int Sprite_fillAnsi(CmdFX_Sprite* sprite, int x, int y, char* ansi, int width, int height);
318
332int Sprite_setAnsiAll(CmdFX_Sprite* sprite, char* ansi);
333
348int Sprite_appendAnsiAll(CmdFX_Sprite* sprite, char* ansi);
349
350// Utility Methods - Sprite Creation
351
369CmdFX_Sprite* Sprite_createFilled(int width, int height, char c, char* ansi, int z);
370
387CmdFX_Sprite* Sprite_loadFromFile(const char* path, int z);
388
389// Utility Methods - Sizing
390
403int Sprite_resize(CmdFX_Sprite* sprite, int width, int height);
404
420int Sprite_resizeWithPadding(CmdFX_Sprite* sprite, int width, int height, char padding);
421
434
449int Sprite_resizeAndCenter(CmdFX_Sprite* sprite, int width, int height);
450
451// Utility Methods - Movement
452
459void Sprite_moveTo(CmdFX_Sprite* sprite, int x, int y);
460
467void Sprite_moveBy(CmdFX_Sprite* sprite, int dx, int dy);
468
469// Utility Methods - Collisions
470
483
491
500int Sprite_isOnTop(CmdFX_Sprite* sprite, int x, int y);
501
510int Sprite_isOnBottom(CmdFX_Sprite* sprite, int x, int y);
511
512// Utility Methods - Color
513
529int Sprite_setForeground(CmdFX_Sprite* sprite, int x, int y, int rgb);
530
547
564
580int Sprite_setBackground(CmdFX_Sprite* sprite, int x, int y, int rgb);
581
598
615
616// Utility Methods - Color Gradient
617
659
679int Sprite_setForegroundGradient(CmdFX_Sprite* sprite, int x, int y, int width, int height, enum CmdFX_GradientDirection direction, int numColors, ...);
680
695int Sprite_setForegroundGradientAll(CmdFX_Sprite* sprite, enum CmdFX_GradientDirection direction, int numColors, ...);
696
716int Sprite_setBackgroundGradient(CmdFX_Sprite* sprite, int x, int y, int width, int height, enum CmdFX_GradientDirection direction, int numColors, ...);
717
732int Sprite_setBackgroundGradientAll(CmdFX_Sprite* sprite, enum CmdFX_GradientDirection direction, int numColors, ...);
733
734#ifdef __cplusplus
735}
736#endif
CmdFX_Sprite ** Sprite_getCollidingSprites(CmdFX_Sprite *sprite)
Gets the sprites that are colliding with the given sprite.
CmdFX_GradientDirection
Represents a color gradient that can be applied to a sprite.
Definition sprites.h:625
@ GRADIENT_VERTICAL_REVERSE
A vertical gradient in reverse.
Definition sprites.h:641
@ GRADIENT_ANGLE_45
A 45-degree gradient.
Definition sprites.h:645
@ GRADIENT_HORIZONTAL
A horizontal gradient.
Definition sprites.h:629
@ GRADIENT_ANGLE_135
A 135-degree gradient.
Definition sprites.h:649
@ GRADIENT_RADIAL
A radial gradient.
Definition sprites.h:653
@ GRADIENT_CONICAL
A conical gradient.
Definition sprites.h:657
@ GRADIENT_VERTICAL
A vertical gradient.
Definition sprites.h:637
@ GRADIENT_HORIZONTAL_REVERSE
A horizontal gradient in reverse.
Definition sprites.h:633
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_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.
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_fillCharEmpty(CmdFX_Sprite *sprite, int x, int y, char c, int width, int height)
Fills positions in the sprite where there isn't a character.
int Sprite_fillChar(CmdFX_Sprite *sprite, int x, int y, char c, int width, int height)
Fills positions in 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.
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_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_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 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_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:28
int z
The Z-index of the sprite.
Definition sprites.h:74
int width
The width of the sprite.
Definition sprites.h:40
char ** data
The text data for the sprite.
Definition sprites.h:54
int height
The height of the sprite.
Definition sprites.h:44
int id
The unique ID of the sprite.
Definition sprites.h:82
int x
The X position of the sprite.
Definition sprites.h:32
int y
The Y position of the sprite.
Definition sprites.h:36
char *** ansi
The ANSI data for the sprite.
Definition sprites.h:65