def update_visibility_bbox(self, bbox): if self.paralax != 1: hw = (bbox.x2 - bbox.x1) / 2 hh = (bbox.y2 - bbox.y1) / 2 cx = (bbox.x1 + bbox.x2) / 2 * self.paralax cy = (bbox.y1 + bbox.y2) / 2 * self.paralax bbox = collide.BBox(cx - hw, cy - hh, cx + hw, cy + hh) # HACK visible_placed = set(self.placed) else: visible_placed = set(self.get_intersecting_placed(bbox)) for placed in self.visible_placed - visible_placed: if _debug: print 'unload', placed placed.unload() if placed in self.manual_draw: self.manual_draw.remove(placed) for placed in visible_placed - self.visible_placed: if _debug: print 'load', placed manual_draw = placed.load(self.batch) if manual_draw: self.manual_draw.append(placed) self.visible_placed = visible_placed
def update_visibility(self, dt=None): if self.x is None: return ww = globals.window.width wh = globals.window.height border = 100 test_bbox = collide.BBox(self.x - border, self.y - border, self.x + ww + border * 2, self.y + wh + border * 2) for layer in globals.game.layers: layer.update_visibility_bbox(test_bbox) if not self.follow: # In editor, don't do progressive globals.game.wait_for_tasks()
def load_task(self): c1 = self.col1 r1 = self.row1 self.bboxes = [[] for i in range(self.rows)] vertex_data = [] texture_data = [] color_data = [] y1 = self.y for row in range(self.rows): y2 = y1 + self.cell_height x1 = self.x for col in range(self.cols): x2 = x1 + self.cell_width self.bboxes[row].append(collide.BBox(x1, y1, x2, y2)) vertex_data.extend([x1, y1, x2, y1, x2, y2, x1, y2]) try: name = self.data[(col + c1, row + r1)] tile = get_tileset_tile(self.tileset, name) if tile.image: texture_data.extend(tile.image.tex_coords) else: texture_data.extend((0, 0, 0) * 4) color_data.extend(tile.color * 4) except KeyError: texture_data.extend((0, 0, 0) * 4) color_data.extend((0, 0, 0, 0) * 4) x1 = x2 y1 = y2 vl = self.batch.add(self.cols * self.rows * 4, GL_QUADS, None, ('v2i', vertex_data), ('t3f', texture_data), ('c4B', color_data)) self.vertex_list = vl yield self.loaded = True self.loading = False
def add_placed(self, placed): self.placed.append(placed) placed.bbox = collide.BBox(placed.x, placed.y, placed.x + placed.placeable.width, placed.y + placed.placeable.height)
def add_placeable_at(self, placeable, x, y): placed = placeable.place(x, y) placed.bbox = collide.BBox(x, y, x + placeable.width, y + placeable.height) self.placed.append(placed)
def __init__(self, name): self.name = name self.frames = [AnimFrame()] self.images = [] self.duration = 1.0 self.bbox = collide.BBox(0, 0, 0, 0)
def get_bbox(self): return collide.BBox(self.x, self.y, self.x + self.cols * self.cell_width, self.y + self.rows * self.cell_height)