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
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
def f(args): props = prop[1] model = props['model'] fliph = props['fliph'] flipp = props['flipAtPlatformEnd'] speed = props.get('speed', 20) goomba = Sprite( model=model, pos=[args[0] * vars.tileSize, args[1] * vars.tileSize, -0.1]) goomba.addComponent( SmartCollider(flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.koopa)) 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)) goomba.addComponent(ScriptPlayer()) 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='walk2', anim='hide', speed=200, acceleration=0, flipHorizontal=fliph, flipWhenPlatformEnds=flipp, left=1)) stateMachine.states.append( FoeWalk(id='hide', anim='hide', speed=0, acceleration=0, flipHorizontal=fliph, flipWhenPlatformEnds=flipp, left=1)) goomba.addComponent(stateMachine) return goomba
def f(args): #model: str, x: float, y: float): props = prop[1] model = props['model'] fliph = props['fliph'] flipp = props['flipAtPlatformEnd'] ctag = props['ctag'] 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=getattr(vars.tags, ctag))) 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)) stateMachine.states.append(SimpleState(id='dead2', anim='idle')) goomba.addComponent(stateMachine) return goomba
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
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)