{{ message }}
Rework HitBox to support multiple named collision regions#2835
Open
Cleptomania wants to merge 3 commits intodevelopmentfrom
Open
Rework HitBox to support multiple named collision regions#2835Cleptomania wants to merge 3 commits intodevelopmentfrom
Cleptomania wants to merge 3 commits intodevelopmentfrom
Conversation
Replaces the single-polygon HitBox with a multi-region system where each HitBox can contain named Point2List regions. This enables sprites to have distinct collision shapes (e.g. separate head/body/feet hitboxes) while maintaining backward compatibility with the single-region API. Key changes: - HitBox accepts either a Point2List (single "default" region) or a dict[str, Point2List] mapping region names to point lists - Merge RotatableHitBox into HitBox (removed RotatableHitBox) - Add serialization support (save/load to JSON, with gzip option) - Update collision detection, pymunk physics, sprite lists, and tilemap to work with multi-region hitboxes - Add sprite_multi_hitbox example - Fix type annotations for pyright/mypy compatibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Member
Author
eruvanos
reviewed
Mar 12, 2026
Add a RawHitBox TypedDict for typed serialization in to_dict/from_dict. Normalize all points to tuples of tuples on construction, add_region, and in adjusted point calculation for immutability and consistency. Update tests to expect tuple-based comparisons. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
28f322a to
0f6d7cc
Compare
Member
Author
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
Point2Listregions (e.g. separate head/body/feet hitboxes), while maintaining backward compatibility with the single-region APIchannel(what it is) andmask(what it collides with). Collision requires bidirectional agreement:(A.channel & B.mask) != 0 AND (B.channel & A.mask) != 0channels()utility to convert 1-based channel numbers to bitmasks (e.g.channels(1, 3)=0b101)RawHitBoxRegionTypedDict and bumps serialization to v2 format (with v1 backward compat), supportingchannelandmaskfields per regionRotatableHitBoxintoHitBoxand adds JSON serialization support (with optional gzip compression)sprite_multi_hitboxexample to demonstrate channel-based collision filtering (body catches coins on channel 1, shield catches gems on channel 2)Test plan
tests/unit/hitbox/test_hitbox.py) — all 34 passsprite_multi_hitboxexample (coins only hit body, gems only hit shield)🤖 Generated with Claude Code