本文整理汇总了Python中background.Background.generate方法的典型用法代码示例。如果您正苦于以下问题:Python Background.generate方法的具体用法?Python Background.generate怎么用?Python Background.generate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类background.Background
的用法示例。
在下文中一共展示了Background.generate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: GameWindow
# 需要导入模块: from background import Background [as 别名]
# 或者: from background.Background import generate [as 别名]
class GameWindow(pyglet.window.Window):
def __init__(self, *args, **kwargs):
super(GameWindow, self).__init__(*args, **kwargs)
self.mainBatch = pyglet.graphics.Batch() #"Misc" drawables
self.hudBatch = pyglet.graphics.Batch() #Drawn after everything
self.background = Background()
self.playerShip = physicalobject.Player(x=0, y=0)
self.push_handlers(self.playerShip.keyHandler)
self.paused = False
self.camera = Vector(0,0)
#Basically targetting either 1920x1080 (and 1920x1200) at 1, or 1366x768 ish at 0.5
self.uiScale = 1
if self.width < 1400 or self.height < 800: self.uiScale = 0.5
self.hud = hud.HUD(window=self, batch=self.hudBatch)
self.currentSystem = solarsystem.SolarSystem(x=0, y=0, seed=0)
self.currentSystem.ships.append(self.playerShip)
components.init()
pyglet.clock.schedule_interval(self.update, 1/60.0)
def update(self, dt):
if not self.paused:
#self.playerShip.update(dt) #player now updated in ships list
self.background.update(dt)
self.currentSystem.update(dt)
self.hud.update(dt)
#print self.mainBatch
def on_draw(self):
pyglet.gl.glClear(pyglet.gl.GL_COLOR_BUFFER_BIT)
pyglet.gl.glLoadIdentity() #Set camera to middle
pyglet.gl.glTranslatef(-self.camera[0], -self.camera[1], 0.5) #Set camera position
self.background.draw()
self.currentSystem.batch.draw()
self.mainBatch.draw()
self.playerShip.draw()
pyglet.gl.glLoadIdentity()
self.hudBatch.draw()
def dispatch_event(self, event_type, *args):
"""This function is Pyglet's; I'm overriding a piece of it"""
if event_type=='on_draw':
#PYGLET HACK: We want it to iterate through the on_draws backwards, and self.on_draw contains the glClear()
self.on_draw()
for frame in reversed(self._event_stack):
handler = frame.get(event_type, None)
if handler:
try:
if handler(*args): return True
except TypeError:
self._raise_dispatch_exception(event_type, args, handler)
return True
else:
return super(GameWindow, self).dispatch_event(event_type, *args)
def enterSystem(self, target):
self.currentSystem.ships.remove(self.playerShip)
self.currentSystem = solarsystem.SolarSystem(x=0, y=0, seed=target)
self.currentSystem.ships.append(self.playerShip)
self.background.generate(seed=self.currentSystem.seed)
self.playerShip.position = self.playerShip.vel * -2.5
self.camera = self.playerShip.vel * -2.5
def leaveJumpspeed(dt):
self.playerShip.brake(dt, mul=1)
if self.playerShip.vel.length() < 75: pyglet.clock.unschedule(leaveJumpspeed)
pyglet.clock.schedule_interval(leaveJumpspeed, 0.1)