示例#1
0
    def process(self, dt):
        for ent, health in self.world.get_component(Health):
            if health.amount < health.maximum and not health.effects:
                if health.regen_timeout:
                    health.regen_timeout -= dt
                    if health.regen_timeout < 0:
                        health.amount += 1
                        health.regen_timeout = 0
                else:
                    health.regen_timeout = 10

            for effect in list(health.effects):
                health.regen_timeout = 0
                if not self.world.has_component(ent, Invulnerable):
                    health.amount -= effect.amount
                    if self.world.has_component(ent, Player):
                        self.world.add_component(ent, Invulnerable(1))
                    if not self.world.has_component(ent, SpriteEffects):
                        self.world.add_component(ent, SpriteEffects())
                    effects = self.world.component_for_entity(
                        ent, SpriteEffects)
                    effects.effects.append(
                        SpinEffect(play_time=0.3, speed=1000))
                    effects.effects.append(
                        FlashEffect(play_time=1, speed=10000))
                    create_sound(self.world, HURT_SOUND)
                health.effects.remove(effect)

            if health.amount <= 0:
                dispatch(self.world, ENTITY_DIED, ent)
示例#2
0
def use_throwable(world, message):
    inventory_item_ent = message.payload['item_ent']
    player_ent = message.payload['player_ent']

    for throwable in world.try_component(inventory_item_ent, Throwable):
        inventory_item = world.component_for_entity(inventory_item_ent, InventoryItem)
        position = world.component_for_entity(player_ent, Position)
        level_ent = position.level
        facing = world.component_for_entity(player_ent, Facing)
        velocity = facing.velocity()
        velocity.magnitude = throwable.throw_distance
        target_x = position.x + velocity.dx
        target_y = position.y + velocity.dy

        level_item_entity = drop_inventory_item(world, inventory_item_ent)
        world.add_component(level_item_entity, SpriteEffects(
            SpinEffect(
                play_time = throwable.throw_speed, 
                speed = throwable.throw_speed * throwable.throw_distance
            )
        ))
        world.add_component(level_item_entity, PositionEffects([
            ThrowToEffect(
                play_time = throwable.throw_speed,
                start_pos = Position(position.x, position.y, level_ent),
                end_pos = Position(target_x, target_y, level_ent),
                height = throwable.throw_distance / 3,
            )]
        ))
        create_sound(world, THROW_SOUND)
示例#3
0
def use_emitter(world, message):
    inventory_item_ent = message.payload['item_ent']
    player_ent = message.payload['player_ent']

    for emitter_comp in world.try_component(inventory_item_ent,
                                            EmitOnActivate):
        position = world.component_for_entity(player_ent, Position)
        create_particles(world, emitter_comp.emitter_factory, position)
        create_sound(world, THROW_SOUND)
示例#4
0
def collision(world, message):
    level_item_ent, inventory_ent = message.payload
    for levelItem in world.try_component(level_item_ent, LevelItem):
        if not world.has_component(level_item_ent, Timeout):
            item_ent = create_inventory_item(world, level_item_ent,
                                             inventory_ent, levelItem.name)
            if item_ent is not None:
                world.delete_entity(level_item_ent)
                create_sound(world, PICKUP_SOUND)
示例#5
0
def collision(world, message):
    goat = message.payload[0]
    for prop in world.try_component(goat, Prop):
        if prop.type == "goat":
            if world.has_component(goat, Timeout):
                return
            effects = world.component_for_entity(goat, SpriteEffects)
            effects.effects.append(ScaleUpDownEffect(0.45))
            world.add_component(goat, Timeout(0.5))
            create_sound(world, "data/sound/344057__reitanna__why2.wav")
示例#6
0
def collide(world, message):
    dispenser_ent, inventory_ent = message.payload
    for dispenser in world.try_component(dispenser_ent, Dispenser):
        inventory = world.component_for_entity(inventory_ent, Inventory)
        for inventory_item_ent in inventory.item_ents:
            if inventory_item_ent is not None:
                item_name = world.component_for_entity(inventory_item_ent, InventoryItem).name
                if item_name == dispenser.item_name:
                    return
        create_inventory_item(world, dispenser_ent, inventory_ent, dispenser.item_name)
        world.add_component(dispenser_ent, SpriteEffects(ScaleUpDownEffect(play_time=0.3, to_scale=0.8)))
        create_sound(world, PICKUP_SOUND)
示例#7
0
def collision(world, message):
    source, dest = message.payload
    if not world.has_component(source, Button) or world.has_component(
            source, Timeout):
        return
    button = world.component_for_entity(source, Button)
    if button.down_state:
        return
    button.down_state = True
    level_ent = None
    if button.in_level:
        level_ent = world.component_for_entity(source, Position).level
    dispatch(world, CHANNEL,
             (source, dest, Channel(button.channel, level_ent)))
    world.add_component(source, Timeout(1))
    create_sound(world, BUTTON_SOUND, volume=0.5)
示例#8
0
def create_player(world, input_source, mp=None):
    _, current_level = world.get_component(LevelProgression)[0]
    level_ent = current_level.level_ent

    spawners = world.component_for_entity(level_ent, PlayerSpawns).spawns
    for spawner in spawners.values():
        if spawner.first:
            break

    players = [mp for _, mp in world.get_component(MultiplayerIdentifier)]

    if mp is None:
        mp = MultiplayerIdentifier.select(players)

    player_ent = world.create_entity(
        mp,
        Position(-100, 0, level_ent),
        Velocity(0, 0),
        HitCircle(radius=25),
        Collidable(),
        Facing(Facing.EAST),
        player_sprite_for(mp.colour, Facing.EAST),
        Health(3),
        Inventory(),
    )

    create_sound(world, PLAYER_FALL_SOUND, volume=0.08, delay=0.5)
    create_sequence(
        world,
        player_ent,
        SpriteEffects(
            ThrowToEffect(
                1,
                Position(-100, 0, level_ent),
                Position(spawner.x, spawner.y, level_ent),
                400,
            ),
            SpinEffect(1, 720),
        ),
        Position(spawner.x, spawner.y, level_ent),
        Player(input_source),
    )

    create_hud(world, player_ent)
示例#9
0
def use_lazorgun(world, message):
    if not world.has_component(message.payload['item_ent'], LazorGun):
        return
    if world.has_component(message.payload['item_ent'], Timeout):
        return

    player_ent = message.payload['player_ent']
    position = world.component_for_entity(player_ent, Position)
    facing = world.component_for_entity(player_ent, Facing)
    velocity = facing.velocity()
    velocity.magnitude = 1000
    world.create_entity(
        Sprite(":resources:images/items/star.png", scale=0.5),
        Position(x=position.x, y=position.y, level=position.level),
        velocity,
        Bullet(0.5, Enemy),
        Collidable(match_components=[Enemy]),
        HitCircle(radius=20),
    )
    world.add_component(message.payload['item_ent'], Timeout(0.5))
    create_sound(world, LAZOR_SOUND)
示例#10
0
    def process(self, dt):
        for thrower_ent, (thrower, thrower_pos) in self.world.get_components(
                FireballThrower, Position):
            level = self.world.component_for_entity(thrower_pos.level, Level)
            if not level.active:
                continue

            thrower.timeout = max(0, thrower.timeout - dt)
            if thrower.timeout:
                continue

            choices = [
                pos
                for _, (p, pos) in self.world.get_components(Player, Position)
            ]
            if not choices:
                continue

            if thrower.use_facing:
                facing = self.world.component_for_entity(thrower_ent, Facing)
                v = facing.velocity()
                v.magnitude = 250
            else:
                target_pos = random.choice(choices)
                v = (-target_pos.point2().connect(
                    thrower_pos.point2()).v.normalize() * 250)
                v = Velocity(v.x, v.y)

            self.world.create_entity(
                Sprite(FIREBALL_IMAGE, scale=0.5),
                Position(x=thrower_pos.x,
                         y=thrower_pos.y,
                         level=thrower_pos.level), v,
                Collidable(match_components=[Player]), HitCircle(radius=10),
                Bullet(1, Player),
                SpriteEffects(SpinEffect(play_time=1, speed=-800)),
                HitEmitter(smoke_poof))
            create_sound(self.world, FIREBALL_SHOOT_SOUND)
            thrower.timeout = random.randint(1, 3)