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); }
protected override void Update(GameTime gameTime) { float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; Drawer.MasterMRT.Parameters["Time"]?.SetValue(elapsedTime); Input.ProcessInput(); BoundingFrustum.Matrix = SelectedCamera.View * SelectedCamera.Projection; Vector3[] frustumCorners = BoundingFrustum.GetCorners(); var lvp = LightCamera.View * LightCamera.Projection; Vector3 center = Vector3.Zero; foreach (var corner in frustumCorners) { center += corner; } center /= frustumCorners.Length; //var cyr = MathHelper.ToRadians(Camera.Yaw); float dif = -MathF.Atan2(Camera.FrontDirection.X - 1f, Camera.FrontDirection.Z - 0f); if (dif > MathHelper.PiOver2) { dif = MathHelper.Pi - dif; } // [0 - 90] // [700- 200] LightCamera.Offset = 200f; //LightCamera.Offset = MathHelper.Lerp(200, 700, 1f - (dif / MathHelper.PiOver2)); //Debug.WriteLine(" dif "+ MathHelper.ToDegrees(dif) + " off " + LightCamera.Offset); //LightCamera.NearPlane = shadowNear; //LightCamera.FarPlane = shadowFar; LightCamera.Update(gameTime); Vector4 zone = Xwing.GetZone(); switch (GameState) { case GmState.StartScreen: #region startscreen Camera.Yaw += 10f * elapsedTime; Camera.Yaw %= 360; Camera.Pitch += 10f * elapsedTime; Camera.Yaw %= 90; Camera.UpdateVectorView(); #endregion break; case GmState.Running: #region running Drawer.trenchesToDraw.Clear(); Drawer.tiesToDraw.Clear(); Drawer.showXwing = true; Drawer.lasersToDraw.Clear(); Drawer.shipsToDraw.Clear(); elementsDrawn = 0; totalElements = 0; //Update camara Camera.Update(gameTime); //Generacion de enemigos, de ser necesario TieFighter.GenerateEnemies(Xwing); TieFighter.AddAllRequiredToDraw(ref Drawer.tiesToDraw, BoundingFrustum); elementsDrawn += Drawer.tiesToDraw.Count; totalElements += TieFighter.Enemies.Count; //Update Xwing Xwing.Update(elapsedTime, Camera); elementsDrawn += 1; totalElements += 1; BackgroundCombat.UpdateAll(elapsedTime); BackgroundCombat.AddAllRequiredToDraw(ref Drawer.shipsToDraw); Trench.UpdateCurrent(); //enemyLasers.Clear(); for (int x = (int)zone.X; x < zone.Y; x++) { for (int z = (int)zone.Z; z < zone.W; z++) { var block = Map[x, z]; block.Update(elapsedTime); if (BoundingFrustum.Intersects(block.BB)) { Drawer.trenchesToDraw.Add(Map[x, z]); } totalElements++; } } elementsDrawn += Drawer.trenchesToDraw.Count; Laser.UpdateAll(elapsedTime, Xwing); totalElements += Laser.AlliedLasers.Count; totalElements += Laser.EnemyLasers.Count; Laser.AddAllRequiredtoDraw(ref Drawer.lasersToDraw, ref BoundingFrustum); elementsDrawn += Drawer.lasersToDraw.Count; Drawer.MasterMRT.Parameters["OmniLightsRadiusMin"]?.SetValue(RadMin); Drawer.MasterMRT.Parameters["OmniLightsRadiusMax"]?.SetValue(RadMax); Drawer.MasterMRT.Parameters["OmniLightsPos"]?.SetValue(Laser.OmniLightsPos); Drawer.MasterMRT.Parameters["OmniLightsColor"]?.SetValue(Laser.OmniLightsColor); Drawer.MasterMRT.Parameters["OmniLightsCount"]?.SetValue(Laser.OmniLightsCount); //Colisiones Xwing.VerifyCollisions(Laser.EnemyLasers, Map); TieFighter.UpdateEnemies(elapsedTime, Xwing); SoundManager.UpdateRandomDistantSounds(elapsedTime); #endregion break; case GmState.Paused: #region paused Camera.PausedUpdate(elapsedTime, Xwing); Drawer.trenchesToDraw.Clear(); for (int x = (int)zone.X; x < zone.Y; x++) { for (int z = (int)zone.Z; z < zone.W; z++) { var block = Map[x, z]; if (BoundingFrustum.Intersects(block.BB)) { Drawer.trenchesToDraw.Add(Map[x, z]); } } } #endregion break; case GmState.Victory: #region victory Camera.PausedUpdate(elapsedTime, Xwing); #endregion break; case GmState.Defeat: #region defeat Camera.PausedUpdate(elapsedTime, Xwing); Drawer.trenchesToDraw.Clear(); for (int x = (int)zone.X; x < zone.Y; x++) { for (int z = (int)zone.Z; z < zone.W; z++) { var block = Map[x, z]; if (BoundingFrustum.Intersects(block.BB)) { Drawer.trenchesToDraw.Add(Map[x, z]); } } } #endregion break; } Gizmos.UpdateViewProjection(SelectedCamera.View, SelectedCamera.Projection); if (Xwing.Score >= 100) { ChangeGameStateTo(GmState.Victory); } base.Update(gameTime); }