Skip to content
Cannot retrieve contributors at this time
from uuid import uuid4
from pyglet import sprite
from birch.util import negate, BG_COLOR, Rect
from birch.cells import *
class Cell(sprite.Sprite):
def __init__(self, name, textures, position, texture_name, batch=None,
size=None, priority=0):
super().__init__(textures[texture_name], position[0], position[1], batch=batch) = name
self.texture_name = texture_name
self.textures = textures
self.position = position
self.next_update = -1
self._impassable = False = uuid4()
self.priority = priority
#self.size = size if size is not None else [self.sprite.width, self.sprite.height]
self.scale = 2.0
def __setattr__(self, attrname, value):
supper = super()
supper.__setattr__(attrname, value)
if hasattr(self, '_dimensions') and attrname in self._dimensions:
def set_dimensions(self):
topper = super()
self._dimensions = {
'left': self.position[0],
'right': self.position[0] + topper.width,
'bottom': self.position[1] + topper.height,
'top': self.position[1],
'width': topper.width,
'height': topper.height,
'topleft': (topper.x, topper.y),
'topright': (topper.x + topper.width, topper.y),
'bottomleft': (topper.x, topper.y + topper.height),
'bottomright': (topper.x + topper.width, topper.y + topper.height),
'rect': Rect(topper.x, topper.y, topper.width, topper.height)
def __str__(self):
return '%s: %s' % (self.__class__, str(self.bounds))
def __repr__(self):
return self.__str__()
def _shift(self, delta):
return self.position[0] + delta[0], self.position[1] + delta[1]
def width(self):
return self._dimensions['width']
def height(self):
return self._dimensions['height']
def w(self):
return self.width
def h(self):
return self.height
def left(self):
return self._dimensions['left']
def top(self):
return self._dimensions['top']
def right(self):
return self._dimensions['right']
def bottom(self):
return self._dimensions['bottom']
def topleft(self):
return self._dimensions['topleft']
def topright(self):
return self._dimensions['topright']
def bottomleft(self):
return self._dimensions['bottomleft']
def bottomright(self):
return self._dimensions['bottomright']
def rect(self):
return self._dimensions['rect']
def bounds(self):
return self._dimensions['rect'].bounds
def collidepoint(self, x, y):
return x >= self.left and x < self.right and \
y >= and y < self.bottom
def intersects(self, x, y=None, w=None, h=None):
if issubclass(type(x), Cell):
sprite = x
x = sprite.x
y = sprite.y
w = sprite.w
h = sprite.h
b = y + h - 1
r = x + w - 1
return not (
r < self._dimensions['left'] or \
x > self._dimensions['right'] - 1 or \
b < self._dimensions['top'] or \
y > self._dimensions['bottom'] - 1
def viewed_position(self, camera):
return self._shift(negate(camera))
def update(self, ticks, engine):
return False
def impassable(self, cell):
return self._impassable