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
Raw Permalink 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):
2019-12-09 20:51:45 +01:00
def __init__(self, rect, static=True, solid=True, cb=None, friction=0):
2019-12-09 12:36:42 +01:00
super().__init__()
2019-11-23 10:46:25 +01:00
self.rect = rect
2019-12-05 11:31:53 +01:00
self.static = static
self.solid = solid
2019-12-09 20:51:45 +01:00
self.friction = friction
2019-12-08 23:47:32 +01:00
self.cb = cb
2019-12-05 11:31:53 +01:00
self.vx = 0
self.vy = 0
2019-12-09 15:34:37 +01:00
def x_change_cb(self, x):
self.rect.x = x
def y_change_cb(self, y):
self.rect.y = y
2019-12-09 12:36:42 +01:00
def load(self):
2019-12-09 15:34:37 +01:00
self.parent.subscribe('x', self.x_change_cb)
self.parent.subscribe('y', self.y_change_cb)
2019-12-09 12:36:42 +01:00
2019-12-05 11:31:53 +01:00
def register(self):
PhysicsServer().register_component(self)
def unregister(self):
2019-12-08 23:47:32 +01:00
PhysicsServer().unregister_component(self)