本文整理匯總了Python中alien.Alien.set_target方法的典型用法代碼示例。如果您正苦於以下問題:Python Alien.set_target方法的具體用法?Python Alien.set_target怎麽用?Python Alien.set_target使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類alien.Alien
的用法示例。
在下文中一共展示了Alien.set_target方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: loop
# 需要導入模塊: from alien import Alien [as 別名]
# 或者: from alien.Alien import set_target [as 別名]
def loop(self):
count = 0
while 1:
count = (count+1)%50
self.clock.tick(25)
#handle input events
ok = self.handle_keys()
if ok == False:
return
if self.game_started == False:
start_text = self.font.render('Press any key to start', 2, (0,0,0))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
continue
if self.game_paused == 1:
start_text = self.font.render('Game paused', 2, (255,255,255))
self.screen.blit(start_text, (150, 200))
pygame.display.flip()
continue
new_enemies = self.level.getenemies()
for enemy_y in new_enemies:
#if random.randint(0,50) == 0:
alien = Alien(enemy_y)
alien.set_target(self.ship)
self.enemies.add(alien)
#aliens damaging the player, remove them
damage = pygame.sprite.spritecollide(self.ship, self.enemies, True)
self.process_powerups()
#check colisions with stage
if self.level.checkcollide(self.ship.rect):
#add some fancy explosions in the damage area
self.explosions.add(Explosion(pygame.Rect(self.ship.rect.x,self.ship.rect.y,0,0)))
damage.append(1)
#Apply damages to the player
if len(damage) > 0:
self.background.warning()
self.ship.damage()
self.lifemeter.shake()
self.explosions.add(Explosion(self.ship.rect))
self.sounds['warning'].play()
self.lifemeter.life = self.ship.life
if self.lifemeter.life < 1:
self.game_finished = True
self.sounds['warning'].stop()
#print (pygame.sprite.spritecollide(ship, level, True))
#aliens hit by the fire, remove them
penetration = self.ship.powerup['penetrate']
for fireball in self.fire:
hit = pygame.sprite.spritecollide(fireball, self.enemies, True)
for dead in hit:
if dead.has_powerup():
powerup = Powerup(dead.rect, dead.value)
self.powerups.add(powerup)
self.explosions.add(Explosion(pygame.Rect(dead.rect.x,dead.rect.y,0,0)))
self.score+=dead.value*1000
if penetration == False:
fireball.kill()
#draw the level
all_sprites = pygame.sprite.Group()
all_sprites.add(self.player.sprites())
all_sprites.add(self.enemies.sprites())
all_sprites.add(self.powerups.sprites())
all_sprites.add(self.fire.sprites())
all_sprites.add(self.hud.sprites())
all_sprites.add(self.explosions.sprites())
all_sprites.update()
self.level.update()
self.background.update()
#Move and draw the background
score_text = 'Score: {0}'.format((self.score))
text = self.font.render(score_text, 1, (255, 255, 255))
text_shadow = self.font.render(score_text, 1, (0,0,0))
self.screen.blit(self.background, (0, 0))
self.screen.blit(self.level, (0, 0))
self.screen.blit(text_shadow, (12, 12))
self.screen.blit(text, (10, 10))
if self.game_finished == True:
gameover_text = self.font.render("Game Over", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 200))
gameover_text = self.font.render("Press Esc", 2, (255, 255, 255))
self.screen.blit(gameover_text, (280, 230))
else:
#.........這裏部分代碼省略.........