Beispiel #1
0
        public override void Update()
        {
            PreUpdate();
            if (!estaEnMenu && !finDePartida)
            {
                if (Input.keyPressed(Key.G))
                {
                    if (!flagGod)
                    {
                        flagGod = true;
                        godMod();
                    }
                    else
                    {
                        flagGod = false;
                    }
                }
                if (flagGod)
                {
                    PosCamara pos = camaraGod.getPosicionGod(ElapsedTime);
                    Camara.SetCamera(pos.posicion, pos.lookAt);
                }
                else
                {
                    moverPersonaje();
                }

                Vector3 dir = this.monstruo.Position - this.personaje.Position;
                float   distanciaAPersonaje = Vector3.Length(dir);
                if (distanciaAPersonaje < 300f && !escondido)
                {
                    persecucion = true;
                    logicaPersecucion();
                }
                else
                {
                    logicaDelMonstruo();
                }

                finDePartida = getFinDePartida();
                if (Input.keyPressed(Key.E))
                {
                    foreach (var armario in armarios)
                    {
                        controlDeArmario(armario);
                    }
                }
                if (Input.keyUp(Key.E))
                {
                    if (escondido)
                    {
                        viewVector = new Vector3(1, 0, 0);
                        escondido  = false;
                    }
                }

                if (Input.keyPressed(Key.V))
                {
                    activoVisionNoctura = true;
                }
                if (Input.keyUp(Key.V))
                {
                    activoVisionNoctura = false;
                }


                actualizarEnergia();
            }
            if (estaEnMenu && Input.keyPressed(Key.Space))
            {
                estaEnMenu = false;
                cargarSonido("pisada.wav");
            }
        }
Beispiel #2
0
        public PosCamara getPosicionGod(float elapsedTime)
        {
            var moveVector = new Vector3(0, 0, 0);

            //Forward
            if (Input.keyDown(Key.W))
            {
                moveVector += new Vector3(0, 0, -1) * MovementSpeed;
            }

            //Backward
            if (Input.keyDown(Key.S))
            {
                moveVector += new Vector3(0, 0, 1) * MovementSpeed;
            }

            //Strafe right
            if (Input.keyDown(Key.D))
            {
                moveVector += new Vector3(-1, 0, 0) * MovementSpeed;
            }

            //Strafe left
            if (Input.keyDown(Key.A))
            {
                moveVector += new Vector3(1, 0, 0) * MovementSpeed;
            }

            //Jump
            if (Input.keyDown(Key.Space))
            {
                moveVector += new Vector3(0, 1, 0) * JumpSpeed;
            }

            //Crouch
            if (Input.keyDown(Key.LeftControl))
            {
                moveVector += new Vector3(0, -1, 0) * JumpSpeed;
            }

            if (Input.keyPressed(Key.L) || Input.keyPressed(Key.Escape))
            {
                LockCam = !lockCam;
            }

            //Solo rotar si se esta aprentando el boton izq del mouse
            if (lockCam)
            {
                leftrightRot -= -Input.XposRelative * RotationSpeed;
                updownRot    -= Input.YposRelative * RotationSpeed;
                //Se actualiza matrix de rotacion, para no hacer este calculo cada vez y solo cuando en verdad es necesario.
                cameraRotation = Matrix.RotationX(updownRot) * Matrix.RotationY(leftrightRot);
            }

            if (lockCam)
            {
                Cursor.Position = mouseCenter;
            }

            //Calculamos la nueva posicion del ojo segun la rotacion actual de la camara.
            var cameraRotatedPositionEye = Vector3.TransformNormal(moveVector * elapsedTime, cameraRotation);

            positionEye += cameraRotatedPositionEye;

            //Calculamos el target de la camara, segun su direccion inicial y las rotaciones en screen space x,y.
            var       cameraRotatedTarget = Vector3.TransformNormal(directionView, cameraRotation);
            var       cameraFinalTarget   = positionEye + cameraRotatedTarget;
            PosCamara pos = new PosCamara(positionEye, cameraFinalTarget);

            return(pos);
        }