Пример #1
0
        public void Update(float elapsedTime)
        {
            // correr
            if (GuiController.Instance.D3dInput.keyPressed(Microsoft.DirectX.DirectInput.Key.LeftShift))
            {
                camera.MovementSpeed = RUNNING_SPEED;
            }
            else if (GuiController.Instance.D3dInput.keyUp(Microsoft.DirectX.DirectInput.Key.LeftShift))
            {
                camera.MovementSpeed = WALKING_SPEED;
            }


            /*Si se movio, chequeo colisiones con objetos... Esto no funciona como debería, aparte no podemos atajar el movimiento antes de renderearlo y queda medio feo.
             * para solucionarlo tendríamos que hacer que la camara sigua al mesh (es decir, que el mesh sea el que se mueve con WASD) y ahí podemos atajar la colision antes
             * El otro problema es como se genera el bounding box del mesh, deje seteado para que se renderize el mesh del sniper así lo ven, solucionar esto CREO que es facil
             */

            if (!posicionSegura.Equals(camera.getPosition()))
            {
                if (moviendo == false)
                {
                    elapsedMOVE = 0.0f;
                    moviendo    = true;
                }
                else
                {
                    elapsedMOVE += elapsedTime;
                }

                if (ColisionesAdmin.Instance.ColisionConObjetos())
                {
                    camera.move(posicionSegura - camera.getPosition());
                }
                else
                {
                    posicionSegura = camera.getPosition();
                }
            }
            else
            {
                moviendo = false;
            }

            if (ColisionesAdmin.Instance.ColisionConEnemigos())
            {
                this.vidas -= 1;
                sound_Die.play();
                camera.move(posicionInicial - camera.getPosition());
            }

            // Disparo

            if (!puedeDisparar)
            {
                elapsedROF += elapsedTime;
            }
            if (elapsedROF >= ROF)
            {
                puedeDisparar = true;
            }

            if (GuiController.Instance.D3dInput.buttonPressed(TgcViewer.Utils.Input.TgcD3dInput.MouseButtons.BUTTON_LEFT))
            {
                if (ammo != 0)
                {
                    if (puedeDisparar)
                    {
                        TgcRay disparo = new TgcRay(camera.getPosition(), Vector3.Subtract(camera.getLookAt(), camera.getPosition()));

                        if (ColisionesAdmin.Instance.ColisionDisparo(disparo))
                        {
                            sound_Hit.play();
                        }


                        sound_Disparo.play();
                        puedeDisparar = false;
                        elapsedROF    = 0;
                        ammo--;
                    }
                }
                else
                {
                    sound_DryFire.play();
                }
            }


            // Activa el scope
            if (GuiController.Instance.D3dInput.buttonPressed(TgcViewer.Utils.Input.TgcD3dInput.MouseButtons.BUTTON_RIGHT))
            {
                // Me fijo el estado del scope, cambio la matriz de proyeccion y la velocidad de rotación del mouse
                // (para disminuir la sens y que el mouse no vuele con el zoom)

                //Reproduzco el sonido del zoom
                sound_Zoom.play();

                scope = !scope;

                if (scope)
                {
                    zoom = zoomBase;
                    camera.RotationSpeed = ROTATION_SPEED_SCOPE;
                }
                else
                {
                    zoom = 1;
                    camera.RotationSpeed = ROTATION_SPEED_NO_SCOPE;
                }
            }

            // Zoom con la rueda del mouse, SOLO si el scope esta activado
            if (scope)
            {
                if (GuiController.Instance.D3dInput.WheelPos > 0)
                {
                    zoom += zoomWheel;
                }
                if (GuiController.Instance.D3dInput.WheelPos < 0)
                {
                    zoom -= zoomWheel;
                }

                if (GuiController.Instance.D3dInput.WheelPos != 0 && zoom <= (zoomBase + zoomMaximo * zoomWheel) && zoom >= 1)
                {
                    sound_Zoom.play();
                }


                if (zoom > zoomBase + (zoomWheel * zoomMaximo))
                {
                    zoom = zoomBase + (zoomWheel * zoomMaximo);
                }
                if (zoom < zoomBase)
                {
                    zoom = zoomBase;
                }
            }
            else
            {
                UpdateRifle();
            }

            matrizConZoom.M11 = matrizSinZoom.M11 * zoom;
            matrizConZoom.M22 = matrizSinZoom.M22 * zoom;

            GuiController.Instance.D3dDevice.Transform.Projection = matrizConZoom;
        }
Пример #2
0
        public Player()
        {
            TgcSceneLoader loaderSniper = new TgcSceneLoader();

            string media = GuiController.Instance.AlumnoEjemplosMediaDir;

            TgcScene sniperRifle = loaderSniper.loadSceneFromFile(media + "CEGA\\Sniper-TgcScene.xml");

            rifle = sniperRifle.Meshes[0];
            rifle.AlphaBlendEnable    = true;
            rifle.AutoTransformEnable = false;

            rifleBaseTransforms =
                Matrix.Scaling(new Vector3(0.01f, 0.01f, 0.01f)) *
                Matrix.RotationY(FastMath.PI - 0.03f) *
                Matrix.Translation(new Vector3(0.5f, -1.0f, 2.0f));

            // Configuracion de la camara
            //
            GuiController.Instance.CurrentCamera.Enable = false;
            camera = new FpsCamera();
            GuiController.Instance.CurrentCamera = camera;
            camera.MovementSpeed = WALKING_SPEED;
            camera.RotationSpeed = ROTATION_SPEED_NO_SCOPE;
            posicionSegura       = camera.getPosition();
            posicionInicial      = camera.getPosition();
            lookAtInicial        = camera.getLookAt();

            // Configuracion del stencil para el modo scope
            //
            scope_stencil         = new TgcSprite();
            scope_stencil.Texture = TgcTexture.createTexture(media + @"CEGA\Textures\scope.png");

            Size screenSize  = GuiController.Instance.Panel3d.Size;
            Size textureSize = scope_stencil.Texture.Size;

            float scope_scale = FastMath.Min(
                (float)screenSize.Width / textureSize.Width,
                (float)screenSize.Height / textureSize.Height) * 0.9f;

            scope_stencil.Scaling = new Vector2(scope_scale, scope_scale);

            scope_stencil.Position = new Vector2(
                FastMath.Max(screenSize.Width / 2 - textureSize.Width * scope_scale / 2, 0),
                FastMath.Max(screenSize.Height / 2 - textureSize.Height * scope_scale / 2, 0));

            // El radio, ajustado a -1% para cubrir el borde
            scope_radius = (textureSize.Height * scope_scale / 2.0f) * 0.99f;

            LoadSounds(media);

            //Inicializo vidas , balas y puntos.

            this.vidas  = 5;
            this.ammo   = -1; //Por ahora son infinitas
            this.puntos = 0;

            //Configuracion de la mira sin scope.
            float mira_scale = 0.08f;

            mira         = new TgcSprite();
            mira.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "CEGA\\Textures\\Mira.png");
            mira.Scaling = new Vector2(mira_scale, mira_scale);

            Size miraSize = mira.Texture.Size;

            miraSize.Height = (int)(miraSize.Height * mira_scale);
            miraSize.Width  = (int)(miraSize.Width * mira_scale);
            mira.Position   = new Vector2(FastMath.Max(screenSize.Width / 2 - miraSize.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - miraSize.Height / 2, 0));

            //Inicialización UI (Texto)
            LoadUI(screenSize);
        }
Пример #3
0
        public Player()
        {
            TgcSceneLoader loaderSniper = new TgcSceneLoader();

            string media = GuiController.Instance.AlumnoEjemplosMediaDir;

            TgcScene sniperRifle = loaderSniper.loadSceneFromFile(media + "CEGA\\Sniper-TgcScene.xml");

            rifle = sniperRifle.Meshes[0];
            rifle.AlphaBlendEnable = true;
            rifle.AutoTransformEnable = false;

            rifleBaseTransforms =
                Matrix.Scaling(new Vector3(0.01f, 0.01f, 0.01f)) *
                Matrix.RotationY(FastMath.PI - 0.03f) *
                Matrix.Translation(new Vector3(0.5f, -1.0f, 2.0f));

            // Configuracion de la camara
            //
            GuiController.Instance.CurrentCamera.Enable = false;
            camera = new FpsCamera();
            GuiController.Instance.CurrentCamera = camera;
            camera.MovementSpeed = WALKING_SPEED;
            camera.RotationSpeed = ROTATION_SPEED_NO_SCOPE;
            posicionSegura = camera.getPosition();
            posicionInicial = camera.getPosition();
            lookAtInicial = camera.getLookAt();

            // Configuracion del stencil para el modo scope
            //
            scope_stencil = new TgcSprite();
            scope_stencil.Texture = TgcTexture.createTexture(media + @"CEGA\Textures\scope.png");

            Size screenSize = GuiController.Instance.Panel3d.Size;
            Size textureSize = scope_stencil.Texture.Size;

            float scope_scale = FastMath.Min(
                (float)screenSize.Width / textureSize.Width,
                (float)screenSize.Height / textureSize.Height) * 0.9f;

            scope_stencil.Scaling = new Vector2(scope_scale, scope_scale);

            scope_stencil.Position = new Vector2(
                FastMath.Max(screenSize.Width / 2 - textureSize.Width * scope_scale / 2, 0),
                FastMath.Max(screenSize.Height / 2 - textureSize.Height * scope_scale / 2, 0));

            // El radio, ajustado a -1% para cubrir el borde
            scope_radius = (textureSize.Height * scope_scale / 2.0f) * 0.99f;

            LoadSounds(media);

            //Inicializo vidas , balas y puntos.

            this.vidas = 5;
            this.ammo = -1; //Por ahora son infinitas
            this.puntos = 0;

            //Configuracion de la mira sin scope.
            float mira_scale = 0.08f;
            mira = new TgcSprite();
            mira.Texture = TgcTexture.createTexture(GuiController.Instance.AlumnoEjemplosMediaDir + "CEGA\\Textures\\Mira.png");
            mira.Scaling = new Vector2(mira_scale, mira_scale);

            Size miraSize = mira.Texture.Size;
            miraSize.Height = (int)(miraSize.Height * mira_scale);
            miraSize.Width = (int)(miraSize.Width * mira_scale);
            mira.Position = new Vector2(FastMath.Max(screenSize.Width / 2 - miraSize.Width / 2, 0), FastMath.Max(screenSize.Height / 2 - miraSize.Height / 2, 0));

            //Inicialización UI (Texto)
            LoadUI(screenSize);
        }