Files
2048/main.c
T
2026-05-26 13:38:15 +02:00

50 lines
1.1 KiB
C

#include "raylib.h"
#include <math.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "game.h"
#include "ui.h"
static GameState_t game_state;
int main() {
srand(time(NULL));
FILE *game_file = fopen("save.dat", "rb");
if (game_file != NULL) {
if (fread(&game_state, sizeof(GameState_t), 1, game_file) != 1) {
reset_board(&game_state);
}
fclose(game_file);
} else {
reset_board(&game_state);
}
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "2048");
SetTargetFPS(90); // We have event blocking so we can affort higher FPS
EnableEventWaiting();
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
// If we are not animating, we can wait for input events instead of continuously rendering
bool animating = render(&game_state);
if (animating) {
DisableEventWaiting();
} else {
EnableEventWaiting();
}
EndDrawing();
handle_mouse_input(&game_state);
handle_keyboard_input(&game_state);
}
CloseWindow();
return 0;
}