pvjc25/du8/main.c
2025-06-12 13:00:33 +02:00

40 lines
829 B
C

#include <stdlib.h>
#include <time.h>
#include "world.h"
#include "game.h"
void* init_game()
{
StavHry *stav = (StavHry*) malloc(sizeof(StavHry));
if (stav == NULL) return NULL;
srand(time(NULL));
return stav;
}
void destroy_game(void* game)
{
free(game);
}
int world_event(struct event* event, void* game)
{
StavHry *stav = (StavHry*) game;
if (event->type == EVENT_START) {
inicializuj_hru(stav, event->width, event->height);
} else if (event->type == EVENT_KEY) {
if (event->key == 'q' || event->type == EVENT_ESC) return 1;
spracuj_vstup(stav, event->key);
} else if (event->type == EVENT_TIMEOUT) {
aktualizuj_stav(stav);
}
vykresli_stav(stav);
return 0;
}
int main()
{
return start_world(init_game, world_event, destroy_game);
}