Skip to main content

Pythonic Entity Collision Resolution System

Project description


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


Via pip

python3 -m pip install pecrs


from pecrs import *

space = Space()
rectA = Rect(0, 0, 32, 32)
rectB = Rect(10, 0, 32, 32)


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}"), 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):
      self.window = pyglet.window.Window(400, 300)
      self.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))

      pyglet.clock.schedule_interval(, 1.0/60)

   def on_collision(self, shape, collisions):
      shape.image = self.red_image

   def run(self, delta):

world = World()





Tested with Python3.6.9

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pecrs-0.35.tar.gz (11.7 kB view hashes)

Uploaded Source

Built Distribution

pecrs-0.35-py3-none-any.whl (12.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page