def generate_borderlines(self): self.borderlines = dict() left = shapes.Line((0, 0), None) right = shapes.Line((self.width, 0), None) top = shapes.Line((0, self.height), 0) bottom = shapes.Line((0, 0), 0) self.borderlines["left"] = left self.borderlines["right"] = right self.borderlines["top"] = top self.borderlines["bottom"] = bottom
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 __setstate__(self, dict): self._ppi = dict['ppi'] self._canvasSize = dict['canvasSize'] self.landscape = dict['landscape'] self.setObjectName(dict['ObjectName']) #load symbols from the file, while building the memory map as well. for item in dict['symbols']: graphic = getattr(shapes, item['_classname_'])() graphic.__setstate__(dict=item) self.painter.addItem(graphic) graphic.setPos(*item['pos']) graphic.updateLineGripItem() graphic.updateSizeGripItem() for gripitem in item['lineGripItems']: memMap[gripitem[0]] = (graphic, gripitem[1]) if item['label']: graphicLabel = shapes.ItemLabel( pos=QPointF(*item['label']['pos']), parent=graphic) graphicLabel.__setstate__(item['label']) self.painter.addItem(graphicLabel) graphic.rotation = item['rotation'] graphic.flipH, graphic.flipV = item['flipstate'] #load lines from the file, while using and building the memory map. for item in dict['lines']: line = shapes.Line(QPointF(*item['startPoint']), QPointF(*item['endPoint'])) memMap[item['id']] = line line.__setstate__(dict=item) self.painter.addItem(line) graphic, index = memMap[item['startGripItem']] line.startGripItem = graphic.lineGripItems[index] graphic.lineGripItems[index].lines.append(line) if item['endGripItem']: graphic, index = memMap[item['endGripItem']] line.endGripItem = graphic.lineGripItems[index] graphic.lineGripItems[index].lines.append(line) else: line.refLine = memMap[item['refLine']] memMap[item['refLine']].midLines.append(line) line.refIndex = item['refIndex'] for label in item['label']: labelItem = shapes.LineLabel(QPointF(*label['pos']), line) line.label.append(labelItem) labelItem.__setstate__(label) self.painter.addItem(labelItem) line.updateLine() line.addGrabber() # add streamtable if it existed in the scene. if dict['streamTable']: table = streamTable(self.labelItems, self) self.addStreamTable(QPointF(*dict['streamTable'][1]), table) table.__setstate__(dict['streamTable'][0]) memMap.clear( ) #clear out memory map as we now have no use for it. Hopefully garbage collected self.painter.advance() #request collision detection
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 get_visibility_polygon(self, current_position, current_rotation, num_rays, visibility_angle): # c = coord.Coord(self.x, self.y) vis_points = [int(current_position.get_x()), int(current_position.get_y())] rotation = current_rotation - visibility_angle offset = (visibility_angle * 2.0)/num_rays bbox = self.get_bbox(current_position) hits = list(self.__rtree_idx.intersection(bbox.get_rtree_bbox(), objects=True)) polygon_hits = [item.object for item in hits] # polygon_ids = [item.id for item in hits] # print('Polygons considered:', polygon_ids) nearby_polygons = polygon_hits + [bbox] + [self.__boundary_polygon] while rotation < current_rotation + visibility_angle: rotation_x = math.cos(coord.Coord.to_radians(-rotation)) rotation_y = math.sin(coord.Coord.to_radians(-rotation)) r = coord.Coord(current_position.get_x() + rotation_x, current_position.get_y() + rotation_y) rotation += offset if r.get_x() < 0 or r.get_x() > self.__width or r.get_y() < 0 or r.get_y() > self.__height: vis_points.append(int(current_position.get_x())) vis_points.append(int(current_position.get_y())) continue ray = shapes.Line(current_position, r) # print('ray:', ray) closest_intersect = None for polygon in nearby_polygons: # print('polygon:',polygon) for i in range(polygon.get_num_lines()): intersect = shapes.Line.get_intersection(ray, polygon.get_line(i)) if not intersect: continue if not closest_intersect or intersect[1] < closest_intersect[1]: closest_intersect = intersect if not closest_intersect: print('Closest intersect not found') print('From coordinate:', current_position) print('Ray:', ray) print('Segment:', polygon.get_line(i)) continue vis_points.append(int(closest_intersect[0].get_x())) vis_points.append(int(closest_intersect[0].get_y())) vis_points_tuple = tuple(vis_points) visibility_polygon = shapes.Polygon(vis_points_tuple) return visibility_polygon
def pumpkin(x, y, z, i, count, color): ''' makes a pumpkin shape ''' body = s.Pentagon(distance=20) body.setColor(color) body.setWidth(2) if i > 0: body.draw(x, y, zpos=z, pitch=-0 + count, orientation=18) body.setColor('orange') body.draw(x, y, zpos=z, pitch=-90 + count, orientation=18) ln = s.Line(distance=20, color='sienna') ln.setWidth(6) ln.draw(x, y, zpos=z, roll=0, pitch=0, orientation=45) i = i - 1 count = count + 60 pumpkin(x, y, z, i, count, color)
def __init__(self, width, height, number_of_seeds, seed_padding): self.width = width self.height = height self.number_of_seeds = number_of_seeds self.seed_padding = seed_padding self.sweepline_height = 0 self.sweepline_step = .5 self.sweepline = shapes.Line((0, self.sweepline_height), 0) try: self.generate_seed_points() self.generate_seeds() except: raise Exception("Too many seeds and/or too much padding") self.generate_borderlines()
def f(*args): x = args[0] * vars.tile_size y = args[1] * vars.tile_size ax = args[2] * vars.tile_size ay = args[3] * vars.tile_size bx = args[4] * vars.tile_size by = args[5] * vars.tile_size minx = min(ax, bx) maxx = max(ax, bx) miny = min(ay, by) maxy = max(ay, by) a = entity.Entity() a.add_component( comp.Collider(flag=vars.flags.platform, mask=vars.flags.player, tag=1, shape=sh.Line(a=[ax, ay, 0], b=[bx, by, 0]))) a.add_component(comp.Info(bounds=[minx, miny, maxx, maxy])) a.pos = (x, y, 0) return a
# Eli Decker # 5/1/17 # task3.py import shapes as s import lsystem as ls import turtle_interpreter as ti def flower(x, y, z, (r, gc, b), pitch=0, orientation=0, roll=0): ''' makes a multicolored flower shape ''' ln = s.Line(distance=90, color='sienna') ln.setWidth(3) ln.draw(x, y, zpos=z, roll=0, pitch=-90, orientation=0) for i in range(20): pt = s.Petal(distance=5) g = gc - (10 * i) c = (r, g, b) pt.setColor(c) pt.setDistance(3 - (i / 7)) pt.draw(x, y, zpos=z + (i * 5), roll=0, pitch=0, orientation=i * 50 + 137.5) def pumpkin(x, y, z, i, count, color): ''' makes a pumpkin shape ''' body = s.Pentagon(distance=20)
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