當前位置: 首頁>>代碼示例>>Python>>正文


Python Avatar.allSprites方法代碼示例

本文整理匯總了Python中Avatar.Avatar.allSprites方法的典型用法代碼示例。如果您正苦於以下問題:Python Avatar.allSprites方法的具體用法?Python Avatar.allSprites怎麽用?Python Avatar.allSprites使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Avatar.Avatar的用法示例。


在下文中一共展示了Avatar.allSprites方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: main

# 需要導入模塊: from Avatar import Avatar [as 別名]
# 或者: from Avatar.Avatar import allSprites [as 別名]
def main():
	pygame.init()
	pygame.font.init()

	size = width, height = 800,600
	screen = pygame.display.set_mode(size)
	pygame.display.set_caption("Juego")
	clock = pygame.time.Clock()
	gameState =  GameState()

	#creating all sprites
	allSprites = pygame.sprite.Group()
	enemies =  pygame.sprite.Group()
	players = pygame.sprite.Group()

	#creating all game objects
	background =  BackgroundVScrolling(width,height)
	avatar = Avatar(width,height)
	scoreboard = ScoreBoard(width,height)

	for i in range(5):
		enemy =  Enemy((width,height))
		enemy.randomTopPosition()
		enemy.randomSpeed(x=0)
		enemy.moving = True
		enemies.add(enemy)
		allSprites.add(enemy)

	allSprites.add(avatar)
	players.add(avatar)
	avatar.allSprites = allSprites

	#Game loop
	while 1:
		for event in pygame.event.get():
			if event.type == pygame.QUIT: sys.exit()
			if event.type == pygame.KEYDOWN:
				if event.key == pygame.K_ESCAPE:
					gameState.togglePause()	
		screen.fill(colors["black"])
		milliseconds = clock.tick()  # milliseconds passed since last frame
		gameState.update()

		#these are not a sprites properly
		#Other shapes or sprites
		background.draw(screen,gameState)	

		#sprites
		players.update(gameState)
		enemies.update(gameState)

		colisionList = pygame.sprite.spritecollide(avatar, enemies, False)
		if avatar.blink == False:
			for enemy in colisionList:
				enemy.randomTopPosition()
				enemy.randomSpeed()
				enemies.add(enemy)
				allSprites.add(enemy)
				avatar.startBlink()
				gameState.lives -=1

		allSprites.draw(screen) #draws all sprites
		scoreboard.draw(screen,gameState)
		pygame.display.flip()
開發者ID:adrfrank,項目名稱:python_tarea_10,代碼行數:66,代碼來源:main.py


注:本文中的Avatar.Avatar.allSprites方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。