archeus/include/arc/graphics/sprite.h

171 lines
4.7 KiB
C
Raw Normal View History

#ifndef ARC_GRAPHICS_SPRITE_H_
#define ARC_GRAPHICS_SPRITE_H_
#ifdef __cplusplus
extern "C" {
#endif
#include "arc/graphics/renderer.h"
#include "arc/graphics/spritesheet.h"
2023-01-03 00:21:29 -07:00
#include "arc/math/point.h"
#include "arc/math/rectangle.h"
2023-01-02 18:05:44 -07:00
#include "arc/std/array.h"
2025-03-23 00:45:39 -06:00
/**
* @brief
*/
typedef enum ARC_SpriteAxis {
ARC_SPRITE_AXIS_NONE = 0x00,
ARC_SPRITE_AXIS_Y = 0x01,
ARC_SPRITE_AXIS_X = 0x02,
} ARC_SpriteAxix;
/**
* @brief a sprite type
2025-03-23 00:45:39 -06:00
*/
typedef struct ARC_Sprite {
ARC_Spritesheet *spritesheet;
ARC_Array frames;
uint32_t frameIndex;
double angle;
ARC_FPoint origin;
float opacity;
ARC_SpriteAxix axis;
2025-03-26 18:26:02 -06:00
float animationCurrentTime;
float animationTime;
2025-03-23 00:45:39 -06:00
} ARC_Sprite;
/**
* @brief creates ARC_Sprite type
*
* @param sprite ARC_Sprite that is being created
* @param spritesheet ARC_Spritesheet that ARC_Sprite will be pulled from
2025-03-23 00:45:39 -06:00
* @param frames ARC_Array of ARC_FRect bounds of sprite on spritesheet
*/
void ARC_Sprite_Create(ARC_Sprite **sprite, ARC_Spritesheet *spritesheet, ARC_Array frames);
/**
* @brief destroys ARC_Sprite type
*
* @param sprite ARC_Sprite to destroy
2025-03-23 00:45:39 -06:00
*/
void ARC_Sprite_Destroy(ARC_Sprite *sprite);
/**
* @brief copies ARC_Sprite to a new ARC_Sprite
*
* @param newSprite ARC_Sprite that is being copied to and created
* @param oldSprite ARC_Sprite contents that are being copied
2023-09-20 02:24:15 -06:00
*/
2025-03-23 00:45:39 -06:00
void ARC_Sprite_Copy(ARC_Sprite **newSprite, ARC_Sprite *oldSprite);
2023-09-20 02:24:15 -06:00
/**
* @brief renders ARC_Sprite type
*
* @param sprite ARC_Sprite that will be rendered
* @param renderer ARC_Renderer that is handling rendering
* @param renderBounds area of renderer that ARC_Sprite will be rendered to
2025-03-23 00:45:39 -06:00
*/
void ARC_Sprite_Render(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_FRect renderBounds);
2023-08-19 20:28:01 +00:00
/**
2025-03-23 00:45:39 -06:00
* @brief renders ARC_Sprite type at a point and at a set scale
2023-08-19 20:28:01 +00:00
*
2025-03-23 00:45:39 -06:00
* @param sprite ARC_Sprite that will be rendered
* @param renderer ARC_Renderer that is handling rendering
* @param point point on the renderer that ARC_Sprite will be rendered to (will be scaled as well)
* @param scale the scale to render at
*/
void ARC_Sprite_RenderAt(ARC_Sprite *sprite, ARC_Renderer *renderer, ARC_FPoint point, double scale);
2023-08-19 20:28:01 +00:00
2023-01-03 00:21:29 -07:00
/**
2025-03-23 00:45:39 -06:00
* @brief switches ARC_Sprite's frames to next for animation
2023-01-03 00:21:29 -07:00
*
2025-03-23 00:45:39 -06:00
* @param sprite ARC_Sprite that is having its frame updated
*/
void ARC_Sprite_IterateFrame(ARC_Sprite *sprite);
2023-01-03 00:21:29 -07:00
2025-03-26 18:26:02 -06:00
/**
* @brief switches ARC_Sprite's frames to next for animation
*
* @param sprite ARC_Sprite that is being animated (having its frame updated based on delta time)
* @param deltatime the ammount of time elapsed in seconds (stored as a float where 1.0 is a second) since last animated
*/
void ARC_Sprite_AnimateFrame(ARC_Sprite *sprite, float deltatime);
2023-08-18 23:06:41 -06:00
/**
* @brief switches ARC_Sprite's frame to specified index
*
* @param sprite ARC_Sprite that is having its frame set
* @param index uint32_t to set ARC_Sprite's frame index to
2025-03-23 00:45:39 -06:00
*/
2023-08-18 23:06:41 -06:00
void ARC_Sprite_SetFrameIndex(ARC_Sprite *sprite, uint32_t index);
/**
2025-03-23 00:45:39 -06:00
* @brief sets the origin point of the sprite (the rotation and position point)
*
2025-03-23 00:45:39 -06:00
* @param sprite ARC_Sprite that is having its angle set
* @param angle the given agnel in degrees to rotate around (rotated clockwise)
2025-03-23 00:45:39 -06:00
*/
void ARC_Sprite_SetAngle(ARC_Sprite *sprite, double angle);
/**
* @brief sets the origin point of the sprite (the rotation and position point)
*
* @param sprite ARC_Sprite that is having its origin set
* @param origin the point on the arc sprite (based on its bounds/frame) to rotate around
*/
void ARC_Sprite_SetOrigin(ARC_Sprite *sprite, ARC_FPoint origin);
/**
* @brief sets ARC_Sprite's opacity
*
* @note opacity is a float value between 0.0 and 1.0 (1.0 is fully opaque)
*
* @param sprite ARC_Sprite that is changing opacity
* @param opacity new opacity for ARC_Sprite
*/
void ARC_Sprite_SetOpacity(ARC_Sprite *sprite, float opacity);
2022-12-13 15:50:24 -07:00
2025-03-26 18:26:02 -06:00
/**
* @brief sets ARC_Sprite's framerate for
*
* @param sprite ARC_Sprite to change its frame rate
* @param rate the new framerate as a float in seconds (1.0 is one second)
*/
void ARC_Sprite_SetFrameRate(ARC_Sprite *sprite, float rate);
2023-11-20 21:34:46 -07:00
/**
* @brief gets ARC_Sprite's current frame
*
* @param sprite ARC_Sprite to get frame from
*
* @return index ARC_Sprite's current frame index
2025-03-23 00:45:39 -06:00
*/
2023-11-20 21:34:46 -07:00
uint32_t ARC_Sprite_GetFrameIndex(ARC_Sprite *sprite);
/**
* @brief returns the current bounds based on the ARC_Sprite's frames
*
* @param sprite ARC_Sprite to get bounds from
2025-03-23 00:45:39 -06:00
*/
ARC_FRect *ARC_Sprite_GetBounds(ARC_Sprite *sprite);
/**
* @brief returns the array of bounds that a sprite has
*
* @param sprite ARC_Sprite to get all the bounds from
*/
2025-03-23 00:45:39 -06:00
ARC_Array ARC_Sprite_GetAllBounds(ARC_Sprite *sprite);
#ifdef __cplusplus
}
#endif
#endif // !ARC_GRAPHICS_SPRITE_H_