def render(self, window): Scene.render(self, window) window.fill((255, 255, 0)) self.player.draw(window) self.player_ia.draw(window) self.ball.draw(window) self.btnGoHome.draw(window)
def render(self, window): Scene.render(self, window) window.fill((255, 0, 255)) self.btnGoHome.draw(window)
def main(): c = Context("pygame", (800, 400), "Renderer") init_engine() clock = Clock() obj0 = Obj(r"./assets/objects/tetrahedron.obj") obj1 = Obj(r"./assets/objects/halfcube.obj") obj2 = Obj(r"./assets/objects/octahedron.obj") obj3 = Obj(r"./assets/objects/dodecahedron.obj") obj4 = Obj(r"./assets/objects/teapot.obj") obj5 = Obj(r"./assets/objects/pointer.obj") tex0 = Tex(r"./assets/textures/_default.png") tex1 = Tex(r"./assets/textures/metal.jpg") tex2 = Tex(r"./assets/textures/abstract.jpg") tex3 = Tex(r"./assets/textures/white.png") model0 = Model(obj0, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8) model1 = Model(obj1, tex2, pos=Point(-1.5, 0.0, 0.0), scale=0.8) model2 = Model(obj2, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8) model3 = Model(obj3, tex0, pos=Point(0.0, 0.0, 0.0), scale=0.8) model4 = Model(obj4, tex3, pos=Point(10, 10, 10), scale=0.8) model5 = Model(obj5, tex1, pos=Point(0.0, 0.0, 0.0), scale=2.0) camera = Camera(pos=Point(0.0, 0.0, 3.0), rot=Rot(0.0, 0.0, 0.0), fovy=90) scene = Scene({model1, model4, model5}) camera_rotdeltas = { pygame.K_LEFT: Rot(0.0, -0.04, 0.0), pygame.K_RIGHT: Rot(0.0, 0.04, 0.0), pygame.K_DOWN: Rot(-0.04, 0.0, 0.0), pygame.K_UP: Rot(0.04, 0.0, 0.0), pygame.K_COMMA: Rot(0.0, 0.0, -0.04), pygame.K_PERIOD: Rot(0.0, 0.0, 0.04) } camera_posdeltas = { pygame.K_a: Point(-0.1, 0.0, 0.0), pygame.K_d: Point(0.1, 0.0, 0.0), pygame.K_s: Point(0.0, 0.0, 0.1), pygame.K_w: Point(0.0, 0.0, -0.1), pygame.K_f: Point(0.0, -0.1, 0.0), pygame.K_r: Point(0.0, 0.1, 0.0) } while True: clock.tick(60) c.idle() model0.rot += Rot(0.01, 0.02, 0.03) model1.rot += Rot(0.02, 0.03, 0.01) model2.rot += Rot(0.03, 0.01, 0.02) model3.rot += Rot(0.03, 0.02, 0.01) ## model4.rot += Rot(0.01, 0.03, 0.02) model5.rot += Rot(0.02, 0.01, 0.03) # rotate camera from keyboard inputs pygame.event.pump() pressed_keys = pygame.key.get_pressed() for k in camera_rotdeltas: if pressed_keys[k]: camera.rot += camera_rotdeltas[k] rx, ry, rz = camera.rot defacto_rot = Rot(rx, -ry, -rz) for k in camera_posdeltas: if pressed_keys[k]: camera.pos += defacto_rot.get_transmat() * camera_posdeltas[k] X, Y = c.getres() glViewport(0, 0, X, Y) scene.render(camera, aspect=X / Y, mode="full") c.dispbuffer()
def render(self, window): Scene.render(self, window) window.fill((255, 255, 255)) self.btnGoPong.draw(window) self.btnGoCamp.draw(window)