mirror of
https://git.sr.ht/~kikoodx/crystal-tower
synced 2024-06-05 02:11:25 +02:00
102 lines
1.6 KiB
C
102 lines
1.6 KiB
C
#include "camera.h"
|
|
#include "conf.h"
|
|
#include "input.h"
|
|
#include "level.h"
|
|
#include "particles.h"
|
|
#include "player.h"
|
|
#include "results.h"
|
|
#include "stars.h"
|
|
#include "vec.h"
|
|
#include <gint/cpu.h>
|
|
#include <gint/display.h>
|
|
#include <gint/keyboard.h>
|
|
#include <gint/timer.h>
|
|
#include <stdlib.h>
|
|
|
|
static void update(void);
|
|
static void draw(void);
|
|
static int callback(volatile int *);
|
|
|
|
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;
|
|
|
|
srand(1337);
|
|
timer = timer_configure(TIMER_ANY, 1000000 / TARGET_FPS,
|
|
GINT_CALL(callback, &has_ticked));
|
|
timer_start(timer);
|
|
input_init();
|
|
stars_init();
|
|
level_load(0);
|
|
camera_init(player_pos());
|
|
dfont(&font_georgia);
|
|
|
|
dimage(0, 0, &bimg_title);
|
|
dupdate();
|
|
getkey();
|
|
has_ticked = 0;
|
|
while (!has_ticked)
|
|
;
|
|
has_ticked = 0;
|
|
|
|
while (!input_down(K_EXIT)) {
|
|
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();
|
|
}
|
|
}
|
|
|
|
timer_stop(timer);
|
|
level_free();
|
|
return 1;
|
|
}
|
|
|
|
static void
|
|
update(void)
|
|
{
|
|
particles_update();
|
|
input_update();
|
|
player_update();
|
|
camera_update();
|
|
stars_update();
|
|
}
|
|
|
|
static void
|
|
draw(void)
|
|
{
|
|
dclear(C_BLACK);
|
|
stars_draw();
|
|
level_draw();
|
|
player_draw();
|
|
particles_draw();
|
|
if (end)
|
|
results_draw();
|
|
dupdate();
|
|
}
|
|
|
|
static int
|
|
callback(volatile int *arg)
|
|
{
|
|
*arg += 1;
|
|
return 0;
|
|
}
|