//--- // game: Static and dynamic information relating to an unfolding game //--- #pragma once #include "map.h" #include "entities.h" #include "render.h" #include "level.h" #include "pathfinding.h" #include "particles.h" typedef struct game { /* The map's coordinate system is the primary coordinate system in all of this game's code */ map_t 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; /* List of effect areas */ effect_area_t **effect_areas; int effect_area_count; /* List of particles */ particle_t **particles; int particle_count; /* Field of movement to reach the player (used by most enemy AIs) */ pfg_all2one_t paths_to_player; } game_t; /* Allocate resources to load a level. */ bool game_load(game_t *g, level_t *level); /* Free resources allocated for the level. */ void game_unload(game_t *g); //--- // Adding 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); /* Add an effect area to the game (takes ownership; ea will be freed). */ void game_add_effect_area(game_t *g, effect_area_t *ea); /* Add a particle to the game (takes ownership; p will be freed) */ void game_add_particle(game_t *g, particle_t *p); //--- // Interacting with game elements //--- /* Try to move an entity at the specified next-frame movement data. The data is applied if valid (no collisions). Otherwise the entity does not move and only some data is updated. The data is obtained by entity_move() or related functions. */ void game_try_move_entity(game_t *g, entity_t *e, entity_movement_t const *next_movement); //--- // Per-frame update functions //--- /* 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_effect_areas(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 entities by increasing y position (which is rendering order). */ void game_sort_entities(game_t *g); /* Remove dead entities. */ void game_remove_dead_entities(game_t *g);