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


Python Ball.die方法代码示例

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


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

示例1: Game

# 需要导入模块: from ball import Ball [as 别名]
# 或者: from ball.Ball import die [as 别名]

#.........这里部分代码省略.........
		self.frame_update += 1
		if time.time() - self.second_count_update >= 1:
			self.second_count_update = time.time()
			print self.frame_update, "updates per second"
			self.frame_update = 0
		
		if self.menu:
			menu_choice = self.menu_obj.update(self.menu, self)
			if menu_choice == "Play":
				self.menu = False
			
			#if menu_choice == "Options":
			#	self.option_menu = True
				
		#Keyboard and mouse events
		for e in pygame.event.get():
			#Clicking the cross to quit
			if e.type == pygame.QUIT:
				raise SystemExit, "QUIT"
			
			#All the input is sent to the Player object
			if (e.type == pygame.KEYDOWN or e.type == pygame.KEYUP) and not self.menu:
				self.player.input(e.type, e.key)
			
			if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
				raise SystemExit, "ESCAPE"
				
			#Pressing V switch between 2 resolution. We could add a menu to choose the resolution later
			if e.type == pygame.KEYDOWN and e.key == pygame.K_v:
				if pygame.display.Info().current_w == 1200:	
					self.__init__(800, 640)
					
				elif pygame.display.Info().current_w == 800:
					self.__init__(1200, 960)

			#pressing B mute the sound
			if e.type == pygame.KEYDOWN and e.key == pygame.K_n:
				self.sound_factory.change_volume()
				
			#If player has no life left, he can press SPACE to restart
			if self.game_over and e.type == pygame.KEYDOWN and e.key == pygame.K_SPACE:
				self.__init__(pygame.display.Info().current_w, pygame.display.Info().current_h)
			
			#If game is paused, player can press SPACE to unpause
			if self.pause and e.type == pygame.KEYDOWN and e.key == pygame.K_SPACE:
				self.pause = False
				
			elif not self.pause and e.type == pygame.KEYDOWN and e.key == pygame.K_SPACE:
				self.pause = True
				
				
		if not self.game_over and not self.pause and not self.menu:
			#Entities update
			self.player.update(self.items, self.sound_factory)
			self.items.update()
			
			#If ball.update() returns 1 it means the player has died
			if self.ball.update(self.player, self.blocks, self.entities, self.items, self.sound_factory) == 1:
					self.player.die()
					self.ball.die()
					if self.player.lives < 0:
						self.game_over = True
					else:
						self.pause = True
						print "pause = ", self.pause

	def draw(self):
		self.frame_draw += 1
		if time.time() - self.second_count_draw >= 1:
			self.second_count_draw = time.time()
			print self.frame_draw, "draws per second"
			self.frame_draw = 0
			
		#Graphics drawing
		self.screen.blit(self.background, (0, 0))
		
		if not self.menu:
			self.entities.draw(self.screen)
			
			#Draw the score
			score_text = self.fontObj.render(str(self.player.score) + " points", 1, (255,255,255))
			self.screen.blit(score_text, (10, 5))
			
			#Draw lives
			lives_text = self.fontObj.render(str(self.player.lives) + " lives", 1, (255,255,255))
			self.screen.blit(lives_text, (10, 25))
			
			#Draw game over and pause message
			if self.game_over:
				game_over_text = self.fontObj.render("Game over :( Press space to restart", 1, (255,255,255))
				self.screen.blit(game_over_text, (pygame.display.Info().current_w/2 - game_over_text.get_rect().width/2, pygame.display.Info().current_h/2))
			
			if self.pause:
				game_over_text = self.fontObj.render("Press space to start", 1, (255,255,255))
				self.screen.blit(game_over_text, (pygame.display.Info().current_w/2 - game_over_text.get_rect().width/2, pygame.display.Info().current_h/2))
				
		elif self.menu:
			self.menu_obj.draw(self.screen)

		pygame.display.flip()	
开发者ID:kirokirokiro,项目名称:breakout,代码行数:104,代码来源:breakout.py


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