#include #include #include #include #include #include #include "conf.h" #include "main.h" #include "debug.h" #include "init.h" #include "vec.h" #include "player.h" #include "level.h" #include "camera.h" #include "input.h" int main(void) { init(); /* initialize gint */ /* main game loop */ play_level(0); /* return to menu */ return 1; } int play_level(int level_id) { /* create player */ Player player = { .pos = {16 * VEC_PRECISION, 16 * VEC_PRECISION}, .hbox = {7 * VEC_PRECISION, 7 * VEC_PRECISION}, .origin = {4 * VEC_PRECISION, 4 * VEC_PRECISION} }; /* create level */ Level level = { .width = 0, .height = 0 }; /* create camera */ Camera camera = { .pos = {DWIDTH * VEC_PRECISION, DHEIGHT * VEC_PRECISION}, .target = &player.pos, .speed = 0.01 }; /* create input manager */ Input input; input.keys[K_LEFT] = KEY_LEFT; input.keys[K_RIGHT] = KEY_RIGHT; input.keys[K_UP] = KEY_UP; input.keys[K_DOWN] = KEY_DOWN; input.keys[K_EXIT] = KEY_EXIT; /* UPS control */ volatile int has_ticked = 1; timer_start(timer_setup(TIMER_ANY, 1000000/UPS, callback, &has_ticked)); uint step = 0; while (!input_is_down(&input, K_EXIT)) { /* repeat step event so the UPS is constant regardless of FPS */ for (int i = 0; i < UPS / FPS; ++i) { /* UPS control */ while(!has_ticked) sleep(); has_ticked = 0; /* step event is where all the logic happens */ step += 1; step_event(&player, &level, &camera, &input, step); } /* draw event just draws stuff */ draw_event(&player, &level, &camera, &input, step); } return 1; } int callback(volatile void *arg) { volatile int *has_ticked = arg; *has_ticked = 1; return 0; } void step_event(Player *player, Level *level, Camera *camera, Input *input, uint step) { //getkey(); input_step(input); player_step(player, input); level_step(level); camera_step(camera); } void draw_event(Player *player, Level *level, Camera *camera, Input *input, uint step) { dclear(C_WHITE); level_draw(level, camera); player_draw(player, camera); #ifdef DEBUG camera_draw_debug(camera); //input_draw_debug(input); player_draw_debug(player, step); #endif dupdate(); }