Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
center_anchor(explosion_image)
explosion_animation = \
pyglet.image.Animation.from_image_sequence(explosion_images,
EXPLOSION_ANIMATION_PERIOD,
loop=False)
pointer_image = resource.image('pointer.png')
pointer_image.anchor_x = pointer_image.width // 2
pointer_image.anchor_y = pointer_image.height // 2
pointer_image_flip = resource.image('pointer.png', flip_x=True)
explosion_sound = resource.media('explosion.wav', streaming=False)
bullet_sound = resource.media('bullet.wav', streaming=False)
starfield = Starfield(resource.image('starfield.jpg'))
player = Player(resource.image('ship.png'), wrapping_batch)
win.push_handlers(player)
# --------------------------------------------------------------------------
# Global game state vars
# --------------------------------------------------------------------------
overlay = None
in_game = False
paused = False
score = 0
difficulty = 2
show_fps = False
enable_sound = True
score_text = pyglet.text.Label('',
def __init__(self, image, position=(0, 0), rotation=0, scale=1,
opacity=255, color=(255, 255, 255), anchor=None, **kwargs):
if isinstance(image, string_types):
image = pyglet.resource.image(image)
self.transform_anchor_x = 0
self.transform_anchor_y = 0
self._image_anchor_x = 0
self._image_anchor_y = 0
# These need to be forward-defined here because pyglet<1.3 sprites don't have them.
self._scale_x = 1
self._scale_y = 1
pyglet.sprite.Sprite.__init__(self, image, **kwargs)
BatchableNode.__init__(self)
if anchor is None:
if isinstance(self.image, pyglet.image.Animation):
anchor = (image.frames[0].image.width // 2,
def __init__(self):
super(BackgroundLayer, self).__init__()
self.img = pyglet.resource.image('background_image.png')
class Frame(glooey.Frame):
class Decoration(glooey.Background):
custom_center = pyglet.resource.texture('center.png')
class Box(glooey.Bin):
custom_horz_padding = 2
class VBar(glooey.VScrollBar):
custom_scale_grip = True
class Decoration(glooey.Background):
custom_top = pyglet.resource.image('bar_top.png')
custom_center = pyglet.resource.texture('bar_vert.png')
custom_bottom = pyglet.resource.image('bar_bottom.png')
custom_vert_padding = 25
class Forward(glooey.Button):
custom_base_image = pyglet.resource.image('forward_base.png')
custom_over_image = pyglet.resource.image('forward_over.png')
custom_down_image = pyglet.resource.image('forward_down.png')
class Backward(glooey.Button):
custom_base_image = pyglet.resource.image('backward_base.png')
custom_over_image = pyglet.resource.image('backward_over.png')
custom_down_image = pyglet.resource.image('backward_down.png')
class Grip(glooey.Button):
custom_height_hint = 20
custom_alignment = 'fill'
barb_vertical = pyglet.resource.image('barb_vertical.png')
barb_horizontal = pyglet.resource.image('barb_horizontal.png')
cat_image = pyglet.resource.image('cat.png')
# it's nine lives
rat_image = pyglet.resource.image('rat.png')
catfood_image = pyglet.resource.image('catfood.png')
drycatfood_image = pyglet.resource.image('drycatfood.png')
fish_image = pyglet.resource.image('fish.png')
goldfish_image = pyglet.resource.image('goldfish.png')
mice_image = pyglet.resource.image('mice.png')
milk_image = pyglet.resource.image('milk.png')
woolenball_image = pyglet.resource.image('woolenball.png')
tinfood_image = pyglet.resource.image('tinfood.png')
center_image(cat_image)
center_image(rat_image)
center_image(catfood_image)
center_image(drycatfood_image)
center_image(fish_image)
center_image(goldfish_image)
center_image(mice_image)
center_image(milk_image)
center_image(woolenball_image)
center_image(tinfood_image)
game_music = pyglet.resource.media('music.ogg', streaming=False)
list_of_lives = [rat_image, catfood_image, drycatfood_image, fish_image,
goldfish_image, mice_image, milk_image, woolenball_image,
def __init__(self):
super( TestLayer, self ).__init__()
x,y = director.get_window_size()
image = pyglet.resource.image('grossini.png')
image.anchor_x = image.width / 2
image.anchor_y = image.height / 2
sprite1 = ActionSprite( image )
image = pyglet.resource.image('grossinis_sister1.png')
image.anchor_x = image.width / 2
image.anchor_y = image.height / 2
sprite2 = ActionSprite( image )
image = pyglet.resource.image('grossinis_sister2.png')
image.anchor_x = image.width / 2
image.anchor_y = image.height / 2
sprite3 = ActionSprite( image )
self.add( sprite1, (320, y/2) )
self.add( sprite2, (620, y/2) )
self.add( sprite3, (20, y/2) )
ju_right = Jump( y=100, x=600, jumps=4, duration=5 )
ju_left = Jump( y=100, x=-600, jumps=4, duration=5 )
rot1 = Rotate( 180 * 4, duration=5)
sprite2.do( Repeat( ju_left + Reverse(ju_left) ) )
sprite2.do( Repeat( Reverse(rot1) + rot1 ) )
sprite3.do( Repeat( ju_right + Reverse(ju_right) ) )
sprite3.do( Repeat( rot1 + Reverse(rot1) ) )
def run_with_visual(self):
pyglet.resource.path = ['./resources']
pyglet.resource.reindex()
SCREEN_WIDTH = self.MAP_SIZE_X * 32
SCREEN_HEIGHT = self.MAP_SIZE_Y * 32
window = pyglet.window.Window(resizable=True)
window.set_size(SCREEN_WIDTH, SCREEN_HEIGHT)
tile_image = pyglet.resource.image("grass.png")
tiles_batch = pyglet.graphics.Batch()
tiles = []
for y in range(0, self.MAP_SIZE_Y):
for x in range(0, self.MAP_SIZE_X):
tiles.append(pyglet.sprite.Sprite(
img=tile_image,
x=x * 32,
y=y * 32,
batch=tiles_batch)
)
goal_image = pyglet.resource.image("target.png")
goals_batch = pyglet.graphics.Batch()
goals = []
for index in range(0, len(self.F_GOAL_LOC)):
goals.append(pyglet.sprite.Sprite(
def _make_dialog_layer(self):
# Load dialog box border
image = pyglet.resource.image('images/Dialog_Border.png')
# The border is a 3x3 tile grid
grid = pyglet.image.ImageGrid(image, 3, 3)
# The width of the dialog box will be the width of the window
w = cocos.director.director.get_window_size()[0]
# Calculate how many tiles can fit in the space we have to fill
num_columns, num_rows = w / grid.item_width, 128 / grid.item_height
# Construct rectmap that creates a dialog box border
columns = list()
for i in range(0, num_columns):
row = list()
columns.append(row)
# Ugly as sin
for j in range(0, num_rows):
if i == 0 and j == 0:
index = 0
elif i == 0 and j == num_rows - 1:
class Box(glooey.Bin):
custom_horz_padding = 2
class VBar(glooey.VScrollBar):
custom_scale_grip = True
class Decoration(glooey.Background):
custom_top = pyglet.resource.image('bar_top.png')
custom_center = pyglet.resource.texture('bar_vert.png')
custom_bottom = pyglet.resource.image('bar_bottom.png')
custom_vert_padding = 25
class Forward(glooey.Button):
custom_base_image = pyglet.resource.image('forward_base.png')
custom_over_image = pyglet.resource.image('forward_over.png')
custom_down_image = pyglet.resource.image('forward_down.png')
class Backward(glooey.Button):
custom_base_image = pyglet.resource.image('backward_base.png')
custom_over_image = pyglet.resource.image('backward_over.png')
custom_down_image = pyglet.resource.image('backward_down.png')
class Grip(glooey.Button):
custom_height_hint = 20
custom_alignment = 'fill'
custom_base_top = pyglet.resource.image('grip_top_base.png')
custom_base_center = pyglet.resource.texture('grip_vert_base.png')
custom_base_bottom = pyglet.resource.image('grip_bottom_base.png')
custom_over_top = pyglet.resource.image('grip_top_over.png')
x, y = self.x, self.y
# move
self.position = (x + self.dx, y + self.dy)
# 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))
def update(dt):
for s in batch: s.update()
pyglet.clock.schedule(update)
numframes = 0
sum_numframes = 0
best_fps = 0
def update_stats(dt):
global numframes, sum_numframes, best_fps
fps = numframes / dt