public override void Update(GameTime gameTime) { #region Exit if (ToLoad.ContentLoaded) { GameState.AddScreen(ToLoad); GameState.RemoveScreen(this); } #endregion }
protected override void Initialize() { GameState.AddScreen(new LoadingScreen(new LevelSelector())); base.Initialize(); }
public override void Update(GameTime gameTime) { if (Updates) { #region Rectangles Vector2 BBottomRight = new Vector2(Backgrounds[Bindex].Value.Width, Backgrounds[Bindex].Value.Height); BRectangle = new Rectangle(Graphics.Width / 2 - (int)BBottomRight.X / 4, (int)BBottomRight.Y / 4, (int)BBottomRight.X / 2, (int)BBottomRight.Y / 2); Vector2 PleftBottomRight = new Vector2(Characters[Pleftindex].Value.Width, Characters[Pleftindex].Value.Height); Vector2 PrightBottomRight = new Vector2(Characters[Prightindex].Value.Width, Characters[Prightindex].Value.Height); PleftRectangle = new Rectangle(Graphics.Width / 4 - (int)PleftBottomRight.X / 2 - 60, Graphics.Height / 4 * 3 - (int)PleftBottomRight.Y / 2, (int)PleftBottomRight.X, (int)PleftBottomRight.Y); PrightRectangle = new Rectangle(Graphics.Width / 4 * 3 - (int)PrightBottomRight.X / 2 + 60, Graphics.Height / 4 * 3 - (int)PrightBottomRight.Y / 2, (int)PrightBottomRight.X, (int)PrightBottomRight.Y); StartTripRectangle = new Rectangle(Graphics.Width / 2 - StartTripTex.Width / 2, Graphics.Height / 4 * 3 - StartTripTex.Height, StartTripTex.Width, StartTripTex.Height); StartTripRectangle.Inflate(80, 40); #endregion foreach (TouchLocation tl in Input.Touches) { #region Selector if (tl.State == TouchLocationState.Pressed) { if (Graphics.Device.Viewport.Bounds.Contains((int)tl.Position.X, (int)tl.Position.Y)) { if (Utilities.PadRectangle(PleftRectangle, 1.2f, 1.03f).Contains((int)tl.Position.X, (int)tl.Position.Y)) { if (OnLeftSide) { if (Pleftindex >= Characters.Count - 1) { Pleftindex = 0; } else { Pleftindex++; } } else { OnLeftSide = true; } } else if (Utilities.PadRectangle(PrightRectangle, 1.25f, 1.04f).Contains((int)tl.Position.X, (int)tl.Position.Y)) { //This code is for the right player selection //if (Prightindex >= Characters.Count - 1) Prightindex = 0; else Prightindex++; if (!OnLeftSide) { if (Pleftindex >= Characters.Count - 1) { Pleftindex = 0; } else { Pleftindex++; } } else { OnLeftSide = false; } } else if (StartTripRectangle.Contains((int)tl.Position.X, (int)tl.Position.Y)) { StartPressed = true; startId = tl.Id; } else { if (Bindex >= Backgrounds.Count - 1) { Bindex = 0; } else { Bindex++; } } } } if (tl.State == TouchLocationState.Released) { if (!StartTripRectangle.Contains((int)tl.Position.X, (int)tl.Position.Y)) { if (startId == tl.Id) { StartPressed = false; } } if (StartTripRectangle.Contains((int)tl.Position.X, (int)tl.Position.Y)) { if (startId == tl.Id) { StartPressed = false; Prightindex = Rand.Next(Characters.Count - 1); Texture2D leftTex = Characters[Pleftindex].Value; Texture2D rightTex = Characters[Prightindex].Value; //Just make it random Texture2D Background = Backgrounds[Bindex].Value; Backgrounds.RemoveAt(Bindex); //logic is wierd here since upon removing indices change //Consider revisiting seperate content managers per Screen if (Pleftindex == Prightindex) { Characters.RemoveAt(Pleftindex); } else if (Pleftindex < Prightindex) { Prightindex--; Characters.RemoveAt(Pleftindex); Characters.RemoveAt(Prightindex); } else if (Pleftindex > Prightindex) { Characters.RemoveAt(Pleftindex); Characters.RemoveAt(Prightindex); } //Manually dispose of unneeded content foreach (var pair in Backgrounds) { pair.Value.Dispose(); } foreach (var pair in Characters) { pair.Value.Dispose(); } StartTripPressedTex.Dispose(); StartTripTex.Dispose(); Player player = new Player(leftTex); Robot robot = new Robot(rightTex, player); //Exceptions can throw if you try to draw disposed content base.Updates = false; base.Draws = false; GameState.AddScreen(new LoadingScreen(new GameScreen(Content, Background, player, robot, OnLeftSide))); GameState.RemoveScreen(this); } } } #endregion } } }