コード例 #1
0
 def f(*args):
     pos = makePos2(*args)
     foe_id = kwargs.get('id')
     foe_info = vars.foes[foe_id]
     model = foe_info['model']
     p = entity.Sprite(model=model, pos=pos)
     p.add_component(
         comp.SmartCollider(flag=vars.flags.foe,
                            mask=vars.flags.player,
                            tag=foe_info['tag']))
     p.add_component(
         comp.Controller2D(mask_up=vars.flags.platform,
                           mask_down=vars.flags.platform
                           | vars.flags.platform_passthrough,
                           max_climb_angle=80,
                           max_descend_angle=80,
                           size=foe_info['size'],
                           debug=True))
     p.add_component(comp.Dynamics2D(gravity=vars.gravity))
     sm = comp.StateMachine(initial_state='walk')
     sm.states.append(states.SimpleState(uid='dead', anim='dead'))
     sm.states.append(
         platformer.states.FoeWalk(
             uid='walk',
             anim='walk',
             speed=foe_info['speed'],
             acceleration=0,
             flip_horizontal=foe_info['flip_h'],
             flip_when_platform_ends=foe_info['flip_when_platform_ends'],
             left=1))
     p.add_component(sm)
     return p
コード例 #2
0
 def f(*args):
     model = kwargs.get('model')
     collision_tag = kwargs.get('tag')
     speed = kwargs.get('speed')
     pos = makePos(*args)
     a = entity.Sprite(model=model, pos=pos)
     a.add_component(
         comp.SmartCollider(flag=vars.flags.foe,
                            mask=vars.flags.player,
                            tag=collision_tag))
     a.add_component(
         comp.Controller2D(mask_up=vars.flags.platform,
                           mask_down=vars.flags.platform
                           | vars.flags.platform_passthrough,
                           size=(14, 16),
                           shift=(0, 8),
                           max_climb_angle=80,
                           max_descend_angle=80,
                           debug=True))
     a.add_component(comp.Dynamics2D(gravity=vars.gravity))
     sm = comp.StateMachine(initial_state='idle')
     sm.states.append(states.SimpleState(uid='idle', anim='walk'))
     sm.states.append(
         platformer.states.FoeWalk(uid='walk',
                                   anim='walk',
                                   speed=speed,
                                   acceleration=0,
                                   flip_horizontal=False,
                                   flip_when_platform_ends=False,
                                   left=1))
     a.add_component(sm)
     return a
コード例 #3
0
ファイル: items.py プロジェクト: fabr1z10/glib3
    def f(*args):
        pos = (args[0] * vars.tile_size, args[1] * vars.tile_size, args[2])
        current_state = vars.states[vars.state]
        model = current_state['model']
        speed = current_state['speed']
        p = entity.Sprite(model=model, pos=pos, tag='player')
        p.add_component(
            comp.SmartCollider(flag=vars.flags.player,
                               mask=vars.flags.foe | vars.flags.foe_attack,
                               tag=vars.tags.player))
        p.add_component(
            comp.Controller2D(mask_up=vars.flags.platform,
                              mask_down=vars.flags.platform
                              | vars.flags.platform_passthrough,
                              max_climb_angle=80,
                              max_descend_angle=80,
                              size=current_state['size'],
                              debug=True))
        p.add_component(comp.Dynamics2D(gravity=vars.gravity))
        sm = comp.StateMachine(initial_state='walk')
        sm.states.append(states.SimpleState(uid='dead', anim='dead'))
        sm.states.append(
            platformer.states.WalkSide(uid='walk',
                                       speed=speed,
                                       acceleration=0.05,
                                       jump_speed=vars.jump_velocity,
                                       flip_horizontal=True))
        # keys=[
        #     [90,  states.StateCallback(func.fire)],
        #     [264, states.StateCallback(func.enter_pipe)],
        # ]))
        sm.states.append(
            platformer.states.Jump(uid='jump',
                                   speed=speed,
                                   acceleration=0.10,
                                   flip_horizontal=True,
                                   anim_up='jump_up',
                                   anim_down='jump_down'))
        #keys=[
        #    [90, states.StateCallback(func.firej)],
        #]))
        sm.states.append(
            platformer.states.FoeWalk(uid='demo',
                                      anim='walk',
                                      speed=speed,
                                      acceleration=0.05,
                                      flip_horizontal=True,
                                      flip_when_platform_ends=False,
                                      left=1,
                                      flip_on_wall=False))
        sm.states.append(states.SimpleState(uid='pipe', anim='pipe'))
        #sm.states.append(states.SimpleState(uid='slide', anim='slide'))

        p.add_component(sm)
        p.add_component(comp.KeyInput())
        p.add_component(comp.Follow())
        return p
コード例 #4
0
def _fire(a: example.Wrap1, state: str):
    if vars.state >= 2:
        a.setState(state, {})
        b = entity.Sprite(model='fire',
                          pos=(a.x + (-2 if a.flipx else 2), a.y + 16, 0))
        b.flipx = a.flipx
        b.add_component(
            comp.Controller2D(mask_up=vars.flags.platform,
                              mask_down=vars.flags.platform
                              | vars.flags.platform_passthrough,
                              max_climb_angle=80,
                              max_descend_angle=80))
        b.add_component(comp.GarbageCollect(10))
        b.add_component(comp.Dynamics2D(gravity=vars.gravity))
        b.add_component(
            comp.SmartCollider(flag=vars.flags.player_attack,
                               mask=vars.flags.foe | vars.flags.platform,
                               tag=vars.tags.player_fire))
        sm = comp.StateMachine(initial_state='jmp')
        sm.states.append(
            platformer.states.Bounce(uid='jmp', speed=300, a=0, b=200))
        b.add_component(sm)
        example.get('main').add(b)
コード例 #5
0
ファイル: items.py プロジェクト: fabr1z10/glib3
    def f(*args):
        pos = (args[0], args[1], args[2])
        scale = kwargs.get('scale', vars.player_scale)
        #char_info = vars.  xcharactersgft```<
        speed = vars.player_speed
        model = vars.player_model
        width = 10
        p = entity.Sprite(model=model, pos=pos, tag='player')
        # TODO shadow
        #shadow = entity.Entity()
        #shadow.add_component(comp.ShadowRenderer(angle=20.0))
        #p.add(shadow)
        #p.layer = 2
        #p.depth = 0x0207
        #p.scale = scale * vars.scale
        p.scale = scale
        p.add_component(
            comp.Controller3D(size=[1, 1, 1],
                              shift=[0, 0.5],
                              debug=True,
                              mask_up=vars.flags.platform,
                              mask_down=vars.flags.platform
                              | vars.flags.platform_passthrough,
                              max_climb_angle=80,
                              max_descend_angle=80))
        p.add_component(comp.Dynamics2D(gravity=vars.gravity))
        p.add_component(
            comp.SmartCollider(flag=vars.flags.player,
                               mask=vars.flags.foe_attack,
                               tag=vars.tags.player,
                               cast_tag=vars.tags.player_attack,
                               cast_mask=vars.flags.foe,
                               debug=True))
        sm = comp.StateMachine(initial_state='walk')
        sm.states.append(
            pstates.WalkSide3D(
                uid='walk',
                speed=speed,
                acceleration=0.05,
                jump_speed=vars.jump_velocity,
                animator=pstates.YAnimator(idle_up='idle_up',
                                           idle_down='idle',
                                           walk_up='walk_up',
                                           walk_down='walk'),
                keys=[
                    [90, states.StateCallback(func.punch)
                     ],  #StateTransition('attack1')],
                    [265, states.StateCallback(func.climb_bottom)],
                    [264, states.StateCallback(func.climb_top)]
                ],
                flip_horizontal=True))
        sm.states.append(
            pstates.Jump3D(uid='jump',
                           speed=speed,
                           acceleration=0.10,
                           flip_horizontal=True,
                           keys=[],
                           anim_up='jump_up',
                           anim_down='jump_down'))
        # attack states
        sm.states.append(states.Attack(uid='attack0', anim='punch1'))
        sm.states.append(states.Attack(uid='attack1', anim='punch2'))
        sm.states.append(states.Attack(uid='attack2', anim='punch3'))
        sm.states.append(
            pstates.IsHit(uid='hit', anim='hit', acceleration=10, dist=4))

        #sm.states.append(states.Attack(uid='attack2', anim='attack2'))
        sm.states.append(
            pstates.Climb(uid='climb',
                          speed=50,
                          idle_anim='climb',
                          climb_anim='climb'))
        p.add_component(sm)
        p.add_component(comp.KeyInput())
        p.add_component(
            comp.DynamicFollow(
                world_width=5216,
                cam_width=384,
                cam_height=224,
                origin=(0, 256),
                path=[
                    3, 256, 2, 256, 3, 16, 2, 64, 3, 16, 2, 624, 0, 16, 2, 336,
                    3, 48, 2, 256, 3, 64, 2, 48, 3, 64, 2, 96, 3, 32, 2, 608,
                    0, 128, 2, 16, 0, 96, 2, 64, 0, 112, 2, 192, 0, 16, 2,
                    1536, 3, 16, 2, 320, 0, 32, 2, 16, 0, 16, 2, 16, 0, 48, 2,
                    144, 3, 160, 2, 192, 3, 32, 2, 432, 0, 336, 1, 80, 0, 48,
                    1, 112, 0, 112, 1, 672, 3, 32, 1, 256, 3, 96, 1, 2048, 3,
                    192, 1, 64, 0, 64, 1, 1984
                ]))
        #p.add_component(comp.Follow(relpos=(0, 0, 5), z=1))
        return p
コード例 #6
0
ファイル: items.py プロジェクト: fabr1z10/glib3
def foe(pos, info):
    model = info.get('model')
    scale = info.get('scale', 1.0)
    speed = info.get('speed', 50)
    energy = info.get('energy', 2)
    p = entity.Sprite(model=model, pos=pos)
    # shadow = entity.Entity()
    # shadow.add_component(comp.ShadowRenderer(angle=20.0))
    # p.add(shadow)
    p.layer = 1
    p.scale = scale
    p.add_component(
        comp.Controller3D(mask_up=vars.flags.platform,
                          mask_down=vars.flags.platform
                          | vars.flags.platform_passthrough,
                          size=[1, 1, 1],
                          shift=[0, 0.5],
                          max_climb_angle=80,
                          max_descend_angle=80,
                          debug=True))
    p.add_component(comp.Dynamics2D(gravity=vars.gravity))
    p.add_component(
        comp.SmartCollider(flag=vars.flags.foe,
                           mask=vars.flags.player_attack,
                           tag=vars.tags.foe,
                           cast_tag=vars.tags.foe_attack,
                           cast_mask=vars.flags.player,
                           debug=True))
    p.add_component(comp.Info(energy=energy))
    sm = comp.StateMachine(initial_state='walk')

    attacks = [{'state': 'attack0', 'prob': 0, 'in_range': True}]
    sm.states.append(states.Attack(uid='attack0', anim='punch'))
    # for i in range(0, n_attacks):
    #     attack_id = 'attack' + str(i+1)
    #     attack_list.append({'state': attack_id, 'prob': patt[i], 'in_range': True})
    #     sm.states.append(states.Attack(uid=attack_id, anim=attack_id))
    #     hp_map[attack_id] = hp[i]

    sm.states.append(
        pstates.FoeChase3D(uid='walk',
                           walk_anim='walk',
                           idle_anim='idle',
                           speed=speed,
                           acceleration=0.05,
                           attacks=attacks,
                           prob_attack=0))
    #     prob_attack=prob_attack))
    sm.states.append(
        pstates.IsHit(uid='hit', anim='hit', acceleration=10, dist=4))
    v0y = math.sqrt(2 * abs(vars.gravity) * 32)
    v0x = 64 * abs(vars.gravity) / v0y
    sm.states.append(
        pstates.Fly(uid='dead',
                    anim_up='dead_up',
                    anim_down='dead_down',
                    anim_lie='dead_lie',
                    v0=(v0x, v0y)))
    # sm.states.append(states.SimpleState(uid='dead', anim='hit'))
    p.add_component(sm)
    return p