本文整理匯總了Python中whale.Whale.shoot方法的典型用法代碼示例。如果您正苦於以下問題:Python Whale.shoot方法的具體用法?Python Whale.shoot怎麽用?Python Whale.shoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類whale.Whale
的用法示例。
在下文中一共展示了Whale.shoot方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Room
# 需要導入模塊: from whale import Whale [as 別名]
# 或者: from whale.Whale import shoot [as 別名]
class Room(GameState):
def __init__(self, whale=None, enemies=None):
super().__init__()
self.background = 210, 210, 210
heart_path = os.path.join(os.path.realpath(''), 'Images', 'heart.gif')
self.heart = pygame.image.load(heart_path).convert()
halfheart_path = os.path.join(os.path.realpath(''), 'Images', 'halfheart.gif')
self.halfheart = pygame.image.load(halfheart_path).convert()
self.healthbar = pygame.sprite.Group()
if whale == None:
self.whale = Whale()
else:
self.whale = whale
if enemies == None:
enemies = [Octopus()]
self.set_enemies(enemies)
self.whale_is_dead = False
self.player_projectiles = pygame.sprite.Group()
self.enemy_projectiles = pygame.sprite.Group()
self.sprites = pygame.sprite.Group(self.whale, self.enemy_sprites,
self.player_projectiles, self.enemy_projectiles, self.healthbar)
self.update_healthbar()
self.next_state = "LevelOne"
def set_enemies(self, enemies):
self.enemy_sprites = pygame.sprite.Group(enemies)
def calc_dmg(self):
player_projectiles = self.player_projectiles
enemies = self.enemy_sprites
for enemy in enemies:
for projectile in player_projectiles:
if projectile.hitbox.colliderect(enemy.hitbox):
enemy.health -= projectile.damage
if enemy.health <= 0:
enemy.kill()
projectile.kill()
enemy_hitboxes = [enemy.hitbox for enemy in self.enemy_sprites]
whale_collide = self.whale.hitbox.collidelist(enemy_hitboxes)
if whale_collide != -1:
if not self.whale.invincible:
self.whale.invincible = 50
self.whale.health -= 1
if self.whale.health <= 0:
self.whale.kill()
self.whale_is_dead = True
def update_healthbar(self):
pos = [0, 0]
for i in range(int(self.whale.health/2)):
self.screen.blit(self.heart.copy(), pos)
pos[0] += 50
if self.whale.health%2 == 1:
self.screen.blit(self.halfheart, pos)
def handle_event(self, event):
super().handle_event(event)
if event.type == KEYDOWN:
if event.key == K_UP or event.key == K_w:
self.whale.state = 'moveup'
if event.key == K_DOWN or event.key == K_s:
self.whale.state = 'movedown'
if event.key == K_LEFT or event.key == K_a:
self.whale.state = 'moveleft'
if event.key == K_RIGHT or event.key == K_d:
self.whale.state = 'moveright'
elif event.type == KEYUP:
if (event.key == K_UP or event.key == K_w) and self.whale.state == 'moveup':
self.whale.state = 'still'
if (event.key == K_DOWN or event.key == K_s) and self.whale.state == 'movedown':
self.whale.state = 'still'
if (event.key == K_LEFT or event.key == K_a) and self.whale.state == 'moveleft':
self.whale.state = 'still'
if (event.key == K_RIGHT or event.key == K_d) and self.whale.state == 'moveright':
self.whale.state = 'still'
elif event.type == MOUSEBUTTONDOWN:
bullet_sprite = self.whale.shoot()
self.player_projectiles.add(bullet_sprite)
self.sprites.add(bullet_sprite)
def is_cleared(self):
if self.enemy_sprites.sprites() == []:
self.cleared = True
def update(self):
#.........這裏部分代碼省略.........