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


Python Ship.damage方法代码示例

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


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

示例1: Vacuum

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

#.........这里部分代码省略.........
    #Main Loop
    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)))
开发者ID:codelurker,项目名称:VacuumFire,代码行数:70,代码来源:main.py

示例2: Vacuum

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

#.........这里部分代码省略.........
                self.hud.add(Flying_Label( self.ship.rect, 'Energy'))
                self.lifemeter.life = self.ship.life
            elif powerup_obtained.type == 1 and self.ship.powerup['speedup'] < 5:
                self.ship.powerup['speedup'] += 1 
                self.powerup_speed.set_status(self.ship.powerup['speedup'])
                self.hud.add(Flying_Label( self.ship.rect, 'Speed up'))
                #print "Increase speed to {0}".format(self.ship.powerup['speedup'])
            elif powerup_obtained.type == 2 and Laser.max_lasers < 5:
                Laser.max_lasers += 1 
                Laser.move += 2 
                self.powerup_weapon.set_status(Laser.max_lasers)
                print "Increase lasers to {0}".format(Laser.max_lasers)
                self.hud.add(Flying_Label( self.ship.rect, 'Lasers'))

            elif powerup_obtained.type == 3 and self.ship.powerup['penetrate'] == False:
                print "Activate penetration"
                self.hud.add(Flying_Label( self.ship.rect, 'Penetration'))
                self.ship.powerup['penetrate'] = True
            elif powerup_obtained.type == 4:
                print "Activate buddy"
                self.buddies.add(Buddy(self.ship))
                self.ship.buddies += 1
                self.powerup_buddy.set_status(self.ship.buddies)
            else:
                print "No more powerups available"

    def add_explosion(self, rect):
        self.explosions.add(Explosion(rect.copy()))

    def add_enemylaser(self, laser):
        self.enemylasers.add(laser)

    def process_stagecollisions(self):
        damage = []
        #check colisions with stage
        side = self.level.checkcollide(self.ship.rect)
        if side != 0:
            #add some fancy explosions in the damage area
            self.explosions.add(Explosion(pygame.Rect(self.ship.rect.x,self.ship.rect.y + side *self.ship.rect.height,0,0)))
            damage.append(1)
        return damage

    def process_damage(self, damage):
        #Apply damages to the player
        if len(damage) > 0:
            self.background.warning()
            self.ship.damage()
            self.lifemeter.shake()
            self.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()

    def process_killedaliens(self):
        #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)
            #Check collisions with masks since the minibosses can have funny shapes
            enemies_hit = []
            for miniboss in self.minibosses:
                if pygame.sprite.collide_mask(fireball, miniboss):
                    fireball.kill()
                    enemies_hit.append(miniboss)
开发者ID:timepilot,项目名称:VacuumFire,代码行数:70,代码来源:vacuum.py


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