def f(*args): pos = makePos(*args) e = entity.Entity(pos=pos) e.add_component( comp.TiledGfx(tile_sheet='gfx/smb1.png', sheet_size=[16, 16], tile_data=[15, 5], width=1, height=1, size=vars.tile_size, repx=args[3], repy=1)) e.add_component( comp.Collider(flag=vars.flags.platform_passthrough, mask=vars.flags.player, tag=0, shape=sh.Line( a=[0, vars.tile_size, 0], b=[args[3] * vars.tile_size, vars.tile_size, 0]))) e.add_component( comp.PolygonalMover(origin=(pos[0], pos[1]), loop=args[6], pct=args[4], moves=[{ 'delta': [0, args[5] * vars.tile_size], 'speed': args[7], 'hold': 0 }])) e.add_component(comp.Platform()) return e
def f(*args): pos = makePos(*args) # coords of the top left tile. if (x, y) is the top left # then (x+1, y) is the top right, and (x, y+1) and (x+1, y+1) # the left and right walls of the pipe. sheet = vars.tile_data['tile_sheets']['main'] tl = kwargs.get('top_left') width = args[3] height = args[4] data = [tl[0], tl[1]] data.extend([tl[0] + 1, tl[1]] * (width - 2)) data.extend([tl[0] + 2, tl[1]]) e = entity.Entity(pos=pos) e.add_component( comp.TiledGfx(tile_sheet=sheet['file'], sheet_size=sheet['sheet_size'], tile_data=data, width=width, height=1, size=vars.tile_size)) shape = sh.Line(a=(0, vars.tile_size), b=(width * vars.tile_size, vars.tile_size)) e.add_component( comp.Collider(flag=vars.flags.platform, mask=1, tag=1, shape=shape, debug=True)) return e
def f(*args): shape = None tile_set_id = kwargs['id'] tile_set = vars.tile_data['tile_sets'][tile_set_id] pos = makePos2(*args) sheet_id = tile_set['sheet'] sheet = vars.tile_data['tile_sheets'][sheet_id] width = tile_set['size'][0] height = tile_set['size'][1] solid = tile_set['solid'] data = tile_set['data'] e = entity.Entity(pos=pos) e.add_component( comp.TiledGfx(tile_sheet=sheet['file'], sheet_size=sheet['sheet_size'], tile_data=data, width=width, height=height, size=vars.tile_size)) if solid: shape = sh.Rect(width=width * vars.tile_size, height=height * vars.tile_size) e.add_component( comp.Collider(flag=vars.flags.platform, mask=1, tag=1, shape=shape)) return e
def f(*args): pos = makePos(*args) # coords of the top left tile. if (x, y) is the top left # then (x+1, y) is the top right, and (x, y+1) and (x+1, y+1) # the left and right walls of the pipe. sheet = vars.tile_data['tile_sheets']['main'] tl = kwargs.get('top_left') height = args[3] data = [tl[0], tl[1] + 1, tl[0] + 1, tl[1] + 1] * (height - 1) data.extend([tl[0], tl[1], tl[0] + 1, tl[1]]) e = entity.Entity(pos=pos) e.add_component( comp.TiledGfx(tile_sheet=sheet['file'], sheet_size=sheet['sheet_size'], tile_data=data, width=2, height=height, size=vars.tile_size)) shape = sh.Rect(width=2 * vars.tile_size, height=height * vars.tile_size) e.add_component( comp.Collider(flag=vars.flags.platform, mask=1, tag=1, shape=shape)) foe = kwargs.get('foe', None) exit = kwargs.get('exit', None) if foe: foe_tag = monkey.engine.get_next_tag() pct = 1 if exit: if exit not in vars.disable_update_on_start: vars.disable_update_on_start[exit] = [] vars.disable_update_on_start[exit].append(foe_tag) pct = 0.5 p = plant(model=foe, pct=pct)(1, height, -0.1) p.tag = foe_tag plant_id = e.add(p) sensor = entity.Entity(pos=(vars.tile_size, height * vars.tile_size)) size = (8.0, 0.4, 0.0) sensor.add_component( comp.Collider(debug=True, flag=vars.flags.foe, mask=vars.flags.player, tag=vars.tags.generic_hotspot, shape=sh3d.AABB(size=size, offset=(-size[0] * 0.5, 0.0, 0.0)))) sensor.add_component( comp.Info(on_enter=freeze_plant(p.tag, False), on_leave=freeze_plant(p.tag, True))) e.add(sensor) warp_info = kwargs.get('warp', None) if warp_info: w = warp()(1, height, 0, warp_info[0], warp_info[1]) e.add(w) return e
def f(*args): sheet_id = kwargs.get('sheet', 0) sheet = vars.tile_sheets[sheet_id] tl = kwargs.get('top_left') tiledata = dict() lup = args[3] ldown = args[4] dy = ldown - lup x0 = tl[0] y0 = tl[1] tiledata[(0, 0)] = (x0 + 3, y0) tiledata[(0, -1)] = (x0, y0 + 3) x = 1 y = 1 for i in range(1, lup): tiledata[(x, y)] = (x0 + 3, y0) tiledata[(x, y - 1)] = (x0, y0 + 2) for j in range(0, 2 * i - 1): tiledata[(x, y - j - 2)] = (x0 + 1, y0 + 1) tiledata[(x, y - 2 - (2 * i - 1))] = (x0 + 2, y0 + 3) x += 1 y += 1 y -= 1 for i in range(0, ldown): tiledata[(x, y)] = (x0 + 1, y0 + 3) if i == 0 else (x0 + 3, y0 + 3) for j in range(0, ldown - i - 1): tiledata[(x, y - j - 1)] = (x0 + 1, y0 + 1) x += 1 y -= 1 # tiledata[(x, y-2*i-1)] = (x0+2,y0+3) # for j in range(0, 2*i-1): # tiledata[(x, y-j-2)] = (x0+1, y0+1) # tiledata[(x, y-2*i-1)] = (x0+2,y0+3) tdata = make_tiledata(tiledata) pos = (args[0] * vars.tile_size, (args[1] - dy) * vars.tile_size, args[2]) e = entity.Entity(pos=pos) e.add_component( comp.TiledGfx(tile_sheet=sheet['file'], sheet_size=sheet['sheet_size'], tile_data=tdata[0], width=tdata[1], height=tdata[2], size=vars.tile_size)) e.add_component( comp.Collider(debug=True, flag=vars.flags.platform_passthrough, mask=0, tag=0, shape=sh.Line(a=[0, dy * vars.tile_size], b=[ lup * vars.tile_size, (dy + lup) * vars.tile_size ]))) return e
def f(*args): sheet_id = kwargs.get('sheet', 0) sheet = vars.tile_sheets[sheet_id] tl = kwargs.get('top_left') extend_down = args[3] pos = (args[0] * vars.tile_size, (args[1]) * vars.tile_size, args[2]) x0 = tl[0] y0 = tl[1] data = args[4:] tiledata = dict() xmap = dict() cd = None x = 0 y = 0 cpoints = [] cpoints.append((0, 0)) left_border = False right_border = False for i in data: if i[-1] == 'S': tiledata[(x, y)] = (x0 + 3, y0 + 1) left_border = True x += 1 cpoints.append((x, y)) cd = 'R' elif i[-1] == 'E': tiledata[(x, y)] = (x0 + 4, y0 + 1) right_border = True x += 1 cpoints.append((x, y)) elif i[-1] == 'R': n = int(i[:-1]) if cd == 'U': y -= 1 tiledata[(x, y)] = (x0, y0) x += 1 n -= 1 elif cd == '/': y -= 1 elif cd == 'D': tiledata[(x, y)] = (x0 + 2, y0 + 2) x += 1 elif cd == '\\': x -= 1 tiledata[(x, y)] = (x0 + 2, y0 + 2) x += 1 for j in range(0, n): tiledata[(x, y)] = (x0 + 1, y0) x += 1 cpoints.append((x, y)) cd = i[-1] elif i[-1] == 'U': if cd == 'R': tiledata[(x, y)] = (x0, y0 + 2) y += 1 elif cd == '/': y -= 1 tiledata[(x, y)] = (x0, y0 + 2) # joint up n = int(i[:-1]) for j in range(0, n): tiledata[(x, y)] = (x0, y0 + 1) y += 1 cpoints.append((x, y - 1)) cd = 'U' elif i[-1] == 'D': n = int(i[:-1]) if cd == 'R': x -= 1 tiledata[(x, y)] = (x0 + 2, y0) y -= 1 n -= 1 for j in range(0, n): tiledata[(x, y)] = (x0 + 2, y0 + 1) y -= 1 cpoints.append((x + 1, y)) cd = 'D' elif i[-1] == '/': # slope up n = int(i[:-1]) if cd == 'R': tiledata[(x, y)] = (x0, y0 + 2) y += 1 for i in range(0, n): tiledata[(x, y)] = (x0 + 3, y0) if i < n - 1: tiledata[(x + 1, y)] = (x0, y0 + 2) x += 1 y += 1 cpoints.append((x, y - 1)) cd = '/' elif i[-1] == '\\': # slope down n = int(i[:-1]) if cd == 'D': tiledata[(x, y)] = (x0 + 2, y0 + 2) x += 1 for i in range(0, n): tiledata[(x, y)] = (x0 + 4, y0) if i < n - 1: tiledata[(x, y - 1)] = (x0 + 2, y0 + 2) x += 1 y -= 1 cpoints.append((x, y)) cd = '\\' print(cpoints) xmin = 0 xmax = 0 ymin = 0 ymax = 0 for t in tiledata.keys(): xmin = min(xmin, t[0]) xmax = max(xmax, t[0]) ymin = min(ymin, t[1]) ymax = max(ymax, t[1]) ymin -= extend_down width = xmax - xmin + 1 height = ymax - ymin + 1 for ix in range(xmin, xmax + 1): for iy in range(ymin, ymax + 1): if (ix, iy) in tiledata: break if ix == 0 and left_border: tiledata[(ix, iy)] = (x0 + 3, y0 + 2) elif ix == xmax and right_border: tiledata[(ix, iy)] = (x0 + 4, y0 + 2) else: tiledata[(ix, iy)] = (x0 + 1, y0 + 1) tdata = [] for iy in range(ymin, ymax + 1): for ix in range(xmin, xmax + 1): td = tiledata.get((ix, iy), None) if td: tdata.extend([td[0], td[1]]) else: tdata.extend([-1]) pos = (args[0] * vars.tile_size, (args[1] - 1 - abs(ymin)) * vars.tile_size, args[2]) e = entity.Entity(pos=pos) e.add_component( comp.TiledGfx(tile_sheet=sheet['file'], sheet_size=sheet['sheet_size'], tile_data=tdata, width=width, height=height, size=vars.tile_size)) for i in range(1, len(cpoints)): a = entity.Entity() a.add_component( comp.Collider( debug=True, flag=vars.flags.platform_passthrough, mask=0, tag=0, shape=sh.Line(a=[ cpoints[i - 1][0] * vars.tile_size, (cpoints[i - 1][1] + 1 + abs(ymin)) * vars.tile_size ], b=[ cpoints[i][0] * vars.tile_size, (cpoints[i][1] + 1 + abs(ymin)) * vars.tile_size ]))) e.add(a) return e