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
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
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
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
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
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
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
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
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
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