public override void Update(GameTime gameTime) { oldGamePadState = currentGamePadState; currentGamePadState = GamePad.GetState((Microsoft.Xna.Framework.PlayerIndex)PlayerIndex); //Save keyboard state so all controllers can access them oldKeyboardState = currentKeyboardState; currentKeyboardState = Keyboard.GetState(); //Update the position of the cursor float directionX = 0, directionY = 0; if (IsKeyDown(PlayerModel.KeyboardLeft)) { directionX = -1; } else if (IsKeyDown(PlayerModel.KeyboardRight)) { directionX = 1; } if (IsKeyDown(PlayerModel.KeyboardUp)) { directionY = -1; } else if (IsKeyDown(PlayerModel.KeyboardDown)) { directionY = 1; } Vector2 stick = currentGamePadState.ThumbSticks.Left; if (stick.X != 0) { directionX = stick.X; } if (stick.Y != 0) { directionY = stick.Y * -1; } if (oldNavigations.Count == 0) { oldNavigations.Enqueue(new Tuple <TimeSpan, Vector2> (gameTime.TotalGameTime, new Vector2(directionX, directionY))); newXdirection = true; newYdirection = true; } else { TimeSpan lastNavigation = new TimeSpan(oldNavigations.Last().Item1.Ticks); if (lastNavigation.Add(new TimeSpan(0, 0, 0, 0, 50)).CompareTo(gameTime.TotalGameTime) <= 0) { Tuple <TimeSpan, Vector2> oldNav = oldNavigations.Peek(); if (new TimeSpan(oldNav.Item1.Ticks).Add(new TimeSpan(0, 0, 0, 0, 200)).CompareTo(gameTime.TotalGameTime) <= 0) { oldNavigations.Dequeue(); } newXdirection = Math.Abs(directionX - oldNav.Item2.X) > 0.8; newYdirection = Math.Abs(directionY - oldNav.Item2.Y) > 0.8; oldNavigations.Enqueue(new Tuple <TimeSpan, Vector2>(gameTime.TotalGameTime, new Vector2(directionX, directionY))); } } if (OnNavigation != null) { OnNavigation.Invoke(directionX, directionY, PlayerIndex, newXdirection, newYdirection); } switch (CurrentState) { case GameState.StartScreen: if (IsKeyDown(Keys.H) || currentGamePadState.IsButtonDown(Buttons.Back)) { Screen.popupMenuController.State = PopupState.Options; } else if (this.currentKeyboardState.GetPressedKeys().Count() != 0 || currentGamePadState.IsButtonDown(Buttons.A) || currentGamePadState.IsButtonDown(Buttons.Start)) { CurrentState = GameState.CharacterMenu; } break; } //Updates all the timers added for the keys float elapsed = gameTime.ElapsedGameTime.Milliseconds; UpdateTimer(PlayerModel.KeyboardHit, Buttons.A, directionX, directionY, elapsed, OnHitkeyDown, OnHitKeyUp, OnHitKeyPressed, ref HitDownTimer, ref HitUpTimer); UpdateTimer(PlayerModel.KeyboardSheild, Buttons.RightTrigger, directionX, directionY, elapsed, OnShieldkeyDown, OnShieldKeyUp, OnShieldKeyPressed, ref ShieldDownTimer, ref ShieldUpTimer); UpdateTimer(PlayerModel.KeyboardSuper, Buttons.X, directionX, directionY, elapsed, OnSuperkeyDown, OnSuperKeyUp, OnSuperKeyPressed, ref SuperDownTimer, ref SuperUpTimer); if ((IsKeyPressed(PlayerModel.KeyboardStart) || isControllerPressed(Buttons.Start)) && OnStartPress != null) { OnStartPress.Invoke(PlayerIndex); } if ((IsKeyPressed(PlayerModel.KeyboardBack) || isControllerPressed(Buttons.Back)) && OnBackPress != null) { OnBackPress.Invoke(PlayerIndex); } }
public void StartPress() { OnStartPress?.Invoke(GetComponent <EntityBase>().entity); }