Esempio n. 1
0
    def init(self, one, two):
        from cocos.actions.interval_actions import Delay

        one = copy.deepcopy(one)
        two = copy.deepcopy(two)
        self.duration = max(one.duration, two.duration)

        if one.duration > two.duration:
            two = two + Delay(one.duration - two.duration)
        elif two.duration > one.duration:
            one = one + Delay(two.duration - one.duration)

        self.actions = [one, two]
Esempio n. 2
0
    def finish(self):
        """Displays a message explaining the player that he finished.
           Also automatically progresses to the results screen."""
        self.player_finished = True

        # state.cup.set_results_for_current_track(self.results)

        player_position = self.results.index(self.stats[self.player_car]) + 1
        if player_position == 1:
            finished_text = 'You won!'
        elif player_position == len(self.stats):
            finished_text = 'You finished last'
        else:
            finished_text = 'You finished %s' % (
                util.ordinal(player_position), )

        label = util.Label(text=finished_text,
                           anchor_y='bottom',
                           font_size=40,
                           background=(0, 0, 0, 125))

        label.transform_anchor_x = label.width / 2
        label.x = director.window.width / 2 - label.width / 2
        label.y = director.window.height / 2
        self.add(label, z=100)

        label.scale = 0
        label.do(
            ScaleTo(1, 0.75) + Delay(3) + ScaleTo(0, 0.75) +
            CallFunc(self.remove, label) + CallFunc(self.show_results))
Esempio n. 3
0
    def start_cpu(self,
                  newUnit,
                  owner,
                  builder=None,
                  researchF=None,
                  upgradeFrom=None):
        #CPU related logic
        cpu = owner.idleCPUs.pop()

        timer = TransTimer(newUnit.buildTime, pos=cpu.position)

        if owner.pid == self.pid:
            action = timer.get_move_action()
            self.map.add(timer, z=TIMER_Z)
        else:
            action = Delay(newUnit.buildTime)
        cpu.action = action
        action += CallFunc(self.stop_cpu, cpu, owner)
        if builder:  #building a building
            action += CallFunc(self.remove_unit, builder)
        elif researchF:  #research
            action += CallFunc(self.finish_research, newUnit, owner, researchF)
        if owner.pid == self.pid:
            timer.do(action)
        else:
            self.do(action)
Esempio n. 4
0
 def perform_research(self, researchName, researchFactory):
     utils.play_sound("Clock.wav")
     researchType = RESEARCH[researchName]
     researchType.on_start(self.player)
     action = Delay(researchType.buildTime)
     action += CallFunc(self.finish_research, researchType, self.player,
                        None)
     self.do(action)
Esempio n. 5
0
    def on_enter(self):
        super(HelpZoraScene, self).on_enter()
        intro_sound_player.stop()

        menu_player.set_volume(3)
        a = Delay(3)
        a += CallFunc(self.on_quit)
        self.poem.do(a)
Esempio n. 6
0
    def add_traffic_lights(self):
        lights = TrafficLights()

        lights.image_anchor_y = 0
        lights.x = director.window.width / 2

        origin_y = director.window.height
        target_y = director.window.height - lights.image.height

        lights.y = origin_y

        self.add(lights, name='traffic_lights', z=100)

        lights.do(
            AccelDeccel(MoveTo((lights.x, target_y), 2)) +
            (Delay(1) + CallFunc(lights.shift_overlay)) *
            TrafficLights.NUM_LIGHTS + CallFunc(self.start) + Delay(1.5) +
            MoveTo((lights.x, origin_y), 0.3) + CallFunc(self.remove, lights))
Esempio n. 7
0
 def mudarCor(self, delay, tipo):
     espera = Delay(delay)
     rotacao = Rotate(360, 0.5)
     self.do(espera + rotacao)
     self.tipo = tipo
     if(self.tipo == 1):
         self.image = Peca.pumpkin
     elif(self.tipo == 2):
         self.image = Peca.skull
     self.opacity = 255
Esempio n. 8
0
 def __init__(self):
     super().__init__()
     self.size, self.count, self.keys, self.pause = size, 0, set(), False
     self.add(Badger(self.size[0] // 4, self.size[1] // 2))
     self.do(Repeat(Delay(1) + CallFunc(self.creating)))
     self.add(
         cocos.text.Label(text='0',
                          position=(15, self.size[1] // 2),
                          font_name='Times New Roman',
                          font_size=32,
                          anchor_x='left'))
Esempio n. 9
0
    def init(self, one, two):
        """Init method

        :Parameters:
            `one` : `Action`
                The first action to execute in parallel
            `two` : `Action`
                The second action to execute in parallel
        """
        from cocos.actions.interval_actions import Delay

        one = copy.deepcopy(one)
        two = copy.deepcopy(two)
        if one.duration > two.duration:
            two = two + Delay(one.duration - two.duration)
        elif two.duration > one.duration:
            one = one + Delay(two.duration - one.duration)

        self.duration = one.duration

        self.actions = [one, two]
        self.cloned_actions = []
Esempio n. 10
0
    def create_menu(self,
                    items,
                    selected_effect=None,
                    unselected_effect=None,
                    activated_effect=None,
                    layout_strategy=verticalMenuLayout):

        super(BrandedMenu,
              self).create_menu(items, selected_effect, unselected_effect,
                                activated_effect, layout_strategy)

        delay = 0.3
        for i in items:
            i.scale = 0
            i.do(
                Delay(delay) + Accelerate(ScaleTo(1.3, duration=0.3), 2) +
                ScaleTo(1, duration=0.1))
            delay += 0.2
Esempio n. 11
0
 def __init__(self, text, callback, delay=2):
     super(AnimatedMenuItem, self).__init__(text, callback)
     self.scale = 0
     self.do(
         Delay(delay) + ScaleTo(1.1, duration=0.2) +
         ScaleTo(1, duration=0.1))
Esempio n. 12
0
    def move_unit(self, dest, unit, pid):
        if issubclass(
                type(unit), Troop
        ) and dest != unit.curVertex and dest.emptyTroopSlots and unit.isSelectable:

            path = self.map.get_path(unit.curVertex, dest, pid, unit)

            #check for firewall
            if not path:
                utils.play_sound("firewall.wav")
                return

            #check for sinkhole
            sinkHoleIndex = -1
            for i in range(1, len(path)):
                vertID = path[i]
                vert = self.map.vertices[vertID]
                if vert.building != None and type(
                        vert.building
                ) == Sinkhole and type(
                        unit) != EncryptedTroop and vert.building.pid != pid:
                    sinkHoleIndex = i
            if sinkHoleIndex != -1:
                dest = unit.curVertex
                t = path[:sinkHoleIndex]
                t.reverse()
                path = path[:sinkHoleIndex + 1] + t

            #set unit logical position
            unit.isSelectable = False
            unit.curVertex.remove_troop(unit)
            slot = dest.add_trans_troop(unit)
            unit.destVertex = dest
            if unit.pid == self.pid:
                self.dispatch_event("click_on_move", unit.__class__.__name__,
                                    dest.vid)

            #dispatch to client
            for p in self.connectedClients.keys():
                d = self.connect_end_point(self.connectedClients[p])

                def c(ampProto):
                    return ampProto.callRemote(MoveTroop,
                                               pid=pid,
                                               uid=unit.uid,
                                               vid=-1,
                                               path=path)

                d.addCallback(c)
                d.addErrback(err)
                reactor.callLater(10, d.cancel)

            # first vertex
            if pid == self.pid:
                utils.play_sound("Move.wav")
                action = CallFuncS(self.cm.remove_tricky)
                action += MoveTo(unit.curVertex.position, 0.2)
            else:
                action = MoveTo(unit.curVertex.position, 0.2)

            # intermediate vertices
            for i in range(1, len(path)):
                vertex = self.map.vertices[path[i]]
                action += MoveTo(vertex.position, 1 / unit.speed)
                action += CallFuncS(self.update_location, vertex.position, pid,
                                    vertex)
                if i == sinkHoleIndex:
                    action += CallFunc(utils.play_sound, "Sinkhole.wav")
                    action += CallFunc(unit.on_attack,
                                       math.ceil(unit.health / 3.0),
                                       vertex.building)
                    action += Delay(1)

            # final position
            if type(dest.building) != RSA or type(
                    unit) == EncryptedTroop or dest.building.pid != unit.pid:
                action += MoveTo(slot.position, 0.2)
                action += CallFuncS(self.update_location, slot.position, pid)
            else:
                action += CallFuncS(self.upgrade_unit, "EncryptedTroop")
            action += CallFuncS(self.cm.add)
            unit.do(action)
            return path
        return []
Esempio n. 13
0
    def on_enter(self):
        super(IntroText, self).on_enter()
        menu_player.play()
        menu_player.set_volume(1)
        intro_sound_player.play()
        intro_sound_player.set_volume(2)
        intro_sound_player.player.eos_action = pyglet.media.Player.EOS_STOP

        a = Delay(2)
        a += MoveBy((0, 6300), 100)
        a += Delay(3)
        a += CallFunc(self.on_quit)

        b = Delay(101)
        b += FadeIn(1)

        #Story images
        c = Delay(5)
        c += FadeIn(1)
        c += Delay(11)
        c += FadeOut(1)

        d = Delay(20)
        d += FadeIn(1)
        d += Delay(5)
        d += FadeOut(1)

        e = Delay(28)
        e += FadeIn(1)
        e += Delay(13)
        e += FadeOut(1)

        f = Delay(44)
        f += FadeIn(1)
        f += Delay(51)
        f += FadeOut(3)


        self.poem.do(a)
        self.help.do(b)
        self.introZora.do(c)
        self.introTownmap.do(d)
        self.introNetmap.do(e)
        self.introNotebook.do(f)
Esempio n. 14
0
    def __init__(self):
        global collision_manager
        super(BirdLayer, self).__init__()
        self.schedule(self.checkBirdPresent)
        self.schedule(self.nextScene)
        self.labelText = cocos.text.Label(scoreText + str(score),
                                          font_name='Times New Roman',
                                          font_size=24,
                                          bold=True)
        self.labelText.position = 520, 620
        self.labelText.do(Blink(3, 3))
        self.add(self.labelText)

        self.indicateLifeLine()

        self.birdSprite = cocos.sprite.Sprite(BirdLayer.birdAnimation)
        self.birdSprite.position = 0, 570
        move_basic = MoveBy((1200, 0), 13)
        self.birdSprite.do(Repeat(move_basic))
        self.add(self.birdSprite, z=1)
        self.birdSprite.cshape = cm.AARectShape(self.birdSprite.position,
                                                self.birdSprite.width // 3,
                                                self.birdSprite.height // 3)
        collision_manager.add(self.birdSprite)

        if level == 1:
            delay = 13
            numOFAsteriods = 16
        elif level == 2:
            delay = 6
            numOFAsteriods = 24
        else:
            delay = 2
            numOFAsteriods = 42

        self.batch = cocos.batch.BatchNode()
        self.obj = [
            cocos.sprite.Sprite(BirdLayer.spriteObj)
            for i in range(numOFAsteriods)
        ]
        xpos = 0
        positions = ((1200, 570), (1300, 570), (1400, 570), (1500, 570),
                     (1200, 620), (1300, 620), (1400, 620), (1500, 620),
                     (1200, 520), (1300, 520), (1400, 520), (1500, 520),
                     (1200, 470), (1300, 470), (1400, 470), (1500, 470),
                     (1200, 420), (1300, 420), (1400, 420), (1500, 420),
                     (1200, 370), (1300, 370), (1400, 370), (1500, 370),
                     (1200, 320), (1300, 320), (1400, 320), (1500, 320),
                     (1200, 270), (1300, 270), (1400, 270), (1500, 270),
                     (1200, 220), (1300, 220), (1400, 220), (1500, 220), (1200,
                                                                          160),
                     (1300, 160), (1400, 100), (1500, 50), (1400, 70), (1500,
                                                                        20))
        for num, enem in enumerate(self.obj):
            enem.position = positions[num]
            enem.cshape = cm.AARectShape(enem.position, enem.width // 3,
                                         enem.height // 3)
            collision_manager.add(enem)
            self.batch.add(enem)

        self.add(self.batch, z=1)
        self.obj[0].do(MoveTo((xpos, 570), delay) + Hide())
        self.obj[1].do(
            RandomDelay(10, 18) + MoveTo((xpos, 570), delay) + Hide())
        self.obj[2].do(
            RandomDelay(18, 28) + MoveTo((xpos, 570), delay) + Hide())
        self.obj[3].do(
            RandomDelay(28, 38) + MoveTo((xpos, 570), delay) + Hide())
        self.obj[4].do(Delay(2) + MoveTo((xpos, 620), delay) + Hide())
        self.obj[5].do(
            RandomDelay(10, 18) + MoveTo((xpos, 620), delay) + Hide())
        self.obj[6].do(
            RandomDelay(18, 28) + MoveTo((xpos, 620), delay) + Hide())
        self.obj[7].do(
            RandomDelay(28, 38) + MoveTo((xpos, 620), delay) + Hide())
        self.obj[8].do(Delay(5) + MoveTo((xpos, 520), delay) + Hide())
        self.obj[9].do(
            RandomDelay(10, 18) + MoveTo((xpos, 520), delay) + Hide())
        self.obj[10].do(
            RandomDelay(18, 28) + MoveTo((xpos, 520), delay) + Hide())
        self.obj[11].do(
            RandomDelay(28, 38) + MoveTo((xpos, 520), delay) + Hide())
        self.obj[12].do(Delay(8) + MoveTo((xpos, 470), delay) + Hide())
        self.obj[13].do(
            RandomDelay(18, 28) + MoveTo((xpos, 470), delay) + Hide())
        self.obj[14].do(
            RandomDelay(28, 38) + MoveTo((xpos, 470), delay) + Hide())
        self.obj[15].do(
            RandomDelay(10, 18) + MoveTo((xpos, 470), delay) + Hide())

        if level == 2:
            self.obj[16].do(Delay(10) + MoveTo((xpos, 420), delay) + Hide())
            self.obj[17].do(
                RandomDelay(18, 28) + MoveTo((xpos, 420), delay) + Hide())
            self.obj[18].do(
                RandomDelay(28, 38) + MoveTo((xpos, 420), delay) + Hide())
            self.obj[19].do(
                RandomDelay(10, 18) + MoveTo((xpos, 420), delay) + Hide())
            self.obj[20].do(Delay(11) + MoveTo((xpos, 370), delay) + Hide())
            self.obj[21].do(
                RandomDelay(18, 28) + MoveTo((xpos, 370), delay) + Hide())
            self.obj[22].do(
                RandomDelay(28, 38) + MoveTo((xpos, 370), delay) + Hide())
            self.obj[23].do(
                RandomDelay(10, 18) + MoveTo((xpos, 370), delay) + Hide())

        if level == 3:
            self.obj[16].do(Delay(10) + MoveTo((xpos, 420), delay) + Hide())
            self.obj[17].do(
                RandomDelay(18, 28) + MoveTo((xpos, 420), delay) + Hide())
            self.obj[18].do(
                RandomDelay(28, 38) + MoveTo((xpos, 420), delay) + Hide())
            self.obj[19].do(
                RandomDelay(10, 18) + MoveTo((xpos, 420), delay) + Hide())
            self.obj[20].do(Delay(11) + MoveTo((xpos, 370), delay) + Hide())
            self.obj[21].do(
                RandomDelay(18, 28) + MoveTo((xpos, 370), delay) + Hide())
            self.obj[22].do(
                RandomDelay(28, 38) + MoveTo((xpos, 370), delay) + Hide())
            self.obj[23].do(
                RandomDelay(10, 18) + MoveTo((xpos, 370), delay) + Hide())
            self.obj[24].do(Delay(12) + MoveTo((xpos, 320), delay) + Hide())
            self.obj[25].do(
                RandomDelay(18, 28) + MoveTo((xpos, 320), delay) + Hide())
            self.obj[26].do(
                RandomDelay(28, 38) + MoveTo((xpos, 320), delay) + Hide())
            self.obj[27].do(
                RandomDelay(10, 18) + MoveTo((xpos, 320), delay) + Hide())
            self.obj[28].do(Delay(13) + MoveTo((xpos, 270), delay) + Hide())
            self.obj[29].do(
                RandomDelay(18, 28) + MoveTo((xpos, 270), delay) + Hide())
            self.obj[30].do(
                RandomDelay(28, 38) + MoveTo((xpos, 270), delay) + Hide())
            self.obj[31].do(
                RandomDelay(10, 18) + MoveTo((xpos, 270), delay) + Hide())
            self.obj[32].do(Delay(14) + MoveTo((xpos, 220), delay) + Hide())
            self.obj[33].do(
                RandomDelay(18, 28) + MoveTo((xpos, 220), delay) + Hide())
            self.obj[34].do(
                RandomDelay(28, 38) + MoveTo((xpos, 220), delay) + Hide())
            self.obj[35].do(
                RandomDelay(10, 18) + MoveTo((xpos, 220), delay) + Hide())
            self.obj[36].do(Delay(15) + MoveTo((xpos, 160), delay) + Hide())
            self.obj[37].do(
                RandomDelay(28, 38) + MoveTo((xpos, 160), delay) + Hide())
            self.obj[38].do(
                RandomDelay(28, 38) + MoveTo((xpos, 100), delay) + Hide())
            self.obj[39].do(
                RandomDelay(28, 38) + MoveTo((xpos, 50), delay) + Hide())
            self.obj[40].do(
                RandomDelay(10, 15) + MoveTo((xpos, 70), delay) + Hide())
            self.obj[41].do(
                RandomDelay(10, 35) + MoveTo((xpos, 20), delay) + Hide())

        self.schedule(self.update)
Esempio n. 15
0
    def update(self, dt):
        global resultText, scoreText, score, lifeLine, lifeFlag, status
        if score >= 900 and lifeLine == 0 and lifeFlag:
            lifeLine = 1
            lifeFlag = False
            self.remove(self.lifeText)
            self.indicateLifeLine()
        gameOver = False
        flag = ''
        self.birdSprite.cshape.center = self.birdSprite.position
        for enem in self.obj:
            enem.cshape.center = enem.position

        collisions = collision_manager.objs_colliding(self.birdSprite)
        if collisions:
            for enem in self.obj:
                collisions = collision_manager.they_collide(
                    self.birdSprite, enem)
                if collisions:
                    self.obj.remove(enem)
                    if lifeLine == 1:
                        flag = 'life'
                    else:
                        flag = 'notscore'
                    gameOver = True
                    break
            if not gameOver:
                for enem in self.coin:
                    collisions = collision_manager.they_collide(
                        self.birdSprite, enem)
                    if collisions:
                        print "scored"
                        enem.do(Hide())
                        self.coin.remove(enem)
                        flag = 'score'
                        break
            if flag is 'notscore':
                print("Game Over!")
                resultText = lossText
                status = 'over'
                self.birdSprite.color = (180, 0, 0)
                self.birdSprite.stop()
                x, y = self.birdSprite.position
                self.birdSprite.do(Delay(0.005) + MoveTo((x, 0), 1) + Hide())
                self.schedule_interval(self.caption, 2)
                self.schedule_interval(self.gameOver, 7)
            elif flag is 'score':
                self.remove(self.labelText)
                score += 100
                print score
                self.labelText = cocos.text.Label(scoreText + str(score),
                                                  font_name='Times New Roman',
                                                  font_size=24,
                                                  bold=True)
                self.labelText.position = 520, 620
                self.labelText.do(Blink(3, 3))
                self.add(self.labelText)
            elif flag is 'life':
                self.birdSprite.do(Blink(2, 1))
                self.remove(self.lifeText)
                lifeLine = 0
                self.indicateLifeLine()