Odyssee/project/src/core.c

54 lines
1.2 KiB
C

#include <gint/keyboard.h>
#include <gint/timer.h>
#include <gint/clock.h>
#include "core.h"
void analyze_input(struct game *game, const int last_key)
{
game->total_tick += ENGINE_TICK;
switch (last_key)
{
case 0:
if (!(game->total_tick % 500)) game->player.animation_frame = (game->player.animation_frame + 1) % 2;
break;
case KEY_UP:
game->player.direction = UP;
game->player.map_y -= 2;
break;
case KEY_RIGHT:
game->player.direction = RIGHT;
game->player.map_x += 2;
break;
case KEY_DOWN:
game->player.direction = DOWN;
game->player.map_y += 2;
break;
case KEY_LEFT:
game->player.direction = LEFT;
game->player.map_x -= 2;
break;
}
}
int rtc_key(void)
{
int opt = GETKEY_DEFAULT & ~GETKEY_MOD_SHIFT & ~GETKEY_MOD_ALPHA;
int timeout = 1;
key_event_t ev = getkey_opt(opt, &timeout);
if (ev.type == KEYEV_NONE) return 0;
return ev.key;
}
int callback_tick(volatile int *tick)
{
*tick = 1;
return TIMER_CONTINUE;
}