def draw(self): p = adjust_for_cam(self._body.position) gl.glEnable(pyglet.gl.GL_TEXTURE_2D) gl.glBindTexture(gl.GL_TEXTURE_2D, BLASTER_IMAGE.id) gl.glEnable(gl.GL_POINT_SPRITE) gl.glTexEnvi(gl.GL_POINT_SPRITE, gl.GL_COORD_REPLACE, gl.GL_TRUE) gl.glPointSize(4 * SPACE.scale) gl.glBegin(gl.GL_POINTS) # TODO: more optimized to draw as one large batch gl.glVertex3f(p.x, p.y, 0) gl.glEnd();
def draw(self): super(ScannerBlock, self).draw() if not self._active: return for b in SPACE.blocks: if not isinstance(b, ReactorBlock) or b.has_exploded: continue v = b._body.position - self._body.position d = v.length if d > BLOCK_SIZE * 5 and d < self.magnitude: v.length = BLOCK_SIZE * 5 pos = adjust_for_cam(self._body.position + v) self._arrow_sprite._x, self._arrow_sprite._y = pos.x, pos.y self._arrow_sprite.rotation = -(v.angle / math.pi * 180) self._arrow_sprite.scale = (self.magnitude - d) / self.magnitude self._arrow_sprite.draw()
def draw(self): # TODO: Let's use particles. And lighting! Way more fun. p = adjust_for_cam(self._body.position) if off_screen(self._body.position): return gl.glEnable(gl.GL_TEXTURE_2D) # enables texturing, without it everything is white gl.glBindTexture(gl.GL_TEXTURE_2D, EXPLOSION_ANIM.id) gl.glEnable(gl.GL_BLEND) gl.glBlendFunc(gl.GL_SRC_ALPHA,gl.GL_ONE_MINUS_SRC_ALPHA); # TODO: more optimized to draw as one large batch gl.glBegin(gl.GL_QUADS) r = (self.radius + BLOCK_SIZE) * SPACE.scale for i, vert in enumerate([Vec2d(p.x - r, p.y - r), Vec2d(p.x + r, p.y - r), Vec2d(p.x + r, p.y + r), Vec2d(p.x - r, p.y + r),]): # TODO: This is really ugly, and a lot of shared code with the # blocks. Let's write a draw_rect function to handle this # with an optional animation option. x = (i // 2) if x == 0: x = FRAME_POSITIONS[int((20 - self.ticks) / 20. * ANIM_FRAMES)][0] else: x = FRAME_POSITIONS[int((20 - self.ticks) / 20. * ANIM_FRAMES)][0] + 1 / ANIM_COLUMNS y = ((i + 1) // 2) % 2 if y == 0: y = FRAME_POSITIONS[int((20 - self.ticks) / 20. * ANIM_FRAMES)][1] else: y = FRAME_POSITIONS[int((20 - self.ticks) / 20. * ANIM_FRAMES)][1] + 1 / ANIM_ROWS gl.glTexCoord2f(x, y) gl.glVertex3f(vert.x, vert.y, 0) gl.glEnd()