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

25 lines
674 B
Python
Raw Normal View History

2019-11-23 10:46:25 +01:00
from .component import Component
2019-12-05 11:31:53 +01:00
from ..servers.physics import PhysicsServer
2019-11-23 10:46:25 +01:00
class CollideRect(Component):
def __init__(self, parent, rect, static=True, solid=True):
super().__init__(parent)
2019-11-23 10:46:25 +01:00
self.rect = rect
def x_change_cb(x):
self.rect.x = x
def y_change_cb(y):
self.rect.y = y
parent.subscribe('x', x_change_cb)
parent.subscribe('y', y_change_cb)
2019-12-05 11:31:53 +01:00
self.static = static
self.solid = solid
self.vx = 0
self.vy = 0
def register(self):
PhysicsServer().register_component(self)
def unregister(self):
PhysicsServer().register_component(self)