Exemplo n.º 1
0
Arquivo: bt2.py Projeto: btdevel/bt
    def __init__(self):
        ShowBase.__init__(self)
        self.disableMouse()
        self.camera.setPos(10, -80, 70)
        self.camera.lookAt(10, 20, 0)
        self.camLens.setFov(90.0)
        self.win.setClearColor(Vec4(0,0,0,0))

        make_level(self.render)

        self.accept("escape", exit)
        self.accept("arrow_up", self.forward)
        self.accept("arrow_down", self.reverse)
        self.accept("arrow_left", self.turn_left)
        self.accept("arrow_right", self.turn_right)

        self.accept("1", self.set_camera)
        self.accept("2", self.set_camera_out)
        self.accept("3", self.spin_camera_left)
        self.accept("4", self.spin_camera_right)
    
        slight = PointLight('slight')
        slight.setColor(Vec4(1, 1, 1, 1))
        slnp = render.attachNewNode(slight)
        render.setLight(slnp)
        slnp.setPos(self.camera, 0, 0, 20)

        alight = AmbientLight('alight')
        alight.setColor((0.2, 0.2, 0.2, 1))
        alnp = render.attachNewNode(alight)
        render.setLight(alnp)

        title = OnscreenText(text="Bard's Tale I",
                             style=1, fg=(1,1,1,1),
                             pos=(0.7,0.92), scale = .07)

        self.dir = Direction()
        self.pos = Vector([0, 0])
        self.set_camera()

        self.map = make_map()
Exemplo n.º 2
0
Arquivo: bt2.py Projeto: btdevel/bt
class App(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        self.disableMouse()
        self.camera.setPos(10, -80, 70)
        self.camera.lookAt(10, 20, 0)
        self.camLens.setFov(90.0)
        self.win.setClearColor(Vec4(0,0,0,0))

        make_level(self.render)

        self.accept("escape", exit)
        self.accept("arrow_up", self.forward)
        self.accept("arrow_down", self.reverse)
        self.accept("arrow_left", self.turn_left)
        self.accept("arrow_right", self.turn_right)

        self.accept("1", self.set_camera)
        self.accept("2", self.set_camera_out)
        self.accept("3", self.spin_camera_left)
        self.accept("4", self.spin_camera_right)
    
        slight = PointLight('slight')
        slight.setColor(Vec4(1, 1, 1, 1))
        slnp = render.attachNewNode(slight)
        render.setLight(slnp)
        slnp.setPos(self.camera, 0, 0, 20)

        alight = AmbientLight('alight')
        alight.setColor((0.2, 0.2, 0.2, 1))
        alnp = render.attachNewNode(alight)
        render.setLight(alnp)

        title = OnscreenText(text="Bard's Tale I",
                             style=1, fg=(1,1,1,1),
                             pos=(0.7,0.92), scale = .07)

        self.dir = Direction()
        self.pos = Vector([0, 0])
        self.set_camera()

        self.map = make_map()


    def spin_camera_right(self, degrees=360):
        s = self.dir.dir * 90.0
        self.camera.hprInterval(1, Point3(s, 0, 0), 
                                startHpr=Point3(s+degrees, 0, 0)).start()
    def spin_camera_left(self, degrees=360):
        s = self.dir.dir * 90.0
        self.camera.hprInterval(1, Point3(s, 0, 0), 
                                startHpr=Point3(s-degrees, 0, 0)).start()

    def set_camera(self):
        print self.pos, self.dir
        def pos2vec(pos):
            return Point3(pos[0]*2, pos[1]*2, 0)
        pos = pos2vec(self.pos)
        dir = pos2vec(self.dir.forward_vec)
        
        self.camera.setPos(pos)
        self.camera.setPos(Point3(pos-dir*0.5))
        self.camera.lookAt(Point3(pos+dir))

    def set_camera_out(self):
        self.camera.setPos(10, -80, 70)
        self.camera.lookAt(10, 20, 0)

    def forward(self):
        self.pos = self.pos + self.dir.forward_vec
        self.set_camera()

    def reverse(self):
        self.dir.reverse()
        self.set_camera()

    def turn_left(self):
        self.dir.left()
        self.set_camera()

    def turn_right(self):
        self.dir.right()
        self.set_camera()