def __init__(self): self.highlight = spryte.Sprite(highlight_image, 0, 0) self.show_highlight = False # CREATE THE MAP self.field = tilemap.Map() self.play_field = {} l = [] for y, line in enumerate(field_rows): m = [] l.append(m) for x, cell in enumerate(line): if cell == '#': m.append( spryte.Sprite(wall_image, x * cw, y * ch, batch=self.field)) content = path.Blocker else: m.append( spryte.Sprite(blank_image, x * cw, y * ch, batch=self.field)) if cell == 'E': content = path.End elif cell == 'S': content = path.Start elif cell == '+': content = path.Blocker else: content = None self.play_field[x * 2, y * 2] = content self.play_field[x * 2 + 1, y * 2] = content self.play_field[x * 2, y * 2 + 1] = content self.play_field[x * 2 + 1, y * 2 + 1] = content self.field.set_cells(cw, ch, l) # PATH FOR ENEMIES self.path = path.Path.determine_path(self.play_field, map_width * 2, map_height * 2) #self.path.dump() self.constructions = spryte.SpriteBatch() self.enemies = spryte.SpriteBatch() self.bullets = spryte.SpriteBatch()
def get_layer(self, z): """Get a layer for the specified Z depth, adding it if necessary. """ for layer in self.layers: if layer.z == z: break else: layer = spryte.SpriteBatch() layer.z = z self.layers.append(layer) self.layers.sort(key=operator.attrgetter('z')) return layer
import math from pyglet import window from pyglet import clock from pyglet import resource import spryte NUM_CARS = 100 if len(sys.argv) > 1: NUM_CARS = int(sys.argv[1]) win = window.Window(vsync=False) fps = clock.ClockDisplay(color=(1, 1, 1, 1)) cars = spryte.SpriteBatch() car = resource.image('car.png') car.anchor_x = 16 car.anchor_y = 20 for i in range(NUM_CARS): s = spryte.Sprite(car, win.width * random.random(), win.height * random.random(), batch=cars, dr=-45 + random.random() * 90) while not win.has_exit: win.dispatch_events() clock.tick() win.clear()
# check bounds if x < 0: self.x = 0 self.dx = -self.dx elif self.right > 600: self.dx = -self.dx self.right = 600 if y < 0: self.y = 0 self.dy = -self.dy elif self.top > 600: self.dy = -self.dy self.top = 600 batch = spryte.SpriteBatch() numsprites = int(sys.argv[1]) pyglet.resource.path.append('examples/noisy') ball = pyglet.resource.image('ball.png') for i in range(numsprites): x = random.randint(0, w.width - ball.width) y = random.randint(0, w.height - ball.height) BouncySprite(ball, x, y, batch=batch, dx=random.randint(-10, 10), dy=random.randint(-10, 10))
import random import math from pyglet import window from pyglet import image from pyglet import clock from pyglet import gl from pyglet import resource from pyglet.window import key import spryte win = window.Window(width=640, height=400, vsync=False) fps = clock.ClockDisplay(color=(1, 1, 1, 1)) balls = spryte.SpriteBatch() ball = resource.image('ball.png') ball.anchor_x = 16 ball.anchor_y = 16 for i in range(200): spryte.Sprite(ball, (win.width - 64) * random.random(), (win.height - 64) * random.random(), batch=balls, dx=-50 + 100 * random.random(), dy=-50 + 100 * random.random()) car = resource.image('car.png') car.anchor_x = 16 car.anchor_y = 20 car = spryte.Sprite(car, win.width / 2, win.height / 2)
from pyglet import window from pyglet import image from pyglet import clock from pyglet import resource import spryte NUM_BOOMS = 20 if len(sys.argv) > 1: NUM_BOOMS = int(sys.argv[1]) win = window.Window(vsync=False) fps = clock.ClockDisplay(color=(1, 1, 1, 1)) explosions = spryte.SpriteBatch() explosion_images = resource.image('explosion.png') explosion_images = image.ImageGrid(explosion_images, 2, 8) explosion_animation = image.Animation.from_image_sequence(explosion_images, .001, loop=False) class EffectSprite(spryte.Sprite): def on_animation_end(self): self.delete() again() booms = spryte.SpriteBatch()