示例#1
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)
示例#2
0
def SPIKE(world, level_ent, obj, target_ent, trigger_source_ent):
    if world.has_component(target_ent, Player):
        health = world.component_for_entity(target_ent, Health)
        health.effects.append(HealthDown(1))

        if not world.has_component(target_ent, Invulnerable):
            # and knockback
            pos = world.component_for_entity(target_ent, Position)
            velocity = world.component_for_entity(target_ent, Velocity)
            p1 = pos.point2()
            p2 = p1 - velocity.vector2().normalized() * 50
            create_sequence(
                world,
                target_ent,
                PositionEffects(
                    [
                        ThrowToEffect(
                            0.5,
                            Position(p1.x, p1.y, pos.level),
                            Position(p2.x, p2.y, pos.level),
                            100,
                        )
                    ]
                ),
            )
示例#3
0
def create_trigger(world, level_ent, obj):
    properties = obj.properties
    if properties is None:
        properties = {}
    collision_shape = None
    if isinstance(obj, UsefulPolygon):
        collision_shape = HitPoly(obj.point_list)
    else:
        #assume circle
        collision_shape = HitCircle(properties.get("radius"))

    match_components = [
        locate(class_name)
        for class_name in properties.get("match_components", "").split(",")
    ]
    avoid_components = [
        locate(class_name)
        for class_name in properties.get("avoid_components", "").split(",")
    ]

    world.create_entity(
        collision_shape,
        Collidable(match_components=match_components,
                   avoid_components=avoid_components),
        Position(obj.location.x, obj.location.y, level_ent),
        Trigger(script=obj.name, obj=obj, level=level_ent))
示例#4
0
def _random_emitter(world, level_ent):
    x = random.randint(0, WINDOW_WIDTH)
    y = random.randint(0, WINDOW_HEIGHT)
    position = Position(x, y, level_ent)
    emitter = random.choice(EMITTERS)(position)

    world.create_entity(Emitter(emitter), InLevel(position.level),
                        DrawLayer(PARTICLE_LAYER, emitter))
示例#5
0
def create_trash_can(world, x, y, level_ent, item_name):
    return world.create_entity(
        Sprite("data/images/trash_can.png"),
        Position(x, y, level_ent),
        Collidable(match_components=[Inventory]),
        HitCircle(radius=25),
        Dispenser(item_name=item_name),
    )
示例#6
0
def create_level_item(world, name, x, y, level_ent):
    level_item_data, _ = ITEM_DATA[name]
    return world.create_entity(
        LevelItem(name), HitCircle(level_item_data.radius),
        Collidable(match_components=[Inventory]), Position(x, y, level_ent),
        Sprite(level_item_data.image,
               scale=level_item_data.scale,
               draw_layer=ITEM_LAYER), Timeout(1),
        *[c.build() for c in level_item_data.component_classes])
示例#7
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)
示例#8
0
def create_inventory_item_animation(world, source_ent, player_ent, index,
                                    inventory_item_data):
    start_pos = world.component_for_entity(source_ent, Position)
    mp = world.component_for_entity(player_ent, MultiplayerIdentifier)
    base_x = player_base_x(mp)
    end_pos = Position(base_x + 100 + INVENTORY_X_SPACING * index, INVENTORY_Y,
                       start_pos.level)
    world.create_entity(
        Sprite(inventory_item_data.image, 0.25), start_pos,
        SpriteEffects(ThrowToEffect(.5, start_pos, end_pos, 50),
                      FadeEffect(.8)))
示例#9
0
def create_enemy(world, spawner_entity, position: Position):
    return world.create_entity(
        Velocity(0, 0),
        DesiredVelocity(0, 0),
        Position(position.x, position.y, position.level),
        Sprite(":resources:images/enemies/bee.png", scale=0.5),
        Enemy(spawner_entity),
        Health(1),
        Hurt(1, [Player]),
        FireballThrower(timeout=1),
        Collidable(match_components=[Player]),
        HitCircle(radius=25),
    )
示例#10
0
def create_gate(world, obj, level_ent):
    level_listen = None
    if obj.properties.get("in_level", False):
        level_listen = level_ent
    closed_path, open_path, scale = GATE_SPRITES[obj.properties.get("sprite")][
        obj.properties.get("orientation")
    ]
    world.create_entity(
        Position(obj.x, obj.y, level_ent),
        Collidable(match_components=[Velocity]),
        HitPoly(obj.point_list),
        Barrier(),
        ChannelListener(
            channel=obj.properties.get("channel"),
            script=toggle_gate,
            level_ent=level_listen,
        ),
        Sprite(closed_path, scale, draw_layer=GATES_LAYER),
        Gate(open_path, closed_path),
    )
示例#11
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)
示例#12
0
def create_button(world, obj, level_ent):
    properties = obj.properties
    if properties is None:
        properties = {}
    channel = properties.get("channel")
    in_level = properties.get("in_level", False)

    match_components = locate_classes(properties, "match_components")
    avoid_components = locate_classes(properties, "avoid_components")
    up_image = "data/button_up_sprite.png"
    down_image = "data/button_down_sprite.png"
    return world.create_entity(
        Button(channel=channel,
               in_level=in_level,
               up_image=up_image,
               down_image=down_image),
        Position(x=obj.location.x, y=obj.location.y, level=level_ent),
        Collidable(match_components=match_components,
                   avoid_components=avoid_components),
        HitCircle(20),
        Sprite(up_image, scale=0.5),
    )
示例#13
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)
示例#14
0
def create_prop(world, x, y, type, radius, level_ent):
    if type == "goat":
        comps = [
            Sprite("data/images/goat-1.png"),
            SpriteEffects(
                AnimatedTextureEffect([
                    (5, arcade.load_texture("data/images/goat-1.png")),
                    (0.05, arcade.load_texture("data/images/goat-2.png")),
                    (0.05, arcade.load_texture("data/images/goat-3.png")),
                    (0.5, arcade.load_texture("data/images/goat-4.png")),
                    (0.05, arcade.load_texture("data/images/goat-3.png")),
                    (0.05, arcade.load_texture("data/images/goat-2.png")),
                ])),
        ]

    if radius:
        comps.extend([Collidable(), HitCircle(radius)])

    world.create_entity(
        Prop(type),
        *comps,
        Position(x, y, level_ent),
    )
示例#15
0
def create_shooter(world, name, x, y, direction, level_ent):
    return world.create_entity(
        FireballThrower(random.random() * 3, True),
        Facing(direction),
        Position(x, y, level_ent),
    )
示例#16
0
def create_enemy_spawner(world, x, y, type, level_ent):
    world.create_entity(
        EnemySpawner(),
        # Sprite("data/kenney_platformerkit2_isometric/buttonSquare_NE.png", scale=0.5),
        Position(x, y, level_ent),
    )
示例#17
0
def create_enemy_path(world, obj, level_ent):
    x, y = obj.point_list[0]
    ent = create_enemy(world, None, Position(x, y, level_ent))
    world.add_component(ent, FollowPath(obj.point_list, 100))