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>
|
|
|
|
|
2021-12-25 11:47:22 +01:00
|
|
|
typedef struct anim_frame
|
|
|
|
{
|
2021-06-09 20:47:39 +02:00
|
|
|
/* 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;
|
2021-12-25 11:47:22 +01:00
|
|
|
|
2021-06-09 20:47:39 +02:00
|
|
|
} anim_frame_t;
|
|
|
|
|
2021-12-25 11:47:22 +01:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
/* Number of directions
|
|
|
|
1: Basic sprite
|
|
|
|
2: LEFT and RIGHT (enemies)
|
|
|
|
4: UP, RIGHT, DOWN and LEFT (player, some attacks) */
|
|
|
|
int directions;
|
|
|
|
/* First frame for each direction */
|
|
|
|
anim_frame_t *start[];
|
|
|
|
|
|
|
|
} anim_t;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
2021-06-09 20:47:39 +02:00
|
|
|
/* Current frame */
|
|
|
|
anim_frame_t const *frame;
|
|
|
|
/* Time elapsed */
|
|
|
|
uint16_t elapsed;
|
2021-12-25 11:47:22 +01:00
|
|
|
|
2021-06-09 20:47:39 +02:00
|
|
|
} anim_state_t;
|
|
|
|
|
2021-12-25 11:47:22 +01:00
|
|
|
/* Duration of an animation, in seconds; assumed unique for all directions */
|
|
|
|
fixed_t anim_duration(anim_t const *anim);
|
2021-06-10 22:48:27 +02:00
|
|
|
|
2021-12-25 11:47:22 +01:00
|
|
|
/* Check if a frame is in an animation. */
|
|
|
|
bool anim_in(anim_frame_t const *frame, anim_t const *anim, int index);
|
2021-06-10 22:48:27 +02:00
|
|
|
|
2022-02-07 09:10:47 +01:00
|
|
|
/* Render a frame at the center position (x,y), similar to dimage(). */
|
2021-06-09 20:47:39 +02:00
|
|
|
void anim_frame_render(int x, int y, anim_frame_t const *frame);
|
|
|
|
|
2022-02-07 09:10:47 +01:00
|
|
|
/* Render a subimage of a frame, similar to dsubimage(). */
|
|
|
|
void anim_frame_subrender(int x, int y, anim_frame_t const *frame, int left,
|
|
|
|
int top, int width, int height);
|
|
|
|
|
2022-12-30 15:59:13 +01:00
|
|
|
/* Update an animation to next frame. Returns true if the update transitioned
|
|
|
|
to another animation. */
|
|
|
|
bool anim_state_update(anim_state_t *state, fixed_t dt);
|
2021-06-10 22:48:27 +02:00
|
|
|
|
|
|
|
/* List of animations. */
|
|
|
|
|
2021-12-25 11:47:22 +01:00
|
|
|
/* Basic skills */
|
|
|
|
extern anim_t anims_skill_hit;
|
2022-02-03 17:39:57 +01:00
|
|
|
extern anim_t anims_skill_projectile;
|
2021-12-25 11:47:22 +01:00
|
|
|
extern anim_t anims_skill_teleport;
|
|
|
|
extern anim_t anims_skill_shock;
|
|
|
|
extern anim_t anims_skill_judgement;
|
|
|
|
/* Directional skills */
|
|
|
|
extern anim_t anims_skill_swing;
|
|
|
|
extern anim_t anims_skill_impale;
|
|
|
|
extern anim_t anims_skill_bullet;
|
|
|
|
|
|
|
|
/* Enemies */
|
2022-05-18 22:48:48 +02:00
|
|
|
|
|
|
|
#define ANIM_ENEMIES(MACRO) \
|
|
|
|
ANIM_E1(MACRO, slime, Idle, Walking, Attack, Fire, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, fire_slime, Idle, Walking, Attack, Fire, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, water_slime, Idle, Walking, Attack, Fire, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, chemical_slime, Idle, Walking, Attack, Fire, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, bat, Idle, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, albinos_bat, Idle, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, crimson_bat, Idle, Hit, Death) \
|
2022-12-30 15:59:13 +01:00
|
|
|
ANIM_E1(MACRO, gunslinger, Idle, Walking, Fire, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, gb_gunslinger, Idle, Walking, Fire, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, master_gunslinger, Idle, Walking, Fire,Hit,Death) \
|
2022-05-18 22:48:48 +02:00
|
|
|
ANIM_E1(MACRO, tifucile, Idle, Walking, Hit, Death) \
|
|
|
|
ANIM_E1(MACRO, washing_machine, Idle, Walking, Attack, Hit, Death)
|
2021-12-25 11:47:22 +01:00
|
|
|
|
|
|
|
/* Player */
|
|
|
|
extern anim_t anims_player_Idle;
|
|
|
|
extern anim_t anims_player_Walking;
|
|
|
|
extern anim_t anims_player_Attack;
|
|
|
|
extern anim_t anims_player_Hit;
|
2023-01-02 11:50:25 +01:00
|
|
|
extern anim_t anims_player_KO;
|
|
|
|
extern anim_t anims_player_IdleKO;
|
2022-02-07 09:10:47 +01:00
|
|
|
|
|
|
|
/* HUD */
|
|
|
|
extern anim_t anims_hud_xp_Idle;
|
|
|
|
extern anim_t anims_hud_xp_Shine;
|
|
|
|
extern anim_t anims_hud_xp_Explode;
|
2022-12-23 22:34:49 +01:00
|
|
|
extern anim_t anims_hud_backpack_Idle;
|
|
|
|
extern anim_t anims_hud_backpack_Open;
|
2022-12-28 11:27:05 +01:00
|
|
|
extern anim_t anims_hud_backpack_InventoryIdle;
|
|
|
|
extern anim_t anims_hud_backpack_InventoryOpen;
|
|
|
|
extern anim_t anims_hud_backpack_InventoryClose;
|
2022-02-16 17:42:05 +01:00
|
|
|
|
|
|
|
/* Items */
|
|
|
|
extern anim_t anims_item_life;
|
2022-05-18 22:48:48 +02:00
|
|
|
extern anim_t anims_item_chest;
|
2022-03-10 19:34:32 +01:00
|
|
|
extern anim_t anims_item_potion_atk;
|
|
|
|
extern anim_t anims_item_potion_cooldown;
|
|
|
|
extern anim_t anims_item_potion_def;
|
|
|
|
extern anim_t anims_item_potion_frz;
|
|
|
|
extern anim_t anims_item_potion_hp;
|
|
|
|
extern anim_t anims_item_potion_spd;
|
|
|
|
extern anim_t anims_item_stick1;
|
|
|
|
extern anim_t anims_item_stick2;
|
2022-02-16 17:42:05 +01:00
|
|
|
extern anim_t anims_item_sword1;
|
2022-03-10 19:34:32 +01:00
|
|
|
extern anim_t anims_item_sword2;
|
2022-03-19 18:14:00 +01:00
|
|
|
extern anim_t anims_item_armor1;
|
2023-01-15 17:17:45 +01:00
|
|
|
extern anim_t anims_item_buff;
|
2022-05-18 22:48:48 +02:00
|
|
|
|
|
|
|
/* Expand definitions for enemies */
|
|
|
|
|
|
|
|
#define ANIM_E1(MACRO, ENEMY, SEQ, ...) \
|
|
|
|
MACRO(ENEMY, SEQ) __VA_OPT__(ANIM_E2(MACRO, ENEMY, __VA_ARGS__))
|
|
|
|
#define ANIM_E2(MACRO, ENEMY, SEQ, ...) \
|
|
|
|
MACRO(ENEMY, SEQ) __VA_OPT__(ANIM_E3(MACRO, ENEMY, __VA_ARGS__))
|
|
|
|
#define ANIM_E3(MACRO, ENEMY, SEQ, ...) \
|
|
|
|
MACRO(ENEMY, SEQ) __VA_OPT__(ANIM_E4(MACRO, ENEMY, __VA_ARGS__))
|
|
|
|
#define ANIM_E4(MACRO, ENEMY, SEQ, ...) \
|
|
|
|
MACRO(ENEMY, SEQ) __VA_OPT__(ANIM_E5(MACRO, ENEMY, __VA_ARGS__))
|
|
|
|
#define ANIM_E5(MACRO, ENEMY, SEQ, ...) \
|
|
|
|
MACRO(ENEMY, SEQ) __VA_OPT__(ANIM_E6(MACRO, ENEMY, __VA_ARGS__))
|
|
|
|
#define ANIM_E6(MACRO, ENEMY, SEQ, ...) \
|
|
|
|
MACRO(ENEMY, SEQ) __VA_OPT__(ANIM_ETOO_MANY_ARGS)
|
|
|
|
|
|
|
|
#define ANIM_ENEMIES_PROTO(ENEMY, SEQ) \
|
|
|
|
extern anim_t anims_ ## ENEMY ## _ ## SEQ;
|
|
|
|
ANIM_ENEMIES(ANIM_ENEMIES_PROTO)
|