Pythonic Entity Collision Resolution System
pecrs is a pure Python 2D physics system with a focus on top-down games and simple platformers.
Pure Python makes pecrs portable and easy to modify to suit your own needs.
Focused use-case makes pecrs simple to learn and use.
Seamless integration with Pyglet
Installation
Via pip
python3 -m pip install pecrs
Quickstart
from pecrs import *
space = Space()
rectA = Rect(0, 0, 32, 32)
rectB = Rect(10, 0, 32, 32)
space.add(rectA)
space.add(rectB)
collision = space.check(rectA)
print(f"Is something colliding with rectA? {collision}")
collisions = space.collisions_with(rectB)
print(f"Who is colliding with rectB? {collisions}")
space.place(rectB, 100, 0)
collision = space.check_two(rectA, rectB)
print(f"Are rectA and rectB still colliding? {collision}")
Structual Overview
Base types of the system are Shapes and Bodies. Shapes have a position and dimensions which describe its physical properties. Bodies are Shapes with an id, direction, speed, and movement state.
Core functionality is providied by the Collider, which detects collisions between Shapes or Shape-like Objects.
The Space handles positioning of Shapes and optimizes collision handling.
The Controller provides high-level object oriented control over Bodies in a Space.
Real-world Usage
from pecrs import *
import pyglet
class World(Space):
def __init__(self):
super().__init__()
self.window = pyglet.window.Window(400, 300)
self.batch = pyglet.graphics.Batch()
self.red_image = pyglet.resource.image("red_rect.png")
self.blue_image = pyglet.resource.image("blue_rect.png")
spriteA = pyglet.sprite.Sprite(self.blue_image, x=0, y=150, batch=self.batch)
spriteB = pyglet.sprite.Sprite(self.blue_image, x=300, y=150, batch=self.batch)
self.add(spriteA, moving=True)
self.turn(spriteA, (150, 0))
self.add(spriteB)
pyglet.clock.schedule_interval(self.run, 1.0/60)
pyglet.app.run()
def on_collision(self, shape, collisions):
shape.image = self.red_image
def run(self, delta):
self.step(delta)
self.window.clear()
self.batch.draw()
world = World()
Documentation
https://solidsmokesoftware.github.io/pecrs-py/
Demonstration
https://github.com/solidsmokesoftware/solconomy
Requirements
Tested with Python3.6.9
Metadata
Release files for pecrs 0.35
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pecrs-0.35.tar.gz | 11.7 kB | Without provenance | Details for pecrs-0.35.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pecrs-0.35-py3-none-any.whl | Python 3 | none | any | Details for pecrs-0.35-py3-none-any.whl |
Total release size: 23.9 kB
Release files / pecrs-0.35.tar.gz
| Download URL | pecrs-0.35.tar.gz |
|---|---|
| Size | 11.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
083c69adae35f4f40c0ab78fcd643da9653221de8b2f992e3dec922948c10f5a
|
|
BLAKE2b-256 checksum How to use checksums |
630f7c9878ba9a8c2b6e98b31f111d8a0b2e8344f48d024a8278a20d9a07aece
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.6.9 Linux/5.3.0-40-generic
|
Release files / pecrs-0.35-py3-none-any.whl
| Download URL | pecrs-0.35-py3-none-any.whl |
|---|---|
| Size | 12.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0e8eca9884f0844ef2f03dc4f58c83d9945423c4f77797e3ea91da9bdde2b4f2
|
|
BLAKE2b-256 checksum How to use checksums |
0109e28792e2eb44e7927b8ea40589928702508367a9526a7fdb900822ee63c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.0.5 CPython/3.6.9 Linux/5.3.0-40-generic
|
Security for pecrs 0.35
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.