static void EnemyDeath(Vector3 pos, Xwing xwing)
 {
     SoundManager.Play3DSoundAt(SoundManager.Effect.TieExplosion, pos);
     //explosion effect
     TGCGame.Instance.HUD.ExplosionAnims.Add(new ExplosionAnim(pos));
     xwing.Score += 10;
 }
 /// <summary>
 ///     Constructor del juego.
 /// </summary>
 public TGCGame()
 {
     // Maneja la configuracion y la administracion del dispositivo grafico.
     Graphics = new GraphicsDeviceManager(this);
     // Descomentar para que el juego sea pantalla completa.
     // Graphics.IsFullScreen = true;
     // Carpeta raiz donde va a estar toda la Media.
     Content.RootDirectory = "Content";
     Instance = this;
     Xwing    = new Xwing();
     Gizmos   = new Gizmos();
 }
        public static void UpdateAll(float time, Xwing xwing)
        {
            Vector4 zone = xwing.GetZone();

            EnemyLasers.ForEach(laser => laser.Update(time, zone));
            AlliedLasers.ForEach(laser => laser.Update(time, zone));

            EnemyLasers.RemoveAll(laser => laser.NotVisible);
            AlliedLasers.RemoveAll(laser => laser.NotVisible);

            //Debug.WriteLine("AL " + AlliedLasers.Count + " EL " + EnemyLasers.Count);
        }
        public static void UpdateEnemies(float time, Xwing xwing)
        {
            foreach (var enemy in Enemies)
            {
                enemy.Update(xwing, time);
                enemy.VerifyCollisions(Laser.AlliedLasers);
                enemy.fireLaser();
            }

            Enemies.FindAll(enemy => enemy.HP <= 0).
            ForEach(enemy => EnemyDeath(enemy.Position, xwing));

            Enemies.RemoveAll(enemy => enemy.HP <= 0);
        }
Beispiel #5
0
        public void ProcessMouse(Xwing Xwing)
        {
            var mouseState = Mouse.GetState();
            //var mousePosition = mouseState.Position.ToVector2();
            //var mouseDelta = mousePosition - pastMousePosition;
            var mouseDelta = (mouseState.Position - screenCenter).ToVector2();

            Mouse.SetPosition(screenCenter.X, screenCenter.Y);
            //System.Diagnostics.Debug.WriteLine(mouseState.ScrollWheelValue);
            mouseDelta *= MouseSensitivity * 0.010f;

            //System.Diagnostics.Debug.WriteLine(time);
            //Evito movimientos muy rapidos con mouse
            //System.Diagnostics.Debug.WriteLine(mouseDelta.X + " " + mouseDelta.Y);
            mouseDelta.X = MathHelper.Clamp(mouseDelta.X, -maxMouseDelta, maxMouseDelta);
            mouseDelta.Y = MathHelper.Clamp(mouseDelta.Y, -maxMouseDelta, maxMouseDelta);

            //if (mouseDelta == Vector2.Zero)
            //    return;
            TGCGame.MutexDeltas.WaitOne();
            delta = mouseDelta;
            TGCGame.MutexDeltas.ReleaseMutex();
            //System.Diagnostics.Debug.WriteLine("delta " + Math.Round(mouseDelta.X, 2) +"|" + Math.Round(mouseDelta.Y, 2));

            Xwing.updateRoll(delta);

            Yaw += mouseDelta.X;
            if (Yaw < 0)
            {
                Yaw += 360;
            }
            Yaw %= 360;

            Pitch -= mouseDelta.Y;

            if (Pitch > 89.0f)
            {
                Pitch = 89.0f;
            }
            if (Pitch < -89.0f)
            {
                Pitch = -89.0f;
            }

            //changed = true;
            UpdateCameraVectors();

            //pastMousePosition = Mouse.GetState().Position.ToVector2();
        }
 public void Update(Xwing xwing, float time)
 {
     Time           = time;
     FrontDirection = Vector3.Normalize(xwing.Position - Position);
     updateDirectionVectors();
     SRT =
         S *
         Matrix.CreateFromYawPitchRoll(Yaw, 0f, 0f) *
         Matrix.CreateTranslation(Position);
     updateFireRate();
     if (xwing.Position.Y > 0)
     {
         fireLaser();
     }
     verifyColision();
 }
        public static void GenerateEnemies(Xwing xwing)
        {
            Random rnd;
            int    maxEnemies = 2;
            int    distance   = 300;

            for (int i = 0; i < maxEnemies - Enemies.Count; i++)
            {
                rnd = new Random();
                Vector3 random = new Vector3(rnd.Next(-distance, distance), 0f, rnd.Next(-distance, distance));
                Vector3 pos    = xwing.Position + random;
                Vector3 dir    = Vector3.Normalize(xwing.Position - pos);


                Matrix SRT = Matrix.CreateScale(TieScale) * Matrix.CreateTranslation(pos);
                Enemies.Add(new TieFighter(pos, dir, Matrix.Identity, SRT));
            }
        }
        public void Update(Xwing xwing, float time)
        {
            Time = time;


            FrontDirection = followError(Vector3.Normalize(xwing.Position - Position));

            updateDirectionVectors();
            if (Vector3.Distance(xwing.Position, Position) > 100)
            {
                Position += FrontDirection * 50f * time;
            }
            SRT =
                Matrix.CreateScale(TieScale) *
                Matrix.CreateFromYawPitchRoll(Yaw, Pitch, 0f) *
                Matrix.CreateTranslation(Position);
            updateFireRate();
            boundingSphere.Center = Position;
        }
Beispiel #9
0
        void DrawXWingMRT(Xwing xwing, DrawType dt)
        {
            int meshCount = 0;

            if (dt == DrawType.Regular)
            {
                MasterMRT.CurrentTechnique = MRTbasicColor;
            }

            //MRTapplyLightEffect.SetValue(0f);

            MRTaddToBloomFilter.SetValue(1f);
            DrawModelMRT(XwingEnginesModel, xwing.EnginesSRT, xwing.EnginesColor);
            MRTaddToBloomFilter.SetValue(0f);

            //MRTapplyLightEffect.SetValue(1f);

            if (dt == DrawType.Regular)
            {
                MasterMRT.CurrentTechnique = MRTtextured;
            }

            foreach (var mesh in XwingModel.Meshes)
            {
                xwing.World = mesh.ParentBone.Transform * xwing.SRT;

                var wvp = xwing.World * Game.SelectedCamera.View * Game.SelectedCamera.Projection;

                MRTtexture.SetValue(XwingTextures[meshCount]);
                MRTmodelNormal.SetValue(XwingNormalTex[meshCount]);
                MRTworld.SetValue(xwing.World);
                MRTworldViewProjection.SetValue(wvp);
                MRTinverseTransposeWorld.SetValue(Matrix.Transpose(Matrix.Invert(xwing.World)));
                meshCount++;

                mesh.Draw();
            }
        }
Beispiel #10
0
        public void ProcessKeyboard(Xwing xwing)
        {
            var keyboardState = Keyboard.GetState();

            SpeedMultiplier = 1f;
            if (!debugging)
            {
                if (keyboardState.IsKeyDown(Keys.W))
                {
                    if (xwing.Energy > 0 && !xwing.BoostLock)
                    {
                        xwing.Boosting  = true;
                        SpeedMultiplier = 1f + 6f * xwing.boostTime;
                        //Debug.WriteLine(SpeedMultiplier);
                    }
                    else if (xwing.Energy == 0 && xwing.Boosting)
                    {
                        xwing.BoostLock = true;
                        xwing.Boosting  = false;
                    }
                    else if (xwing.Energy >= 3 && xwing.BoostLock)
                    {
                        xwing.BoostLock = false;
                    }
                }
                else if (keyboardState.IsKeyDown(Keys.S))
                {
                    xwing.Boosting  = false;
                    SpeedMultiplier = 0.5f;
                }
                else
                {
                    xwing.Boosting = false;
                }
            }
            else
            {
                //Free cam for debug
                if (keyboardState.IsKeyDown(Keys.LeftShift))
                {
                    CurrentMovementSpeed *= 10f;
                }

                if (keyboardState.IsKeyDown(Keys.A))
                {
                    Position += -RightDirection * CurrentMovementSpeed;
                }
                if (keyboardState.IsKeyDown(Keys.D))
                {
                    Position += RightDirection * CurrentMovementSpeed;
                }
                if (keyboardState.IsKeyDown(Keys.W))
                {
                    Position += FrontDirection * CurrentMovementSpeed;
                }
                if (keyboardState.IsKeyDown(Keys.S))
                {
                    Position += -FrontDirection * CurrentMovementSpeed;
                }

                if (ArrowsLookEnabled)
                {
                    if (keyboardState.IsKeyDown(Keys.Up))
                    {
                        Pitch  += CurrentTurnSpeed;
                        delta.Y = CurrentTurnSpeed;
                        if (Pitch > 89.0f)
                        {
                            Pitch = 89.0f;
                        }
                    }
                    if (keyboardState.IsKeyDown(Keys.Down))
                    {
                        Pitch  -= CurrentTurnSpeed;
                        delta.Y = -CurrentTurnSpeed;
                        if (Pitch < -89.0f)
                        {
                            Pitch = -89.0f;
                        }
                    }
                    if (keyboardState.IsKeyDown(Keys.Left))
                    {
                        Yaw    -= CurrentTurnSpeed;
                        delta.X = -CurrentTurnSpeed;
                        if (Yaw < 0)
                        {
                            Yaw += 360;
                        }
                        Yaw %= 360;
                    }
                    if (keyboardState.IsKeyDown(Keys.Right))
                    {
                        Yaw    += CurrentTurnSpeed;
                        delta.X = CurrentTurnSpeed;
                        Yaw    %= 360;
                    }
                    xwing.updateRoll(delta);
                }
            }
        }
Beispiel #11
0
        public void PausedUpdate(float elapsedTime, Xwing xwing)
        {
            float y = 0f;

            if (!Resuming)
            {
                if (PauseRotationDir)
                {
                    PauseRotation += elapsedTime * 0.5f;
                    PauseRotation %= MathHelper.TwoPi;
                }
                else
                {
                    PauseRotation -= elapsedTime * 0.5f;
                    if (PauseRotation < 0)
                    {
                        PauseRotation += MathHelper.TwoPi;
                    }
                }


                if (xwing.Position.Y > 0)
                {
                    y     = xwing.Position.Y + 8;
                    Pitch = 0f;
                }
                else
                {
                    y     = 30f;
                    Pitch = -15f;
                }

                Position = new Vector3(
                    xwing.Position.X + 100f * MathF.Cos(PauseRotation),
                    y,
                    xwing.Position.Z + 100f * MathF.Sin(PauseRotation));

                Vector3 frontDirection = Vector3.Normalize(xwing.Position - Position);

                Yaw = MathHelper.ToDegrees(MathF.Atan2(frontDirection.Z, frontDirection.X));
            }
            else
            {
                var posDif = PrevPosition - Position;
                var len    = posDif.Length();
                var dir    = Vector3.Normalize(posDif);

                var restoredPos   = len < 2f;
                var restoredYaw   = Yaw > PrevYaw - 6f && Yaw < PrevYaw + 6f;
                var restoredPitch = Pitch > PrevPitch - 2f && Pitch < PrevPitch + 2f;


                if (!restoredPos)
                {
                    Position += dir * elapsedTime * len * 5f;
                }
                if (!restoredYaw)
                {
                    if (!yawCorrectionDir)
                    {
                        Yaw += elapsedTime * yawDelta * 1.5f;
                    }
                    else
                    {
                        Yaw -= elapsedTime * yawDelta * 1.5f;
                        if (Yaw < 0)
                        {
                            Yaw += 360;
                        }
                    }
                }
                if (!restoredPitch)
                {
                    Pitch += elapsedTime * pitchDelta * 1.5f;
                }

                if (restoredPos && restoredYaw && restoredPitch)
                {
                    restorePreviousPitchYawPos();
                }
            }

            UpdateVectorView();
        }