Add rect_overlap and sprite_overlap collision detection helpers#439
Open
jonathanpeppers wants to merge 2 commits intomainfrom
Open
Add rect_overlap and sprite_overlap collision detection helpers#439jonathanpeppers wants to merge 2 commits intomainfrom
jonathanpeppers wants to merge 2 commits intomainfrom
Conversation
Add two new NESLib collision detection APIs: - rect_overlap(x1, y1, w1, h1, x2, y2, w2, h2) for AABB rectangle overlap - sprite_overlap(x1, y1, x2, y2, threshold) for distance-based same-size sprite collision Both return bool (0/1 in A register) and are implemented as 6502 subroutines that read arguments directly from the cc65 parameter stack for efficiency. Updated samples: - climber: replaced manual byte-distance collision with sprite_overlap - pong: replaced nested paddle collision checks with rect_overlap Closes #421 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
080d711 to
236a528
Compare
The transpiler's HandleLdelemU1 saves prior values to a single TEMP register, not the cc65 parameter stack. When multiple array accesses are chained as function arguments, values get overwritten. Fix by storing array element values in local variables before the call, which uses WriteLdloc's pusha emission path instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add two new NESLib collision detection APIs as described in #421:
rect_overlap(x1, y1, w1, h1, x2, y2, w2, h2)— Full AABB rectangle overlap test. Returns true if two axis-aligned rectangles overlap. Uses unsigned byte arithmetic, suitable for NES screen coordinates.sprite_overlap(x1, y1, x2, y2, threshold)— Distance-based collision for same-size sprites. Returns true if the unsigned absolute difference on both axes is less than the threshold.Both are implemented as 6502 subroutines that read arguments directly from the cc65 parameter stack via indirect indexed addressing, avoiding expensive per-arg
popacalls. They depend onaddyspfor stack cleanup.Changes
ForEachOptionalBuiltInwithaddyspdependencysprite_overlaprect_overlapBefore/After (climber)
Before/After (pong)
Closes #421