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 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
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 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
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 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
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
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
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
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 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 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
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
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
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
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
def __init__(self, model: str = None, anim : str = None, item : str = None, tag = None, pos = [0,0,0]): super().__init__(tag, pos) if not tag: self.tag = item if item: it : scumm.Item = s.State.items[item] if it.model is not None: self.type = 'sprite' self.model = model if model is not None else it.model self.anim = anim if anim is not None else it.anim self.addComponent(compo.HotSpot( shape = sh.Rect(width=it.width, height=it.height, offset = it.offset), priority=it.priority, onenter = hoverOn(item), onleave = hoverOff, onclick = sf.run_action))
def create(self, **kwargs): pos = kwargs.get('pos', self.pos) tag = kwargs.get('tag', self.id) anim = kwargs.get('anim', self.anim) e = entity.Entity (tag, pos) if self.model is not None: e.type = 'sprite' e.model = self.model e.anim = anim # check if hotspot is to be added if self.text is not None: if self.width is None or self.height is None: raise('you need to specify width & height for hotspots!') e.addComponent(compo.HotSpot( shape = sh.Rect(width = self.width, height = self.height, offset = self.offset), priority= self.priority, onenter = hoverOn(self.id), onleave = hoverOff, onclick = sf.run_action)) return e
def makeStaticItem(tmp, x, y): tr1 = Entity() tr1.pos = [x, y, -0.01 * y] tr1.children.append(poly(0, 0, sh.Rect(tmp[0], tmp[1], offset=tmp[2]))) tr1.addComponent(compo.Gfx(image=tmp[3])) return tr1