26 lines
706 B
Python
26 lines
706 B
Python
from .component import Component
|
|
from ..servers.physics import PhysicsServer
|
|
|
|
|
|
class CollideRect(Component):
|
|
def __init__(self, parent, rect, static=True, solid=True, cb=None):
|
|
super().__init__(parent)
|
|
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)
|
|
self.static = static
|
|
self.solid = solid
|
|
self.cb = cb
|
|
self.vx = 0
|
|
self.vy = 0
|
|
|
|
def register(self):
|
|
PhysicsServer().register_component(self)
|
|
|
|
def unregister(self):
|
|
PhysicsServer().unregister_component(self)
|