Beispiel #1
0
        /// <summary>
        /// Se llama cada vez que hay que refrescar la pantalla.
        ///     Escribir aquí todo el código referido al renderizado.
        /// </summary>
        /// <param name="gameTime">The gameTime<see cref="GameTime"/>.</param>
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);

            var mouse = Mouse.GetState();

            if (mouse.LeftButton == ButtonState.Pressed && Recoil == 0)
            {
                Recoil = 10;
            }
            if (mouse.RightButton == ButtonState.Pressed && Recoil == 0)
            {
                Recoil = 13.5f;
            }

            Map.Draw(World, Camera.View, Camera.Projection);

            SpawnerModel.Draw(Camera.View, Camera.Projection);

            foreach (Enemy enemy in Enemies)
            {
                if (enemy.GetLife() > 0)
                {
                    Vector3 SkullRight    = Vector3.Cross(enemy.GetDirection(), enemy.GetUp());
                    Vector3 SkullPosition = enemy.GetPosition() + enemy.GetDirection() + SkullRight - enemy.GetUp();
                    Skull.Draw(Matrix.CreateScale(0.75f) * Matrix.CreateWorld(SkullPosition, -SkullRight, enemy.GetUp()), Camera.View, Camera.Projection);
                }
            }

            foreach (Bullet bullet in Bullets)
            {
                Vector3 BulletRight    = Vector3.Cross(bullet.GetDirection(), bullet.GetUp());
                Vector3 BulletPosition = bullet.GetPosition() + bullet.GetDirection() + BulletRight - bullet.GetUp();
                if (Vector3.Distance(bullet.GetPosition(), Camera.Position) < 2550)
                {
                    BulletModel.Draw(Matrix.CreateScale(5) * Matrix.CreateWorld(BulletPosition, -BulletRight, bullet.GetDirection()), Camera.View, Camera.Projection);
                }
            }

            if (Recoil > 0)
            {
                Recoil -= 0.25f;
            }

            Vector3 cameraRight    = Vector3.Cross(Camera.FrontDirection, Camera.UpDirection);
            Vector3 weaponPosition = new Vector3(Camera.Position.X, 0, Camera.Position.Z) + new Vector3(0, -15, 0) + Camera.FrontDirection * MathHelper.Lerp(40, 35, Recoil) + cameraRight * 10 - Camera.UpDirection * 4;
            Matrix  shotgunWorld   = Matrix.CreateScale(0.1f, 0.1f, 0.1f) * Matrix.CreateWorld(weaponPosition, -cameraRight, Camera.UpDirection);

            Shotgun.Draw(shotgunWorld, Camera.View, Camera.Projection);

            base.Draw(gameTime);
        }