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