lordmauve / lordmauve/pgzero

Add pixel perfect collision detection

Open
#216 10 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
611
Forks
211
PR merge metrics
No merged PRs in 30d

Description

Hi, many thanks for creating Pgzero, it's working really well at our Coder Dojo in Brighton :)

I've hacked together some code for pixel perfect collision detection, would you consider adding it to pgzero? I can submit a pull request if you are happy to review.

Here's the code:

```
def collide_pixel(actor1, actor2):

# Get masks for pixel perfect collision detection:
for a in [actor1, actor2]:
if not hasattr(a, 'mask'):
a.mask = mask.from_surface(a._orig_surf)

# Offsets based on current positions of actors
xoffset = int(actor2.left - actor1.left)
yoffset = int(actor2.top - actor1.top)

# Check for overlap = collision
return actor1.mask.overlap(actor2.mask, (xoffset, yoffset))
```

Bit more background here:
http://chalkpath.co.uk/blog/html/2020/01/12/pixel_perfect_collision_detection_with_pygamezero.html

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the proposed collide_pixel function in the issue and read the linked pixel-perfect collision article for context. The issue names no repository files or tests, so first locate the existing actor and collision APIs, then define where this capability belongs and how it should be tested. Done means the feature is integrated consistently with Pgzero and its behavior is covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
game-dev
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.