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


Python Ship.resetToStartingPosition方法代码示例

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


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

示例1: __init__

# 需要导入模块: import Ship [as 别名]
# 或者: from Ship import resetToStartingPosition [as 别名]

#.........这里部分代码省略.........
				self.explosion_sprites.remove(explosion)
				
		for enemy in self.enemy_sprites: #Enemies
			if enemy.removeMe == True:
				self.enemy_sprites.remove(enemy)	

		for bullet2 in self.en_bullet_sprites: #Enemy bullets
			if bullet2.removeMe == True:
				self.en_bullet_sprites.remove(bullet2)
	
	def gameOver(self): #GG!
		self.END_GAME = True
		pygame.key.set_repeat(120, 60)
		name = inputbox.ask(self.screen, "GG! Your name?")
		self.setHighscore(name)
		
	def drawScore(self):
		text = self.font.render("{0:d}".format(self.SCORE), 1, (255, 255, 0))
		textpos = text.get_rect()
		textpos.x = Settings.SCREEN_WIDTH/2
		textpos.y = Settings.SCREEN_HEIGHT - Settings.FONT_SIZE
		self.screen.blit(text, textpos)

	def MainLoop(self):
		self.LoadSprites()
		pygame.key.set_repeat(10, 20)#Input every 20ms, read every 10mss
		
		#Clear background
		self.backgrounds.add(pygame.sprite.RenderPlain(Background(0,0*Settings.BACKGROUND_HEIGHT)))
		self.backgrounds.add(pygame.sprite.RenderPlain(Background(0,1*Settings.BACKGROUND_HEIGHT)))
		self.backgrounds.add(pygame.sprite.RenderPlain(Background(0,2*Settings.BACKGROUND_HEIGHT)))
		
		self.clear_bg = pygame.Surface(self.screen.get_size())
		self.clear_bg = self.clear_bg.convert()
		self.clear_bg.fill((0,0,0))
		
		self.music.play()
		
		while self.END_GAME != True:
			self.clock.tick(600) #Cap framerate at 60 fps
			if self.RESPAWNING == True:
				if self.respawn_ticker % 120 == 0 and self.respawn_ticker > 119: #Periodic explosions, leaving 120 frames for respawn "stillness", but still exploding at frame = 120
					self.explosivifySprite(self.last_death_rect)
				elif self.respawn_ticker < 120:
					self.ship.resetToStartingPosition()
				if self.respawn_ticker == 0:
					if self.GAME_OVER:
						self.gameOver()
					else:
						self.ship.giveInvinciblity()
						self.RESPAWNING = False
				self.respawn_ticker -= 1
			else:
				#Event checking
				self.handleEvents()
				#Check if player can shoot
				self.checkShoot()
				#Collisions
				self.checkCollisions()
			####End RESPAWNING if statement - WARNING!! - anything outside will run during respawn!
			
			#Update sprites
			self.updateSprites()
			#Spawn enemies
			self.spawnEnemies()
			#Drawing sprites
			self.drawSprites()
			#Update score
			self.drawScore()
			
			pygame.display.flip()
			
			#Clean all entity groups up	
			self.cleanupSprites()
			#########
			credits_ticker = 600 * len(self.HIGHSCORES) * 2
		while self.END_CREDITS != True:
			font = pygame.font.Font(None, 36) #No specific font, size 36 pt
			text = font.render("GAME OVER!", 1, (255, 0, 0))#Gameover in red -> (255,0,0)
			textpos = text.get_rect()
			textpos.centerx = Settings.SCREEN_WIDTH/2
			
			

			credits_ticker -= 1
			if credits_ticker <= 0:
				self.END_CREDITS = True
			self.drawSprites()
			
			for i in range(len(self.HIGHSCORES)):
				scores = self.font.render(self.HIGHSCORES[i], 1, (255, 255, 0))
				textpos2 = scores.get_rect()
				textpos2.centerx = Settings.SCREEN_WIDTH/2
				textpos2.y = (i+2)*Settings.FONT_SIZE
				self.screen.blit(scores, textpos2)
			self.screen.blit(text, textpos)
			
			self.explosion_sprites.update()
			self.cleanupSprites() #Remove explosions
			pygame.display.flip()
开发者ID:spencer-hanson,项目名称:PythonGame,代码行数:104,代码来源:pygame_project.py


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