#include "conf.h" #include "editor.h" #include "input.h" #include "level.h" #include "missile.h" #include "player.h" #include "time.h" #include "util.h" #include #include #include #include static struct Player player; static int timer; volatile int has_ticked; int time = 0; static void init(void); static void deinit(void); static void draw(void); static void update(void); static int timer_callback(volatile int *); int main(void) { int frameskip = 1; init(); level_load(0); for (;;) { int i; draw(); for (i = 0; i < frameskip; i++) { if (has_ticked > frameskip) frameskip = has_ticked; while (!has_ticked) sleep(); while (has_ticked) { time += has_ticked; has_ticked = 0; } update(); if (input_pressed(K_EXIT) && ask_confirm("exit game")) goto game_loop_end; if (input_pressed(K_SKIP) && ask_confirm("skip level")) level_next(); } }; game_loop_end: deinit(); return 0; } static void init(void) { extern font_t font_dina; dfont(&font_dina); timer = timer_configure(TIMER_ANY, 1000000 / TARGET_FPS, GINT_CALL(timer_callback, &has_ticked)); timer_start(timer); input_init(); level_init(&player); } static void deinit(void) { level_deinit(); missile_manager_free(); timer_stop(timer); } static void update(void) { input_update(); missile_manager_update(vecf(player_middle(&player))); player_update(&player); /* enter editor */ if (input_pressed(K_EDITOR)) editor(); /* save replay */ if (input_pressed(K_SAVE_REPLAY)) { gint_world_switch(GINT_CALL(input_dump_replay)); has_ticked = 0; } /* playback */ if (input_pressed(K_PLAYBACK)) gint_world_switch(GINT_CALL(input_load_replay)); } static void draw(void) { dclear(C_BLACK); level_draw(); missile_manager_draw(); player_draw(&player); level_draw_name(); time_draw(); dupdate(); } static int timer_callback(volatile int *arg) { *arg += 1; return 0; }