forked from NotAShelf/rogged
rogged: re-seed on game-over; display seed in game-end screen
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I0178392036902a87b64fde63f5a5f56a6a6a6964
This commit is contained in:
parent
f51b754e76
commit
8bbca55b78
3 changed files with 16 additions and 8 deletions
10
src/main.c
10
src/main.c
|
|
@ -482,9 +482,9 @@ static int handle_input(GameState *gs) {
|
||||||
|
|
||||||
// Check for restart (works during game over)
|
// Check for restart (works during game over)
|
||||||
if (IsKeyPressed(KEY_R) && gs->game_over) {
|
if (IsKeyPressed(KEY_R) && gs->game_over) {
|
||||||
unsigned int saved_seed = gs->run_seed;
|
|
||||||
memset(gs, 0, sizeof(GameState));
|
memset(gs, 0, sizeof(GameState));
|
||||||
gs->run_seed = saved_seed;
|
// Generate a new random seed for the new run
|
||||||
|
gs->run_seed = (unsigned int)time(NULL);
|
||||||
init_floor(gs, 1);
|
init_floor(gs, 1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -539,9 +539,9 @@ static void game_loop(unsigned int run_seed) {
|
||||||
if (IsKeyPressed(KEY_Q))
|
if (IsKeyPressed(KEY_Q))
|
||||||
break;
|
break;
|
||||||
if (IsKeyPressed(KEY_R)) {
|
if (IsKeyPressed(KEY_R)) {
|
||||||
unsigned int saved_seed = gs.run_seed;
|
|
||||||
memset(&gs, 0, sizeof(GameState));
|
memset(&gs, 0, sizeof(GameState));
|
||||||
gs.run_seed = saved_seed;
|
// Generate a new random seed for the new run
|
||||||
|
gs.run_seed = (unsigned int)time(NULL);
|
||||||
gs.game_over = 0;
|
gs.game_over = 0;
|
||||||
gs.game_won = 0;
|
gs.game_won = 0;
|
||||||
load_audio_assets(&gs);
|
load_audio_assets(&gs);
|
||||||
|
|
@ -598,7 +598,7 @@ static void game_loop(unsigned int run_seed) {
|
||||||
}
|
}
|
||||||
render_end_screen(gs.game_won, gs.total_kills, gs.items_collected, gs.damage_dealt, gs.damage_taken,
|
render_end_screen(gs.game_won, gs.total_kills, gs.items_collected, gs.damage_dealt, gs.damage_taken,
|
||||||
gs.crits_landed, gs.times_hit, gs.potions_used, gs.floors_reached, gs.turn_count,
|
gs.crits_landed, gs.times_hit, gs.potions_used, gs.floors_reached, gs.turn_count,
|
||||||
gs.final_score);
|
gs.final_score, gs.run_seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
|
|
|
||||||
11
src/render.c
11
src/render.c
|
|
@ -507,7 +507,7 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
|
||||||
}
|
}
|
||||||
|
|
||||||
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
||||||
int times_hit, int potions, int floors, int turns, int score) {
|
int times_hit, int potions, int floors, int turns, int score, unsigned int seed) {
|
||||||
// Semi-transparent overlay
|
// Semi-transparent overlay
|
||||||
Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT};
|
Rectangle overlay = {0, 0, (float)SCREEN_WIDTH, (float)SCREEN_HEIGHT};
|
||||||
DrawRectangleRec(overlay, (Color){0, 0, 0, 210});
|
DrawRectangleRec(overlay, (Color){0, 0, 0, 210});
|
||||||
|
|
@ -523,7 +523,7 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i
|
||||||
int box_x = SCREEN_WIDTH / 2 - 200;
|
int box_x = SCREEN_WIDTH / 2 - 200;
|
||||||
int box_y = 110;
|
int box_y = 110;
|
||||||
int box_w = 400;
|
int box_w = 400;
|
||||||
int box_h = 320;
|
int box_h = 350;
|
||||||
DrawRectangle(box_x, box_y, box_w, box_h, (Color){20, 20, 20, 240});
|
DrawRectangle(box_x, box_y, box_w, box_h, (Color){20, 20, 20, 240});
|
||||||
DrawRectangleLines(box_x, box_y, box_w, box_h, (Color){100, 100, 100, 255});
|
DrawRectangleLines(box_x, box_y, box_w, box_h, (Color){100, 100, 100, 255});
|
||||||
|
|
||||||
|
|
@ -589,7 +589,14 @@ void render_end_screen(int is_victory, int kills, int items, int damage_dealt, i
|
||||||
DrawText("SCORE:", col1_x, row_y, 22, GOLD);
|
DrawText("SCORE:", col1_x, row_y, 22, GOLD);
|
||||||
snprintf(line, sizeof(line), "%d", score);
|
snprintf(line, sizeof(line), "%d", score);
|
||||||
DrawText(line, col1_x + 90, row_y, 22, GOLD);
|
DrawText(line, col1_x + 90, row_y, 22, GOLD);
|
||||||
|
row_y += 35;
|
||||||
|
|
||||||
|
// Seed display
|
||||||
|
DrawText("SEED:", col1_x, row_y, 18, label_color);
|
||||||
|
snprintf(line, sizeof(line), "%u", seed);
|
||||||
|
DrawText(line, col1_x + 60, row_y, 18, END_SEED);
|
||||||
|
|
||||||
|
// Instructions
|
||||||
if (is_victory) {
|
if (is_victory) {
|
||||||
const char *subtitle = "Press R to play again or Q to quit";
|
const char *subtitle = "Press R to play again or Q to quit";
|
||||||
int sub_width = MeasureText(subtitle, 20);
|
int sub_width = MeasureText(subtitle, 20);
|
||||||
|
|
|
||||||
|
|
@ -68,6 +68,7 @@
|
||||||
#define END_OVERLAY (Color){0, 0, 0, 210}
|
#define END_OVERLAY (Color){0, 0, 0, 210}
|
||||||
#define END_BOX_BG (Color){20, 20, 20, 240}
|
#define END_BOX_BG (Color){20, 20, 20, 240}
|
||||||
#define END_BOX_BORDER (Color){100, 100, 100, 255}
|
#define END_BOX_BORDER (Color){100, 100, 100, 255}
|
||||||
|
#define END_SEED (Color){150, 200, 255, 255}
|
||||||
|
|
||||||
// Portrait placeholder
|
// Portrait placeholder
|
||||||
// FIXME: remove when player sprites are available
|
// FIXME: remove when player sprites are available
|
||||||
|
|
@ -99,7 +100,7 @@ void render_floating_texts(FloatingText *texts, int count, int shake_x, int shak
|
||||||
|
|
||||||
// Render end screen (victory or death) with stats breakdown
|
// Render end screen (victory or death) with stats breakdown
|
||||||
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
void render_end_screen(int is_victory, int kills, int items, int damage_dealt, int damage_taken, int crits,
|
||||||
int times_hit, int potions, int floors, int turns, int score);
|
int times_hit, int potions, int floors, int turns, int score, unsigned int seed);
|
||||||
|
|
||||||
// Render a message popup
|
// Render a message popup
|
||||||
void render_message(const char *message);
|
void render_message(const char *message);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue