RogueLife/src/comp/visible.h

56 lines
1.8 KiB
C

//---
// visible: Component for visible entities with a sprite
//
// Visible entities (which must also be physical in order to have a position)
// mostly consist of 2D sprites that either lie flat on the ground or stand
// vertically. They also have a visual elevation (z) which only affects the
// display, and can drop shadows.
//
// Below is a schematic diagram of visible objects' geometry.
//
// |-_
// | `-_ z
// | `. | y
// ^--- :-_ | < Wall |_.-`
// z | : `-_ | sprite `-_
// | : `: x
// v--- :_.-``-:
// _.-``-_ :`-_
// `-_ `x_ :_.-` < Floor sprite
// `-_ _.-``
// `
//
// The "x" marks the entity's anchor, which is the point of the object tied to
// its position (which is used for depth ordering among other things). The
// anchor is aligned with the sprite's anchor, before optionally adding a z
// displacement for elevated visible entities.
//---
#pragma once
#include "comp/entity.h"
#include "geometry.h"
#include "anim.h"
typedef struct
{
/* Display elevation; has no influence on mechanics */
fixed_t z;
/* Current sprite */
anim_state_t anim;
/* Priority of current sprite (used to avoid animation conflicts) */
uint8_t anim_priority;
/* Sprite plane (either VERTICAL or HORIZONTAL) */
uint8_t sprite_plane;
/* Size of shadow cast (0 for no shadow; not all values are valid) */
uint8_t shadow_size;
} visible_t;
/* Set the entity's animation. If the priority is strictly lower than the
current animation's priority, this operation is ignored. */
void visible_set_anim(entity_t *e, anim_t const *anim, int priority);
/* Regular update function */
void visible_update(entity_t *e, fixed_t dt);