def test_sectorize(): """ Test the sectorize function. Currently assumes sector_size is 16, should make this not hard coded! """ my_pos = [65, 30, 65] expected = [4, 0, 4] sector = util.sectorize(my_pos) for i, e in zip(sector, expected): assert i == e, "Returned sector not what was expected"
def update(self, dt, ticks_per_second): self.world.process_queue(ticks_per_second) sector = sectorize(self.player.position) if sector != self.world.sector: self.world.change_sectors(self.world.sector, sector) if self.world.sector is None: self.world.process_entire_queue() self.world.sector = sector m = 8 dt = min(dt, 0.2) for _ in range(m): self.player.update(dt / m, self.world.objects)
def update(self, dt, ticks_per_second): self.world.process_queue(ticks_per_second) sector = sectorize(self.player.position) if sector != self.world.sector: self.world.change_sectors(self.world.sector, sector) if self.world.sector is None: self.world.process_entire_queue() self.world.sector = sector m = 8 dt = min(dt, 0.2) for _ in range(m): self.player.update(dt / m, self.world.area.get_blocks())
def remove_block(self, position, immediate=True): """Remove the block at the given `position`. Parameters ---------- position : tuple of len 3 The (x, y, z) position of the block to remove. immediate : bool Whether or not to immediately remove block from canvas. """ del self.objects[position] self.sectors[sectorize(position)].remove(position) if immediate: if position in self.shown: self.hide_block(position) self.check_neighbors(position)
def remove_block(self, position, immediate=True): """Remove the block at the given `position`. Parameters ---------- position : tuple of len 3 The (x, y, z) position of the block to remove. immediate : bool Whether or not to immediately remove block from canvas. """ del self.objects[position] # if all the blocks get removed from a sector the sector will stay in # sectors as a 'ghost sector' or something. I don't know if this matters. self.sectors[sectorize(position)][0].remove(position) if immediate: if position in self.shown: self.hide_block(position) self.check_neighbors(position)
def update(self, dt): """This method is scheduled to be called repeatedly by the pyglet clock. Parameters ---------- dt : float The change in time since the last call. """ self.world.process_queue(TICKS_PER_SEC) sector = sectorize(self.player.position) if sector != self.world.sector: self.world.change_sectors(self.world.sector, sector) if self.world.sector is None: self.world.process_entire_queue() self.world.sector = sector m = 8 dt = min(dt, 0.2) for _ in range(m): self.player.update(dt / m, self.world.objects)
def add_block(self, position, texture, immediate=True): """Add a block with the given `texture` and `position` to the world. Parameters ---------- position : tuple of len 3 The (x, y, z) position of the block to add. texture : list of len 3 The coordinates of the texture squares. Use `tex_coords()` to generate. immediate : bool Whether or not to draw the block immediately. """ if position in self.objects: self.remove_block(position, immediate) self.objects[position] = texture self.sectors.setdefault(sectorize(position), []).append(position) if immediate: if self.exposed(position): self.show_block(position) self.check_neighbors(position)