예제 #1
0
 def f(args):
     spawn = Entity(pos=[args[0] * vars.tileSize, args[1] * vars.tileSize])
     spawn.addComponent(
         Collider(flag=vars.flags.foe,
                  mask=vars.flags.player,
                  tag=vars.tags.spawn,
                  shape=sh.Rect(1, 256)))
     spawn.addComponent(
         Info(factory=prop[1],
              info=prop[2],
              delta=[args[2], args[3]],
              bounds=[0, 0, 1, 256]))
     return spawn
예제 #2
0
 def f(args):
     # the first argument is the callback function
     # the second, if present, is the model
     model = prop[1].get('model', None)
     func = prop[1].get('func')
     info = prop[1].get('info', None)
     pos = [args[0]*vars.tileSize,args[1]*vars.tileSize]
     if model is None:
         a = Entity(pos=pos)
         size = prop[1].get('size')
         a.addComponent (Collider (flag = vars.flags.foe, mask = vars.flags.player, tag= vars.tags.key, shape=sh.Rect(width=size[0],height=size[1])))
     else:
         a = Sprite(model=model, pos=pos)
         a.addComponent (SmartCollider(flag=vars.flags.foe, mask = vars.flags.player, tag = vars.tags.key))
     a.addComponent (Info (func = func, info = info))
     return a
예제 #3
0
def _brick(x, y, model, hits, callback):
    a = Sprite(model=model, pos=[x * vars.tileSize, y * vars.tileSize, 0])
    a.addComponent(
        Collider(flag=vars.flags.platform,
                 mask=0,
                 tag=0,
                 shape=sh.Rect(width=vars.tileSize, height=vars.tileSize)))
    a.addComponent(Info(hitsLeft=hits, callback=callback))
    b = Entity()
    b.pos = [2, -0.5, 0]
    b.addComponent(
        Collider(flag=vars.flags.foe,
                 mask=vars.flags.player,
                 tag=vars.tags.bonus_brick_sensor,
                 shape=sh.Rect(width=vars.tileSize - 4, height=1.0)))
    a.add(b)
    return a
예제 #4
0
 def f(args):
     model = props[1]
     x = args[0]
     y = args[1]
     a = Sprite(model = model)
     a.addComponent (Collider (flag = vars.flags.platform, mask = 0, tag = 0, shape = sh.Rect(width=vars.tileSize, height=vars.tileSize)))
     a.pos = [x * vars.tileSize, y * vars.tileSize, 0]
     a.addComponent (Info(piece = props[2]))
     b = Entity()
     b.pos = [2, -0.5, 0]
     b.addComponent (Collider (
         flag=vars.flags.foe,
         mask=vars.flags.player,
         tag = vars.tags.brick_sensor,
         shape = sh.Rect(width = vars.tileSize-4, height = 1.0)
     ))
     a.add(b)
     return a    
예제 #5
0
 def f(args):
     print ('xxx')
     x = args[0] * vars.tileSize
     y = args[1] * vars.tileSize
     Ax = args[2] * vars.tileSize
     Ay = args[3] * vars.tileSize
     Bx = args[4] * vars.tileSize
     By = args[5] * vars.tileSize
     minx = min(Ax, Bx)
     maxx = max(Ax, Bx)
     miny = min(Ay, By)
     maxy = max(Ay, By)
     a = Entity()
     print ('xxx')
     a.addComponent (Collider(flag = vars.flags.platform, mask = vars.flags.player, tag = 1, 
         shape = sh.Line(A=[Ax,Ay,0], B=[Bx,By,0])))
     a.addComponent (Info (bounds = [minx,miny,maxx,maxy]))
     a.pos = (x,y,0)
     return a
예제 #6
0
 def f(args):
     x = args[0]
     y = args[1]
     w = args[2]
     h = args[3]
     a = Entity()
     #print ('image = ' + props[1])
     if len(props) > 1:
         a.addComponent(Gfx(image=props[1], repeat=[w, h]))
     else:
         a.addComponent(
             Info(bounds=[0, 0, w * vars.tileSize, h * vars.tileSize]))
     a.addComponent(
         Collider(flag=vars.flags.platform,
                  mask=vars.flags.player,
                  tag=1,
                  shape=sh.Rect(width=w * vars.tileSize,
                                height=h * vars.tileSize)))
     a.pos = (x * vars.tileSize, y * vars.tileSize, 0)
     return a
예제 #7
0
def makeFoe (id: str, x:float, y:float): #model: str, x: float, y: float, speed: float, scale: float = 1.0, energy=1):
    model, speed, scale, energy = vars.foes[id]
    

    collFlag = vars.flags.foe
    collMask = vars.flags.player | vars.flags.player_attack
    collTag = vars.tags.foe    
    castTag = vars.tags.foe_attack
    castMask = vars.tags.player
    
    entity = Sprite (model = model, pos = [x * vars.tileSize, y*vars.tileSize, 0])
    entity.addComponent (SmartCollider(
        flag = collFlag,
        mask = collMask,
        tag = collTag,
        castTag=castTag,
        castMask=castMask))
    entity.scale = scale
    entity.addComponent (Info (energy=energy))
    entity.addComponent (Controller2D(
        maskUp = vars.flags.platform, 
        maskDown = vars.flags.platform | vars.flags.platform_passthrough, 
        maxClimbAngle = 80, 
        maxDescendAngle = 80))
    
    entity.addComponent (Dynamics2D(gravity= vars.gravity))
    
    stateMachine = StateMachine(initialState='walk')
    
    stateMachine.states.append (FoeChase(id='walk', walkanim='walk', idleanim='idle', speed = 20, acceleration=0, attacks=['attack3'], prob_attack= 0.1))
    stateMachine.states.append (Attack(id='attack1', anim= 'attack1'))
    stateMachine.states.append (Attack(id='attack2', anim= 'attack2'))
    stateMachine.states.append (JAttack (id='attack3', animup='jumpup', animdown = 'jumpdown', animland='ciao', height=80, timeDown=0.2))
    stateMachine.states.append (SimpleState(id='dead', anim='hit'))
    stateMachine.states.append (IsHit(id='ishit', acceleration=300, anim='hit', dist =32))
    stateMachine.states.append (FoeWalk(id='landed', anim='landed',speed=0,acceleration=0,flipHorizontal=True,flipWhenPlatformEnds=False, left=False))
    stateMachine.states.append (FoeWalk(id='idle', anim='idle',speed=0,acceleration=0,flipHorizontal=True,flipWhenPlatformEnds=False, left=False))
    entity.addComponent (stateMachine)
    return entity
예제 #8
0
 def f(args):
     ps = prop[1] if len(prop)>0 else {}
     pin = Entity(pos = [args[0] * vars.tileSize, args[1] * vars.tileSize], tag=ps.get('tag',None))
     pin.addComponent (Collider(flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.warp, shape = sh.Rect(4, 2)))
     pin.addComponent (Info (world=args[2], start=args[3]))
     return pin
예제 #9
0
 def f(args):
     a = Sprite(model='door', pos = [args[0]* vars.tileSize, args[1]* vars.tileSize, -1])
     a.addComponent (Collider (flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.door, shape=sh.Rect(vars.tileSize, vars.tileSize*2)))
     a.addComponent (Info (var = args[2], world = args[3], start=args[4]))
     return a