131 lines
3.7 KiB
C
131 lines
3.7 KiB
C
//---
|
|
// game: Static and dynamic information relating to an unfolding game
|
|
//---
|
|
|
|
#pragma once
|
|
|
|
#include "anim.h"
|
|
#include "level.h"
|
|
#include "map.h"
|
|
#include "pathfinding.h"
|
|
#include "player.h"
|
|
#include "render.h"
|
|
|
|
#include "comp/entity.h"
|
|
|
|
typedef struct game {
|
|
/* The map's coordinate system is the primary coordinate system in all of
|
|
this game's code */
|
|
map_t const *map;
|
|
/* Number of entities currently on each cell of the map */
|
|
uint8_t *occupation;
|
|
/* Position of each map cell in its animation cycle, in ms. Cells have
|
|
random offsets so animations are not all synchronized. We ignore the
|
|
wrapping effect entirely. */
|
|
uint16_t *map_anim;
|
|
/* User's camera */
|
|
camera_t camera;
|
|
|
|
/* Time played */
|
|
fixed_t time_total;
|
|
/* Time when victory was reached or defeat was dealt */
|
|
fixed_t time_victory;
|
|
fixed_t time_defeat;
|
|
/* Screenshake duration left (effect disabled when 0), and amplitude */
|
|
fixed_t screenshake_duration;
|
|
int screenshake_amplitude;
|
|
/* List of entities */
|
|
entity_t **entities;
|
|
int entity_count;
|
|
/* Player; this must be one of the entities loaded in the game */
|
|
entity_t *player;
|
|
/* Field of movement to reach the player (used by most enemy AIs) */
|
|
pfg_all2one_t paths_to_player;
|
|
|
|
/* Level being played */
|
|
level_t const *level;
|
|
/* Current wave, number of enemies spawned in wave, time spent in wave */
|
|
int wave;
|
|
int wave_spawned;
|
|
fixed_t time_wave;
|
|
/* Enemies left to spawn; has level->waves[wave]->entry_count elements */
|
|
uint8_t *wave_left;
|
|
|
|
/* XP bar animation */
|
|
anim_state_t hud_xp_anim;
|
|
|
|
} game_t;
|
|
|
|
/* Allocate resources to load a level. */
|
|
bool game_load(game_t *g, level_t const *level);
|
|
|
|
/* Free resources allocated for the level. */
|
|
void game_unload(game_t *g);
|
|
|
|
/* Current wave */
|
|
level_wave_t const *game_current_wave(game_t const *g);
|
|
|
|
/* Whether the current wave is finished */
|
|
bool game_current_wave_finished(game_t const *g);
|
|
|
|
/* Move to next wave */
|
|
void game_next_wave(game_t *g);
|
|
|
|
/* Shake the screen for the specified amount of time */
|
|
void game_shake(game_t *g, int amplitude, fixed_t duration);
|
|
|
|
//---
|
|
// Managing dynamic game elements
|
|
//---
|
|
|
|
/* Compute the number of entities on each cell. */
|
|
void game_compute_occupation(game_t *g);
|
|
|
|
/* Add an entity to the game (takes ownership; e will be freed). */
|
|
void game_add_entity(game_t *g, entity_t *e);
|
|
|
|
/* Like game_add_entity(), but with a visual effect */
|
|
void game_spawn_entity(game_t *g, entity_t *e);
|
|
|
|
/* Remove dead entities. */
|
|
void game_remove_dead_entities(game_t *g);
|
|
|
|
//---
|
|
// Generic entity functions
|
|
//---
|
|
|
|
/* Count entities satisfying the provided predicate. */
|
|
int game_count_entities(game_t const *g, entity_predicate_t *predicate);
|
|
|
|
/* Filter and sort entities. The entities are sorted by increasing measure,
|
|
with negative measures filtering entities out. Returns an array of entity
|
|
indices (within [g->entities]) to be freed with free() in [*result], while
|
|
returning the number of matching entities. If 0, *result is NULL. */
|
|
int game_sort_entities(game_t const *g, entity_measure_t *measure,
|
|
uint16_t **result);
|
|
|
|
//---
|
|
// Per-frame update functions
|
|
//---
|
|
|
|
/* Spawn enemies from the current wave. */
|
|
void game_spawn_enemies(game_t *g);
|
|
|
|
/* Update all entities' and effect areas' animations. */
|
|
void game_update_animations(game_t *g, fixed_t dt);
|
|
|
|
/* Update all entities' status ailments and temporary buffs/debuffs */
|
|
void game_update_effects(game_t *g, fixed_t dt);
|
|
|
|
/* Update all effect areas and apply their effects. */
|
|
void game_update_aoes(game_t *g, fixed_t dt);
|
|
|
|
/* Update all particles and remove the oldest ones. */
|
|
void game_update_particles(game_t *g, fixed_t dt);
|
|
|
|
/* Sort particles by increasing y position */
|
|
void game_sort_particles(game_t *g);
|
|
|
|
/* Decrease cooldowns for all fighters' skills */
|
|
void game_run_cooldowns(game_t *g, fixed_t dt);
|