crystal-tower/src/main.c

123 lines
1.8 KiB
C

#include "camera.h"
#include "conf.h"
#include "input.h"
#include "level.h"
#include "particles.h"
#include "player.h"
#include "raygint/display.h"
#include "results.h"
#include "stars.h"
#include "vec.h"
#ifdef GINT
#include <gint/cpu.h>
#include <gint/keyboard.h>
#include <gint/timer.h>
#endif
#include <stdlib.h>
static void update(void);
static void draw(void);
#ifdef GINT
static int callback(volatile int *);
#endif
int time = 0;
int deaths = 0;
int end = 0;
int
main(void)
{
int timer;
int frameskip = 1;
volatile int has_ticked = 0;
extern bopti_image_t bimg_title;
extern font_t font_georgia;
rDisplayInit();
srand(1337);
#ifdef GINT
timer = timer_configure(TIMER_ANY, 1000000 / TARGET_FPS,
GINT_CALL(callback, &has_ticked));
timer_start(timer);
dfont(&font_georgia);
#endif
#ifdef RAYLIB
SetTargetFPS(60);
#endif
input_init();
stars_init();
level_load(0);
camera_init(player_pos());
#ifdef GINT
dimage(0, 0, &bimg_title);
dupdate();
getkey();
has_ticked = 0;
while (!has_ticked)
;
has_ticked = 0;
#endif
while (!input_down(K_EXIT)) {
int i;
draw();
for (i = 0; i < frameskip; i++) {
#ifdef GINT
if (has_ticked > frameskip) {
frameskip = has_ticked;
}
while (!has_ticked)
sleep();
while (has_ticked) {
time += has_ticked;
has_ticked = 0;
}
#endif
update();
}
}
rDisplayDeinit();
#ifdef GINT
timer_stop(timer);
#endif
level_free();
return 1;
}
static void
update(void)
{
particles_update();
input_update();
player_update();
camera_update();
stars_update();
}
static void
draw(void)
{
rDrawBegin();
dclear(C_BLACK);
stars_draw();
level_draw();
player_draw();
particles_draw();
if (end)
results_draw();
dupdate();
rDrawEnd();
}
#ifdef GINT
static int
callback(volatile int *arg)
{
*arg += 1;
return 0;
}
#endif