Repository navigation
Add sweep_line() and a lasers and mirrors example - #2941
Merged
Merged
Conversation
sweep_line(start, end, sprite_list) returns a SweepInfo for the first sprite a line hits, or None. It's sweep_sprite() for a point: the swept overlap code now takes any convex shape's points, bounds, and axes, so sweep_sprite passes the sprite's hit box and sweep_line a single point. It follows the same rules: touching doesn't count, a line ending on an edge doesn't hit, and a line starting inside a sprite is an immediate hit with a normal out of the nearest edge (the deepest, if several). The sprite_laser_mirrors example aims a laser at the mouse; each part of the beam uses sweep_line(), and mirrors reflect it with the normal. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.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.
Summary
Adds
arcade.sweep_line(start, end, sprite_list), the line version ofsweep_sprite, plus a Lasers and Mirrors example.It returns the existing
SweepInfo(sprite,fraction,distance,normal) for the first sprite the line hits, orNone. Use it for lasers, hitscan weapons, or seeing what's in the way between two points. The docstring shows how to get the hit point and how to reflect off the normal.How it works
A line is a moving point, so it reuses
sweep_sprite's swept overlap math:_sweep_shape(), which takes any convex shape's points, bounds and edge axes._sweep_against()passes the sprite's hit box, exactly as before, andsweep_linepasses a single point with no edge axes.sweep_sprite:_point_push_out). If the start is inside several sprites, the one it's deepest inside wins.sweep_spritebehavior is unchanged, and its tests pass.The example:
sprite_laser_mirrorsA turret fires a laser at the mouse. Each straight part of the beam uses
sweep_line():d - 2 * d.dot(normal) * normal.It has the code, the rst page with a screenshot, and a gallery entry under "Shooting with Sprites", next to
sprite_bullets_sweep.Tests
New in
tests/unit/sprite/test_sprite_collision.py, with and without a spatial hash where it matters:Full suite: 1741 passed. With CI's ruff (
uv run), formatting, import order and lint all pass. The docs build withsphinx-build -W, and the example page and gallery link render.The changelog has an entry under Unreleased → New Features.
🤖 Generated with Claude Code