mystnb/src/engine.h

66 lines
1.4 KiB
C

#ifndef _MYSTNB_ENGINE_H
#define _MYSTNB_ENGINE_H
#include <stdint.h>
#include <gint/display.h>
#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;
/* Raw data */
uint8_t *data;
};
/* 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 */