class BaseClass: """The Baseclass for the Survivor, Zombie, Bullet and PickUp classes Params: x: The x coordinate y: The y coordinate width: (Optional) Used by the Bullet Class as it has another size. Defaults to Tile.length height: (Optional) Used by the Bullet Class as it has another size. Defaults to Tile.length""" def __init__(self, x, y, width=None, height=None): if width is None and height is None: self.width, self.height = Tile.length, Tile.length else: self.width, self.height = width, height self._size = Vector(self.width, self.height) self.to = None self.pos = Vector(x, y) def get_centre(self): return self.pos + self._size.scale(1 / 2) centre = property(get_centre, doc="""Return a vector of the pos in the middle of self >>> a = BaseClass(x=0, y=0, width=10, height=10) >>> a.centre Vector(x=5, y=5)""") def get_number(self): """Return the index of tile that self is on""" return int(self.pos.x // Tile.length + self.pos.y // Tile.length * Options.tiles_x) def get_tile(self): """Return the tile on which self is""" return Tile.instances[self.get_number()]
def test_elem_wise(self): v1 = Vector(5, 2) v2 = Vector(1, 2) self.assertEqual(v1 + v2, v2 + v1) self.assertEqual(v1 + v2, (6, 4)) self.assertEqual(v1.scale(*v2), (5, 4)) v1 += v2 self.assertEqual(v1, (6, 4))