RogueLife/src/anim.h

61 lines
1.6 KiB
C

//---
// anim: Renderer's animations
//
// Animations in this engine are simply linked variants of sprites. Animated
// images change over time, moving from frame to frame, and that's it.
//---
#pragma once
#include <stdint.h>
#include "fixed.h"
#include <gint/display.h>
typedef struct anim_frame {
/* Sheet */
bopti_image_t const *sheet;
/* Box for the frame within the sheet */
uint8_t x, y, w, h;
/* Position of center for this frame */
int8_t cx, cy;
/* Duration of the frame (ms) */
uint16_t duration;
/* Next frame */
struct anim_frame *next;
} anim_frame_t;
typedef struct {
/* Current frame */
anim_frame_t const *frame;
/* Time elapsed */
uint16_t elapsed;
} anim_state_t;
/* Duration of an animation, in seconds (assuming linear order until end). */
fixed_t anim_duration(anim_frame_t const *first_frame);
#define anim_duration(ff) _Generic((ff), \
anim_frame_t *: anim_duration((void *)ff), \
anim_frame_t **: anim_duration(*(void **)ff))
/* Render a frame at the center position (x,y). */
void anim_frame_render(int x, int y, anim_frame_t const *frame);
/* Update an animation to next frame. */
void anim_state_update(anim_state_t *state, fixed_t dt);
/* List of animations. */
/* Basic animations. */
extern anim_frame_t anim_slime_idle_down[];
extern anim_frame_t anim_slime_death[];
extern anim_frame_t anim_bat_idle_down[];
extern anim_frame_t anim_bat_death[];
extern anim_frame_t anim_hit[];
/* Directional animations. */
extern anim_frame_t *anim_player_idle[4];
extern anim_frame_t *anim_player_attack[4];
extern anim_frame_t *anim_swing[4];