#ifndef _MYSTNB_ENGINE_H #define _MYSTNB_ENGINE_H #include #include #include "animation.h" /* Maximum number of players */ #define PLAYER_COUNT 1 /* 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 playing 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 game: A running game with a map and some players */ struct game { /* Current map */ struct map *map; /* Players */ struct player *players[PLAYER_COUNT + 1]; /* Current game time (ms) */ int time; }; /* 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); #endif /* _MYSTNB_ENGINE_H */