This repository has been archived on 2019-12-09. You can view files and clone it, but cannot push or open issues or pull requests.
pacman2/engine/components/collide_rect.py

31 lines
776 B
Python

from .component import Component
from ..servers.physics import PhysicsServer
class CollideRect(Component):
def __init__(self, rect, static=True, solid=True, cb=None, friction=0):
super().__init__()
self.rect = rect
self.static = static
self.solid = solid
self.friction = friction
self.cb = cb
self.vx = 0
self.vy = 0
def x_change_cb(self, x):
self.rect.x = x
def y_change_cb(self, y):
self.rect.y = y
def load(self):
self.parent.subscribe('x', self.x_change_cb)
self.parent.subscribe('y', self.y_change_cb)
def register(self):
PhysicsServer().register_component(self)
def unregister(self):
PhysicsServer().unregister_component(self)