-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[Sprig App] Coin Collector+ #3503
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
moriz1432-dotcom
wants to merge
1
commit into
hackclub:main
Choose a base branch
from
moriz1432-dotcom:Automated-PR-1764979242120
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+138
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| const player = "p" | ||
| const wall = "w" | ||
| const coin = "c" | ||
|
|
||
| setLegend( | ||
| [player, bitmap` | ||
| ................ | ||
| ................ | ||
| ................ | ||
| ......0000...... | ||
| .....022220..... | ||
| ....02222220.... | ||
| ....02222220.... | ||
| ....02222220.... | ||
| ....02222220.... | ||
| ....02222220.... | ||
| .....022220..... | ||
| ......0000...... | ||
| ................ | ||
| ................ | ||
| ................ | ||
| ................`], | ||
|
|
||
| [wall, bitmap` | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111 | ||
| 1111111111111111`], | ||
|
|
||
| [coin, bitmap` | ||
| ................ | ||
| ................ | ||
| ................ | ||
| ......3333...... | ||
| .....344443..... | ||
| ....34444443.... | ||
| ....34444443.... | ||
| ....34444443.... | ||
| ....34444443.... | ||
| ....34444443.... | ||
| .....344443..... | ||
| ......3333...... | ||
| ................ | ||
| ................ | ||
| ................ | ||
| ................`] | ||
| ) | ||
|
|
||
| setSolids([wall]) | ||
|
|
||
| // --- LEVELS --- | ||
| let level = 0 | ||
|
|
||
| const levels = [ | ||
| // Level 1 | ||
| map` | ||
| wwwwwwwww | ||
| wp....c.w | ||
| w..ww...w | ||
| w..w....w | ||
| w..w.c..w | ||
| w....w..w | ||
| wc...w..w | ||
| wwwwwwwww`, | ||
|
|
||
| // Level 2 | ||
| map` | ||
| wwwwwwwwwww | ||
| wp.......cw | ||
| w.w.www.w.w | ||
| w.w...w.w.w | ||
| w.w.c.w.w.w | ||
| w...w.....w | ||
| wc....c...w | ||
| wwwwwwwwwww`, | ||
|
|
||
| // Level 3 (Hard mode) | ||
| map` | ||
| wwwwwwwwwww | ||
| w.c...c...w | ||
| w.www.www.w | ||
| wp..c.....w | ||
| www.w.www.w | ||
| w...c..c..w | ||
| w.www.www.w | ||
| w....c....w | ||
| wwwwwwwwwww` | ||
| ] | ||
|
|
||
| setMap(levels[level]) | ||
|
|
||
| // --- MOVEMENT --- | ||
| onInput("w", () => getFirst(player).y--) | ||
| onInput("s", () => getFirst(player).y++) | ||
| onInput("a", () => getFirst(player).x--) | ||
| onInput("d", () => getFirst(player).x++) | ||
|
|
||
| // --- GAME LOGIC --- | ||
| afterInput(() => { | ||
| const p = getFirst(player) | ||
|
|
||
| // Remove coins if player steps on them | ||
| getTile(p.x, p.y) | ||
| .filter(t => t.type === coin) | ||
| .forEach(c => c.remove()) | ||
|
|
||
| // Next level if all coins are gone | ||
| if (tilesWith(coin).length === 0) { | ||
| clearText() | ||
| addText("Level Complete!", { y: 1, color: color`4` }) | ||
|
|
||
| level++ | ||
|
|
||
| if (level < levels.length) { | ||
| setTimeout(() => { | ||
| clearText() | ||
| setMap(levels[level]) | ||
| }, 500) | ||
| } else { | ||
| setTimeout(() => { | ||
| clearText() | ||
| addText("YOU WIN!", { y: 1, color: color`3` }) | ||
| }, 500) | ||
| } | ||
| } | ||
| }) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: A race condition allows
levelto be incremented multiple times due to re-entrantafterInput()calls during the 500ms delay after coin collection.Severity: CRITICAL | Confidence: High
🔍 Detailed Analysis
The
afterInput()callback increments thelevelvariable and then schedulessetMap()with a 500ms delay. During this 500ms window, if a player input occurs, theafterInput()callback re-executes. SincetilesWith(coin).lengthis still0, thelevelvariable is incremented again, and anothersetTimeoutis scheduled. This can cause the game to skip multiple levels, corrupt game state, and trigger the "YOU WIN!" condition prematurely.💡 Suggested Fix
To prevent re-entry, either load the new map immediately after incrementing
levelwithout asetTimeoutdelay, or introduce a flag to preventafterInput()from processing level transitions if one is already in progress.🤖 Prompt for AI Agent
Did we get this right? 👍 / 👎 to inform future reviews.
Reference ID:
5920927