townengine/apps/templates/c/game.c

37 lines
887 B
C
Raw Normal View History

#include "twn_game_api.h"
2024-07-29 22:20:30 +00:00
#include "state.h"
#include <stdlib.h>
2024-07-29 22:20:30 +00:00
2024-08-21 14:29:06 +00:00
void game_tick(void) {
2024-08-21 13:55:34 +00:00
/* do state initialization when engine asks for it */
/* it could happen multiple times per application run, as game code is reloadable */
if (ctx.initialization_needed) {
2024-07-29 22:20:30 +00:00
/* application data could be stored in ctx.udata and retrieved anywhere */
2024-08-21 13:55:34 +00:00
if (!ctx.udata)
ctx.udata = calloc(1, sizeof (struct state));
2024-07-29 22:20:30 +00:00
}
/* a lot of data is accessible from `ctx`, look into `townengine/context.h` for more */
struct state *state = ctx.udata;
++state->counter;
m_sprite("nothing!",
(Rect) {
.x = 0,
.y = 0,
.w = 32,
.h = 32,
}
);
2024-07-29 22:20:30 +00:00
}
void game_end(void) {
/* do your deinitialization here */
struct state *state = ctx.udata;
free(state);
}