Adoranda/src/main.c

76 lines
1.4 KiB
C
Raw Normal View History

2021-07-29 18:33:22 +02:00
#include <gint/display.h>
#include <gint/keyboard.h>
#include "game.h"
2021-08-04 20:12:53 +02:00
#include "map.h"
#include "engine.h"
#include "player.h"
#include "animation.h"
2021-08-06 23:42:49 +02:00
#include "character.h"
2021-08-19 02:29:51 +02:00
#include "camera.h"
#include "define.h"
2021-07-29 18:33:22 +02:00
2021-08-04 20:12:53 +02:00
#include <gint/timer.h>
#include <gint/clock.h>
2021-08-15 03:46:49 +02:00
extern struct Map map_1;
2021-08-04 20:12:53 +02:00
2021-08-15 03:46:49 +02:00
struct Map *maps[] = {
2021-08-04 20:12:53 +02:00
&map_1,
};
static int callback_tick(volatile int *tick) {
*tick = 1;
return TIMER_CONTINUE;
2021-07-29 18:33:22 +02:00
}
2021-08-04 20:12:53 +02:00
int main(void) {
/*Structure definition*/
2021-08-15 03:46:49 +02:00
struct Player player = {
2021-08-25 01:01:43 +02:00
.pos = VEC2(32, 30),
.pos_visual = VEC2F(32*TILE_SIZE, 30*TILE_SIZE),
.x_mid = 6,
.y_mid = 1,
2021-08-04 20:12:53 +02:00
.show_x = 12,
.show_y = 7,
.direction = DIR_DOWN,
.anim.function = anim_player_idle,
.anim.dir = DIR_DOWN
};
player.idle = !anim_player_idle(&player.anim, 1);
2021-08-15 03:46:49 +02:00
struct Game game = {
2021-08-04 20:12:53 +02:00
.map = maps[0],
2021-08-05 03:12:40 +02:00
.player = &player,
2021-08-25 01:01:43 +02:00
.camera = camera_new(&player.pos_visual),
2021-08-05 03:12:40 +02:00
.background = C_WHITE
2021-08-04 20:12:53 +02:00
};
game.characters = get_map_characters(1);
2021-08-04 20:12:53 +02:00
/*Timer*/
2021-08-04 20:12:53 +02:00
static volatile int tick = 1;
int t = timer_configure(TIMER_ANY, ENGINE_TICK*1000,
GINT_CALL(callback_tick, &tick));
if(t >= 0) timer_start(t);
/*Main loop*/
2021-08-05 03:12:40 +02:00
while(!keydown(KEY_MENU)) {
2021-08-04 20:12:53 +02:00
while(!tick) sleep();
tick = 0;
engine_draw(&game);
dupdate();
2021-08-07 01:49:03 +02:00
int action = get_inputs();
2021-08-25 01:01:43 +02:00
if(action >= 0 && action <= 3)
2021-08-07 01:49:03 +02:00
engine_move(&game, action);
else if(action >= 4) {
engine_action(&game, action);
}
2021-08-04 20:12:53 +02:00
engine_tick(&game, ENGINE_TICK);
}
if(t >= 0) timer_stop(t);
return 0;
2021-08-15 03:46:49 +02:00
}