public int Update(GameTime gameTime) { float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; /*frame++; * frame %= 30;*/ frame += delta; frame %= 0.8f; if (frame <= 0.4) { selectedColor = new Color(159, 255, 111); } else { selectedColor = Color.Yellow; } Timer(gameTime); if (!IsChangingState) { allowKeyboard = MouseHandler.CheckIfSameSpot(); if (Opacity + (0.05f * delta * 60) <= 1.0f) { Opacity += (0.05f * delta * 60); } if (InputHandler.Press(Keys.Down) && allowKeyboard) { if (selected < displayGamesItems.Count - 1) { selected++; } } if (InputHandler.Press(Keys.Up) && allowKeyboard) { if (selected > 0) { selected--; } } if (InputHandler.Press(Keys.D) && allowKeyboard) { if (displayGamesItems.Any()) { GameHandler _gameHandler = displayGamesItems[selected].Game; Simpsons.RemoveGameHandler(_gameHandler); for (int i = selected; i < displayGamesItems.Count; i++) { var tempRect = displayGamesItems[i].Rectangle; Rectangle rect = new Rectangle(tempRect.X, tempRect.Y - 35, tempRect.Width, tempRect.Height); displayGamesItems[i].Rectangle = rect; } displayGamesItems.RemoveAt(selected); _durationOpacity = 1f; _deleteMessage = $"Game {_gameHandler.GameID} deleted"; if (displayGamesItems.ElementAtOrDefault(selected) == null) { selected--; } if (displayGamesItems.Count == 0) { selected = 0; } } } //Checks if user presses enter //or if the user presses mouse1 and is hovering over the correct object if (displayGamesItems.Any()) { if (InputHandler.Press(Keys.Enter) || (MouseHandler.MouseState.LeftButton == ButtonState.Pressed && displayGamesItems[selected].Rectangle.Contains(MouseHandler.MouseState.X, MouseHandler.MouseState.Y))) { return((int)Simpsons.StartGame(displayGamesItems[selected].Game)); } } if (InputHandler.GoBackPressed()) { IsChangingState = true; } for (int i = 0; i < displayGamesItems.Count; i++) { if (displayGamesItems[i].Rectangle. Contains(MouseHandler.MouseState.X, MouseHandler.MouseState.Y) && !allowKeyboard) { selected = i; } } } if (IsChangingState) { if (!IsOpacityDone) { Opacity -= (0.1f * delta * 60); } if (Opacity <= 0 && !IsOpacityDone) { IsOpacityDone = true; } if (IsOpacityDone) { return(StartStateChange(15, 3, 0, 400, gameTime)); } } return((int)Simpsons.States.Saves); }
public int Update(GameTime gameTime, GameWindow window) { float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; if (!IsChangingState) { if (Opacity + (0.05f * 60 * delta) <= 1f) { Opacity += (0.05f * 60 * delta); } if (Opacity >= 1f) { Opacity = 1f; } frame += (float)gameTime.ElapsedGameTime.TotalSeconds; frame %= 0.8f; allowKeyboard = MouseHandler.CheckIfSameSpot(); prevselected = selected; if (InputHandler.GoBackPressed()) { return((int)Simpsons.States.Quit); } if (InputHandler.Press(Keys.Down) && allowKeyboard) { menu[selected].SinValue = 0; selected++; if (selected > menu.Count - 1) { selected = 0; } } if (InputHandler.Press(Keys.Up) && allowKeyboard) { menu[selected].SinValue = 0; selected--; if (selected < 0) { selected = menu.Count - 1; } else if (selected > menu.Count - 1) { selected = 0; } } for (int i = 0; i < menu.Count; ++i) { if (menu[i].Rec.Contains(MouseHandler.MouseState.X, MouseHandler.MouseState.Y) && !allowKeyboard) { selected = i; } } if (InputHandler.Press(Keys.Enter) || MouseHandler.MouseState.LeftButton == ButtonState.Pressed && menu[selected].Rec.Contains(MouseHandler.MouseState.X, MouseHandler.MouseState.Y)) { IsChangingState = true; state = menu[selected].State; } for (int i = 0; i < menu.Count; i++) { if (i == selected) { if (menu[i].cX + (2 * 60f * gameTime.ElapsedGameTime.TotalSeconds) < menu[i].Position.X + 30) //15 frames to reach { menu[i].cX += (float)(2 * 60f * gameTime.ElapsedGameTime.TotalSeconds); menu[i].cY += (float)Math.Sin(menu[i].SinValue) * (float)(gameTime.ElapsedGameTime.TotalSeconds * 60); menu[i].SinValue -= 0.15f * (float)(60 * gameTime.ElapsedGameTime.TotalSeconds); } else { menu[i].cY = menu[i].Position.Y; menu[i].SinValue = 0.0f; } } else { if (menu[i].cX - (2 * 60f * gameTime.ElapsedGameTime.TotalSeconds) >= menu[i].Position.X) { menu[i].cX -= (float)(2 * 60f * gameTime.ElapsedGameTime.TotalSeconds); } menu[i].cY = menu[i].Position.Y; } } } else { if (menu[selected].cX - (6 * gameTime.ElapsedGameTime.TotalSeconds * 60f) != menu[selected].Position.X && menu[selected].cX > menu[selected].Position.X) { menu[selected].cX -= (float)(6 * gameTime.ElapsedGameTime.TotalSeconds * 60f); } Opacity -= (0.05f * 60 * delta); if (Opacity <= 0 && !IsOpacityDone) { IsOpacityDone = true; } if (IsOpacityDone) { switch (state) { case (int)Simpsons.States.Saves: return(StartStateChange(15, 3, 550, 500, gameTime)); case (int)Simpsons.States.Store: return(StartStateChange(15, 3, 550, 500, gameTime)); default: IsChangingState = false; return(menu[selected].State); } } } return(defaultMenuState); }