示例#1
0
    def do_events(self):
        self.next_frame()
        #Emergency maneuvers
        for obj in self.game.units + self.game.trees:
            if obj != self:
                if (obj.x, obj.y) == (self.x, self.y):
                    self.sidestep()
                    self.reset()

        if self.current_activity == 'walking':
            if self.ticks == 2:
                self.move((self.dx, self.dy))
            elif self.ticks == 4:
                self.reset()

        elif self.current_activity == 'attacking_club':
            if self.ticks == 8:
                self.end_attack()
            elif self.ticks == 16:
                self.reset()

        elif self.current_activity == 'standing':
            if self.ticks == 4:
                self.reset()

        elif self.current_activity == 'falling':
            if self.ticks == 8:
                self.refresh_activity('dead')
                self.reset_ticks()
                self.game.corpses.append(Corpse(self.game, self))
                self.game.bandits_killed += 1
                powerup_chance = 0.40
                if random.random() < powerup_chance:
                    for powerup in self.game.powerups:
                        if (powerup.x, powerup.y) == (self.x, self.y):
                            break
                    else:
                        self.game.powerups.append(
                            HealthPowerup(self.game, (self.x, self.y), 25))
                for unit in self.game.units:
                    if unit.target_unit == self:
                        unit.target_unit = None
                self.game.remove_unit(self)
                return True

        elif self.ticks == 16:
            if self.current_activity == 'stunned':
                self.reset()

        if self.ticks == 0:
            if self.current_activity in [
                    'falling', 'dead', 'decapitated', 'dead_decapitated',
                    'stunned'
            ]:
                pass
            else:
                self.get_action()
示例#2
0
    def do_events(self, game):
        self.next_frame(game)
        for unit in game.units:
            if unit.name != self.name:
                if (unit.x, unit.y) == (self.x, self.y):
                    self.sidestep(game)
                    return

        if self.current_activity == 'walking':
            if self.ticks == 2:
                for unit in game.units:
                    if (unit.x, unit.y) == (self.x + self.dx,
                                            self.y + self.dy):
                        if unit.hostile == self.hostile:
                            if unit.current_activity == 'standing':
                                if unit.name != self.target_unit:
                                    unit.knockback(game, (self.dx, self.dy))
                if obstacle(game, (self.x + self.dx, self.y + self.dy)):
                    self.sidestep(game)
                else:
                    self.move((self.dx, self.dy))
            elif self.ticks == 4:
                self.reset(game)

        elif self.current_activity == 'standing':
            if self.ticks == 4:
                self.reset(game)

        elif self.current_activity == 'falling':
            if self.ticks == 8:
                self.refresh_activity(game, 'dead')
                game.corpses.append(Corpse(game, self))
                self.selected = False
                for unit in game.units:
                    if unit.target_unit == self.name:
                        unit.target_unit = None
                game.units.remove(self)
                return

        elif self.current_activity == 'stunned':
            if self.ticks == 16:
                self.reset(game)

        if self.ticks >= 16:
            print "WaypointedCivilian failsafe"
            self.reset(game)

        if self.ticks == 0:
            self.get_action(game)
示例#3
0
    def do_events(self, game):
        self.next_frame(game)
        for unit in game.units:
            if unit.name != self.name:
                if (unit.x, unit.y) == (self.x, self.y):
                    self.sidestep(game)
                    return

        if self.current_activity == 'walking':
            if self.ticks == 2:
                for unit in game.units:
                    if (unit.x, unit.y) == (self.x + self.dx,
                                            self.y + self.dy):
                        if unit.hostile == self.hostile:
                            if unit.current_activity == 'standing':
                                if unit.name != self.target_unit:
                                    unit.knockback(game, (self.dx, self.dy))
                if obstacle(game, (self.x + self.dx, self.y + self.dy)):
                    self.sidestep(game)
                else:
                    self.move((self.dx, self.dy))
            elif self.ticks == 4:
                self.reset(game)
                if (self.target_x, self.target_y) != (None, None):
                    if (self.x, self.y) == (self.target_x, self.target_y):
                        (self.target_x, self.target_y) = (None, None)
                        enemy_units = [
                            u for u in game.units if u.hostile != self.hostile
                        ]
                        closest_enemy = None
                        max_distance = 10
                        for u in enemy_units:
                            if distance((self.x, self.y),
                                        (u.x, u.y)) < max_distance:
                                if game.LOS((self.x, self.y), (u.x, u.y)):
                                    if closest_enemy == None:
                                        closest_enemy = u
                                    else:
                                        if distance((self.x, self.y),
                                                    (u.x, u.y)) < distance(
                                                        (self.x, self.y),
                                                        (closest_enemy.x,
                                                         closest_enemy.y)):
                                            closest_enemy = u
                        if closest_enemy:
                            self.target_unit = closest_enemy.name
                            self.point_at(closest_enemy)
                            self.refresh_activity(game, 'throwing')
                            for rocks in game.rock_piles:
                                if (rocks.x, rocks.y) == (self.x, self.y):
                                    rocks.remove_one(game)

        elif self.current_activity == 'standing':
            if self.ticks == 4:
                self.reset(game)

        elif self.current_activity == 'falling':
            if self.ticks == 8:
                self.refresh_activity(game, 'dead')
                game.corpses.append(Corpse(game, self))
                self.selected = False
                for unit in game.units:
                    if unit.target_unit == self.name:
                        unit.target_unit = None
                game.units.remove(self)
                return

        elif self.current_activity == 'stunned':
            if self.ticks == 16:
                self.reset(game)

        elif self.current_activity == 'throwing':
            if self.ticks == 4:
                game.darts.append(
                    ThrowingRock(game, 8, self.name, self.target_unit))
            elif self.ticks == 16:
                self.reset(game)

        if self.ticks >= 16:
            print "WaypointedCivilian failsafe"
            self.reset(game)

        if self.ticks == 0:
            if self.current_activity != 'throwing':
                self.get_action(game)
示例#4
0
    def do_events(self, game):
        if self.current_activity in ["falling", "decapitated"]:
            if self.current_animation.findex < len(
                    self.current_animation.frames) - 1:
                self.next_frame(game)
        else:
            self.next_frame(game)
        #Emergency maneuvers
        for obj in game.units + game.trees:
            if obj != self:
                if (obj.x, obj.y) == (self.x, self.y):
                    self.sidestep(game)
                    self.move((self.dx, self.dy))

        if self.current_activity == 'walking':
            if self.ticks == 3:
                game.pointers.append(Pointer((self.x, self.y), self.name))
                self.move((self.dx, self.dy))
            elif self.ticks == 6:
                self.reset(game)
        if self.current_activity == 'lurching':
            if self.ticks < 3:
                unit = game.unit_by_name(self.target_unit)
                self.point_at(unit)
                if distance((self.x, self.y), (unit.x, unit.y)) > 1:
                    if obstacle(game, (self.x + self.dx, self.y + self.dy)):
                        pass
                    elif not obstacle_unit(
                            game, (self.x + self.dx, self.y + self.dy)):
                        game.pointers.append(
                            Pointer((self.x, self.y), self.name))
                        self.move((self.dx, self.dy))
                    else:
                        pass
            elif self.ticks == 3:
                self.reset(game)
        elif self.current_activity == 'rising':
            if self.ticks == 8:
                self.reset(game)
                self.play_target_sound()

        elif self.current_activity == 'attacking':
            if self.ticks == 8:
                self.end_attack(game)
            elif self.ticks == 12:
                self.reset(game)

        elif self.current_activity == 'standing':
            if self.ticks == 4:
                self.reset(game)

        elif self.current_activity == 'falling':
            if self.ticks == 8:
                self.reset_ticks()
                self.refresh_activity(game, 'dead')
                game.corpses.append(Corpse(game, self))
                powerup_chance = 0.20
                if random.random() < powerup_chance:
                    for powerup in game.powerups:
                        if (powerup.x, powerup.y) == (self.x, self.y):
                            break
                    else:
                        game.powerups.append(
                            HealthPowerup((self.x, self.y), 30))
                for unit in game.units:
                    if unit.target_unit == self.name:
                        unit.target_unit = None
                game.units.remove(self)
                return True

        elif self.current_activity == 'decapitated':
            if self.ticks == 8:
                self.reset_ticks()
                self.refresh_activity(game, 'dead_decapitated')
                game.corpses.append(Corpse(game, self))
                powerup_chance = 0.20
                if random.random() < powerup_chance:
                    for powerup in game.powerups:
                        if (powerup.x, powerup.y) == (self.x, self.y):
                            break
                    else:
                        game.powerups.append(
                            HealthPowerup((self.x, self.y), 30))
                for unit in game.units:
                    if unit.target_unit == self.name:
                        unit.target_unit = None
                game.units.remove(self)
                return True

        elif self.current_activity == 'stunned':
            if self.ticks == 16:
                self.reset(game)
        if self.ticks >= 16:
            self.reset(game)
            print "Zombie failsafe"
        if self.ticks == 0:
            if self.current_activity in [
                    'falling', 'dead', 'decapitated', 'dead_decapitated',
                    'stunned'
            ]:
                #print 'bad zombie!'
                pass
            else:
                self.get_action(game)