Example #1
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
Example #2
0
    def __init__(self, id: str, width, height, worldWidth: int,
                 worldHeight: int, startPos):
        super().__init__(id, width, height)

        # adding pause button
        self.keyl.addKey(key=32, func=func.togglePause)
        self.keyl.addKey(key=299, func=func.restart)

        main = Entity(tag='main')
        main.camera = OrthoCamera(worldwidth=worldWidth * vars.tileSize,
                                  worldheight=worldHeight * vars.tileSize,
                                  camwidth=width,
                                  camheight=height,
                                  viewport=[0, 0, width, height],
                                  tag='maincam')
        self.main = main
        self.add(main)

        # create the collision engine (maybe to put into the ctor of the room subclass)
        ce = CollisionEngine(80, 80)
        #         ce.addResponse(vars.tags.player, vars.tags.brick_sensor, CollisionResponse(onenter=func.brickResponse))
        #         ce.addResponse(vars.tags.player, vars.tags.bonus_brick_sensor, CollisionResponse(onenter=func.bonusBrickResponse))
        #         ce.addResponse(vars.tags.player, vars.tags.mushroom, CollisionResponse(onenter=func.mushroomResponse))
        #         ce.addResponse(vars.tags.player, vars.tags.warp, CollisionResponse(onenter = func.onWarpEnter, onleave= func.onWarpExit))
        #         ce.addResponse(vars.tags.player, vars.tags.hotspot, CollisionResponse(onenter = func.hotspotEnter))
        #         ce.addResponse(vars.tags.player, vars.tags.coin, CollisionResponse(onenter = func.coinResponse))
        #         ce.addResponse(vars.tags.player, vars.tags.goomba, CollisionResponse(onenter = func.goombaResponse))
        #         ce.addResponse(vars.tags.player, vars.tags.koopa, CollisionResponse(onenter = func.koopaResponse))
        #         ce.addResponse (vars.tags.player, vars.tags.spawn, CollisionResponse (onenter = func.onSpawn))
        #         ce.addResponse (vars.tags.player, vars.tags.key, CollisionResponse (onenter = func.onCollectItem))
        #         ce.addResponse(vars.tags.goomba, vars.tags.player_fire, CollisionResponse (onenter = func.fireHitsFoe))
        self.addRunner(ce)
        self.addRunner(Scheduler())

        self.dw = DynamicWorld(256, 256, 'maincam')
        self.addRunner(self.dw)

        #         diag = Entity (tag = 'diag')
        #         diag.camera = OrthoCamera(worldwidth = width, worldheight = height,
        #             camwidth=width, camheight=height, viewport=[0, 0, width, height], tag='diagcam')
        #         diag.add(Text ('main', 8, engine.getString('mario'), [255, 255, 255, 255], TextAlignment.topleft, pos=[24, 248, 2]))
        #         diag.add(Text ('main', 8, '{:06d}'.format(vars.score), [255, 255, 255, 255], TextAlignment.topleft, tag='score_label', pos=[24, 240, 2]))
        #         diag.add(Text ('main', 8, engine.getString('world'), [255, 255, 255, 255], TextAlignment.topleft, pos=[144, 248, 2]))
        #         diag.add(Text ('main', 8, id, [255, 255, 255, 255], TextAlignment.top, pos=[164, 240, 2]))
        #         diag.add(Text ('main', 8, engine.getString('time'), [255, 255, 255, 255], TextAlignment.topright, pos=[232, 248, 2]))
        #         diag.add(Text ('main', 8, str(vars.time), [255, 255, 255, 255], TextAlignment.topright, tag='score_label', pos=[232, 240, 2]))
        #         diag.add(Sprite (model = 'coin_counter', pos=[96, 232, 2]))
        #         diag.add(Text ('main', 8, 'x', [255,255,255,255], pos=[108,240,2]))
        #         diag.add(Text ('main', 8, '{:02d}'.format(vars.coins), [255, 255, 255, 255], TextAlignment.topleft, tag='coin_label', pos=[116, 240, 2]))

        #         fpsCount = Text ('main', 8, '0', [255,255,255,255], align = TextAlignment.topleft, tag='fps', pos = [0, 256, 2])
        #         fpsCount.addComponent (FPSCounter())
        #         diag.add (fpsCount)

        #         self.add(diag)

        # add player
        wboy = build.makePlayer('wonderboy', startPos[0], startPos[1])
        main.add(wboy)
Example #3
0
def line(x: float, y: float, A, B):
    e = Entity(pos=[x, y])
    e.addComponent(
        compo.Collider(flag=vars.flags.platform,
                       mask=1,
                       tag=1,
                       shape=sh.Line(A, B)))
    return e
Example #4
0
def togglePause():
    if vars.paused:
        example.get('main').enableUpdate(True)
        example.removeByTag('shader')
    else:
        example.get('main').enableUpdate(False)
        a = Entity(pos=[0, 0, 1], tag='shader')
        a.addComponent(
            compo.ShapeGfxColor(shape=sh.Rect(256, 256),
                                fill=sh.SolidFill(r=0, g=0, b=0, a=64)))
        example.get('diag').add(a)
    vars.paused = not vars.paused
Example #5
0
def builder():
    r = PlatformerRoom(
        id = 'world1_1', 
        width = 256, 
        height = 256, 
        worldWidth = 224, 
        worldHeight = 16, 
        playerModel = 'cody', 
        startPos = [32, 32])
    
    # r.main.add (b.line(x=0,y=0,A=[128,0],B=[128,50]))
    # r.main.add (b.line(x=0,y=0,A=[128,50],B=[256,100]))
    # r.main.add (b.line(x=0,y=0,A=[256,100],B=[256,200]))
    # r.main.add (b.line(x=0,y=0,A=[0,200],B=[256,200]))
    # r.main.add (b.line(x=0,y=0,A=[0,200],B=[0,0]))
    shape = Polygon([0, 0, 512, 0, 512, 100, 0, 100])
    r.main.add (b.poly(0, 0, shape))
    e = Entity()
    e.pos = [0,0,-5]
    e.addComponent (ShapeGfx(shape = shape, texture = 'gfx/floor1.png', x0=2, repx=25, repy=25,slantx = 0.4 ))
    r.main.add(e)
    r.main.add (b.makeFoe('andore', 80, 32, 0.5, 5))
    
    wall = Entity()
    wall.pos=[0,100,-0.01*100]
    wall.addComponent (ShapeGfx(shape = Polygon([0,0,100,0,100,100,0,100]), texture='gfx/wall1.png', repx=32, repy=32))
    r.main.add(wall)
    r.main.add(b.makeStaticItem (ti.tree1, 50, 80))

    #ba=Entity()
    #ba.addComponent(compo.ShapeGfxColor(shape=sh.Rect(200,100), color=[255,255,255,255]))
    #r.main.add(ba)

    # with open(example.dir+ '/rooms/world1_1.yaml') as f:
    #     rooms = yaml.load(f, Loader=yaml.FullLoader)
    #     for a in rooms['room']:
    #         f = a['template'][0]
    #         args = a['template'][1:]
    #         print (args)
    #         method_to_call = getattr(fact, f, None)
    #         if method_to_call:
    #             template = method_to_call(*args)
    #             print (f + ' found')
    #             for im in a['d']:
    #                 print (im)
    #                 e = template(*im)
    #                 r.addToDynamicWorld(e)
    #         else:
    #             print (f + ' not found')

    return r
Example #6
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
Example #7
0
def togglePause():
    if vars.paused:
        example.get('main').enableUpdate(True)
        example.removeByTag('shader')
        #msg : example.Wrap1 = example.get('msg')
        #if msg.valid:
        #    example.killScript('msgscript')
        #    example.removeByTag('msg')
        #    example.removeByTag('msgbox')
        #    example.get('player').setState('walk', {})    
    else:
        example.get('main').enableUpdate(False)
        a = Entity(pos=[0,0,1], tag='shader')
        a.addComponent (compo.ShapeGfxColor(shape = sh.Rect(256, 256), fill = sh.SolidFill(r=0, g=0, b=0, a=64)))
        example.get('diag').add(a)
    vars.paused = not vars.paused
Example #8
0
 def f(args):
     x = args[0]
     y = args[1]
     z = args[2]        
     w = args[3]
     h = args[4]
     a=Entity()
     a.addComponent (Gfx(image = props[1], repeat = [w, h]))
     #f = Fader()
     ##f.addColor (0, [255,255,255,255])
     #f.addColor (1, [255,255,255,0])
     #f.addColor (2, [255,255,255,255])
     #a.addComponent (f)
     #a.addComponent (TexAnim (period=[0,-1]))
     a.pos = (x * vars.tileSize, y * vars.tileSize, z)
     return a
Example #9
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
Example #10
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    
Example #11
0
def makeBrick(model: str, x: float, y: float):
    a = Sprite(model=model)
    a.addComponent(
        compo.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]

    b = Entity()
    b.pos = [2, -0.5, 0]
    b.addComponent(
        compo.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
Example #12
0
def mapHotSpotItem(id: str):
    desc = Data.items[id]
    tag = desc.get('tag', id)
    pos = desc.get('pos', [0, 0, 0])
    e = Entity(tag, pos)
    width = desc.get('width', 10)
    height = desc.get('height', 10)
    textid = desc['text']
    from lib_py.engine import data
    text = data['strings']['objects'][textid]
    e.addComponent(
        HotSpot(shape=Rect(width=width,
                           height=height,
                           offset=(-width / 2, -height / 2)),
                priority=0,
                onenter=updateText(text),
                onleave=clearText,
                onclick=gotohotspot(id)))
    return e
Example #13
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
Example #14
0
 def f(args):
     p = props[1]
     print (p)
     a = Entity(pos=[args[0],args[1],args[2]])
     a.addComponent (Gfx(image=p['image'], repeat=p['repeat']))
     a.addComponent (Parallax(cam='maincam', factor=p['parallax'], campos0=[128,112], pos0=[0,64]))
     return a
Example #15
0
def tiled(x: float,
          y: float,
          tileSheet: str,
          sheetSize,
          tileData: list,
          width: int,
          height: int,
          size: float,
          z: float = 0,
          shape: sh.Shape = None):
    e = Entity(pos=[x * vars.tileSize, y * vars.tileSize, z])
    e.addComponent(
        compo.TiledGfx(tilesheet=tileSheet,
                       sheetSize=sheetSize,
                       tileData=tileData,
                       width=width,
                       height=height,
                       size=size))
    if shape:
        e.addComponent(
            compo.Collider(flag=vars.flags.platform,
                           mask=1,
                           tag=1,
                           shape=shape))

#if (args.collide) then
#	table.insert(components, { type = "collider", flag = variables.collision.flags.platform, mask = 1, tag=1, shape = { type="rect", width = args.width*engine.tilesize, height =
#		args.height*engine.tilesize }})
#end
    return e
Example #16
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
Example #17
0
def makePlayer(model: str, x: float, y: float):
    player = Sprite(model=model, pos=[x, 0], tag='player')
    player.scale = 0.5
    player.addComponent(
        compo.SmartCollider(flag=vars.flags.player,
                            mask=vars.flags.foe | vars.flags.foe_attack,
                            tag=vars.tags.player,
                            castTag=vars.tags.player_attack,
                            castMask=vars.flags.foe))
    player.addComponent(
        compo.Controller25(mask=vars.flags.platform, depth=y, elevation=256))
    player.addComponent(compo.Info(energy=5))
    #     maskDown = vars.flags.platform | vars.flags.platform_passthrough,
    #     maxClimbAngle = 80,
    #     maxDescendAngle = 80))
    # speed = 75
    player.addComponent(compo.Dynamics2D(gravity=vars.gravity))
    stateMachine = compo.StateMachine(initialState='walk')
    # stateMachine.states.append (compo.SimpleState (id='warp', anim='idle'))
    stateMachine.states.append(
        compo.Walk25(id='walk',
                     speed=200,
                     acceleration=0.05,
                     flipHorizontal=True,
                     jumpvelocity=vars.jump_velocity))
    stateMachine.states.append(compo.Hit25(id='attack', anim='attack'))
    stateMachine.states.append(
        compo.IsHit25(id='ishit', acceleration=0.5, anim='idle'))
    # stateMachine.states.append (pc.Jump(id='jump', speed=200, acceleration=0.10, flipHorizontal=True, animUp='jump', animDown='jump'))
    # stateMachine.states.append (pc.FoeWalk(id='demo', anim='walk', speed = 75,
    #     acceleration=0.05, flipHorizontal=True, flipWhenPlatformEnds = False, left=1))
    player.addComponent(stateMachine)
    player.addComponent(compo.KeyInput())
    player.addComponent(compo.Follow())
    baa = Entity(tag='pane')
    baa.addComponent(
        compo.ShapeGfxColor(shape=sh.Ellipse(20, 10), color=[0, 0, 0, 64]))
    player.add(baa)

    return player
Example #18
0
    def __init__(self, id: str, width, height, worldWidth: int,
                 worldHeight: int):
        super().__init__(id, width, height)
        # adding pause button
        #self.keyl.addKey(key=32, func = f)
        #self.keyl.addKey(key=264, func = checkWarp)

        main = Entity(tag='main')
        main.camera = OrthoCamera(worldwidth=worldWidth,
                                  worldheight=worldHeight,
                                  camwidth=width,
                                  camheight=height,
                                  viewport=[0, 0, width, height],
                                  tag='maincam')
        self.add(main)

        # create the collision engine (maybe to put into the ctor of the room subclass)
        ce = CollisionEngine(80, 80)
        ce.addResponse(var.Tags.player, var.Tags.wall,
                       CollisionResponse(onenter=f, onleave=g))
        self.addRunner(ce)
        self.addRunner(Scheduler())
Example #19
0
def makePlatform(img: str, x: float, y: float, width: int, height: int):
    a = Entity()
    a.addComponent(compo.Gfx(image=img, repeat=[width, height]))
    a.addComponent(
        compo.Collider(flag=vars.flags.platform,
                       mask=vars.flags.player,
                       tag=1,
                       shape=sh.Rect(width=width * vars.tileSize,
                                     height=height * vars.tileSize)))
    a.pos = [x * vars.tileSize, y * vars.tileSize]
    return a
Example #20
0
def bonusBrick(model: str,
               x: float,
               y: float,
               callback: callable,
               hits: int = 1):
    a = Sprite(model=model, pos=[x * vars.tileSize, y * vars.tileSize, 0])
    a.addComponent(
        compo.Collider(flag=vars.flags.platform,
                       mask=0,
                       tag=0,
                       shape=sh.Rect(width=vars.tileSize,
                                     height=vars.tileSize)))
    a.addComponent(compo.Info(hitsLeft=hits, callback=callback))
    b = Entity()
    b.pos = [2, -0.5, 0]
    b.addComponent(
        compo.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
Example #21
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
Example #22
0
def hotspot(x: float, y: float, warpTo, newCamBounds):
    e = Entity(pos=[x * vars.tileSize, y * vars.tileSize])
    e.addComponent(
        compo.Collider(flag=vars.flags.foe,
                       mask=vars.flags.player,
                       tag=vars.tags.hotspot,
                       shape=sh.Rect(16, 2)))
    e.addComponent(compo.Info(func=func.warpUp(warpTo, newCamBounds)))
    return e
Example #23
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
Example #24
0
def makeSpawn(x: float, y: float, f: callable, *args):
    print(args)
    e = Entity(pos=[x * vars.tileSize, y * vars.tileSize])
    e.addComponent(
        compo.Collider(flag=vars.flags.foe,
                       mask=vars.flags.player,
                       tag=vars.tags.hotspot,
                       shape=sh.Rect(1, 100)))
    e.addComponent(compo.Info(func=func.createItem(f, *args)))
    return e
Example #25
0
def hotspot2(x: float, y: float, width: float, height: float, f: callable):
    e = Entity(pos=[x * vars.tileSize, y * vars.tileSize])
    e.addComponent(
        compo.Collider(flag=vars.flags.foe,
                       mask=vars.flags.player,
                       tag=vars.tags.hotspot,
                       shape=sh.Rect(width * vars.tileSize,
                                     height * vars.tileSize)))
    e.addComponent(compo.Info(func=f))
    return e
Example #26
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
Example #27
0
 def f(args):
     a = Entity(pos=[args[0], args[1], args[2]])
     a.addComponent(
         ShapeGfxColor(shape=sh.Rect(256, 256),
                       fill=sh.SolidFill(r=props[1], g=props[2],
                                         b=props[3])))
     a.addComponent(
         Parallax(cam='maincam',
                  factor=[1, 1],
                  campos0=[128, 128],
                  pos0=[0, 0]))
     return a
Example #28
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
Example #29
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
Example #30
0
    def __init__(self, id:str, width, height, worldWidth: int, worldHeight : int, startPos):
        super().__init__(id, width, height)
        # adding pause button
        self.keyl.addKey(key=32, func = func.togglePause)
        #self.keyl.addKey(key=264, func = checkWarp)
        # restart on F10
        self.keyl.addKey(key=299, func = func.restart)

        main = Entity (tag='main')
        main.camera = OrthoCamera(worldwidth = worldWidth * vars.tileSize, worldheight = worldHeight * vars.tileSize, 
        camwidth=width, camheight=height, viewport=[0, 0, width, height], tag='maincam')
        self.main = main
        self.add(main)

        # create the collision engine (maybe to put into the ctor of the room subclass)
        ce = CollisionEngine(80, 80)
        ce.addResponse(vars.tags.player, vars.tags.brick_sensor, CollisionResponse(onenter=func.brickResponse))
        ce.addResponse(vars.tags.player, vars.tags.bonus_brick_sensor, CollisionResponse(onenter=func.bonusBrickResponse))
        ce.addResponse(vars.tags.player, vars.tags.mushroom, CollisionResponse(onenter=func.mushroomResponse))
        ce.addResponse(vars.tags.player, vars.tags.warp, CollisionResponse(onenter = func.onWarpEnter, onleave= func.onWarpExit))
        ce.addResponse(vars.tags.player, vars.tags.hotspot, CollisionResponse(onenter = func.hotspotEnter))
        ce.addResponse(vars.tags.player, vars.tags.coin, CollisionResponse(onenter = func.coinResponse))
        ce.addResponse(vars.tags.player, vars.tags.goomba, CollisionResponse(onenter = func.goombaResponse))
        ce.addResponse(vars.tags.player, vars.tags.koopa, CollisionResponse(onenter = func.koopaResponse))		
        ce.addResponse (vars.tags.player, vars.tags.spawn, CollisionResponse (onenter = func.onSpawn))
        ce.addResponse (vars.tags.player, vars.tags.key, CollisionResponse (onenter = func.onCollectItem))
        ce.addResponse(vars.tags.goomba, vars.tags.player_fire, CollisionResponse (onenter = func.fireHitsFoe))
        self.addRunner(ce)
        self.addRunner(Scheduler())


        self.dw = DynamicWorld(256, 256, 'maincam')
        self.addRunner(self.dw)

        diag = Entity (tag = 'diag')
        diag.camera = OrthoCamera(worldwidth = width, worldheight = height, 
            camwidth=width, camheight=height, viewport=[0, 0, width, height], tag='diagcam')
        diag.add(Text ('main', 8, engine.getString('mario'), [255, 255, 255, 255], TextAlignment.topleft, pos=[24, 248, 2]))
        diag.add(Text ('main', 8, '{:06d}'.format(vars.score), [255, 255, 255, 255], TextAlignment.topleft, tag='score_label', pos=[24, 240, 2]))
        diag.add(Text ('main', 8, engine.getString('world'), [255, 255, 255, 255], TextAlignment.topleft, pos=[144, 248, 2]))
        diag.add(Text ('main', 8, id, [255, 255, 255, 255], TextAlignment.top, pos=[164, 240, 2]))
        diag.add(Text ('main', 8, engine.getString('time'), [255, 255, 255, 255], TextAlignment.topright, pos=[232, 248, 2]))
        diag.add(Text ('main', 8, str(vars.time), [255, 255, 255, 255], TextAlignment.topright, tag='score_label', pos=[232, 240, 2]))
        diag.add(Sprite (model = 'coin_counter', pos=[96, 232, 2]))
        diag.add(Text ('main', 8, 'x', [255,255,255,255], pos=[108,240,2]))
        diag.add(Text ('main', 8, '{:02d}'.format(vars.coins), [255, 255, 255, 255], TextAlignment.topleft, tag='coin_label', pos=[116, 240, 2]))

        fpsCount = Text ('main', 8, '0', [255,255,255,255], align = TextAlignment.topleft, tag='fps', pos = [0, 256, 2])
        fpsCount.addComponent (FPSCounter())
        diag.add (fpsCount)

        self.add(diag)

	    # scene = {

		# 	[2] = {
		# 		tag = "diag",
		# 		camera = {
		# 			tag = "diagcam",
		# 			type ="ortho",
		# 			pos = {0,0,5},
		# 			size = {args.screen_size[1]*16, args.screen_size[2]*16},
		# 			bounds = {0,0,args.screen_size[1]*16, args.screen_size[2]*16},
		# 			viewport = {0, 0, args.screen_size[1]*16, args.screen_size[2]*16}
		# 		},
		# 		children = {
		# 	 		{
		# 				pos = {24,248,0},
		# 				components = {
		# 					{ type = "text", id="MARIO", font="main", size=8, }
		# 				}
		# 			},
		# 			{
		# 				tag = "score_label",
		# 				pos = {24, 240, 0},
		# 				components = {
		# 					{ type = "text", id=string.format("%06d", variables.score), font="main", size=8, }	
		# 				}
		# 			},
		# 	 		{
		# 				pos = {144,248,0},
		# 				components = {
		# 					{ type = "text", id="WORLD", font="main", size=8, }
		# 				}
		# 			},	
		# 	 		{
		# 				pos = {164,236,0},
		# 				components = {
		# 					{ type = "text", id=variables.world_name, font="main", size=8, align="center" }
		# 				}
		# 			},						
		# 			{
		# 				pos = {232,248,0},
		# 				components = {
		# 					{ type = "text", id="TIME", font="main", size=8, align="topright" }
		# 				}
		# 			},	
		# 			{
		# 				tag = "time_label",
		# 				pos = {232,240,0},
		# 				components = {
		# 					{ type = "text", id=tostring(variables.time), font="main", size=8, align="topright" }
		# 				}
		# 			},				
		# 			{
		# 				pos = {96, 232, 0},
		# 				type="sprite",
		# 				model="coin_counter"
		# 			},
		# 			{
		# 				pos = {108,240,0},
		# 				components = {
		# 					{ type = "text", id="x", font="main", size=8 }
		# 				}
		# 			},	
		# 			{
		# 				tag = "coin_label",
		# 				pos = {116, 240, 0},
		# 				components = {
		# 					{ type = "text", id=string.format("%02d", variables.coins), font="main", size=8, }	
		# 				}
		# 			},
		# 		}
		# 	}
		# },

        # add player
        mario = build.makePlayer(vars.stateInfo[vars.state], startPos[0], startPos[1])
        main.add(mario)