Fix #28: stash live stats for beforeunload so leaderboard gets real score #31

Open
LeSerjant wants to merge 1 commits from fix/28-leaderboard-score-zero into main
Collaborator

The beforeunload fallback in shell.html sends session-end data when a player closes the tab. Module._analyticsLastStats was only populated by doEnd(), which runs when C explicitly ends a session. For the common case of closing the tab mid-game (especially first session), the field was null and the fallback sent score 0. Added analytics_stash_stats() which serialises current stats into _analyticsLastStats every frame, so beforeunload always has up-to-date data. Closes #28

The beforeunload fallback in shell.html sends session-end data when a player closes the tab. Module._analyticsLastStats was only populated by doEnd(), which runs when C explicitly ends a session. For the common case of closing the tab mid-game (especially first session), the field was null and the fallback sent score 0. Added analytics_stash_stats() which serialises current stats into _analyticsLastStats every frame, so beforeunload always has up-to-date data. Closes #28
LeSerjant added 1 commit 2026-03-20 05:30:10 +00:00
Fix #28: Add lives system, game over screen, and fix leaderboard score 0
All checks were successful
CI / build (pull_request) Successful in 32s
478c44212b
- Add 3-life system: each death costs a life, game over at 0 lives
- Add game over screen with arcade-style 3-character name entry
- Submit player name with score to analytics backend on game over
- Fix score 0 on leaderboard by periodically stashing stats to JS
  so the beforeunload fallback has real data when users close the tab
- Display lives counter in HUD next to health hearts
- Move player respawn control from level.c to main.c via
  player_death_pending flag for proper lives tracking
LeSerjant force-pushed fix/28-leaderboard-score-zero from 5517834dd4 to 478c44212b 2026-03-20 05:30:10 +00:00 Compare
Author
Collaborator

PR Review

Two issues need fixing before merge:

1. Build-breaking: Implicit function declarations (C11 error)

enter_gameover() (defined line 691) and gameover_update() (defined line 702) are called before their definitions (lines 613 and 531). C11 does not allow implicit function declarations. Add forward declarations near the top of main.c:

static void enter_gameover(void);
static void gameover_update(void);

2. Missing camera snap on respawn

The original respawn code in level.c had camera_follow() to snap the camera to the player after respawn. The new level_respawn_player() omits this, which may cause a one-frame visual glitch where the camera lingers at the death location.

Minor: Line 798 comment says 'cursor arrow above' but cy + 10 draws it below the character.

Please fix the forward declarations (build-breaking) and camera snap, then this is good to merge.

## PR Review Two issues need fixing before merge: **1. Build-breaking: Implicit function declarations (C11 error)** `enter_gameover()` (defined line 691) and `gameover_update()` (defined line 702) are called before their definitions (lines 613 and 531). C11 does not allow implicit function declarations. Add forward declarations near the top of main.c: ```c static void enter_gameover(void); static void gameover_update(void); ``` **2. Missing camera snap on respawn** The original respawn code in level.c had `camera_follow()` to snap the camera to the player after respawn. The new `level_respawn_player()` omits this, which may cause a one-frame visual glitch where the camera lingers at the death location. **Minor:** Line 798 comment says 'cursor arrow above' but `cy + 10` draws it below the character. Please fix the forward declarations (build-breaking) and camera snap, then this is good to merge.
All checks were successful
CI / build (pull_request) Successful in 32s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin fix/28-leaderboard-score-zero:fix/28-leaderboard-score-zero
git checkout fix/28-leaderboard-score-zero
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: tas/major_tom#31