Esempio n. 1
0
    def updateJoystick(self, fDelta_f:float) -> None:
        for jo in self.joysticks_l:
            a = jo.get_axis(0)
            b = jo.get_axis(1)
            if abs(a) < 0.1:
                a = 0.0
            if abs(b) < 0.1:
                b = 0.0
            self.target.moveAround(mm.Vec4(a, 0, b),fDelta_f*3)

            a = jo.get_axis(3)
            b = jo.get_axis(4)
            if abs(a) < 0.1:
                a = 0.0
            if abs(b) < 0.1:
                b = 0.0
            self.target.getAngleY().addDegree(-fDelta_f*b*100)
            self.target.getAngleX().addDegree(-fDelta_f*a*100)
Esempio n. 2
0
    def __init__(self):
        super().__init__("player", (0.0, 1.0, 0.0))

        self.nearbyTriggers = []

        self.boundingBoxAabb = co.Aabb(
            (-0.4, 0.0, -0.4), (0.4, 1.8, 0.4), "player_boudingbox", 10,
            (0.0, 0.0, 0.0), False, True, True, False, [], 2)

        self.flashLightOn_b = True
        self.flashLight = SpotLight("flashlight", False, (0.0, 1.4, 0.0),
                                    (0.8, 0.8, 0.8), 30.0, 30.0)
        self.flashLight.genShadowMap()

        self.segment = co.Segment("aim", False, (0.0, 1.6, 0.0),
                                  mm.Vec4(0, 0, -1000, 0))

        self.biggerBoundingBoxAabb = co.Aabb(
            (-2, -1, -2), (2, 3, 2), "player_reach_area", 10, (0.0, 0.0, 0.0),
            False, True, True, False, [], 2)
Esempio n. 3
0
 def getLookingVec(self) -> mmath.Vec4:
     ver, hor, _ = self.getWorldDegreeXYZ()
     vec = mmath.Vec4(0, 0, -1)
     vec = vec.transform(mmath.getRotateXYZMat4(-ver, 1, 0, 0),
                         mmath.getRotateXYZMat4(-hor, 0, 1, 0)).normalize()
     return vec
Esempio n. 4
0
    def update(self) -> None:
        openedConsole_b = False
        if self.globalStates.titleScreen_b:
            for event in p.event.get():
                if event.type == pl.QUIT:
                    self.mainLoop.commandQueue_l.append("sys_exit")
                elif event.type == pl.VIDEORESIZE:
                    self.globalStates.winWidth_i = event.dict['w']
                    self.globalStates.winHeight_i = event.dict['h']
                    self.mainLoop.onResize()
                elif event.type == pl.KEYDOWN:
                    console = self.mainLoop.console
                    if event.key == pl.K_BACKQUOTE:
                        if self.globalStates.consolePopUp_b:
                            self.returnToGame()
                        else:
                            self.globalStates.consolePopUp_b = True
                            self.globalStates.menuPopUp_b = True
                            self.enableMouseControl(False)
                            openedConsole_b = True
                    if self.globalStates.consolePopUp_b:
                        if event.key == pl.K_SPACE:
                            console.addTextInTextBox(" ")
                        elif event.key == pl.K_BACKSPACE:
                            console.eraseOneTextInTextBox()
                        elif event.key == pl.K_RETURN:
                            self.mainLoop.commandQueue_l.append( console.popTextInTextBox() )
                        else:
                            try:
                                console.addTextInTextBox(event.unicode)
                            except:
                                pass
                elif event.type == pl.MOUSEMOTION:
                    self.mainLoop.resourceManager.overlayUiMan.getSelectedButtons(*p.mouse.get_pos())
                elif event.type == pl.MOUSEBUTTONDOWN:
                    if event.button == 1:  # left click
                        selectedButtons_t = self.mainLoop.resourceManager.overlayUiMan.getSelectedButtons(*p.mouse.get_pos())
                        if selectedButtons_t[0]:
                            self.mainLoop.commandQueue_l.append("sys_start_new_game")
                        elif selectedButtons_t[1]:
                            self.mainLoop.commandQueue_l.append("win_load_game")
                        elif selectedButtons_t[2]:
                            self.mainLoop.commandQueue_l.append("win_settings")
                        elif selectedButtons_t[3]:
                            self.mainLoop.commandQueue_l.append("sys_exit")
                    if self.globalStates.consolePopUp_b:
                        a, b, c, d = self.mainLoop.console.logBox.getBoundingCoord(
                            self.globalStates.winWidth_i, self.globalStates.winHeight_i
                        )
                        if not self.checkMouseInsideBox((a, b), (c, d)):
                            continue

                        if event.button == 4:  # scroll up
                            self.mainLoop.console.addScroll(20.0)
                        elif event.button == 5:  # scroll down
                            self.mainLoop.console.addScroll(-20.0)
        elif self.globalStates.menuPopUp_b:
            for event in p.event.get():
                if event.type == pl.QUIT:
                    self.mainLoop.commandQueue_l.append("sys_exit")
                elif event.type == pl.VIDEORESIZE:
                    self.globalStates.winWidth_i = event.dict['w']
                    self.globalStates.winHeight_i = event.dict['h']
                    self.mainLoop.onResize()
                elif event.type == pl.KEYDOWN:
                    console = self.mainLoop.console
                    if event.key == pl.K_ESCAPE:
                        self.returnToGame()
                    elif event.key == pl.K_BACKQUOTE:
                        if self.globalStates.consolePopUp_b:
                            self.returnToGame()
                        else:
                            self.globalStates.consolePopUp_b = True
                            self.globalStates.menuPopUp_b = True
                            self.enableMouseControl(False)
                            openedConsole_b = True
                    if self.globalStates.consolePopUp_b:
                        if event.key == pl.K_SPACE:
                            console.addTextInTextBox(" ")
                        elif event.key == pl.K_BACKSPACE:
                            console.eraseOneTextInTextBox()
                        elif event.key == pl.K_RETURN:
                            self.mainLoop.commandQueue_l.append( console.popTextInTextBox() )
                        else:
                            try:
                                console.addTextInTextBox(event.unicode)
                            except:
                                pass
                elif event.type == pl.MOUSEMOTION:
                    self.mainLoop.resourceManager.overlayUiMan.getSelectedButtons(*p.mouse.get_pos())
                elif event.type == pl.MOUSEBUTTONDOWN:
                    if event.button == 1:  # left click
                        selectedButtons_t = self.mainLoop.resourceManager.overlayUiMan.getSelectedButtons(*p.mouse.get_pos())
                        if selectedButtons_t[0]:
                            self.mainLoop.commandQueue_l.append("sys_start_new_game")
                        elif selectedButtons_t[1]:
                            self.mainLoop.commandQueue_l.append("win_load_game")
                        elif selectedButtons_t[2]:
                            self.mainLoop.commandQueue_l.append("win_settings")
                        elif selectedButtons_t[3]:
                            self.mainLoop.commandQueue_l.append("sys_exit")
                        elif selectedButtons_t[4]:
                            self.returnToGame()
                    if self.globalStates.consolePopUp_b:
                        a, b, c, d = self.mainLoop.console.logBox.getBoundingCoord(
                            self.globalStates.winWidth_i, self.globalStates.winHeight_i
                        )
                        if not self.checkMouseInsideBox((a, b), (c, d)):
                            continue

                        if event.button == 4:  # scroll up
                            self.mainLoop.console.addScroll(20.0)
                        elif event.button == 5:  # scroll down
                            self.mainLoop.console.addScroll(-20.0)
        else:
            for event in p.event.get():
                if event.type == pl.QUIT:
                    self.mainLoop.commandQueue_l.append("sys_exit")
                elif event.type == pl.VIDEORESIZE:
                    self.globalStates.winWidth_i = event.dict['w']
                    self.globalStates.winHeight_i = event.dict['h']
                    self.mainLoop.onResize()
                elif event.type == pl.KEYDOWN:
                    if event.key == pl.K_ESCAPE:
                        self.globalStates.menuPopUp_b = True
                        self.enableMouseControl(False)
                    elif event.key == pl.K_f:
                        if self.target.flashLightOn_b:
                            self.target.flashLightOn_b = False
                        else:
                            self.target.flashLightOn_b = True
                    elif event.key == pl.K_e:
                        self.mainLoop.commandQueue_l += self.mainLoop.player.nearbyTriggers
                        self.mainLoop.player.nearbyTriggers = []
                    elif event.key == pl.K_BACKQUOTE:
                        self.globalStates.consolePopUp_b = True
                        self.globalStates.menuPopUp_b = True
                        self.enableMouseControl(False)
                        openedConsole_b = True

        if openedConsole_b:
            self.mainLoop.console.flushTextInTextBox()

        if self.target is None:
            return
        elif self.globalStates.menuPopUp_b:
            return
        elif self.globalStates.freezeLogic_b:
            return

        fDelta_f = self.mainLoop.fMan.getFrameDelta()
        pressed_t = p.key.get_pressed()

        x = 0.0
        z = 0.0
        if pressed_t[pl.K_w]:
            z -= 1.0
        if pressed_t[pl.K_a]:
            x -= 1.0
        if pressed_t[pl.K_s]:
            z += 1.0
        if pressed_t[pl.K_d]:
            x += 1.0
        directionVec4 = mm.Vec4(x, 0, z).normalize().transform(mm.getRotateYMat4(-self.target.getAngleY().getDegree()))
        self.target.giveHorizontalMomentum(directionVec4.getX(), directionVec4.getZ())

        if pressed_t[pl.K_RIGHT]:
            self.target.getAngleY().addDegree(-fDelta_f * self.configs.keyboardLookSensitivity_f * 5)
        if pressed_t[pl.K_LEFT]:
            self.target.getAngleY().addDegree(fDelta_f * self.configs.keyboardLookSensitivity_f * 5)
        if pressed_t[pl.K_UP]:
            self.target.getAngleX().addDegree(fDelta_f * self.configs.keyboardLookSensitivity_f * 5)
        if pressed_t[pl.K_DOWN]:
            self.target.getAngleX().addDegree(-fDelta_f * self.configs.keyboardLookSensitivity_f * 5)
        if pressed_t[pl.K_SPACE]:
            self.target.startJumping()

        if self.mouseControl_b:
            self.updateMouse()
        if self.joystick_b:
            self.updateJoystick(fDelta_f)

        self.target.validateValuesForCamera()