Example #1
0
def mushroom(x: float, y: float):
    a = Sprite(model='mushroom',
               pos=[x * vars.tileSize, y * vars.tileSize, -0.1])
    a.addComponent(
        SmartCollider(flag=vars.flags.foe,
                      mask=vars.flags.player,
                      tag=vars.tags.mushroom))
    a.addComponent(
        Controller2D(maskUp=vars.flags.platform,
                     maskDown=vars.flags.platform
                     | vars.flags.platform_passthrough,
                     maxClimbAngle=80,
                     maxDescendAngle=80))
    a.addComponent(Dynamics2D(gravity=vars.gravity))
    stateMachine = StateMachine(initialState='idle')
    stateMachine.states.append(SimpleState(id='idle', anim='walk'))
    stateMachine.states.append(
        FoeWalk(id='walk',
                anim='walk',
                speed=30,
                acceleration=0,
                flipHorizontal=False,
                flipWhenPlatformEnds=False,
                left=1))
    a.addComponent(stateMachine)
    return a
Example #2
0
def coin(x: float, y: float):
    a = Sprite(model='pickupcoin',
               pos=[x * vars.tileSize, y * vars.tileSize, 1])
    a.addComponent(
        compo.SmartCollider(flag=vars.flags.foe,
                            mask=vars.flags.player,
                            tag=vars.tags.coin))
    return a
Example #3
0
 def f(args):
     x = args[0]
     y = args[1]
     z = 0
     a = Sprite(model=props[1],
                pos=[x * vars.tileSize, y * vars.tileSize, z])
     return a
Example #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
Example #5
0
def makePiece(pos, vx, vy, model, parent : example.Wrap1):
    a = Sprite(model = model, pos = pos)
    id = parent.add(a)
    s = Script()
    s.addAction (act.MoveAccelerated (id = id, v0 = [vx, vy], a = [0, 0.5*vars.gravity], yStop=0))
    s.addAction (act.RemoveEntity (id = id))
    #		type = action.remove_object, args = { id = id1}
    example.play(s)
Example #6
0
def m3(x: float, y: float):
    a = Sprite('score100', pos=[x * vars.tileSize, (y + 1) * vars.tileSize, 0])
    main = example.get('main')
    id = main.add(a)
    s = Script()
    s.addAction(Move(speed=100, by=[0, 64], id=id))
    s.addAction(RemoveEntity(id=id))
    example.play(s)
Example #7
0
def m2(x: float, y: float):
    print ('x='+ str(x))
    def score():
        m3(x, y+1)
    a = Sprite ('flyingcoin', pos=[x * vars.tileSize, (y+1)*vars.tileSize, 0])
    main = example.get('main')
    id = main.add(a)
    s = Script()
    s.addAction(MoveAccelerated(v0 = [0, 100], a = [0, -100], yStop = (y*vars.tileSize) +16, id = id))
    s.addAction(RemoveEntity(id=id))
    s.addAction(CallFunc(f = score))
    example.play(s) 
Example #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    
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):
     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
Example #11
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 #12
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 #13
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
Example #14
0
    def f(args):  #model: str, x: float, y: float):
        props = prop[1]
        model = props['model']
        fliph = props['fliph']
        flipp = props['flipAtPlatformEnd']
        scale = props.get('scale', 1)
        speed = props.get('speed', 20)
        goomba = Sprite(
            model=model,
            pos=[args[0] * vars.tileSize, args[1] * vars.tileSize, -0.1])
        goomba.scale = scale
        goomba.addComponent(
            SmartCollider(flag=vars.flags.foe,
                          mask=vars.flags.player,
                          tag=vars.tags.goomba))
        goomba.addComponent(
            Controller2D(maskUp=vars.flags.platform,
                         maskDown=vars.flags.platform
                         | vars.flags.platform_passthrough,
                         maxClimbAngle=80,
                         maxDescendAngle=80))
        goomba.addComponent(Dynamics2D(gravity=vars.gravity))
        stateMachine = StateMachine(initialState='walk')
        stateMachine.states.append(
            FoeWalk(id='walk',
                    anim='walk',
                    speed=speed,
                    acceleration=0,
                    flipHorizontal=fliph,
                    flipWhenPlatformEnds=flipp,
                    left=1))
        stateMachine.states.append(
            FoeWalk(id='dead',
                    anim='dead',
                    speed=0,
                    acceleration=0,
                    flipHorizontal=fliph,
                    flipWhenPlatformEnds=flipp,
                    left=1))

        goomba.addComponent(stateMachine)
        return goomba
Example #15
0
def spr(model: str, x: float, y: float, z: float = 0.0, tag: str = None):
    a = Sprite(model=model,
               pos=[x * vars.tileSize, y * vars.tileSize, z],
               tag=tag)
    return a
Example #16
0
def makeFoe(model: str, x: float, y: float, scale: float, energy: int):
    foe = Sprite(model=model, pos=[x, 0])
    foe.scale = scale
    foe.addComponent(
        compo.SmartCollider(flag=vars.flags.foe,
                            mask=vars.flags.player | vars.flags.player_attack,
                            tag=vars.tags.foe,
                            castTag=vars.tags.foe_attack,
                            castMask=vars.flags.player))
    foe.addComponent(compo.Info(energy=energy))
    foe.addComponent(
        compo.Controller25(mask=vars.flags.platform, depth=y, elevation=0))
    foe.addComponent(compo.Dynamics2D(gravity=vars.gravity))
    stateMachine = compo.StateMachine(initialState='walk')
    # stateMachine.states.append (compo.SimpleState (id='warp', anim='idle'))
    stateMachine.states.append(
        compo.FoeWalk25(id='walk',
                        speed=20,
                        acceleration=0.05,
                        flipHorizontal=True,
                        delta=80))
    stateMachine.states.append(
        compo.IsHit25(id='ishit', acceleration=0.5, anim='idle'))
    stateMachine.states.append(compo.Hit25(id='attack', anim='attack'))
    foe.addComponent(stateMachine)
    return foe
Example #17
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)
Example #18
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 #19
0
def makePlayer(model: str, x: float, y: float):
    player = Sprite(model=model,
                    pos=[x * vars.tileSize, y * vars.tileSize],
                    tag='player')
    player.addComponent(
        SmartCollider(flag=vars.flags.player,
                      mask=vars.flags.foe | vars.flags.foe_attack,
                      tag=vars.tags.player))
    player.addComponent(
        Controller2D(maskUp=vars.flags.platform,
                     maskDown=vars.flags.platform
                     | vars.flags.platform_passthrough,
                     maxClimbAngle=80,
                     maxDescendAngle=80))
    speed = 75
    player.addComponent(Dynamics2D(gravity=vars.gravity))
    stateMachine = StateMachine(initialState='walk')
    stateMachine.states.append(SimpleState(id='dead', anim='dead'))
    stateMachine.states.append(
        WalkSide(id='walk',
                 speed=200,
                 acceleration=0.05,
                 jumpSpeed=vars.jump_velocity,
                 keys=[
                     [90, StateCallback(f=scripts.fire)],
                     [264, StateCallback(f=scripts.enterPipe)],
                 ],
                 flipHorizontal=True))
    stateMachine.states.append(
        Jump(id='jump',
             speed=200,
             acceleration=0.10,
             keys=[
                 [90, StateCallback(f=scripts.firej)],
             ],
             flipHorizontal=True,
             animUp='jump',
             animDown='jump'))
    stateMachine.states.append(Attack(id='attack1', anim='fire'))
    stateMachine.states.append(
        JumpAttack(id='attack2',
                   anim='fire',
                   speed=200,
                   acceleration=0.10,
                   flipHorizontal=True))
    stateMachine.states.append(
        FoeWalk(id='demo',
                anim='walk',
                speed=75,
                acceleration=0.05,
                flipHorizontal=True,
                flipWhenPlatformEnds=False,
                left=1))
    stateMachine.states.append(SimpleState(id='pipe', anim='idle'))
    stateMachine.states.append(SimpleState(id='slide', anim='slide'))
    player.addComponent(stateMachine)
    player.addComponent(KeyInput())
    player.addComponent(Follow())
    return player
Example #20
0
 def f(args):
     x = args[0]
     y = args[1]
     z = args[2] if len(args)>2 else 0
     a = Sprite(model=props[1], pos = [x * vars.tileSize, y * vars.tileSize, z])
     return a
Example #21
0
def _fire(a: example.Wrap1, state: str):
    if vars.state >= 2:
        a.setState(state, {})
        b = Sprite(model='fire',
                   pos=[a.x + (-2 if a.flipx else 2), a.y + 16, 0])
        b.flipx = a.flipx
        b.addComponent(
            Controller2D(maskUp=vars.flags.platform,
                         maskDown=vars.flags.platform
                         | vars.flags.platform_passthrough,
                         maxClimbAngle=80,
                         maxDescendAngle=80))
        b.addComponent(GarbageCollect(10))
        b.addComponent(Dynamics2D(gravity=vars.gravity))
        b.addComponent(
            SmartCollider(flag=vars.flags.player_attack,
                          mask=vars.flags.foe | vars.flags.platform,
                          tag=vars.tags.player_fire))
        sm = StateMachine(initialState='jmp')
        sm.states.append(Bounce(id='jmp', speed=300, a=0, b=200))
        b.addComponent(sm)
        id = example.get('main').add(b)