Esempio n. 1
0
        public void init()
        {
            moto       = new TgcSceneLoader().loadSceneFromFile(MediaDir + Game.Default.pathMoto).Meshes[0];
            moto.Scale = new Vector3(0.5f, 0.5f, 0.5f);
            moto.move(posInicial);

            velocidad       = 0;
            velocidadMaxima = 250;

            rotando           = 0;
            velocidadRotacion = 25;
            anguloRotado      = 0;

            posY           = 0;
            distMaxSalto   = 50;
            velocidadSalto = 40;
            saltando       = 0;

            moto.moveOrientedY(35);
            pathlight = new PathLight(moto.Position);
            moto.moveOrientedY(-35);

            jugando  = true;
            modoDios = false;

            vertexbuffer = new VertexBuffer(typeof(CustomVertex.PositionColored), 3, D3DDevice.Instance.Device,
                                            Usage.Dynamic | Usage.WriteOnly, CustomVertex.PositionColored.Format, Pool.Default);
        }
Esempio n. 2
0
        public void girarIzquierda(bool generoPath)
        {
            moto.moveOrientedY(35);
            var rotAngle = FastMath.ToRad(-90);

            moto.rotateY(rotAngle);

            if (generoPath)
            {
                pathlight.agregarSegmento(moto.Position);
            }
            moto.moveOrientedY(-35);

            rotar(-1);
        }
        /// <summary>
        ///     Renderizar toda la parte cliente, con el manejo de input
        /// </summary>
        private void renderClient()
        {
            //Calcular proxima posicion de personaje segun Input
            var   elapsedTime = GuiController.Instance.ElapsedTime;
            var   moveForward = 0f;
            float rotate      = 0;
            var   d3dInput    = TgcD3dInput.Instance;
            var   moving      = false;
            var   rotating    = false;

            //Adelante
            if (d3dInput.keyDown(Key.W))
            {
                moveForward = -VELODICAD_CAMINAR;
                moving      = true;
            }

            //Atras
            if (d3dInput.keyDown(Key.S))
            {
                moveForward = VELODICAD_CAMINAR;
                moving      = true;
            }

            //Derecha
            if (d3dInput.keyDown(Key.D))
            {
                rotate   = VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Izquierda
            if (d3dInput.keyDown(Key.A))
            {
                rotate   = -VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Si hubo rotacion
            if (rotating)
            {
                meshPrincipal.rotateY(Geometry.DegreeToRadian(rotate * elapsedTime));
                this.camara.rotateY(rotate);
            }

            //Si hubo desplazamiento
            if (moving)
            {
                meshPrincipal.moveOrientedY(moveForward * elapsedTime);
            }

            //Hacer que la camara siga al personaje en su nueva posicion
            this.camara.Target = meshPrincipal.Position;

            //Render piso
            piso.render();

            //Renderizar meshPrincipal
            if (meshPrincipal != null)
            {
                meshPrincipal.render();
            }

            //Renderizar otrosMeshes
            foreach (var entry in otrosMeshes)
            {
                entry.Value.render();
            }
        }
Esempio n. 4
0
        public override void render(float elapsedTime)
        {
            #region Controller

            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;

            #endregion

            #region Transformaciones

            //nave.Transform = Matrix.Scaling(NAVE_SCALE) * Matrix.Translation(0, 9000, 0);
            //nave.Transform = Matrix.Translation(0, 500, 0);
            //nave.Transform = Matrix.Scaling(NAVE_SCALE);

            #endregion

            #region Movimiento y Rotacion

            bool        moving      = false;
            bool        rotating    = false;
            float       moveForward = 0f;
            float       rotate      = 0;
            TgcD3dInput input       = GuiController.Instance.D3dInput;

            //Vector3 movement = new Vector3(0, 0, 0);
            if (input.keyDown(Key.Left) || input.keyDown(Key.A))
            {
                rotate   = -NAVE_ROTATION_SPEED;
                rotating = true;
            }
            else if (input.keyDown(Key.Right) || input.keyDown(Key.D))
            {
                rotate   = NAVE_ROTATION_SPEED;
                rotating = true;
            }
            if (input.keyDown(Key.Up) || input.keyDown(Key.W))
            {
                moveForward = -NAVE_MOVEMENT_SPEED;
                moving      = true;
            }
            else if (input.keyDown(Key.Down) || input.keyDown(Key.S))
            {
                moveForward = NAVE_MOVEMENT_SPEED;
                moving      = true;
            }

            Vector3 Position_prev = nave.Position;

            if (rotating)
            {
                nave.rotateY(Geometry.DegreeToRadian(rotate * elapsedTime));
                GuiController.Instance.ThirdPersonCamera.rotateY(Geometry.DegreeToRadian(rotate * elapsedTime));
            }

            if (moving)
            {
                Vector3 lastPos = nave.Position;
                nave.moveOrientedY(moveForward * elapsedTime);
            }

            //Aplicar movimiento (VIEJO)
            //movement *= MOVEMENT_SPEED * elapsedTime;
            //nave.move(movement);

            bool Collision = false;

            foreach (TgcMesh planeta in planetas)
            {
                TgcBoundingBox nave_BBox    = nave.BoundingBox;
                TgcBoundingBox planeta_BBox = planeta.BoundingBox;

                TgcCollisionUtils.BoxBoxResult Collision_Type = TgcCollisionUtils.classifyBoxBox(nave_BBox, planeta_BBox);

                if (Collision_Type != TgcCollisionUtils.BoxBoxResult.Afuera)
                {
                    Collision = true;
                    break;
                }
            }

            if (Collision)
            {
                ;
            }

            #endregion

            #region Camara

            GuiController.Instance.ThirdPersonCamera.Target = nave.Position;

            #endregion

            #region Render

            nave.render();
            for (int i = 0; i < 10; i++)
            {
                planetas[i].render();
            }
            //universo.renderAll();

            nave.BoundingBox.render();
            foreach (TgcMesh planeta in planetas)
            {
                planeta.BoundingBox.render();
            }

            #endregion
        }
Esempio n. 5
0
        public void colisionEntreAutos(List <TgcBox> obbsAuto, List <TgcBox> obbsOtroAuto, Jugador jugadorAuto, Auto auto, Auto otroAuto, TgcMesh meshAuto, TgcMesh meshOtroAuto, float elapsedTime)
        {
            TgcBoundingBox dDAuto = obbsAuto[0].BoundingBox;
            TgcBoundingBox dIAuto = obbsAuto[2].BoundingBox;
            TgcBoundingBox tDAuto = obbsAuto[1].BoundingBox;
            TgcBoundingBox tIAuto = obbsAuto[3].BoundingBox;

            TgcBoundingBox dDOtroAuto = obbsOtroAuto[0].BoundingBox;
            TgcBoundingBox dIOtroAuto = obbsOtroAuto[2].BoundingBox;
            TgcBoundingBox tDOtroAuto = obbsOtroAuto[1].BoundingBox;
            TgcBoundingBox tIOtroAuto = obbsOtroAuto[3].BoundingBox;

            if (!jugadorAuto.estaMarchaAtras())
            {
                if (TgcCollisionUtils.testAABBAABB(tIAuto, dIOtroAuto) || TgcCollisionUtils.testAABBAABB(tIAuto, dDOtroAuto) ||
                    TgcCollisionUtils.testAABBAABB(tDAuto, dIOtroAuto) || TgcCollisionUtils.testAABBAABB(tDAuto, dDOtroAuto))
                {
                    //auto gira cierto angulo hacia izquierda y sube velocidad
                    if (Math.Truncate(auto.velocidad) == 0)
                    {
                        auto.velocidad = 300;
                    }
                    else
                    {
                        auto.velocidad = Math.Abs(auto.velocidad * 0.5f);
                    }
                    //otroAuto reduce bastante velocidad y se lo traslada un poco hacia atrás para no seguir chocando
                    meshOtroAuto.moveOrientedY(10 * otroAuto.velocidad * elapsedTime); //Lo hago "como que rebote un poco" para no seguir colisionando
                    otroAuto.velocidad = -(otroAuto.velocidad * 0.3f);
                    if (tiempoDeChoque == 0)
                    {
                        tiempoDeChoque = 5;
                    }
                }
                else if (TgcCollisionUtils.testAABBAABB(tIOtroAuto, dIAuto) || TgcCollisionUtils.testAABBAABB(tIOtroAuto, dDAuto) ||
                         TgcCollisionUtils.testAABBAABB(tDOtroAuto, dIAuto) || TgcCollisionUtils.testAABBAABB(tDOtroAuto, dDAuto))
                {
                    //auto gira cierto angulo hacia derecha y sube velocidad
                    if (Math.Truncate(otroAuto.velocidad) == 0)
                    {
                        otroAuto.velocidad = 300;
                    }
                    else
                    {
                        otroAuto.velocidad = Math.Abs(otroAuto.velocidad * 0.5f);
                    }
                    //otroAuto reduce bastante velocidad y se lo traslada un poco hacia atrás para no seguir chocando
                    meshAuto.moveOrientedY(10 * auto.velocidad * elapsedTime); //Lo hago "como que rebote un poco" para no seguir colisionando
                    auto.velocidad = -(auto.velocidad * 0.3f);
                    if (tiempoDeChoque == 0)
                    {
                        tiempoDeChoque = 5;
                    }
                }
                else if (TgcCollisionUtils.testAABBAABB(dIAuto, dIOtroAuto) || TgcCollisionUtils.testAABBAABB(dDAuto, dIOtroAuto) || TgcCollisionUtils.testAABBAABB(dIAuto, dDOtroAuto) || TgcCollisionUtils.testAABBAABB(dDAuto, dDOtroAuto))
                {
                    //auto se mueve hacia atrás y cambia de sentido 180° (rebota)
                    if (Math.Truncate(auto.velocidad) == 0)
                    {
                        auto.velocidad = -300;
                    }
                    else
                    {
                        meshAuto.moveOrientedY(10 * auto.velocidad * elapsedTime); //Lo hago "como que rebote un poco" para no seguir colisionando
                        auto.velocidad = -(auto.velocidad * 0.3f);                 //Lo hago ir atrás un tercio de velocidad de choque
                    }
                    //otroAuto hace lo mismo que el auto
                    meshOtroAuto.moveOrientedY(10 * otroAuto.velocidad * elapsedTime); //Lo hago "como que rebote un poco" para no seguir colisionando
                    otroAuto.velocidad = -(otroAuto.velocidad * 0.3f);                 //Lo hago ir atrás un tercio de velocidad de choque
                    if (tiempoDeChoque == 0)
                    {
                        tiempoDeChoque = 5;
                    }
                }
            }
            else
            {
                if (TgcCollisionUtils.testAABBAABB(tIAuto, dIOtroAuto) || TgcCollisionUtils.testAABBAABB(tIAuto, dDOtroAuto) || TgcCollisionUtils.testAABBAABB(tDAuto, dIOtroAuto) || TgcCollisionUtils.testAABBAABB(tDAuto, dDOtroAuto))
                {
                    //ambos autos rebotan (cambia sentido 180°)
                    if (Math.Truncate(auto.velocidad) == 0)
                    {
                        auto.velocidad = 300;
                    }
                    else
                    {
                        auto.velocidad = Math.Abs(auto.velocidad * 0.5f);
                    }

                    meshOtroAuto.moveOrientedY(10 * otroAuto.velocidad * elapsedTime); //Lo hago "como que rebote un poco" para no seguir colisionando
                    otroAuto.velocidad = -(otroAuto.velocidad * 0.3f);                 //Lo hago ir atrás un tercio de velocidad de choque
                    if (tiempoDeChoque == 0)
                    {
                        tiempoDeChoque = 5;
                    }
                }
                else if (TgcCollisionUtils.testAABBAABB(tIAuto, tIOtroAuto) || TgcCollisionUtils.testAABBAABB(tIAuto, tDOtroAuto) || TgcCollisionUtils.testAABBAABB(tDAuto, tIOtroAuto) || TgcCollisionUtils.testAABBAABB(tDAuto, tDOtroAuto))
                {
                    //rebota auto
                    meshAuto.moveOrientedY(10 * auto.velocidad * elapsedTime); //Lo hago "como que rebote un poco" para no seguir colisionando
                    auto.velocidad = -(auto.velocidad * 0.3f);                 //Lo hago ir atrás un tercio de velocidad de choque
                    if (tiempoDeChoque == 0)
                    {
                        tiempoDeChoque = 5;
                    }
                }
            }
        }
Esempio n. 6
0
        public override void Render()
        {
            PreRender();

            //Calcular proxima posicion de personaje segun Input
            var   moveForward = 0f;
            float rotate      = 0;
            var   moving      = false;
            var   rotating    = false;

            //Adelante
            if (Input.keyDown(Key.W))
            {
                moveForward = -VELODICAD_CAMINAR;
                moving      = true;
            }

            //Atras
            if (Input.keyDown(Key.S))
            {
                moveForward = VELODICAD_CAMINAR;
                moving      = true;
            }

            //Derecha
            if (Input.keyDown(Key.D))
            {
                rotate   = VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Izquierda
            if (Input.keyDown(Key.A))
            {
                rotate   = -VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Si hubo rotacion
            if (rotating)
            {
                //Rotar personaje y la camara, hay que multiplicarlo por el tiempo transcurrido para no atarse a la velocidad el hardware
                var rotAngle = Geometry.DegreeToRadian(rotate * ElapsedTime);
                personaje.rotateY(rotAngle);
                camaraInterna.rotateY(rotAngle);
            }

            //Si hubo desplazamiento
            if (moving)
            {
                //Aplicar movimiento hacia adelante o atras segun la orientacion actual del Mesh
                var lastPos = personaje.Position;
                personaje.moveOrientedY(moveForward * ElapsedTime);

                //Detectar colisiones
                var collide = false;
                foreach (var obstaculo in obstaculos)
                {
                    var result = TgcCollisionUtils.classifyBoxBox(personaje.BoundingBox, obstaculo.BoundingBox);
                    if (result == TgcCollisionUtils.BoxBoxResult.Adentro ||
                        result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                    {
                        collide = true;
                        break;
                    }
                }

                //Si hubo colision, restaurar la posicion anterior
                if (collide)
                {
                    personaje.Position = lastPos;
                }
            }

            //Hacer que la camara siga al personaje en su nueva posicion
            camaraInterna.Target = personaje.Position;

            //Render piso
            piso.render();

            //Render obstaculos
            foreach (var obstaculo in obstaculos)
            {
                obstaculo.render();
            }

            //Render personaje
            personaje.render();

            PostRender();
        }
Esempio n. 7
0
        public override void render(float elapsedTime)
        {
            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;

            //Calcular proxima posicion de personaje segun Input
            float       moveForward = 0f;
            float       rotate      = 0;
            TgcD3dInput d3dInput    = GuiController.Instance.D3dInput;
            bool        moving      = false;
            bool        rotating    = false;

            //Adelante
            if (d3dInput.keyDown(Key.W))
            {
                moveForward = -VELODICAD_CAMINAR;
                moving      = true;
            }

            //Atras
            if (d3dInput.keyDown(Key.S))
            {
                moveForward = VELODICAD_CAMINAR;
                moving      = true;
            }

            //Derecha
            if (d3dInput.keyDown(Key.D))
            {
                rotate   = VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Izquierda
            if (d3dInput.keyDown(Key.A))
            {
                rotate   = -VELOCIDAD_ROTACION;
                rotating = true;
            }

            //Si hubo rotacion
            if (rotating)
            {
                //Rotar personaje y la camara, hay que multiplicarlo por el tiempo transcurrido para no atarse a la velocidad el hardware
                float rotAngle = Geometry.DegreeToRadian(rotate * elapsedTime);
                personaje.rotateY(rotAngle);
                GuiController.Instance.ThirdPersonCamera.rotateY(rotAngle);
            }

            //Si hubo desplazamiento
            if (moving)
            {
                //Aplicar movimiento hacia adelante o atras segun la orientacion actual del Mesh
                Vector3 lastPos = personaje.Position;
                personaje.moveOrientedY(moveForward * elapsedTime);

                //Detectar colisiones
                bool collide = false;
                foreach (TgcBox obstaculo in obstaculos)
                {
                    TgcCollisionUtils.BoxBoxResult result = TgcCollisionUtils.classifyBoxBox(personaje.BoundingBox, obstaculo.BoundingBox);
                    if (result == TgcCollisionUtils.BoxBoxResult.Adentro || result == TgcCollisionUtils.BoxBoxResult.Atravesando)
                    {
                        collide = true;
                        break;
                    }
                }

                //Si hubo colision, restaurar la posicion anterior
                if (collide)
                {
                    personaje.Position = lastPos;
                }
            }

            //Hacer que la camara siga al personaje en su nueva posicion
            GuiController.Instance.ThirdPersonCamera.Target = personaje.Position;



            //Render piso
            piso.render();


            //Render obstaculos
            foreach (TgcBox obstaculo in obstaculos)
            {
                obstaculo.render();
            }

            //Render personaje
            personaje.render();
        }
Esempio n. 8
0
 private void MoverMesh()
 {
     this.meshAuto.Rotation = new Vector3(0f, this.rotacion, 0f);
     meshAuto.moveOrientedY(-this.velocidad * elapsedTime);
 }
Esempio n. 9
0
        public override void render(float elapsedTime)
        {
            motionBlurFlag = (bool)GuiController.Instance.Modifiers["motionBlurFlag"];
            TgcTexture texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "TheC#\\Pista\\pistaCarreras.png");

            Microsoft.DirectX.Direct3D.Device d3dDevice = GuiController.Instance.D3dDevice;


            //pantalla De Inicio
            if (flagInicio == 0)
            {
                //Actualizar valores cargados en modifiers

                /*sprite.Position = (Vector2)GuiController.Instance.Modifiers["position"];
                 * sprite.Scaling = (Vector2)GuiController.Instance.Modifiers["scaling"];
                 * sprite.Rotation = FastMath.ToRad((float)GuiController.Instance.Modifiers["rotation"]);
                 */
                //Iniciar dibujado de todos los Sprites de la escena (en este caso es solo uno)
                GuiController.Instance.Drawer2D.beginDrawSprite();
                sprite.render();
                //Finalizar el dibujado de Sprites
                GuiController.Instance.Drawer2D.endDrawSprite();
                flagInicio = jugador.verSiAprietaSpace();
                textIngreseTeclaSombra.render();
                textIngreseTecla.render();
                musica.verSiCambioMP3();
            }
            else
            {
                //Para contar el tiempo desde que preciona la barra espaciadora y comienza el juego
                if (primerRenderDelJuegoAndando == true)
                {
                    this.horaInicio             = DateTime.Now;
                    primerRenderDelJuegoAndando = false;
                }
                //Todo lo referente a lo que debe hacer el IA
                autoIA.elapsedTime = elapsedTime;
                autoIA.establecerVelocidadMáximaEn((float)GuiController.Instance.Modifiers["velocidadMaxima"] * 1.02f);

                if (colision.getTiempoQueChoco() == 0)
                {
                    jugadorIA.jugar(trayectoDeIA[0].Center, meshAutoIA.Position);
                }

                meshAutoIA.Rotation = new Vector3(0f, autoIA.rotacion, 0f);
                jugadorIA.setRotacion(meshAutoIA.Rotation);

                meshAutoIA.moveOrientedY(-autoIA.velocidad * elapsedTime);
                //Fin movimiento de auto IA

                //Le paso el elapsed time al auto porque sus metodos no deben depender de los FPS
                auto.elapsedTime = elapsedTime;

                //Varío la velocidad Máxima del vehículo con el modifier "velocidadMáxima"
                auto.establecerVelocidadMáximaEn((float)GuiController.Instance.Modifiers["velocidadMaxima"]);

                //El jugador envia mensajes al auto dependiendo de que tecla presiono
                //Se pone un tiempo para que luego de chocar 2 autos, estos no puedan ingresar movimiento (sólo se mueve por inercia)
                if (colision.getTiempoQueChoco() == 0)
                {
                    jugador.jugar(cantidadDeNitro);
                }
                else
                {
                    colision.setTiempoQueChoco(colision.getTiempoQueChoco() - (8 * elapsedTime));
                    if (colision.getTiempoQueChoco() < 0)
                    {
                        colision.setTiempoQueChoco(0);
                    }
                }

                //Transfiero la rotacion del auto abstracto al mesh, y su obb
                autoMesh.Rotation = new Vector3(0f, auto.rotacion, 0f);
                oBBAuto.Center    = autoMesh.Position;
                oBBAuto.setRotation(autoMesh.Rotation);
                meshAutoIA.Rotation = new Vector3(0f, autoIA.rotacion, 0f);
                oBBAutoIa.Center    = meshAutoIA.Position;
                oBBAutoIa.setRotation(meshAutoIA.Rotation);


                //Calculo de giro de la rueda
                rotacionVertical -= auto.velocidad * elapsedTime / 60;

                //Calculo el movimiento del mesh dependiendo de la velocidad del auto
                autoMesh.moveOrientedY(-auto.velocidad * elapsedTime);
                //Detección de colisiones
                //Hubo colisión con un objeto. Guardar resultado y abortar loop.



                //Si hubo alguna colisión, hacer esto:
                if (huboColision(oBBAuto))
                {
                    autoMesh.moveOrientedY(20 * auto.velocidad * elapsedTime); //Lo hago "como que rebote un poco" para no seguir colisionando
                    auto.velocidad = -(auto.velocidad * 0.3f);                 //Lo hago ir atrás un tercio de velocidad de choque
                }
                if (huboColision(oBBAutoIa))
                {
                    meshAutoIA.moveOrientedY(20 * autoIA.velocidad * elapsedTime); //Lo hago "como que rebote un poco" para no seguir colisionando
                    autoIA.velocidad = -(autoIA.velocidad * 0.3f);                 //Lo hago ir atrás un tercio de velocidad de choque
                }

                //Colisión entre los autos
                for (int i = 0; i < 4; i++)
                {
                    float ro, alfa_rueda;
                    float posicion_xA1;
                    float posicion_yA1;
                    float posicion_xA2;
                    float posicion_yA2;

                    ro = FastMath.Sqrt(dx[i] * dxAColision[i] + dyAColision[i] * dyAColision[i]);

                    alfa_rueda = FastMath.Asin(dxAColision[i] / ro);
                    if (i == 0 || i == 2)
                    {
                        alfa_rueda += FastMath.PI;
                    }
                    posicion_xA1 = FastMath.Sin(alfa_rueda + auto.rotacion) * ro;
                    posicion_yA1 = FastMath.Cos(alfa_rueda + auto.rotacion) * ro;

                    posicion_xA2 = FastMath.Sin(alfa_rueda + autoIA.rotacion) * ro;
                    posicion_yA2 = FastMath.Cos(alfa_rueda + autoIA.rotacion) * ro;

                    obbsAuto[i].Position = (new Vector3(posicion_xA1, 15.5f, posicion_yA1) + autoMesh.Position);

                    obbsOtroAuto[i].Position = (new Vector3(posicion_xA2, 15.5f, posicion_yA2) + meshAutoIA.Position);
                }

                colision.colisionEntreAutos(obbsAuto, obbsOtroAuto, jugador, auto, autoIA, autoMesh, meshAutoIA, elapsedTime);

                //Cosas sobre derrape
                int direcGiroDerrape = 0;

                if (auto.velocidad > 1500 && (jugador.estaGirandoDerecha() || jugador.estaGirandoIzquierda()))
                {
                    if (jugador.estaGirandoIzquierda())
                    {
                        direcGiroDerrape = -1;
                    }
                    else if (jugador.estaGirandoDerecha())
                    {
                        direcGiroDerrape = 1;
                    }

                    autoMesh.Rotation = new Vector3(0f, auto.rotacion + (direcGiroDerrape * anguloDerrape), 0f);
                    oBBAuto.setRotation(new Vector3(autoMesh.Rotation.X, autoMesh.Rotation.Y + (direcGiroDerrape * anguloDerrape / 2), autoMesh.Rotation.Z));


                    if (anguloDerrape <= anguloMaximoDeDerrape)
                    {
                        anguloDerrape += velocidadDeDerrape * elapsedTime;
                    }
                }
                else
                {
                    direcGiroDerrape = 0;
                    anguloDerrape    = 0;
                }
                //Fin derrape

                //Posiciono las ruedas
                for (int i = 0; i < 4; i++)
                {
                    float ro, alfa_rueda;
                    float posicion_x;
                    float posicion_y;
                    ro = FastMath.Sqrt(dx[i] * dx[i] + dy[i] * dy[i]);

                    alfa_rueda = FastMath.Asin(dx[i] / ro);
                    if (i == 0 || i == 2)
                    {
                        alfa_rueda += FastMath.PI;
                    }
                    posicion_x = FastMath.Sin(alfa_rueda + auto.rotacion + (anguloDerrape * direcGiroDerrape)) * ro;
                    posicion_y = FastMath.Cos(alfa_rueda + auto.rotacion + (anguloDerrape * direcGiroDerrape)) * ro;

                    ruedas[i].Position = (new Vector3(posicion_x, 15.5f, posicion_y) + autoMesh.Position);
                    //Si no aprieta para los costados, dejo la rueda derecha (por ahora, esto se puede modificar)
                    if (input.keyDown(Key.Left) || input.keyDown(Key.A) || input.keyDown(Key.Right) || input.keyDown(Key.D))
                    {
                        ruedas[i].Rotation = new Vector3(rotacionVertical, auto.rotacion + auto.rotarRueda(i) + (anguloDerrape * direcGiroDerrape), 0f);
                    }
                    else
                    {
                        ruedas[i].Rotation = new Vector3(rotacionVertical, auto.rotacion + (anguloDerrape * direcGiroDerrape), 0f);
                    }
                }

                //comienzo humo
                float rohumo, alfa_humo;
                float posicion_xhumo;
                float posicion_yhumo;
                rohumo = FastMath.Sqrt(-19f * -19f + 126f * 126f);

                alfa_humo      = FastMath.Asin(-19f / rohumo);
                posicion_xhumo = FastMath.Sin(alfa_humo + auto.rotacion + (anguloDerrape * direcGiroDerrape)) * rohumo;
                posicion_yhumo = FastMath.Cos(alfa_humo + auto.rotacion + (anguloDerrape * direcGiroDerrape)) * rohumo;

                humo.Position = (new Vector3(posicion_xhumo, 15.5f, posicion_yhumo) + autoMesh.Position);
                //Si no aprieta para los costados, dejo la rueda derecha (por ahora, esto se puede modificar)
                if (input.keyDown(Key.Left) || input.keyDown(Key.A) || input.keyDown(Key.Right) || input.keyDown(Key.D))
                {
                    humo.Rotation = new Vector3(0f, auto.rotacion + (anguloDerrape * direcGiroDerrape), 0f);
                }
                else
                {
                    humo.Rotation = new Vector3(0f, auto.rotacion + (anguloDerrape * direcGiroDerrape), 0f);
                }
                //fin de humo
                fuego.Position = humo.Position;
                fuego.Rotation = humo.Rotation;
                //fin fuego

                cantidadDeNitro += 0.5f * elapsedTime;
                cantidadDeNitro  = FastMath.Min(cantidadDeNitro, 100f);
                if (auto.nitro)
                {
                    cantidadDeNitro -= 7 * elapsedTime;
                    cantidadDeNitro  = FastMath.Max(cantidadDeNitro, 0f);
                    if (cantidadDeNitro > 1)
                    {
                        humo.Enabled  = false;
                        fuego.Enabled = false;
                    }
                }
                else
                {
                    humo.Enabled  = false;
                    fuego.Enabled = false;
                }
                tiempoHumo   += elapsedTime;
                humo.UVOffset = new Vector2(0.9f, tiempoHumo);
                humo.updateValues();
                fuego.UVOffset = new Vector2(0.9f, tiempoHumo);
                fuego.updateValues();

                if (tiempoHumo > 50f)
                {
                    tiempoHumo = 0f;
                }
                autoMeshPrevX = autoMesh.Position.X;
                autoMeshPrevZ = autoMesh.Position.Z;

                //Lineas de Frenado
                if (jugador.estaFrenandoDeMano())
                {
                    lineaDeFrenado[0].addTrack(new Vector3(ruedaDerechaDelanteraMesh.Position.X, 0, ruedaDerechaDelanteraMesh.Position.Z));
                    lineaDeFrenado[1].addTrack(new Vector3(ruedaDerechaTraseraMesh.Position.X, 0, ruedaDerechaTraseraMesh.Position.Z));
                    lineaDeFrenado[2].addTrack(new Vector3(ruedaIzquierdaDelanteraMesh.Position.X, 0, ruedaIzquierdaDelanteraMesh.Position.Z));
                    lineaDeFrenado[3].addTrack(new Vector3(ruedaIzquierdaTraseraMesh.Position.X, 0, ruedaIzquierdaTraseraMesh.Position.Z));
                }
                if (jugador.dejoDeFrenarDeMano())
                {
                    for (int i = 0; i < lineaDeFrenado.Length; i++)
                    {
                        lineaDeFrenado[i].endTrack();
                    }
                }

                for (int i = 0; i < lineaDeFrenado.Length; i++)
                {
                    lineaDeFrenado[i].render();
                    lineaDeFrenado[i].pasoDelTiempo(elapsedTime);
                }

                //Dibujo el reflejo de la luz en el auto
                reflejo.Render();

                //////Camara///////

                if (jugador.estaMirandoHaciaAtras())
                {
                    GuiController.Instance.ThirdPersonCamera.setCamera(autoMesh.Position, 200, -500);
                    GuiController.Instance.ThirdPersonCamera.Target    = autoMesh.Position;
                    GuiController.Instance.ThirdPersonCamera.RotationY = auto.rotacion;
                }
                else
                {
                    coheficienteCamara = jugador.verSiCambiaCamara();
                    GuiController.Instance.ThirdPersonCamera.setCamera(autoMesh.Position, 100 + (coheficienteCamara), 900 - (coheficienteCamara) * 4);
                    GuiController.Instance.ThirdPersonCamera.Target    = autoMesh.Position;
                    GuiController.Instance.ThirdPersonCamera.RotationY = auto.rotacion;
                }

                //La camara no rota exactamente a la par del auto, hay un pequeño retraso
                //GuiController.Instance.ThirdPersonCamera.RotationY += 5 * (auto.rotacion - prevCameraRotation) * elapsedTime;
                //Ajusto la camara a menos de 360 porque voy a necesitar hacer calculos entre angulos
                while (prevCameraRotation > 360)
                {
                    prevCameraRotation -= 360;
                }
                prevCameraRotation = GuiController.Instance.ThirdPersonCamera.RotationY;

                ///////Musica/////////
                jugador.verSiModificaMusica(musica);

                //Dibujar objeto principal
                //Siempre primero hacer todos los cálculos de lógica e input y luego al final dibujar todo (ciclo update-render)
                foreach (TgcMesh mesh in scenePista.Meshes)
                {
                    mesh.Enabled = (TgcCollisionUtils.classifyFrustumAABB(GuiController.Instance.Frustum, mesh.BoundingBox) != TgcCollisionUtils.FrustumResult.OUTSIDE);
                }
                if (motionBlurFlag)
                {
                    motionBlur.update(elapsedTime);
                    motionBlur.motionBlurRender(elapsedTime, HighResolutionTimer.Instance.FramesPerSecond, auto.velocidad, 0);
                }
                else
                {
                    foreach (TgcMesh mesh in scenePista.Meshes)
                    {
                        mesh.Technique = "DefaultTechnique";
                        mesh.render();
                    }
                }

                //Mostrar al auto IA
                meshAutoIA.render();

                //Muestro el punto siguiente
                trayecto[0].render();
                //mostrar el auto manejado por el humano
                autoMesh.render();

                for (int i = 0; i < 4; i++)
                {
                    ruedas[i].render();
                }

                humo.render();
                fuego.render();

                //Colision con puntos de control, tanto de persona como IA
                for (int i = 0; i < trayecto.Count; i++)
                {
                    //Pregunto si colisiona con un punto de control activado. Lo sé, feo.
                    if ((i == 0) && TgcCollisionUtils.testPointCylinder(oBBAuto.Position, trayecto[i].BoundingCylinder))
                    {
                        TgcCylinder cilindroModificado = new TgcCylinder(trayecto[i].Center, 130, 30);

                        if (contadorDeActivacionesDePuntosDeControl != (posicionesPuntosDeControl.Count * 3))
                        {
                            trayecto.RemoveAt(i);
                            trayecto.Add(cilindroModificado);
                            contadorDeActivacionesDePuntosDeControl++;
                            textPuntosDeControlAlcanzados.Text = "Puntos De Control Alcanzados = " + contadorDeActivacionesDePuntosDeControl.ToString();
                            textTiempo.Text = (Convert.ToDouble(textTiempo.Text) + 3).ToString();
                        }
                        else
                        {
                            gano             = true;
                            textGanaste.Text = "Ganaste y obtuviste un puntaje de  " + textTiempo.Text + " puntos";
                            textGanaste.render();
                            auto.estatico();
                            //Para el IA
                            autoIA.estatico();
                        }
                    }
                }
                for (int i = 0; i < trayectoDeIA.Count; i++)
                {
                    //Pregunto si colisiona con un punto de control activado
                    if ((i == 0) && TgcCollisionUtils.testPointCylinder(meshAutoIA.Position, trayectoDeIA[i].BoundingCylinder))
                    {
                        TgcCylinder cilindroModificado = new TgcCylinder(trayectoDeIA[i].Center, 130, 30);

                        if (contadorDeActivacionesDePuntosDeControlDeIA != (posicionesPuntosDeControlDeIA.Count * 3))
                        {
                            trayectoDeIA.RemoveAt(i);
                            trayectoDeIA.Add(cilindroModificado);
                            contadorDeActivacionesDePuntosDeControlDeIA++;
                        }
                        else
                        {
                            gano             = true;
                            textGanaste.Text = "Ganó la máquina :P  ";
                            textGanaste.render();
                            //Para el IA
                            autoIA.estatico();
                            auto.estatico();
                        }
                    }
                }

                textPosicionDelAutoActual.Text = autoMesh.Position.ToString();

                //Renderizar los tres textos

                textoVelocidad.mostrarVelocidad(auto.velocidad / 10).render(); //renderiza la velocidad

                textPuntosDeControlAlcanzados.render();
                textPosicionDelAutoActual.render();

                //Cosas del tiempo
                tiempo.incrementarTiempo(this, elapsedTime, (bool)GuiController.Instance.Modifiers["jugarConTiempo"]);

                //Actualizo y dibujo el relops
                if ((bool)GuiController.Instance.Modifiers["jugarConTiempo"])
                {
                    if ((DateTime.Now.Subtract(this.horaInicio).TotalSeconds) > segundosAuxiliares)
                    {
                        if (Convert.ToDouble(textTiempo.Text) == 0)
                        {
                            textPerdiste.Text = "Perdiste y lograste " + contadorDeActivacionesDePuntosDeControl.ToString() + " puntos de control";
                            textPerdiste.render();
                            auto.estatico();
                            //Para el IA
                            autoIA.estatico();
                        }
                        else if (gano == true)
                        {
                        }
                        else
                        {
                            this.textTiempo.Text = (Convert.ToDouble(textTiempo.Text) - 1).ToString();
                            segundosAuxiliares++;
                        }
                    }
                }
                emisorHumo.update(elapsedTime, GuiController.Instance.CurrentCamera.getLookAt(), auto.rotacion, autoMesh.Position, anguloDerrape, direcGiroDerrape, auto.nitro && (cantidadDeNitro > 1), auto.velocidad);
                emisorHumo.render(GuiController.Instance.CurrentCamera.getPosition());
                textTiempo.render();
                stringTiempo.render();
                contadorDeFrames++;

                hud.render(auto.velocidad, cantidadDeNitro);
            }//cierra el if de que no esta en pantalla inicio
            textFPS.Text = "            FPS: " + HighResolutionTimer.Instance.FramesPerSecond.ToString();
            textFPS.render();
        }
Esempio n. 10
0
 protected bool mover(float t)
 {
     //bala.moveOrientedY((float)GuiController.Instance.Modifiers.getValue("VelocidadBala"));
     bala.moveOrientedY(VELOCIDAD_BALA);
     return(true);
 }