Exemplo n.º 1
0
 def run(self):
   self.time = 0
   window = pyglet.window.Window(caption = 'Fragmented Space', width = 800, height = 600)
   try:
     self.music = pyglet.media.Player()
     music = pyglet.resource.media('sounds/music.ogg')
     sg = pyglet.media.SourceGroup(music.audio_format, music.video_format)
     sg.queue(music)
     sg.loop = True
     self.music.queue(sg)
     self.music.play()
     self.music.volume = NORMAL_MUSIC_VOLUME
   except:
     self.music = None
   self.window = window
   self.layers = collections.defaultdict(pyglet.graphics.Batch)
   self.keys = key.KeyStateHandler()
   self.fullscreen = False
   try:
     window.set_icon(pyglet.resource.image('images/icon256.png'))
   except:
     pass # Doesn't work on Windows for some reason.
   self.add(MainMenu())
   background = sprite('background.png')
   gl.glClearColor(247 / 255.0, 251 / 255.0, 1, 1)
   gl.glEnable(gl.GL_LINE_SMOOTH);
   gl.glHint(gl.GL_LINE_SMOOTH_HINT, gl.GL_NICEST);
   @window.event
   def on_draw():
     window.clear()
     gl.glLoadIdentity()
     gl.glTranslatef(window.width / 2, window.height / 2, 0)
     background.draw()
     for l in ['corruption', 'longest', 'blocks-inside', 'blocks-outside']:
       self.layers[l].draw()
     self.objs.sort(key=lambda o: o.z if hasattr(o, 'z') else 100)
     for o in self.objs:
       o.draw()
   @window.event
   def on_key_release(symbol, modifiers):
     if symbol == key.F:
       self.fullscreen = not self.fullscreen
       window.set_fullscreen(self.fullscreen)
   def update(dt):
     self.time += dt
     for o in self.objs[:]:
       o.think(dt)
     if self.keys[key.R]:
       levels[self.level].make()
   pyglet.clock.schedule_interval(update, 1.0 / 70)
   window.push_handlers(self.keys)
   pyglet.app.run()
Exemplo n.º 2
0
 def draw(self):
   bx, by = toX(self.bi), toY(self.bj)
   lx, ly = self.x, self.y
   flat = math.copysign(self.text1.content_width / 2, lx - bx)
   coords = int(bx), int(by), int(lx - flat), int(ly), int(lx + flat), int(ly)
   gl.glEnable(gl.GL_BLEND);
   gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA);
   gl.glLineWidth(1)
   vs = len(coords) / 2
   t = game.time - self.t0
   if self.ttl and self.ttl - game.time < 1:
     t = self.ttl - game.time
   op = int(min(1, t) * self.opacity)
   pyglet.graphics.draw(vs, gl.GL_LINE_STRIP, ('v2i', coords), ('c4B', (0, 0, 0, 0) + (0, 0, 0, op) * (vs - 1)))
   if t > 0.5 or t > 0.25 and t % 0.05 < 0.02:
     self.text1.draw()
     self.text2.draw()