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


Python Player.get_pos方法代码示例

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


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

示例1: Scene

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

#.........这里部分代码省略.........
	#--------------------------------------LOGIC PROCESSING SECTION-----------------------------------------------
	def process_ball(self):
		# Check if hit goals
		if (pygame.sprite.collide_mask(self.ball, self.goal[0])) is not None:
			self.sound_list['goal'].play()
			self.hud.update_right_score()
			self.match_state = Match_state.GOAL
			return
		elif pygame.sprite.collide_mask(self.ball, self.goal[1]) is not None:
			self.sound_list['goal'].play()
			self.hud.update_left_score()
			self.match_state = Match_state.GOAL
			return

		# Check if hit field's border
		self.process_collide_border()

		# Check if hit players 
		player_list = [players for sublist in (list(self.teams[Team_side.LEFT].values()) + list(self.teams[Team_side.RIGHT].values())) for players in sublist]
		hit_player = pygame.sprite.spritecollideany(self.ball, player_list, pygame.sprite.collide_circle)

		if hit_player is not None:
			self.sound_list['ball_kick'].play()
			self.ball.collide_object(hit_player)

		# Process AI list(chain(*self.teams[Team_side.LEFT].values()))
		"""for position in self.teams[Team_side.RIGHT].keys():
			action = 'move_up' if random.randrange(0, 2) is 0 else 'move_down'
			apply_all(self.teams[Team_side.RIGHT][position], action)"""

	def process_collide_border(self):
		"""Check if ball touch field's border and calculate rebound direction
		"""
		ball_pos = self.ball.get_pos()

		if ball_pos[0] < 50:
			self.ball.move_to(51, self.ball.get_pos()[1])
			self.ball.toggle_x_vel()
		elif  (ball_pos[0] + self.ball.get_width()) > SCREEN_WIDTH - 50:
			self.ball.move_to(SCREEN_WIDTH - 51 - self.ball.get_width(), self.ball.get_pos()[1])
			self.ball.toggle_x_vel()
		elif ball_pos[1] < 20:
			self.ball.move_to(self.ball.get_pos()[0], 21)
			self.ball.toggle_y_vel()
		elif (ball_pos[1] + self.ball.get_height()) > SCREEN_HEIGHT - 20:
			self.ball.move_to(self.ball.get_pos()[0], SCREEN_HEIGHT - 21 - self.ball.get_height())
			self.ball.toggle_y_vel()

	def calculate_position(self):
		"""Calculate and move ball and players to the right position
		"""

		# Calculate ball postion
		x = (SCREEN_WIDTH - self.ball.get_width()) // 2
		y = (SCREEN_HEIGHT - 8 - self.ball.get_height()) // 2
		self.ball.move_to(x, y)

		# Generate and calculate red team players
		for i in range(len(self.formation[Team_side.LEFT])):
			if len(self.teams[Team_side.LEFT]) == 4:
				apply_all(self.teams[Team_side.LEFT][self.position[i]], 'kill')

			self.teams[Team_side.LEFT].update({self.position[i]: []})

			# Calculate offset
			x_offset = 100
开发者ID:tr1et,项目名称:pygame-table-football,代码行数:70,代码来源:Scene.py

示例2: Scene

# 需要导入模块: import Player [as 别名]
# 或者: from Player import get_pos [as 别名]
class Scene(State):
	def __init__(self):
		super(Scene, self).__init__()

		pygame.mixer.init(44100, -16, 4, 2048)
		self.all_object_list = pygame.sprite.LayeredUpdates()
		self.zombie_list = pygame.sprite.Group()
		self.blood_splash = BloodSplash()
		self.background = Object()
		self.player = Player()
		self.zombie_sprite = []
		self.grave_list = []
		self.hud = HUD()
		self.sound_list = dict()
		self.bg_music = pygame.mixer.music
		self.game_over = False
		self.time = pygame.time.get_ticks()

	def init(self):
		self.read_scene()

		# Bring cursor to front
		self.all_object_list.move_to_front(self.player)

		# Set background music
		self.sound_list['background'].play().set_endevent(pygame.constants.USEREVENT)

		# Scale background to screen size
		self.background.image = pygame.transform.scale(self.background.image, (SCREEN_WIDTH, SCREEN_HEIGHT))

	def process_events(self, event):
		if event.type == pygame.USEREVENT:
			self.sound_list['background'].play()
		elif event.type == pygame.MOUSEBUTTONDOWN:
			self.sound_list['gunshot'].play()
			self.process_raycast()
		elif event.type == pygame.KEYDOWN:
			if (event.key == pygame.K_p):
				if self.is_running:
					self.pause()
				else:
					self.resume()

	def update(self):
		if (not self.is_running):
			return

		# Process game
		self.process_zombie()

		# Update all objects
		self.all_object_list.update(self.hud)
		self.hud.update()

	def draw(self, screen):
		screen.fill(WHITE)
		self.all_object_list.draw(screen)
		apply_all(self.zombie_list.sprites(), 'show_timer', screen)
		self.hud.draw(screen)

	#--------------------------------------LOGIC PROCESSING SECTION-----------------------------------------------
	def process_zombie(self):
		# Randomly choose an interval between 0.5 to 1.5 second to spawn another zombie
		if (pygame.time.get_ticks() - self.time >= random.randrange(1, 3) * 500):
			# Random location for zombie
			zombie_pos = random.randrange(0, len(self.grave_list))

			# Check if grave's position already had zombie
			if (not next((True for zombie in self.zombie_list.sprites() if zombie.pos == zombie_pos), False)):
				# Randomly pick zombie from zombie sprite list
				zombie = deepcopy(self.zombie_sprite[random.randrange(0, len(self.zombie_sprite))])
				zombie.set_pos(zombie_pos)

				# Set zombie to the right position
				zombie.move_to(*self.grave_list[zombie_pos].get_pos())
				zombie.translate(35, -10)

				# Set zombie layer
				zombie.set_layer(self.grave_list[zombie_pos]._layer - 1)

				# Add to zombie list and object list
				self.zombie_list.add(zombie)
				self.all_object_list.add(zombie)

			# Reset timer
			self.time = pygame.time.get_ticks()

	def process_raycast(self):
		mouse_pos = pygame.mouse.get_pos()

		hit_zombie = next((zombie for zombie in self.zombie_list.sprites() if zombie.collide_point(list(map(operator.sub, mouse_pos, zombie.get_pos())))), None)

		if (hit_zombie is not None):
			# Play zombie's death sound
			self.sound_list['dying_scream'].play()

			# Update hit count
			self.hud.update_hit()

			# Splash blood
#.........这里部分代码省略.........
开发者ID:tr1et,项目名称:pygame-hittheblock,代码行数:103,代码来源:Scene.py


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