Exemplo n.º 1
0
def builder():
    r = Phy2DRoom(id='test1', width=256, height=256,worldWidth= 256,worldHeight= 256)
    
    # add player
    p = Entity( pos = [160, 100])
    shape_player = Rect (10, 20, offset=[-5,-10])
    p.addComponent (ShapeGfxOutline(shape_player, color=[255, 255, 255, 255]))
    p.addComponent (Collider(flag=var.Flags.player, mask = var.Flags.wall, tag = var.Tags.player, shape = shape_player))
    sm = StateMachine('walk')
    sm.states.append(Walk3D('walk', 5))
    p.addComponent(sm)
    p.addComponent(KeyInput())
    r.add (p, 'main')

    # add object
    o1 = Entity (pos= [200,170])
    o_shape = Rect(20,10)
    o1.addComponent (ShapeGfxOutline(o_shape, color=[255,255,255,255]))
    o1.addComponent (Collider(flag=var.Flags.wall, mask = var.Flags.player, tag= var.Tags.wall, shape=o_shape))
    r.add(o1, 'main')

    r.add (s(10,80,Line(A=[0,0],B=[50,25])), 'main')
    r.add (s(30,130,PolygonSimple(outline=[0, 0, 10, 0, 5, 20])), 'main')
    r.add (s(150,30,Circle(20)), 'main')
    r.add (s(190,20,PolygonTri(outline=[0,0,10,10,10,20,20,20,20,0,30,0,30,40,20,40,20,30,0,30])), 'main')
    #r.add (s(-150,80,Line(A=[0,0],B=[50,25])), 'main')
    return r
Exemplo n.º 2
0
 def f(args):
     P = [args[0] * vars.tileSize, args[1] * vars.tileSize]
     e = Entity(pos=P)
     e.addComponent(
         TiledGfx(tilesheet='gfx/smb1.png',
                  sheetSize=[16, 16],
                  tileData=[15, 5],
                  width=1,
                  height=1,
                  size=vars.tileSize,
                  repx=args[2],
                  repy=1))
     e.addComponent(
         Collider(flag=vars.flags.platform_passthrough,
                  mask=vars.flags.player,
                  tag=0,
                  shape=sh.Line(
                      A=[0, vars.tileSize, 0],
                      B=[args[2] * vars.tileSize, vars.tileSize, 0])))
     e.addComponent(
         PolygonalMover(origin=P,
                        loop=args[5],
                        pct=args[3],
                        moves=[{
                            'delta': [0, args[4] * vars.tileSize],
                            'speed': args[6],
                            'hold': 0
                        }]))
     e.addComponent(Platform())
     return e
Exemplo n.º 3
0
 def f(args):
     shape = None
     tm = getattr(tiles, props[1])
     x = args[0]
     y = args[1]
     z = args[2] if len(args) > 2 else 0
     width = tm[0]
     height = tm[1]
     collision = tm[2]
     data = tm[3]
     if collision:
         shape = sh.Rect(width=width * vars.tileSize,
                         height=height * vars.tileSize)
     e = Entity(pos=[x * vars.tileSize, y * vars.tileSize, z])
     e.addComponent(
         TiledGfx(tilesheet='gfx/smb1.png',
                  sheetSize=[16, 16],
                  tileData=data,
                  width=width,
                  height=height,
                  size=vars.tileSize))
     if collision:
         e.addComponent(
             Collider(flag=vars.flags.platform, mask=1, tag=1, shape=shape))
     return e
Exemplo n.º 4
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')
         size = [args[2], args[3]]
         a.addComponent(
             Collider(flag=vars.flags.foe,
                      mask=vars.flags.player,
                      tag=vars.tags.key,
                      shape=sh.Rect(width=size[0], height=size[1])))
         a.addComponent(
             Info(func=func, info=info, bounds=[0, 0, size[0], 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
Exemplo n.º 5
0
def basicItem(id: str):
    desc = Data.items[id]
    # create the entity
    tag = read(desc, 'tag', default_value=id)  # desc.get ('tag', id)

    pos = read(desc, 'pos', default_value=[0, 0, 0])
    e = Entity(tag, pos)

    # if the item has model
    model = read(desc, 'model', default_value=None)
    if model is not None:
        e.type = 'sprite'
        e.model = model
        if 'anim' in desc:
            e.anim = read(desc, 'anim')

    # check if hotspot is to be added
    text = read(desc, 'text', default_value=None)
    if text is not None:
        width = desc.get('width', None)
        height = desc.get('height', None)
        offset = desc.get('offset', (0, 0))
        priority = desc.get('priority', 1)
        if width is None or height is None:
            raise BaseException(
                'you need to specify width & height for hotspots!')
        e.addComponent(
            HotSpot(shape=Rect(width=width, height=height, offset=offset),
                    priority=priority,
                    onenter=hoverOn(id),
                    onleave=hoverOff,
                    onclick=run_action))

    # if speed is set --> item is a character
    speed = desc.get('speed', None)
    # add the character stuff
    if speed is not None:
        direction = desc.get('dir')
        state = desc.get('state', 'idle')
        text_color = desc.get('text_color')
        text_offset = desc.get('text_offset')
        e.addComponent(Character(speed, direction, state))
        e.addComponent(Info(text_color=text_color, text_offset=text_offset))
        # check if this is the current player
        # if so, I tag it as player, and make the camera follow him
        if State.player == id:
            e.tag = 'player'
            e.addComponent(Follow())

    if State.collision_enabled and 'collision' in desc:
        coll = desc['collision']
        box = read(coll, 'size')
        offset = read(coll, 'offset', default_value=[0, 0])
        flag = read(coll, 'flag')
        mask = read(coll, 'mask')
        tag = read(coll, 'tag')
        e.addComponent(
            Collider(flag, mask, tag, Rect(box[0], box[1], offset=offset)))

    return e
Exemplo n.º 6
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
Exemplo n.º 7
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(info=prop[1], delta=[args[2], args[3]]))
     return spawn
Exemplo n.º 8
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    
Exemplo n.º 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
Exemplo n.º 10
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
Exemplo n.º 11
0
 def f(args):
     x = args[0]
     y = args[1]
     a = Entity()
     a.addComponent(
         Collider(
             flag=vars.flags.platform,
             mask=vars.flags.player,
             tag=1,
             shape=sh.Line(
                 A=[args[2] * vars.tileSize, args[3] * vars.tileSize, 0],
                 B=[args[4] * vars.tileSize, args[5] * vars.tileSize, 0])))
     a.pos = (x * vars.tileSize, y * vars.tileSize, 0)
     return a
Exemplo n.º 12
0
 def f(args):
     x = args[0]
     y = args[1]
     w = args[2]
     h = args[3]
     rx = args[4]
     ry = args[5]
     a = Entity()
     #print ('image = ' + props[1])
     if len(props) > 1:
         a.addComponent (Gfx(image = props[1], repeat = [rx, ry]))
     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
Exemplo n.º 13
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
Exemplo n.º 14
0
def s(x: float, y: float, shape):
    o1 = Entity (pos = [x, y])
    o1.addComponent (ShapeGfxOutline(shape, color=[255,255,255,255]))
    o1.addComponent (Collider(flag=var.Flags.wall, mask = var.Flags.player, tag= var.Tags.wall, shape=shape))
    return o1