#ifndef _MYSTNB_ENGINE_H #define _MYSTNB_ENGINE_H #include #include #include #include "animation.h" /* Maximum number of players */ #define PLAYER_COUNT 1 /* Maximum number of dynamic tiles on the map */ #define MAP_DYNAMIC_TILES 32 /* Time per engine tick (ms) */ #define ENGINE_TICK 25 /* Directions */ #define DIR_DOWN 0 #define DIR_RIGHT 1 #define DIR_UP 2 #define DIR_LEFT 3 /* struct player: A player on the map, triggering actions as they move */ struct player { /* Position in map */ int x, y; /* Direction currently facing */ int dir; /* Whether player is currently idle (ie. can move) */ int idle; /* Current animation function and data */ struct anim_data anim; }; /* struct map: A map with moving doors, collectibles, and fog */ struct map { /* Width and height */ int w, h; /* Whether fog is enabled */ int fog; /* Door cycle string */ char door_cycle[128]; /* Mapping of door types to cycle string index */ uint8_t door_cycle_index[16]; /* Background image */ bopti_image_t *img; /* Array of tiles in row-major order */ uint8_t *tiles; }; /* enum map_tile: Single cell in the map */ enum map_tile { TILE_AIR = 0, TILE_WALL = 1, TILE_START = 2, TILE_END = 3, /* 8 keys in interval 16..23 */ TILE_KEY = 16, /* 8 vertical doors in interval 24..31 */ TILE_VDOOR = 24, /* 8 horizontal doors in interval 32..39 */ TILE_HDOOR = 32, }; /* struct dynamic_tile: Dynamic tile information */ struct dynamic_tile { /* Position */ int x, y; /* Current state */ int state; int state2; /* Whether animation is idle */ int idle; /* Current animation */ struct anim_data anim; }; /* struct game: A running game with a map and some players */ struct game { /* Current map */ struct map const *map; /* Players */ struct player *players[PLAYER_COUNT + 1]; /* Current game time (ms) */ int time; /* Dynamic tiles */ struct dynamic_tile dynamic_tiles[MAP_DYNAMIC_TILES]; /* Number of dynamic tiles */ int dynamic_tile_count; }; /* Load map with no players */ void engine_load(struct game *game, struct map const *map); /* Spawn all the players on the map */ void engine_spawn(struct game *game); /* Check whether all players are idle */ bool engine_all_players_idle(struct game *game); /* Check whether all dynamic tiles are idle */ bool engine_all_dynamic_tiles_idle(struct game *game); /* Check whether a player stands on the exit */ bool engine_wins(struct game *game, struct player *player); /* Update animations */ void engine_tick(struct game *game, int dt); /* Draw the current game frame from scratch; does not dupdate() */ void engine_draw(struct game const *game); /* Try to move a player along a direction. Returns 1 if the move is successful, 0 otherwise (collisions or out-of-bounds moves) */ int engine_move(struct game *game, struct player *player, int direction); /* Process automatic actions at the end of a turn */ void engine_finish_turn(struct game *game); #endif /* _MYSTNB_ENGINE_H */