Beispiel #1
0
    def alignPhys(self):
        self.torso.set_position(*self.body.position + (20,50))
        self.head.set_position(*self.body.position + (20,80))
        self.torsor.set_position(*self.body.position + (20,50))
        self.headr.set_position(*self.body.position + (20,80))
        self.larm.set_position(*self.body.position + (0,30))
        self.rarm.set_position(*self.body.position + (40,30))
        self.lleg.set_position(*self.body.position + (10,10))
        self.rleg.set_position(*self.body.position + (30,10))

        self.torso.rotation = self.body.angle
        self.head.rotation = self.body.angle
        self.torsor.rotation = self.body.angle
        self.headr.rotation = self.body.angle
        self.larm.rotation = self.body.angle + self.larmrot
        self.rarm.rotation = self.body.angle + self.rarmrot
        self.lleg.rotation = self.body.angle + self.llegrot
        self.rleg.rotation = self.body.angle + self.rlegrot

        i = 0
        for item in self.crownObj:
            item.position = self.body.position + (20,(crownFloatDistance + (playerCrownVisualSeperation * i)))
            i += 1

        if self.living == 0:
            self.head.do(ac.Hide())
            self.headr.do(ac.Hide())
        if self.living == 1:
            self.head.do(ac.Show())
            self.headr.do(ac.Show())
Beispiel #2
0
    def show_message(self, msg, callback=None):
        w, h = director.get_window_size()

        self.msg = cocos.text.Label(msg,
                                    font_size=52,
                                    font_name=consts['view']['font_name'],
                                    anchor_y='center',
                                    anchor_x='center',
                                    width=w,
                                    multiline=True,
                                    align="center")
        self.msg.position = (w / 2.0, h)

        self.add(self.msg)

        actions = (
                ac.Show() + ac.Accelerate(ac.MoveBy((0, -h / 2.0), duration=0.1)) +
                ac.Delay(1) +
                ac.Accelerate(ac.MoveBy((0, -h / 2.0), duration=0.1)) +
                ac.Hide()
        )

        if callback:
            actions += ac.CallFunc(callback)

        self.msg.do(actions)
Beispiel #3
0
    def update(self, dt):
        self.checkforwin()
        global prevKeys
        pdt = 1.0/60.  # override dt to keep physics simulation stable
        space.step(pdt)
        self.numS += 1
        # if self.numS > 7*60:
        #     r = Ruler(side=0, spawnHeight=random.randint(50, 400), width=800, height=10, speed=random.randint(50, 400), layer=self.player_layer)
        #     r.addComponents(self.player_layer)
        #     self.rulers.append(r)
        if self.numS > 20*60:
            self.numS = 0
            r = Ruler(side=0, spawnHeight=random.randint(50, 400), width=800, height=10, speed=random.randint(50, 400), layer=self.player_layer)
            r.addComponents(self.player_layer)
            self.rulers.append(r)

        self.player1.alignPhys()
        self.player2.alignPhys()
        self.player3.alignPhys()
        self.player4.alignPhys()
        for r in self.rulers:
            r.alignPhys()



        # a = self.player1.bbody.cache_bb()
        # try:
        #     self.scene.remove("aa")
        # except:
        #     pass
        # bar = cocos.layer.ColorLayer(255, 0, 0, 255, width=int(a.right-a.left), height=int(a.top-a.bottom))
        # bar.position = (a.left,a.bottom)
        # self.scene.add(bar, 5, "aa")

        # a = self.player2.bbody.cache_bb()
        # try:
        #     self.scene.remove("bb")
        # except:
        #     pass
        # bar = cocos.layer.ColorLayer(255, 0, 0, 255, width=int(a.right-a.left), height=int(a.top-a.bottom))
        # bar.position = (a.left,a.bottom)
        # self.scene.add(bar, 5, "bb")

        # a = self.ruler.bruler.cache_bb()
        # try:
        #     self.scene.remove("cc")
        # except:
        #     pass
        # bar = cocos.layer.ColorLayer(255, 0, 0, 255, width=int(a.right-a.left), height=int(a.top-a.bottom))
        # bar.position = (a.left,a.bottom)
        # self.scene.add(bar, 5, "cc")

        # print(self.player.head.position)
        # print(self.player.head_attach.position)


        #print(self.player.body.position)
        # update player
        buttons = self.buttons

        # Check key presses

        #print(self.player1.bbody.bb)

        #self.ruler.body.apply_impulse(j=(1000,0), r=(0, 0))
        rot = buttons['p1Up']
        if rot != 0 and self.player1.living == 1:
            self.player1.body.velocity = self.player1.body.velocity + (0, upSpeed)
            self.player1.larmrot = self.player1.larmrot  + 10
            self.player1.rarmrot = self.player1.rarmrot  + 10
        rot = buttons['p1Down']
        if rot != 0 and self.player1.living == 1:
            self.player1.body.velocity = self.player1.body.velocity + (0, -upSpeed)
            self.player1.larmrot = self.player1.larmrot  - 10
            self.player1.rarmrot = self.player1.rarmrot  - 10
        rot = buttons['p1Left']
        if rot != 0 and self.player1.living == 1:
            self.player1.body.velocity = self.player1.body.velocity + (-sideSpeed, 0)
            self.player1.llegrot = self.player1.llegrot  - 10
            self.player1.rlegrot = self.player1.rlegrot  - 10
            self.player1.torsor.do(ac.Show())
            self.player1.torso.do(ac.Hide())
            self.player1.headr.do(ac.Show())
            self.player1.head.do(ac.Hide())
        rot = buttons['p1Right']
        if rot != 0 and self.player1.living == 1:
            self.player1.body.velocity = self.player1.body.velocity + (sideSpeed, 0)
            self.player1.llegrot = self.player1.llegrot  + 10
            self.player1.rlegrot = self.player1.rlegrot  + 10
            self.player1.torso.do(ac.Show())
            self.player1.torsor.do(ac.Hide())
            self.player1.head.do(ac.Show())
            self.player1.headr.do(ac.Hide())

        rot = buttons['p2Up']
        #print(self.player1.body.velocity)
        if rot != 0 and self.player2.living == 1:
            self.player2.body.velocity = self.player2.body.velocity + (0, upSpeed)
            self.player2.larmrot = self.player2.larmrot  + 10
            self.player2.rarmrot = self.player2.rarmrot  + 10
        rot = buttons['p2Down']
        if rot != 0 and self.player2.living == 1:
            self.player2.body.velocity = self.player2.body.velocity + (0, -upSpeed)
            self.player2.larmrot = self.player2.larmrot  - 10
            self.player2.rarmrot = self.player2.rarmrot  - 10
        rot = buttons['p2Left']
        if rot != 0 and self.player2.living == 1:
            self.player2.body.velocity = self.player2.body.velocity + (-sideSpeed, 0)
            self.player2.llegrot = self.player2.llegrot  - 10
            self.player2.rlegrot = self.player2.rlegrot  - 10
            self.player2.torsor.do(ac.Show())
            self.player2.torso.do(ac.Hide())
            self.player2.headr.do(ac.Show())
            self.player2.head.do(ac.Hide())
        rot = buttons['p2Right']
        if rot != 0 and self.player2.living == 1:
            self.player2.body.velocity = self.player2.body.velocity + (sideSpeed, 0)
            self.player2.llegrot = self.player2.llegrot  + 10
            self.player2.rlegrot = self.player2.rlegrot  + 10
            self.player2.torso.do(ac.Show())
            self.player2.torsor.do(ac.Hide())
            self.player2.head.do(ac.Show())
            self.player2.headr.do(ac.Hide())

        rot = buttons['p3Up']
        if rot != 0 and self.player3.living == 1:
            self.player3.body.velocity = self.player3.body.velocity + (0, upSpeed)
            self.player3.larmrot = self.player3.larmrot  + 10
            self.player3.rarmrot = self.player3.rarmrot  + 10
        rot = buttons['p3Down']
        if rot != 0 and self.player3.living == 1:
            self.player3.body.velocity = self.player3.body.velocity + (0, -upSpeed)
            self.player3.larmrot = self.player3.larmrot  - 10
            self.player3.rarmrot = self.player3.rarmrot  - 10
        rot = buttons['p3Left']
        if rot != 0 and self.player3.living == 1:
            self.player3.body.velocity = self.player3.body.velocity + (-sideSpeed, 0)
            self.player3.llegrot = self.player3.llegrot  - 10
            self.player3.rlegrot = self.player3.rlegrot  - 10
            self.player3.torsor.do(ac.Show())
            self.player3.torso.do(ac.Hide())
            self.player3.headr.do(ac.Show())
            self.player3.head.do(ac.Hide())
        rot = buttons['p3Right']
        if rot != 0 and self.player3.living == 1:
            self.player3.body.velocity = self.player3.body.velocity + (sideSpeed, 0)
            self.player3.llegrot = self.player3.llegrot  + 10
            self.player3.rlegrot = self.player3.rlegrot  + 10
            self.player3.torso.do(ac.Show())
            self.player3.torsor.do(ac.Hide())
            self.player3.head.do(ac.Show())
            self.player3.headr.do(ac.Hide())

        rot = buttons['p4Up']
        if rot != 0 and self.player4.living == 1:
            self.player4.body.velocity = self.player4.body.velocity + (0, upSpeed)
            self.player4.larmrot = self.player4.larmrot  + 10
            self.player4.rarmrot = self.player4.rarmrot  + 10
        rot = buttons['p4Down']
        if rot != 0 and self.player4.living == 1:
            self.player4.body.velocity = self.player4.body.velocity + (0, -upSpeed)
            self.player4.larmrot = self.player4.larmrot  - 10
            self.player4.rarmrot = self.player4.rarmrot  - 10
        rot = buttons['p4Left']
        if rot != 0 and self.player4.living == 1:
            self.player4.body.velocity = self.player4.body.velocity + (-sideSpeed, 0)
            self.player4.llegrot = self.player4.llegrot  - 10
            self.player4.rlegrot = self.player4.rlegrot  - 10
            self.player4.torsor.do(ac.Show())
            self.player4.torso.do(ac.Hide())
            self.player4.headr.do(ac.Show())
            self.player4.head.do(ac.Hide())
        rot = buttons['p4Right']
        if rot != 0 and self.player4.living == 1:
            self.player4.body.velocity = self.player4.body.velocity + (sideSpeed, 0)
            self.player4.llegrot = self.player4.llegrot  + 10
            self.player4.rlegrot = self.player4.rlegrot  + 10
            self.player4.torso.do(ac.Show())
            self.player4.torsor.do(ac.Hide())
            self.player4.head.do(ac.Show())
            self.player4.headr.do(ac.Hide())

        prevKeys = buttons
Beispiel #4
0
    def __init__(self, note: BaseNote):
        def p(state: BaseNote.NoteState):
            res = copy.copy(state)
            res.pos *= settings.size
            res.speed *= settings.size
            return res

        states = list(map(p, sorted(note.states, key=lambda e: e.sec)))
        dis = 0
        img = 'click.png'
        if isinstance(note, Drag):
            img = 'drag.png'
        elif isinstance(note, Flick):
            img = 'flick.png'
        elif isinstance(note, Hold):
            img = 'hold.png'
            sec = note.tap_sec
            length = 0
            for i in states:
                if i.sec <= note.tap_sec:
                    continue
                length += i.speed * (i.sec - sec)
                sec = i.sec
            length += states[-1].speed * (note.end_sec - sec)
            dis += length // 2
        sec = note.tap_sec
        for i in states[::-1]:
            if i.sec > note.tap_sec:
                break
            note.show_sec = min(
                note.show_sec,
                sec - (settings.size * 2 - abs(dis) + (length if isinstance(note, Hold) else 0)) / abs(i.speed)
            )
            dis += (sec - i.sec) * i.speed
            sec = i.sec
        note.show_sec = min(
            note.show_sec,
            sec - (settings.size * 2 - abs(dis) + (length if isinstance(note, Hold) else 0)) / abs(states[0].speed)
        )
        dis += sec * states[0].speed
        super().__init__(img, (states[0].pos, dis))
        if isinstance(note, Hold):
            self.scale_y = length / self.image.height
        action = cac.Hide()
        sec = 0
        speed = states[0].speed
        for i in states:
            if i.sec > note.tap_sec:
                break
            dis -= (i.sec - sec) * speed
            act = cac.MoveTo((i.pos, dis), i.sec - sec)
            if sec <= note.show_sec < i.sec:
                act |= cac.Delay(note.show_sec - sec) + cac.Show()
            action += act
            sec = i.sec
            speed = i.speed
        act = cac.MoveTo((states[-1].pos, length // 2 if isinstance(note, Hold) else 0), note.tap_sec - sec)
        if sec <= note.show_sec < note.tap_sec:
            act |= cac.Delay(note.show_sec - sec) + cac.Show()
        action += act
        action += cac.CallFunc(play_sound)

        if isinstance(note, Hold):
            class Qwq(cac.IntervalAction):
                def init(self, length, duration):
                    self._length = length
                    self.duration = duration

                def start(self):
                    self._cur = self.target.scale_y

                def update(self, t):
                    from random import randint
                    if randint(0, 6) < 3:
                        self.target.parent.add(NoteExplode((self.target.x, 0)))
                    self.target.scale_y = (self._cur - self._length) * (1 - t) + self._length

            nowlen = length // 2
            sec = note.tap_sec
            for i in states:
                if i.sec <= note.tap_sec:
                    continue
                nowlen -= (i.sec - sec) * i.speed
                action += cac.MoveTo((states[-1].pos, nowlen // 2), i.sec - sec) | \
                          Qwq(nowlen / self.image.height, i.sec - sec)
                sec = i.sec
            action += cac.MoveTo((states[-1].pos, 0), note.end_sec - sec) | \
                      Qwq(0, note.end_sec - sec)

        def explode(e: NoteSprite):
            e.kill()
            e.parent.add(NoteExplode((e.x, e.y)))
            score()

        action += cac.CallFuncS(explode)
        self.do(action)
Beispiel #5
0
 def showing(self, value):
     self._visible = value
     if value == False:
         self.do(actions.Hide())
     else:
         self.do(actions.Show())