2021-06-09 20:47:39 +02:00
|
|
|
//---
|
|
|
|
// 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 */
|
2021-06-10 22:48:27 +02:00
|
|
|
int8_t cx, cy;
|
2021-06-09 20:47:39 +02:00
|
|
|
/* 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;
|
|
|
|
|
2021-06-10 22:48:27 +02:00
|
|
|
/* 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))
|
|
|
|
|
2021-06-09 20:47:39 +02:00
|
|
|
/* Render a frame at the center position (x,y). */
|
|
|
|
void anim_frame_render(int x, int y, anim_frame_t const *frame);
|
|
|
|
|
2021-06-10 22:48:27 +02:00
|
|
|
/* Update an animation to next frame. */
|
2021-06-09 20:47:39 +02:00
|
|
|
void anim_state_update(anim_state_t *state, fixed_t dt);
|
2021-06-10 22:48:27 +02:00
|
|
|
|
|
|
|
/* List of animations. */
|
|
|
|
|
|
|
|
/* Basic animations. */
|
2021-10-17 16:22:09 +02:00
|
|
|
extern anim_frame_t anims_skill_hit[];
|
|
|
|
extern anim_frame_t anims_skill_teleport[];
|
2021-08-30 11:39:14 +02:00
|
|
|
extern anim_frame_t anims_skill_shock[];
|
2021-10-17 16:22:09 +02:00
|
|
|
extern anim_frame_t anims_skill_judgement[];
|
2021-06-10 22:48:27 +02:00
|
|
|
|
2021-07-16 11:06:28 +02:00
|
|
|
/* Enemy animations (bidirectional). */
|
2021-08-15 11:05:04 +02:00
|
|
|
|
2021-10-23 16:46:33 +02:00
|
|
|
extern anim_frame_t anims_slime_left_Idle[];
|
|
|
|
extern anim_frame_t anims_slime_right_Idle[];
|
|
|
|
extern anim_frame_t anims_slime_left_Walking[];
|
|
|
|
extern anim_frame_t anims_slime_right_Walking[];
|
|
|
|
extern anim_frame_t anims_slime_left_Hit[];
|
|
|
|
extern anim_frame_t anims_slime_right_Hit[];
|
|
|
|
extern anim_frame_t anims_slime_left_Death[];
|
|
|
|
extern anim_frame_t anims_slime_right_Death[];
|
2021-08-15 11:05:04 +02:00
|
|
|
|
2021-10-23 17:14:59 +02:00
|
|
|
extern anim_frame_t anims_bat_left_Idle[];
|
|
|
|
extern anim_frame_t anims_bat_right_Idle[];
|
|
|
|
extern anim_frame_t anims_bat_left_Hit[];
|
|
|
|
extern anim_frame_t anims_bat_right_Hit[];
|
|
|
|
extern anim_frame_t anims_bat_left_Death[];
|
|
|
|
extern anim_frame_t anims_bat_right_Death[];
|
2021-07-16 11:06:28 +02:00
|
|
|
|
|
|
|
/* Quadri-directional animations. */
|
2021-08-28 13:52:14 +02:00
|
|
|
extern anim_frame_t *anims_player_Idle[4];
|
|
|
|
extern anim_frame_t *anims_player_Walking[4];
|
|
|
|
extern anim_frame_t *anims_player_Attack[4];
|
|
|
|
extern anim_frame_t *anims_player_Hit[4];
|
2021-10-17 16:22:09 +02:00
|
|
|
extern anim_frame_t *anims_skill_swing[4];
|
|
|
|
extern anim_frame_t *anims_skill_impale[4];
|
2021-10-17 18:43:38 +02:00
|
|
|
extern anim_frame_t *anims_skill_bullet[4];
|