示例#1
0
    def get_next_action(self):
        if self.obj1.busy or self.obj2.busy:
            return
        self.i += 1
        if self.i >= len(self.events):
            print(self.i)
            self.exit()
            return
        event = self.events[self.i]
        print(event)
        color = (0, 255, 0, 255)
        if event[0] < 0:  # show info on screen
            content = event[1]
            if content is 'Defeatenemy':
                if event[0] is -1:
                    self.map.defeated_character(self.df.pid)
                    self.defeat = self.at.pid
                elif event[0] is -2:
                    self.map.defeated_character(self.at.pid)
                    self.defeat = self.df.pid
            self.add_new_infos(content)
            pass
        else:
            hit, dmg, amg = event[1].split(',')
            dmg = int(dmg)
            amg = int(amg)
            if event[0] is 1:
                self.hp2 += dmg
                self.hp1 -= amg
                if hit is 'H':
                    content = "Heal by " + str(dmg) + ' Damage'
                elif hit is 'C':
                    content = 'Critical Attack by ' + str(dmg) + ' Damage'
                elif hit is 'M':
                    content = 'Miss'
                    color = (255, 0, 0, 255)
                else:
                    content = 'oooops'
            elif event[0] is 2:
                color = (255, 255, 0, 255)
                self.hp1 += dmg
                self.hp2 -= amg
                if hit is 'H':
                    content = "Counter by " + str(dmg) + ' Damage'
                elif hit is 'C':
                    content = 'Critical Reflect by ' + str(dmg) + ' Damage'
                elif hit is 'M':
                    content = 'Counter Miss'
                    color = (255, 0, 0, 255)
                else:
                    content = 'oooops'
            self.add_new_infos(content, color)

            t1, a1 = self.attacker.set_angle_action(self.hp1 / self.mhp1)
            t2, a2 = self.defender.set_angle_action(self.hp2 / self.mhp2)
            t1.busy = t2.busy = True
            t1.do(a1 + CallFunc(t1.parent.set_busy) +
                  CallFunc(self.get_next_action))
            t2.do(a2 + CallFunc(t2.parent.set_busy) +
                  CallFunc(self.get_next_action))
示例#2
0
 def set_angle_action(self, proportion, max_duration=4, min_duration=2):
     angle = 360 - proportion * 360
     delta = abs(self.angles - angle)
     if delta <= 10:
         return self.right_ring, Delay(min_duration)
     duration = min(1, delta / 90) * (max_duration - min_duration)
     if self.angles > angle: # right rotation
         if angle >= 180:
             return self.right_ring, (Delay(0.5) + RotateTo(180, duration + min_duration) + CallFunc(self.change_angle, angle))
         elif self.angles <= 180:
             return self.right_ring, (Delay(0.5) + RotateTo(angle, duration + min_duration) + CallFunc(self.change_angle, angle))
         else:
             d1 = (duration + min_duration) * (self.angles - 180) / delta
             d2 = duration + min_duration - d1
             return self.right_ring, (Delay(0.5) + RotateTo(180, d1)
                                + RotateBy(angle - 180, d2) + CallFunc(self.change_angle, angle))
     else: #
         if angle <= 180:
             return self.right_ring, (Delay(0.5) + RotateTo(angle, duration + min_duration) + CallFunc(self.change_angle, angle))
         elif self.angles >= 180:
             return self.right_ring, (Delay(0.5) + RotateTo(angle, duration + min_duration) + CallFunc(self.change_angle, angle))
         else:
             d1 = (duration + min_duration) * (180 - self.angles) / delta
             d2 = duration + min_duration - d1
             return self.right_ring, (Delay(0.5) + RotateBy(180 - self.angles, d1)
                                + RotateBy(angle - 180, d2) + CallFunc(self.change_angle, angle))
示例#3
0
    def __init__(self):
        super(TestLayer, self).__init__()

        self.add(TestFigure())
        self.schedule(lambda x: 0)
        if autotest:
            self.do(
                Delay(1.0) + CallFunc(self.upscale) + Delay(1.0) +
                CallFunc(self.upscale))
示例#4
0
 def getHit(self):
     if self.is_dead_scene_Playing == False and self.is_shield == False:
         self.total_lives -= 1
         self.revive_Pattern = Place(self.startLocation) + CallFunc(
             self.revive) + Blink(4, 2) + CallFunc(self.shieldoff)
         self.deadtemplate = Delay(0.5) + CallFunc(self.destroy)
         self.die()
         if self.total_lives <= 0:
             director.replace(FadeTransition(FinishScene(self.gScene)))
示例#5
0
 def attack(self, battle_element):
     at, df, wp, map, pos = battle_element
     battle = Battle(at, df, wp, df.item[0], map, pos)
     res = battle.battle()
     del battle
     obj = self.person[at.pid]
     action = self._sequential_move(self.select, self.dst)
     obj.do(action + CallFunc(self._battle_scene, res) + CallFunc(self.clear_map)
            + CallFunc(self.take_turn))
示例#6
0
    def _add_animation(self, node, drink):
        """
        Construct an animation path for the label.
        """
        node.scale = 0.5

        content_offset = (node.scale * node.label.element.content_width +
                          self._drink_distance) / 2

        # Make sure only one item has focus
        minimum_offset = (
            (self._focus_length + self._focus_ramp) * self._screen_width) / 2
        if content_offset < minimum_offset:
            content_offset = minimum_offset

        content_time = float(content_offset) / self._scroll_speed

        # Set start position
        node.position = (self._screen_width + content_offset, self._ticker_y)

        # Construct the path
        # Move to beginning of screen
        (coordinates, _) = self._path[0]
        move_actions = MoveTo(coordinates, content_time)

        # Move to ramp up
        (coordinates, time) = self._path[1]
        move_actions += MoveTo(coordinates, time)

        # Do the ramp
        (coordinates, time) = self._path[2]
        move_actions += (MoveTo(coordinates, time) |
                         (Delay(time / 2) + ScaleTo(1, time / 2))
                         | CallFunc(self._set_focused_drink, drink))

        # Move in focus
        (coordinates, time) = self._path[3]
        move_actions += MoveTo(coordinates, time)

        # Ramp down
        (coordinates, time) = self._path[4]
        move_actions += MoveTo(coordinates, time) | (ScaleTo(0.5, time / 2))

        # Move to end of screen
        (coordinates, time) = self._path[5]
        move_actions += MoveTo(coordinates, time)

        # Move out of sight
        move_actions += MoveTo((0 - content_offset, self._ticker_y),
                               content_time)

        # Prepare spawn point
        spawn_actions = Delay(content_time * 2) + CallFunc(self._next_drink)
        self.do(spawn_actions)

        # Start animation
        node.do(move_actions + CallFunc(self._safe_kill, node))
示例#7
0
文件: menu.py 项目: LLNT/3X-Project
 def on_mouse_press(self, x, y, buttons, modifiers):
     left = self.parent.get('left')
     right = self.parent.get('right')
     if buttons == 4:
         if left.selected:
             self.do(Delay(0.5) + CallFunc(left.inactivate))
         elif right.selected:
             self.do(Delay(0.5) + CallFunc(right.inactivate))
         else:
             self.cancel()
    def __init__(self):
        super( HelloWorld, self ).__init__()

        # a cocos.text.Label is a wrapper of pyglet.text.Label
        # with the benefit of being a cocosnode
        self.label = cocos.text.Label('Hi',
            font_name='Times New Roman',
            font_size=32,
            x=320, y=240,
            anchor_x='center', anchor_y='center')
        self.add( self.label )
        if autotest:
            self.do( Delay(1) + CallFunc(self.move_label, 100, 100) +
                     Delay(1) + CallFunc(self.move_label, 500, 300))
示例#9
0
    def _replace_node(self, new_node):
        """
        Move a new node into display, slow animation.
        """
        if not self.is_running:
            if debug_mode:
                print("Not running")
            if self._current_node:
                self._current_node.kill()
                self._current_node = None

            return

        if self._current_node:
            self._current_node.do(
                MoveTo(self._point_offscreen_left, 0.5 * self._move_time) +
                CallFunc(self._current_node.kill))

        self._current_node = UpdatableNode(new_node,
                                           self._point_offscreen_right)

        self._current_node.do(
            Delay(0.5 * self._move_time) +
            MoveTo(self._point_onscreen, 0.5 * self._move_time))
        self.add(self._current_node)
示例#10
0
    def __init__(self, pos):
        super().__init__(Image.coin)

        self.position = pos
        self.scale = 0.8

        self.do(MoveBy((0, 35), 0.1) + Delay(0.1) + CallFunc(self.kill))
示例#11
0
    def __init__(self, back_team, front_team, location):
        """

        :param back_team:
        :type back_team: team.Team
        :param front_team:
        :type front_team: team.Team
        :param location:
        :type location: str
        """
        Layer.__init__(self)

        self.background_image = Sprite(pyglet.image.load(
            resource.load_resource("bg-" + location + ".jpg", "BattleBackgrounds")),
            position=(640/2, 480/2), scale=0.8)
        self.add(self.background_image)

        self.back_team = back_team
        self.front_team = front_team

        self.back_team.set_orientation(constants.BACK_FACING)
        self.front_team.set_orientation(constants.FRONT_FACING)

        self.back_team.add_to_battle(self)
        self.front_team.add_to_battle(self)

        self.add(self.front_team)
        self.add(self.back_team)

        self.animation_locked = False
        self.toggle_animation_lock = CallFunc(self._toggle_animation_lock)
        self.hud = BattleHUD(self)
        self.add(self.hud)
示例#12
0
    def switch_pokemon(self, source_index, target_index):
        if not self.current_battle:
            raise RuntimeError("Trying to switch active pokemon when there is no battle active!")
        elif self.current_battle.animation_locked:
            return

        source_pokemon = self.pokemon[source_index]
        source_sprite = source_pokemon.get_sprite_for_orientation(self.orientation)
        destination_pokemon = self.pokemon[target_index]
        destination_sprite = destination_pokemon.get_sprite_for_orientation(self.orientation)
        original_position = source_sprite.position

        if self.orientation == constants.BACK_FACING:
            switch_out = MoveTo((0, 0), duration=0.25)
        else:
            destination_sprite.position = (640, 480)
            switch_out = MoveTo((640, 480), duration=0.25)

        def switch_in():
            destination_sprite.do(self.add_sprite +
                                  MoveTo(original_position, duration=0.25) +
                                  self.current_battle.toggle_animation_lock)

        switch_in = CallFunc(switch_in)

        source_sprite.do(switch_out + self.remove_sprite + switch_in)
        self.current_battle.enable_animation_lock()
        self.pokemon[target_index] = source_pokemon
        self.pokemon[source_index] = destination_pokemon
        self.current_battle.hud.update_health_bars()
示例#13
0
    def level_up(self):
        if self.i == self.level:
            if self.flag:
                director.window.push_handlers(self.parent)
                self.flag = False
                del self
            return
        self.info_clear(1)
        self.info_clear(2)
        self.info_clear(3)
        
        content_origin = ['Origin']
        for ability in self.abilities:
            content_origin.append(str(self.origin[ability]))
        self.display(content_origin, font_size=20, contentid=1,
                     pos_range=((self.width // 3, 0), (self.width * 5 // 9, self.height)))
        growth = self.growthlist[self.i]
        content_grow = ['Grow']
        for ability in self.abilities:
            content_grow.append(str(growth[ability]))
        self.display(content_grow, font_size=20, contentid=2,
                     pos_range=((self.width*5//9, 0), (self.width*7//9, self.height)))
        content_new = ['New']
        for ability in self.abilities:
            self.origin[ability] = growth[ability] + self.origin[ability]
            content_new.append(str(self.origin[ability]))
        self.display(content_new, font_size=20, contentid=3,
                     pos_range=((self.width *7//9, 0), (self.width, self.height)))


        self.do(Delay(0.5) + CallFunc(self.bar_raise))
        self.i += 1
    def __init__(self):
        super(TestLayer, self).__init__()

        x, y = director.get_window_size()
        self.color1 = [255, 0, 0, 255]
        self.color2 = [0, 0, 255, 255]

        self.label = Label('', (x // 2, y // 2))
        self.label.do(Rotate(360, 10))
        self.label.do(
            Repeat(
                Delay(1) + CallFunc(self.set_color, 0) + Delay(1) +
                CallFunc(self.set_color, 1) + Delay(1) +
                CallFunc(self.set_color, 2)))
        self.add(self.label)
        self.set_color(2)
示例#15
0
文件: map_scene.py 项目: J-GG/Pymon
    def pkmn_center_door(self, x: int, y: int) -> None:
        """Animate the pkmn center door opening or closing.

        :param x: The x coordinates of the pkmn center door.
        :param y: The y coordinates of the pkmn center door.
        """

        reverse = True if "pkmn_center_door" in self._scroller.children_names else False

        tileset = pyglet.image.load(PATH + "/assets/map/pkmn_center_door.png")
        tileset_grid = pyglet.image.ImageGrid(tileset, 1, 4, MapScene.TILE_SIZE, tileset.height)
        tileset_anim = pyglet.image.Animation.from_image_sequence(
            reversed(tileset_grid) if reverse else tileset_grid,
            0.1,
            loop=False
        )
        animation = cocos.sprite.Sprite(tileset_anim)
        animation.position = (x + MapScene.TILE_SIZE / 2, y + MapScene.TILE_SIZE + tileset.height / 2)

        scrollable_layer = cocos.layer.ScrollableLayer()
        scrollable_layer.add(animation)

        if reverse:
            self._scroller.remove("pkmn_center_door")
            callback = lambda: self._scroller.remove("pkmn_center_door")
            self.do(Delay(0.4) + CallFunc(callback))

        self._scroller.add(scrollable_layer, z=1, name="pkmn_center_door")
示例#16
0
 def on_enter(self):
     # handler's auto registration only happens for window's events;
     # we want to listen director events, so explicitly registering
     super(AutocenteredBackgroundLayer,self).on_enter()
     director.push_handlers(self.on_cocos_resize)
     if autotest:
         self.do(Delay(2.0) + CallFunc(resize) )
示例#17
0
 def start_animation(self):
     self.clean_skins()
     self.animating = True
     self.clean_control_points()
     if self.user_skin:
         skin = BitmapSkin(self.skeleton, self.user_skin)
     else:
         skin = ColorSkin(self.skeleton, (255, 255, 255, 255))
     self.add(skin)
     xs, ys = director.get_window_size()
     skin.position = xs / 2 - 6, ys / 2 - 11
     self.animation.move_start()
     skin.do(
         Animate(self.animation) + CallFunc(lambda: self.remove(skin)) +
         CallFunc(self.stop_animation))
     skin.do(UpdateTimeline(self.animation.get_duration()),
             target=self.animation)
示例#18
0
 def excute(self, i=0):
     if i < self.length:
         _target, _action = self.actionlist[i]  #type:CocosNode, Action
         if _target is None:
             _target = CocosNode()
         _target.do(_action + CallFunc(self.excute, i+1))
     else:
         print('excuted')
def main():
    show_common_text()
    autoscale = True
    if autoscale:
        show_mode_1_text()
    else:
        show_mode_2_text()
    director.init(view_width, view_height, autoscale=autoscale)

    scene = TestScene()
    world_layer = SquareLand(world_width, world_height)
    scroller = cocos.layer.ScrollingManager()
    if autotest:
        def resize_scroller():
            scroller.scale = 0.75
        w, h = world_width, world_height
        template_action = (
            Delay(0.05) + 
            CallFunc(world_layer.teleport_player, 0, 0) + Delay(1) +
            CallFunc(world_layer.teleport_player, w//2, 0) + Delay(1) +
            CallFunc(world_layer.teleport_player, w//2, h) +Delay(1) +
            CallFunc(world_layer.teleport_player, w, h) + Delay(1) +
            CallFunc(resize_scroller) + Delay(1) +
            CallFunc(director.window.set_size, 800, 600) + CallFunc(world_layer.update_after_change)
            )
        world_layer.do(template_action)
    scroller.add(world_layer)
    scene.add(scroller)
    director.run(scene)
示例#20
0
    def raise_flag(self, x):
        ground_y = Mario.GROUND_POS_Y[self.state]

        def lower_flag():
            self.image = Image.mario_lower_flag[self.state]

            delta_y = ground_y - self.y + 16
            self.do(MoveBy((8, 0), 0.2) + MoveBy((0, delta_y), 1.8))

        def turn_around_after_lower_flag():
            delta_y = ground_y - self.y
            self.do(MoveBy((16, 0), 0.1) + MoveBy((8, delta_y), 0.1))
            self.image = Image.mario_lower_flag_turn_around[self.state]

        self.do(
            CallFunc(lower_flag) + Delay(2) +
            CallFunc(turn_around_after_lower_flag) + Delay(0.5) +
            CallFunc(Sound.play, "stage_clear") + WalkToCastle((x, ground_y)) +
            CallFunc(self.kill))
示例#21
0
 def bar_raise(self, duration=3):
     if self.bar.scale_x == 1:
         self.bar.scale_x = 0
     if self.i < self.level:
         d = duration * (1 - self.bar.scale_x)
         scale = 1
     else:
         scale = self.leftexp / 100
         d = duration * (scale - self.bar.scale_x)
     self.bar.do(Scale_to(scale_x=scale, scale_y=1, duration=d) + CallFunc(self.level_up))
示例#22
0
    def update_timer(self, dt):
        stats.update_timer(dt)

        if stats.time == 100:
            Sound.stop("mario")
            Sound.play("out_of_time")
            self.do(Delay(2) + CallFunc(Sound.play, "mario"))

        if stats.time <= 0:
            self.game_over("timeout")
示例#23
0
    def __init__(self):
        super(TestLayer, self).__init__()

        x, y = director.get_window_size()

        self.sprite = Sprite('grossini.png')
        self.add(self.sprite)
        self.sprite.do(MoveTo((x, y), 10))
        if autotest:
            self.do(Delay(1) + CallFunc(self.resize))
示例#24
0
    def __init__(self, name, pos):
        if name == "unknown":
            image = Image.unknown_brick
        else:
            image = Image.normal_brick

        super().__init__(image)

        self.position = pos

        self.do(JumpBy((0, 0), 8, 1, 0.2) + CallFunc(self.kill))
示例#25
0
    def level_up(self):
        print(self.i, self.level)
        if self.i >= self.level:
            if self.flag:
                print('end')
                self.flag = False
                self.do(Delay(0.5) + CallFunc(self._callback))
                return
        self.info_clear(1)
        self.info_clear(2)
        self.info_clear(3)

        content_origin = ['Origin']
        for ability in self.abilities:
            content_origin.append(str(self.origin[ability]))
        self.display(content_origin,
                     font_size=20,
                     contentid=1,
                     pos_range=((self.width // 3, 0), (self.width * 5 // 9,
                                                       self.height)))
        growth = self.growthlist[self.i]
        content_grow = ['Grow']
        for ability in self.abilities:
            content_grow.append(str(growth[ability]))
        self.display(content_grow,
                     font_size=20,
                     contentid=2,
                     pos_range=((self.width * 5 // 9, 0), (self.width * 7 // 9,
                                                           self.height)))
        content_new = ['New']
        for ability in self.abilities:
            self.origin[ability] = growth[ability] + self.origin[ability]
            content_new.append(str(self.origin[ability]))
        self.display(content_new,
                     font_size=20,
                     contentid=3,
                     pos_range=((self.width * 7 // 9, 0), (self.width,
                                                           self.height)))

        self.do(Delay(0.5) + CallFunc(self.bar_raise))
        self.i += 1
示例#26
0
文件: game.py 项目: m-game/pygames
    def __init__(self):
        super(Oneself, self).__init__()
        self.position = (WIDTH / 2, 0 + 100)

        self.sprite = Sprite('airplane_710px_1219057_easyicon.net.png',
                             scale=0.1)
        self.add(self.sprite)

        # self.cshape = cm.AARectShape(eu.Vector2(self.anchor_x, self.anchor_y), self.anchor_x, self.anchor_y)

        fire = Repeat(Delay(0.2) + CallFunc(self.fire))
        self.do(fire)
示例#27
0
    def __init__(self):
        super( TestLayer, self ).__init__()

        x,y = director.get_window_size()

        self.sprite = Sprite( 'grossini.png', (x//2, y//2) )
        self.sprite.visible = False
        self.add( self.sprite )

        def make_visible( sp ):
            sp.visible = True
        self.sprite.do( Delay(1) + CallFunc( make_visible, self.sprite ) )
示例#28
0
    def __init__(self):

        # call superclass with the title
        super(MainMenu, self).__init__("MultiplexLayer")

        l = []
        l.append(MenuItem('Options', self.on_new_game))
        l.append(MenuItem('Quit', self.on_quit))

        self.create_menu(l)
        if autotest:
            self.do(Delay(1) + CallFunc(self.on_new_game))
示例#29
0
文件: menu.py 项目: LLNT/3X-Project
    def item(self, item):
        if self.selected is not None:
            for name in self.parent.children_names:
                if self.parent.children_names[name] == self:
                    self.name = name
            self.parent.remove('left')
            self.parent.remove('right')
            self.do(
                Delay(0.5) + CallFunc(
                    self.arena.exchange_item(self.selected, item, self.name)))

        else:
            self.selected = item
            left = self.parent.get('left').selected
            right = self.parent.get('right').selected
            if left is not None and right is not None:
                self.parent.remove('left')
                self.parent.remove('right')
                self.do(
                    Delay(0.5) +
                    CallFunc(self.arena.exchange_item(left, right)))
示例#30
0
 def __init__(self, e):
     super(EnemyObject, self).__init__(e[0].R.ENEMY[e[1]])
     #X(axis)-Location for enemy
     self.e = e
     self.isDead = False
     self.scale = 0.7
     self.position = (director._window_virtual_width,
                      random.randint(30,director._window_virtual_height - 34 - self.height/2))
     self.velocity = (-100, 0)
     self.deadtemplate = Delay(0.5) + CallFunc(self.destroy)
     self.do(Move())
     #Collision Shape
     self.cshape = CollisionModel.AARectShape(self.position, self.width/2, self.height/2)