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


Python Ship.hasInvincibility方法代码示例

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


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

示例1: __init__

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

#.........这里部分代码省略.........
				tmp = random.randint(0,2)
				if tmp == 0:
					new_enemy1 = Enemy01()
					self.enemy_sprites.add(new_enemy1)
				tmp = random.randint(0,3)
				if tmp == 0:
					new_enemy2 = Enemy02()
					self.enemy_sprites.add(new_enemy2)
				new_enemy = Enemy03()
				self.enemy_sprites.add(new_enemy)
				self.spawn_ticker = self.MAX_SPAWN_TICKER
		elif self.enemies_killed >= Settings.WAVE3_PASS and self.wave3_pass == False:
			self.enemies_killed = 0
			self.wave3_pass = True
		#Boss
		if self.wave1_pass and self.wave2_pass and self.wave3_pass and self.boss_spawned == False:
			self.enemy_sprites.add(Boss())
			self.music = Music("Blaze")
			self.music.play()
			self.boss_spawned = True

	def checkCollisions(self):
		hit_enemies = pygame.sprite.groupcollide(self.enemy_sprites, self.bullet_sprites, False, True) #Check collide between two sprite groups, remove bullet on true collision
		for enemy in hit_enemies:
			if enemy.hp - 1 <= 0:
				self.explosivifySprite(enemy.rect)
				self.SCORE += enemy.bounty
				self.enemies_killed += 1
				enemy.removeMe = True
			else:
				enemy.hp -= 1
				self.explosivifySprite(enemy.rect, 1)

		if self.ship.hasInvincibility() == False:
			player_isHit = False
			hit_sprites = pygame.sprite.groupcollide(self.enemy_sprites, self.ship.hitbox_sprite, False, False) #Check between ship and enemies
			for enemy_sprite in hit_sprites:
				player_isHit = True
				self.explosivifySprite(enemy_sprite.rect)
				enemy_sprite.removeMe = True
				self.enemies_killed += 1
				
			hit_sprites = pygame.sprite.groupcollide(self.en_bullet_sprites, self.ship.hitbox_sprite, False, False)
			for enemy_bullet in hit_sprites: 
				player_isHit = True
				enemy_bullet.removeMe = True
						
			if player_isHit == True:
				self.LIVES -= 1
				self.last_death_rect = self.ship.rect
				self.ship_lives_sprites.loseLife()
				self.respawn_ticker = Settings.RESPAWN_TIME * 120 * 2 # fps x seconds x 2(for explosion and respawn) = frames to respawn
				self.RESPAWNING = True

		if self.LIVES < 1: #Classic game programming 'if' statement :)
			self.GAME_OVER = True

	def handleEvents(self):
		for event in pygame.event.get():
			keys = pygame.key.get_pressed()
			if event.type == pygame.QUIT:
					sys.exit()
			elif event.type == KEYDOWN: #Key presses
				self.ship.move() #Move the ship
				if keys[Settings.SHOOT]:
					self.shooting = True
开发者ID:spencer-hanson,项目名称:PythonGame,代码行数:70,代码来源:pygame_project.py


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