示例#1
0
文件: fishy.py 项目: encukou/mufl
    def catch_fish(self):
        self.hooked_fish = self.caught_fish
        self.hooked_fish.fin_task.cancel()
        if self.hooked_fish.speed[0] > 0:
            angle = -tau / 4
        else:
            angle = tau / 4
        animate(self.hooked_fish.group, angle=angle)
        animate(
            self,
            tween='accelerate',
            duration=15,
            pullout_speed=1000,
        )
        animate(self, duration=3, want_h=self.scene.height // 2)
        self.pull_timer = 0

        clock.schedule(self.fishing.spawner.stop, 3, strong=True)
        clock.schedule(lambda: setattr(self, 'active', False),
                       0.5,
                       strong=True)

        if self.hooked_fish.bonus['cube']:
            self.fishing.game.info.add_boxfish(self.hooked_fish.color)
        self.fishing.on_finish(**self.hooked_fish.bonus)
示例#2
0
def set_music(tracktype):
    global current_music
    newmusic = tracks.get(tracktype, 'the_triumph_of_the_clock_maker')
    if current_music != newmusic:
        current_music = newmusic
        music.fadeout(0.5)
        clock.schedule(lambda: music.play(newmusic), 0.5, strong=True)
示例#3
0
    def set_inputs(self, inputs):
        """Pass information from the controller."""

        defend, attack, charge, bomb = inputs

        if not self.can_act:
            return

        if defend:
            self.can_act.lock(0.3)
            animate(self.shield, duration=0.1, angle=-0.2, radius=8)
            animate(self.sword, duration=0.3, angle=1.3, radius=25)
        elif bomb:
            self.can_act.lock(0.5)
            self.knight.throw_bomb()
        elif charge:
            self.can_move.lock(1.8)
            self.can_act.lock(1.8)
            animate(self.shield, duration=0.1, angle=0, radius=10)
            animate(self.sword, duration=0.1, angle=0, radius=20)
            clock.schedule(self._start_charge, 0.3)
        elif attack:
            self.can_act.lock(0.5)
            animate(
                self.sword,
                'accel_decel',
                duration=0.05,
                angle=2.5,
                on_finished=self._start_attack
            )
        else:
            self.normal_stance()
示例#4
0
文件: dicy.py 项目: encukou/mufl
    def collide(self, dt):
        to_collide = []
        for die in self.dice:
            for other in to_collide:
                die.collide(other)
            to_collide.append(die)

        if all(d.locked for d in self.dice):
            for die in self.dice:
                bonuses = BONUSES[die.face]
                self.game.info.give(**bonuses,
                                    pos=die.pos[:2],
                                    sleep=0.5 + 0.5 * len(self.dice),
                                    outline=True,
                                    hoffset=0.5)

            def give_bonus_pairs(dt=None):
                to_check = set()
                for die in self.dice:
                    for other in set(to_check):
                        if die.face == other.face:
                            line = self.line_layer.add_line(
                                (die.pos[:2], other.pos[:2]),
                                color=(np.array(die.color) + other.color) / 2,
                                stroke_width=0,
                            )
                            to_check.discard(other)
                            animate(line, stroke_width=5)
                            bonuses = Counter(BONUSES[die.face]) + Counter(
                                BONUSES[other.face]) + Counter(magic=3)
                            if BONUSES[die.face] == {'magic': 1}:
                                bonuses['magic'] += 6
                            midpos = (die.pos[:2] + other.pos[:2]) / 2
                            self.game.info.give(**bonuses,
                                                pos=midpos,
                                                sleep=1.5,
                                                outline=True,
                                                hoffset=0.5)
                            animate(die, size=die.size * 1.1)
                            animate(other, size=other.size * 1.1)
                            break
                    else:
                        to_check.add(die)
                for left_die in set(to_check):
                    animate(left_die, size=left_die.size * 0.99)
                self.on_finish(speedup=1.1)

            clock.unschedule(self.collide)
            clock.schedule(give_bonus_pairs, 0.5 * len(self.dice), strong=True)
示例#5
0
文件: burrow.py 项目: encukou/mufl
 def add_card(self, i):
     try:
         card = self.decks[i].pop()
     except IndexError:
         return
     play_sound('set-card')
     card.face_up = True
     clock.schedule(lambda: self.turn_deck(i), 0.2, strong=True)
     card.origin_deck = i
     card.selected_index = len(self.selected)
     self.selected.append(card)
     card.active = self.update_arrow()
     self.set_animation(card, self.do_put_animation(card))
     card.sel_sprite = self.selcard_layer.add_sprite(
         card.value,
         pos=selected_pos(card.selected_index),
         color=(1, 1, 1, 0),
         scale=0.3,
     )
     self.update_deck_sprites()
示例#6
0
文件: burrow.py 项目: encukou/mufl
def sched(func, time):
    clock.schedule(func, time, strong=True)
示例#7
0
    def fire_missile(self):
        self.deselect()
        self.game.info.magic -= 30
        scene = self.game.scene
        chain = scene.chain
        camera = scene.camera
        prev_pos = camera.pos
        mask_fill = self.game.set_missile_chain()
        clock.schedule(
            lambda: animate(
                mask_fill, color=(1, 1, 1, 0), duration=2, tween='accelerate'),
            2,
            strong=True,
        )

        async def anim():
            self.input_frozen = True
            try:
                missile_layer = scene.layers[1]
                sparks_layer = scene.layers[2]
                sprite = missile_layer.add_sprite(
                    'blur_circle',
                    pos=FIRE_POS,
                    scale=1 / 6,
                )
                pg = sparks_layer.add_particle_group(
                    'magic_particle',
                    grow=0.9,
                    max_age=3,
                    spin_drag=1.1,
                    gravity=numpy.array([0, -4]),
                )
                pg.add_color_stop(0, (1, 1, 1))
                pg.add_color_stop(0.2, (0, 1, 1))
                pg.add_color_stop(1, (1, 0, 1))
                pg.add_color_stop(2, (1, 1, 0, 1))
                pg.add_color_stop(3, (1, 1, 0, 0))
                em = pg.add_emitter(
                    rate=50,
                    pos=FIRE_POS,
                    pos_spread=(3, 3),
                    vel=(0, 0),
                    emit_angle_spread=tau,
                    vel_spread=(16, 16),
                    size=15,
                    size_spread=5,
                    spin_spread=tau / 4,
                )
                play_sound('missile-launch')
                play_sound('missile-launch2')

                duration = 8
                async for t in clock.coro.frames(seconds=duration):
                    t /= duration
                    anit = t * t
                    camera.pos = scene.width / 2, scene.height / 2 - anit * scene.height * 2
                    sprite.pos = em.pos = FIRE_POS[0], FIRE_POS[1] - anit * (
                        scene.height * 2 + 400)
                    em.vel = 0, -t * 400
                    em.rate = max(0, (.7 - t) * 50)
                em.vel = 0, 0
                pg.gravity = numpy.array([0, 200])
                pg.emit(
                    400,
                    pos=em.pos,
                    vel=(0, 0),
                    vel_spread=(300, 300),
                    spin_spread=tau / 4,
                    angle_spread=tau,
                    size=20,
                    size_spread=10,
                )
                pg.max_age = 5
                sparks_layer.set_effect('trails', fade=0.7)
                play_sound('missile-boom')
                play_sound('missile-boom')
                play_sound('missile-boom2')
                await animate(sprite,
                              scale=3,
                              color=(1, 1, 1, 0),
                              duration=2,
                              tween='decelerate')
                await clock.coro.sleep(4)
                cam_x, cam_y = camera.pos
                if self.game.info.message_assembled:
                    for i, line in enumerate((
                            "The explosion, combined with your message,",
                            "got the attention of a broom-mounted,",
                            "teleport-savvy savior.",
                            "You made it out alive and well – just with",
                            "a lifetime ban on any more magic parties.",
                    )):
                        l = missile_layer.add_label(
                            line,
                            font='kufam_medium',
                            align='center',
                            pos=(cam_x, cam_y + i * 32),
                            color=(1, 1, 1, 0),
                            fontsize=15,
                        )
                        animate(l, color=(1, 1, 1, 1))
                    l = missile_layer.add_label(
                        'Congratulations!',
                        font='kufam_medium',
                        align='center',
                        pos=(cam_x, cam_y - 64),
                        color=(1, 1, 1, 1),
                        fontsize=50,
                    )
                    animate(l, color=(1, 1, 1, 1))
                    await clock.coro.sleep(3600)
                duration = 2
                async for t in clock.coro.frames(seconds=duration):
                    t /= duration
                    camera.pos = scene.width / 2, scene.height / 2 - (
                        1 - t) * scene.height * 2
                await animate(mask_fill,
                              color=(1, 1, 1, 1),
                              duration=.2,
                              tween='accelerate')
                sparks_layer.clear_effect()
            finally:
                scene.chain = chain
                camera.pos = prev_pos
                scene.layers.pop(1, None)
                scene.layers.pop(2, None)
                self.input_frozen = False

        clock.coro.run(anim())