crystal-tower/src/main.c

81 lines
1.2 KiB
C
Raw Normal View History

2021-11-10 12:10:04 +01:00
#include "camera.h"
2021-11-10 06:15:41 +01:00
#include "conf.h"
2021-11-09 22:34:40 +01:00
#include "input.h"
2021-11-10 00:37:45 +01:00
#include "level.h"
2021-11-10 20:44:53 +01:00
#include "particles.h"
2021-11-10 06:15:41 +01:00
#include "player.h"
2021-11-12 00:52:28 +01:00
#include "stars.h"
2021-11-10 06:15:41 +01:00
#include "vec.h"
#include <gint/cpu.h>
2021-11-10 00:37:45 +01:00
#include <gint/display.h>
2021-11-10 06:15:41 +01:00
#include <gint/timer.h>
2021-11-12 00:52:28 +01:00
#include <stdlib.h>
2021-11-10 00:37:45 +01:00
2021-11-10 06:15:41 +01:00
static void update(void);
2021-11-10 00:37:45 +01:00
static void draw(void);
2021-11-10 06:15:41 +01:00
static int callback(volatile int *);
2021-11-09 22:28:28 +01:00
2021-11-09 22:34:40 +01:00
int
main(void)
{
2021-11-10 06:15:41 +01:00
int timer;
int frameskip = 1;
volatile int has_ticked = 0;
2021-11-12 00:52:28 +01:00
srand(1337);
2021-11-10 06:15:41 +01:00
timer = timer_configure(TIMER_ANY, 1000000 / TARGET_FPS,
GINT_CALL(callback, &has_ticked));
timer_start(timer);
2021-11-09 22:34:40 +01:00
input_init();
2021-11-12 00:52:28 +01:00
stars_init();
2021-11-11 16:59:37 +01:00
level_load(0);
2021-11-10 12:10:04 +01:00
camera_init(player_pos());
2021-11-10 00:37:45 +01:00
2021-11-10 23:29:12 +01:00
while (!input_down(K_EXIT)) {
2021-11-10 06:15:41 +01:00
int i;
2021-11-10 14:05:00 +01:00
draw();
2021-11-10 06:15:41 +01:00
for (i = 0; i < frameskip; i++) {
if (has_ticked > frameskip) {
frameskip = has_ticked;
}
while (!has_ticked)
sleep();
while (has_ticked)
has_ticked = 0;
update();
}
}
2021-11-10 00:37:45 +01:00
2021-11-10 06:15:41 +01:00
timer_stop(timer);
2021-11-10 08:08:29 +01:00
level_free();
2021-11-09 22:28:28 +01:00
return 1;
}
2021-11-10 00:37:45 +01:00
2021-11-10 06:15:41 +01:00
static void
update(void)
{
2021-11-10 20:44:53 +01:00
particles_update();
2021-11-10 06:15:41 +01:00
input_update();
2021-11-10 08:08:29 +01:00
player_update();
2021-11-10 12:10:04 +01:00
camera_update();
2021-11-12 00:52:28 +01:00
stars_update();
2021-11-10 06:15:41 +01:00
}
2021-11-10 00:37:45 +01:00
static void
draw(void)
{
dclear(C_BLACK);
2021-11-12 00:52:28 +01:00
stars_draw();
2021-11-10 08:08:29 +01:00
level_draw();
player_draw();
2021-11-10 20:44:53 +01:00
particles_draw();
2021-11-10 00:37:45 +01:00
dupdate();
}
2021-11-10 06:15:41 +01:00
static int
callback(volatile int *arg)
{
*arg += 1;
return 0;
}