def __init__(self, graph, world): self._batch = pyglet.graphics.Batch() self._node_shapes = [[None] * world.grid_width for y in range(world.grid_height)] self._conn_shapes = [] cell = world.cell half_cell = world.cell / 2 color = ('c4B', (150, 150, 150, 100)) # create nodes for node in graph.get_nodes(): x, y = node shape = shapes.Circle(4, cell * x + half_cell, cell * y + half_cell, color=color) shape.add_to_batch(self._batch) self._node_shapes[y][x] = shape # create connections for node in graph.get_nodes(): x1, y1 = node for dest in graph.get_connections(node): x2, y2 = dest[0] shape = shapes.Line(cell * x1 + half_cell, cell * y1 + half_cell, cell * x2 + half_cell, cell * y2 + half_cell, color=color) shape.add_to_batch(self._batch) self._conn_shapes.append(shape)
def __init__(self, x, y, radius=100): super(LightSource, self).__init__(x, y) self.inf = influence.CircularInfluence(x, y, radius=radius, limit=0.001) # use a quadratic diffuse function self.inf.func = influence.CircularInfluence.light_diffuse self.add_shape(shapes.Circle(4, color=('c3B', (210, 210, 0))))
def __init__(self, x, y, cell_size, batch): super(Pellet, self).__init__(x, y) self.value = 50 half = cell_size / 2 shape = shapes.Circle(half / 1.5, x * cell_size + half, y * cell_size + half, color=ColorConfig.PELLET) shape.add_to_batch(batch) self._shapes.append(shape)
class BouncerObject(objects.SimplePhysicsObject): def __init__(self, w, h, x=0, y=0, angle=0): super(BouncerObject, self).__init__(x, y, angle) self._w = w self._h = h def update(self, delta): super(BouncerObject, self).update(delta) if self.x > self._w or self.x < 0: self.angle = 180 - self.angle if self.y > self._h or self.y < 0: self.angle = -self.angle if __name__ == '__main__': world = pyafai.World2D() display = pyafai.Display(world) obj = BouncerObject(world.width, world.height, 200, 200) shape = shapes.Circle(5) obj.add_shape(shape) world.add_object(obj) obj.velocity = 300 obj.angle = 30 pyafai.run()
__author__ = 'Tiago Baptista' # Allow the import of the framework from one directory down the hierarchy import sys sys.path.insert(1,'..') import pyafai from pyafai import shapes from pyafai import objects if __name__ == '__main__': world = pyafai.World2D() display = pyafai.Display(world) obj = pyafai.Object(200,200) shape = shapes.Circle(10) obj.add_shape(shape) world.add_object(obj) obj2 = objects.SimplePhysicsObject(150,150) shape = shapes.Triangle(0, -10, 20, 0, 0, 10, color=('c3B', (200,0,0))) obj2.add_shape(shape) world.add_object(obj2) obj2.ang_velocity = 120 obj2.velocity = 100 obj3 = pyafai.Object(300,300) shape = shapes.Sprite('resources/pac_man.png') obj3.add_shape(shape) world.add_object(obj3)
def __init__(self, x, y, cell): super(PacmanBody, self).__init__(x, y) shape = shapes.Circle(int(cell * 0.6), color=ColorConfig.PACMAN) self.add_shape(shape)