def on_draw(self): from pyglet.sprite import Sprite if not self.initialized: self.initialized = True self.init_gl() width, height = self.get_size() x_max = width // 32 + 1 y_max = height // 32 + 1 gl.glBlendFunc(gl.GL_SRC_ALPHA, gl.GL_ONE_MINUS_SRC_ALPHA) gl.glEnable(gl.GL_BLEND) fov = towel.FieldOfVision(self.passable.__contains__) fov.place_viewer(self.player, self.player_view) x, y = self.player x_offset = x - x_max // 2 y_offset = y - y_max // 2 x_range = range(0, x_max + 1) y_range = range(0, y_max + 1) self.clear() batch = pyglet.graphics.Batch() sprites = [] player_screen_pos = None for iy in y_range: for ix in x_range: p = (ix + x_offset, iy + y_offset) image = None color = (255, 255, 255) if fov.is_visible(p): if p in self.passable: image = self.image_floor else: image = self.image_wall self.remembered[p] = image else: image = self.remembered.get(p, None) color = (128, 128, 128) if image: sprite = Sprite(image, ix*32, iy*32, batch=batch) sprite.color = color sprites.append(sprite) if p == self.player: player_screen_pos = (ix*32, iy*32) batch.draw() if player_screen_pos: self.image_player.blit(*player_screen_pos) self.invalid = False
def draw(self, group): batch = Batch() ss = [] for particle in group: s = Sprite(self.image, batch=batch) s.position = list(particle.position)[:2] s.color = [c * 255 for c in list(particle.color)[:3]] s.scale = particle.size[0] / 64.0 s.rotation = particle.age * 720 s.opacity = particle.color[3] * 255 ss.append(s) batch.draw()