Save file bugfix and high dpi support
This commit is contained in:
@@ -30,14 +30,17 @@ static GameState_t game_state;
|
|||||||
int main() {
|
int main() {
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
reset_board(&game_state);
|
|
||||||
FILE *game_file = fopen("save.dat", "rb");
|
FILE *game_file = fopen("save.dat", "rb");
|
||||||
if (game_file != NULL) {
|
if (game_file != NULL) {
|
||||||
fseek(game_file, 0, SEEK_SET);
|
if (fread(&game_state, sizeof(GameState_t), 1, game_file) != 1) {
|
||||||
fread(&game_state, sizeof(GameState_t), 1, game_file);
|
reset_board(&game_state);
|
||||||
|
}
|
||||||
fclose(game_file);
|
fclose(game_file);
|
||||||
|
} else {
|
||||||
|
reset_board(&game_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SetConfigFlags(FLAG_WINDOW_HIGHDPI);
|
||||||
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "2048");
|
InitWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "2048");
|
||||||
SetTargetFPS(30); // So my laptop doesn't burn
|
SetTargetFPS(30); // So my laptop doesn't burn
|
||||||
|
|
||||||
@@ -52,7 +55,7 @@ int main() {
|
|||||||
int pos_y = BOARD_MARGIN + y * (TILE_SIZE + TILE_SPACING);
|
int pos_y = BOARD_MARGIN + y * (TILE_SIZE + TILE_SPACING);
|
||||||
int color_index = (tile_value == 0) ? 0 : (int)log2(tile_value);
|
int color_index = (tile_value == 0) ? 0 : (int)log2(tile_value);
|
||||||
|
|
||||||
if (color_index >= sizeof(tile_colors) / sizeof(tile_colors[0])) {
|
if ((size_t)color_index >= sizeof(tile_colors) / sizeof(tile_colors[0])) {
|
||||||
color_index = sizeof(tile_colors) / sizeof(tile_colors[0]) - 1; // Cap to the last color
|
color_index = sizeof(tile_colors) / sizeof(tile_colors[0]) - 1; // Cap to the last color
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user