当前位置: 首页>>代码示例>>Python>>正文


Python Background.generate方法代码示例

本文整理汇总了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)
开发者ID:Nebual,项目名称:spad,代码行数:80,代码来源:game.py


注:本文中的background.Background.generate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。