RogueLife/src/game.h

107 lines
2.9 KiB
C

//---
// game: Static and dynamic information relating to an unfolding game
//---
#pragma once
#include "map.h"
#include "render.h"
#include "level.h"
#include "pathfinding.h"
#include "player.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;
/* 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;
/* List of entities */
entity_t **entities;
int entity_count;
/* Player; this must be one of the entities loaded in the game */
entity_t *player;
/* Associated player data */
player_t *player_data;
/* 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;
} 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);
//---
// Managing dynamic game elements
//---
/* 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 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);