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


Python RenderUpdates.sprites方法代码示例

本文整理汇总了Python中pygame.sprite.RenderUpdates.sprites方法的典型用法代码示例。如果您正苦于以下问题:Python RenderUpdates.sprites方法的具体用法?Python RenderUpdates.sprites怎么用?Python RenderUpdates.sprites使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame.sprite.RenderUpdates的用法示例。


在下文中一共展示了RenderUpdates.sprites方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from pygame.sprite import RenderUpdates [as 别名]
# 或者: from pygame.sprite.RenderUpdates import sprites [as 别名]

#.........这里部分代码省略.........
		self.parkGeography.PlaceVisitor( visitor, pos )
		allobjects.allVisitors.add( visitor )

	#---------------------------------------------------------------------
	def DoVisitorEntries( self ):
		if len( allobjects.allVisitors ) >= simulation.capacity:
			return

		totalVisitors = simulation.getEntryRate( allobjects.timeOfDay )
		#print "entering ", totalVisitors
		numGreen = int(totalVisitors*simulation.deviceAcceptanceRate)
		if not allobjects.thousandCounter%2:
			numGreen += 1
		numRed = totalVisitors - numGreen
		pos = self.parkGeography.GetEntryPoint()
		for i in xrange( numGreen ):
			device = allobjects.server.NewDevice()
			if device:
				self.deviceGroup.add( device )
				newGuy = GuidedVisitor( device )
			else:
				newGuy = UnGuidedVisitor()
			self.AddVisitor( newGuy, pos )
		for i in xrange( numRed ):
			newGuy = UnGuidedVisitor()
			self.AddVisitor( newGuy, pos )

	#---------------------------------------------------------------------
	def DoVisitorExits( self ):
		if not allobjects.allVisitors:
			return
		totalVisitors = simulation.getExitRate( allobjects.timeOfDay )
		for i in xrange( totalVisitors ):
			allobjects.allVisitors.sprites()[i].LeaveThePark()

	#---------------------------------------------------------------------
	def RemoveVisitor(self, visitor):
		visitor.kill()

	#---------------------------------------------------------------------
	def FindVisitorNear(self,pos,radius=4):
		for v in self.greenVisitorGroup.sprites():
			if abs( v.rect.centerx - pos[0] ) < radius \
			  and abs( v.rect.centery - pos[1] ) < radius:
				return v
		for v in self.redVisitorGroup.sprites():
			if abs( v.rect.centerx - pos[0] ) < radius \
			  and abs( v.rect.centery - pos[1] ) < radius:
			  	return v
		return None

	#---------------------------------------------------------------------
	def HighlightRideNear(self,pos):
		events.Fire( "UnHighlightRide" )

		for r in self.rideGroup.sprites():
			if r.rect.collidepoint( pos ):
				events.Fire( "HighlightRide", r )
				return

	#---------------------------------------------------------------------
	def HighlightLineupNear(self,pos):
		events.Fire( "UnHighlightLineup" )

		for l in self.lineupGroup.sprites():
			if l.rect.collidepoint( pos ):
开发者ID:sjbrown,项目名称:theme_park_simulation,代码行数:70,代码来源:parkpanel.py

示例2: main

# 需要导入模块: from pygame.sprite import RenderUpdates [as 别名]
# 或者: from pygame.sprite.RenderUpdates import sprites [as 别名]
def main():
	"""this function is called when the program starts.
	   it initializes everything it needs, then runs in
	   a loop until the function returns."""
#Initialize Everything
	global screen
	screen = None
	pygame.init()
	screen = pygame.display.set_mode(RESOLUTION)
	pygame.display.set_caption('Example Poutine Window')

#Create The Backgound
	bg = pygame.Surface( RESOLUTION )
	bg.fill( BGCOLOR )

#Display The Background
	screen.blit(bg, (0, 0))
	pygame.display.flip()

#Prepare Game Objects
	clock = pygame.time.Clock()

	label = LabelSprite( 'foo' )
	label.rect.move_ip( 100, 100 )
	#this will be the callback function of the button
	def buttonWasClicked():
		print "button clicked"
	button = ButtonSprite( 'bar', None, buttonWasClicked )
	button.rect.move_ip( 100, 300 )

	tEntry = TextEntrySprite('textentry')
	tEntry.rect.move_ip( 100, 400 )

	allWidgets = RenderUpdates()
	allWidgets.add( label )
	allWidgets.add( button )
	allWidgets.add( tEntry )



#Main Loop
	while 1:
		timeChange = clock.tick(40)

	#Handle Input Events
		oldEvents = []
		remainingEvents = pygame.event.get()
		for event in remainingEvents:
			oldEvents.append( remainingEvents.pop(0) )
			if event.type == QUIT:
				return
			elif event.type == KEYDOWN and event.key == K_ESCAPE:
				return

			elif event.type == KEYDOWN:
				key = event.unicode.encode("ascii")
				if key and key in string.printable:
					for s in  allWidgets.sprites():
						if hasattr( s, "OnKeyPressed" ):
							s.OnKeyPressed( key )
				else:
					key = event.key
					for s in  allWidgets.sprites():
						if hasattr( s, "OnMetaPressed"):
							s.OnMetaPressed( key )
			elif event.type == MOUSEMOTION:
				for sprite in  allWidgets.sprites():
					if hasattr( sprite, "OnMouseMove" ):
						sprite.OnMouseMove( event.pos )
			elif event.type == MOUSEBUTTONDOWN:
				for sprite in  allWidgets.sprites():
					if hasattr( sprite, "OnMouseClick" ):
						sprite.OnMouseClick( event.pos )

	#Draw Everything
		allWidgets.clear( screen, bg )
		allWidgets.update( )
		changedRects =  allWidgets.draw(screen)
		pygame.display.update( changedRects )


#Game Over
	pygame.quit()
开发者ID:sjbrown,项目名称:poutine,代码行数:85,代码来源:example.py

示例3: GameView

# 需要导入模块: from pygame.sprite import RenderUpdates [as 别名]
# 或者: from pygame.sprite.RenderUpdates import sprites [as 别名]

#.........这里部分代码省略.........


	def OnBubbleLaunch( self, centerx ):
		#log.debug( 'bubble birth' )
		if self.ins_spin:
			self.ins_spin.kill()
			self.ins_spin = None

		bubble = Bubble( 438 )
		minX = 140
		maxX = 790
		xpos = int(rng.normalvariate( 0,50 )) + centerx
		xpos = min( xpos, maxX )
		xpos = max( xpos, minX )
		bubble.rect.x = xpos
		bubble.rect.bottom = 470
		self.bubbleGroup.add( bubble )

	def Update( self, timeChange ):
		self.viewOnlyGroup.update( timeChange )
		self.bubbleGroup.update( timeChange )

		self.currentTime += timeChange
		#twoSecondsAgo = self.currentTime - 2000
		#halfSecondAgo = self.currentTime - 500

		heaterRange = [444,530]

		for sb in self.purseStatusbars:
			sb.update()

	def OnBladderShoot( self, power, height ):
		if self.ins_press:
			self.ins_press.kill()
		if height > 3:
			gey = Geyser( "tall" )
		else:
			gey = Geyser( "short" )
		colorName = self.stripeOrder[height]
		gey.rect.midtop = (450, self.stripeHeights[colorName])
		self.viewOnlyGroup.add( gey )

		self.viewOnlyGroup.add( self.squeezePrompt )
		#print len(self.viewOnlyGroup)

	def OnBladderShootStop( self ):
		self.viewOnlyGroup.remove( self.squeezePrompt )

	def OnBladderVent( self, power, height ):
		if height > 3:
			gey = Geyser( "tall" )
		else:
			gey = Geyser( "short" )
		colorName = self.stripeOrder[height]
		gey.rect.midtop = (450, self.stripeHeights[colorName])
		self.viewOnlyGroup.add( gey )

	def OnDropBirth( self, drop ):
		self.lowGroup.add( drop )

	def OnStripeHitMaxOpacity(self, stripe):
		yPos = self.stripeHeights[stripe.name]+4
		if yPos in [lock.rect.top for lock in self.locks]:
			#log.debug( 'already have that lock' )
			return
		lock = Lock()
		lock.rect.topleft = (111, self.stripeHeights[stripe.name]+4 )
		self.hiGroup.add( lock )
		self.locks.append( lock )

	def OnHeaterBirth( self, heater ):
		switch= { SolarHeater:'violet',
		          WaterWheelHeater:'blue',
		          WindHeater:'green',
		          FireHeater:'yellow',
		          NuclearHeater:'orange',
		}
		klass = heater.__class__
		heater.rect.topleft = self.heaterRects[switch[klass]].topleft
		self.hiGroup.add( heater )

	def OnBladderVentingImminent( self ):
		if self.ins_press == None:
			self.ins_press = InstructionPress()
			self.ins_press.rect.topleft = (560, 300)
			self.viewOnlyGroup.add( self.ins_press )

	def Kill( self ):
		controller = mvcState.GetController()
		controller.gameEventListeners.remove( self )
		for s in self.viewOnlyGroup.sprites():
			s.kill()
		for s in self.bubbleGroup.sprites():
			s.kill()

	def OnUserQuit( self ):
		self.Kill()

	def OnWin( self, time, money ):
		self.Kill()
开发者ID:sjbrown,项目名称:steam_jet_blower,代码行数:104,代码来源:model.py

示例4: Random

# 需要导入模块: from pygame.sprite import RenderUpdates [as 别名]
# 或者: from pygame.sprite.RenderUpdates import sprites [as 别名]
class GameWorld:
    """Hold Game World objects

       Initialize display
       >>> import pygame as pygame
       >>> import random
       >>> from widget import *
       >>> randomizer = Random()

       Create a gameworld
       >>> g = GameWorld(randomizer)
       >>> s = pygame.surface.Surface((30,30))
       >>> w = Widget(s, (0,0,30,30), (0,0))

       Add and test bomberman to world
       >>> g.appendBomber(w)
       >>> g.bomberGroup
       <RenderUpdates(1 sprites)>

       Add and test an immutable to world
       >>> w1 = Widget(s, (0,0,30,30), (0,0))
       >>> g.appendImmutable(w1)
       >>> g.immutableGroup
       <RenderUpdates(1 sprites)>

       Add another bomberman to world
       >>> p2 = Widget(s, (100,100, 30,30), (0,0))
       >>> g.appendBomber(p2)

       Add a bomb to the game world
       >>> bomb = Widget(s, (100,100,30,30), (0,0))
       >>> g.appendBomb(bomb)

       Check the number of objects in game world
       >>> g.universalGroup
       <RenderUpdates(4 sprites)>

       Detonate bomb in game world
       >>> g.detonateBomb(bomb)
       >>> g.bombGroup
       <RenderUpdates(0 sprites)>
       >>> g.universalGroup
       <RenderUpdates(3 sprites)>

       Add bomb to populatedBombGroup
       >>> g.appendPopulatedBomb(bomb)
       >>> g.populatedBombGroup
       <RenderUpdates(1 sprites)>

       Add an explosion to game world
       >>> explosion = Widget(s, (0,0,30,30),(0,0))
       >>> g.appendExplosion(explosion)
       >>> g.explosionGroup
       <RenderUpdates(1 sprites)>

       Add a power up to game world
       >>> powerup = Widget(s,(0,0,30,30),(0,0))
       >>> g.appendPowerUp(powerup)
       >>> g.powerUpGroup
       <RenderUpdates(1 sprites)>

       Remove power up from game world
       >>> g.removePowerUp(powerup)
       >>> g.powerUpGroup
       <RenderUpdates(0 sprites)>

       Test bomberstrafe algorithm
       >>> g.bomberStrafe([98, 100])
       (98, 100)

       >>> g.bomberStrafe([90, 100])
       (80, 100)

       >>> g.bomberStrafe([98, 90])
       (98, 80)

       >>> g.bomberStrafe([139, 140])
       (144, 144)

       Test worldWrap
       >>> g.mapColumns = 19
       >>> bomb = Bomb(s, (0,0,30,30),3,3,3,(0,0))
       >>> bomb.beingPunched = 1
       >>> g.appendBomb(bomb)
       >>> bomb.setPosition((10,100))
       >>> g.worldWrap(bomb)
       >>> bomb.getPosition()
       (624, 100)

       >>> bomb.setPosition((630,100))
       >>> g.worldWrap(bomb)
       >>> bomb.getPosition()
       (16, 100)

       >>> g.mapRows = 19
       >>> bomb.setPosition((100, 10))
       >>> g.worldWrap(bomb)
       >>> bomb.getPosition()
       (100, 656)

#.........这里部分代码省略.........
开发者ID:bry,项目名称:pybomber2,代码行数:103,代码来源:gameworld.py


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