def draw(self): model = Matrix.identity() # translate model[3,0] = self.pos.x + (self.dir == -1 and 1.0 or 0.0) model[3,1] = self.pos.y model[0,0] = self.dir Shader.upload_model(model) self.texture.texture_bind() self.vbo.draw()
def draw(self, *args, **kwargs): Shader.upload_model(Matrix.identity()) self.texture.texture_bind() self.vbo.draw(*args, **kwargs)
def draw(self, q): Shader.upload_model(self.mat) self.texture.texture_bind() q.draw()
def render(self): glClearColor(1,0,1,1) glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT) with self.hpmeter as hud: hud.clear((0.3,0,0,1)) hud.cr.identity_matrix() hud.rectangle(0,0, hud.width, hud.height * self.player.hp_ratio, (0,0.3,0,1)) hud.cr.translate(18,0) hud.cr.rotate(math.pi*0.5) hud.text(' Energy: %d / %d' % (int(math.ceil(self.player.hp/10)) * 10, Player.max_hp), self.font2, color=(1,0.8,0,1)) with self.hud: self.hud.clear((0,0,0,0)) self.hud.cr.identity_matrix() t = pygame.time.get_ticks() / 1000.0 s = (t - self.texttime) / 4.0 if s > 1.0: if len(self.textbuf) > 0: self.texttime = pygame.time.get_ticks() / 1000.0 self.text = self.textbuf.pop(0) else: a = min(1.0-s, 0.2) * 5 self.hud.cr.translate(0,25) self.hud.text(self.text, self.font, color=(1,0.8,0,a), width=self.hud.width, alignment=ALIGN_CENTER) view = Matrix.lookat( self.player.pos.x, self.player.pos.y+7, 15, self.player.pos.x, self.player.pos.y+7, 0, 0,1,0) with self.fbo as frame: frame.clear(0,0.03,0.15,1) Shader.upload_projection_view(self.projection, view) Shader.upload_player(self.player) self.shader.bind() # parallax background pm1 = Matrix.identity() pm1[3,0] = self.player.pos.x * 0.35 - 20 pm1[3,1] = self.player.pos.y * 0.5 - 20 pm1[0,0] = 42.0 * self.parallax_rep pm1[1,1] = 42.0 self.parallax.texture_bind() Shader.upload_model(pm1) self.repquad.draw() Shader.upload_projection_view(self.projection, view) self.map.draw() # entities for obj in self.map.pickups: obj.draw(self.quad) self.player.draw() # parallax 2 pm1 = Matrix.identity() pm1[3,0] = self.player.pos.x * -2.0 + 100 pm1[3,1] = self.player.pos.y * 0.5 - 45 * 3 + 10 pm1[0,0] = 45.0 * self.parallax_rep * 3 pm1[1,1] = 45 * 3 self.parallax2.texture_bind() Shader.upload_model(pm1) self.repquad.draw() mat = Matrix.identity() mat[0,0] = self.size.x mat[1,1] = self.size.y Shader.upload_projection_view(self.ortho, Matrix.identity()) Shader.upload_model(mat) self.fbo.bind_texture() self.herp.bind() self.quad.draw() # messagebox mat = Matrix.identity() mat[3,0] = self.size.x / 2 - self.hud.width / 2 mat[3,1] = self.size.y - self.hud.height Shader.upload_model(mat) self.hud.draw() # hpmeter mat = Matrix.identity() mat[3,1] = self.size.y / 2 - self.hpmeter.height / 2 Shader.upload_model(mat) self.hpmeter.draw() Shader.unbind() pygame.display.flip()