當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。