Exemple #1
0
        public void Update(GameTime gameTime)
        {
            // Get the game pad state.
            GamePadState currentState = GamePad.GetState(player);

            if (currentState.IsConnected)
            {
                #region Rotation
                if (currentState.ThumbSticks.Left.Y == 0)
                {
                    if (currentState.ThumbSticks.Left.X == 1)
                    {
                        rotationAngle = MathHelper.PiOver2;
                    }
                    if (currentState.ThumbSticks.Left.X == -1)
                    {
                        rotationAngle = -MathHelper.PiOver2;
                    }
                }
                else
                {
                    rotationAngle = (float)Math.Atan((double)(currentState.ThumbSticks.Left.X / currentState.ThumbSticks.Left.Y));
                    if (currentState.ThumbSticks.Left.Y < 0)
                    {
                        rotationAngle += MathHelper.Pi;
                    }
                }
                #endregion
                #region Movement
                if (currentState.Triggers.Right > 0)
                {
                    triggerPressed = true;
                    positionMove.X = (float)Math.Sin(rotationAngle);
                    positionMove.Y = -(float)Math.Cos(rotationAngle);
                    positionMove  *= currentState.Triggers.Right * 10;
                    triggerForce   = currentState.Triggers.Right;
                    position      += positionMove;

                    brake   = 1.0f;
                    slowing = false;
                }
                else
                {
                    if (triggerPressed) //Just released
                    {
                        slowing = true;
                        if (triggerForce < 0.2)
                        {
                            positionMove *= 4;
                        }
                    }

                    if (slowing)
                    {
                        if (brake > 0)
                        {
                            position += positionMove * brake;
                            brake    -= 0.05f;
                        }
                        else
                        {
                            brake   = 1.0f;
                            slowing = false;
                        }
                    }

                    triggerPressed = false;
                }
                #endregion
                #region Bound Movement
                if (position.X < 0 + scaledTexture.width / 2)
                {
                    position.X = 0 + scaledTexture.width / 2;
                }
                if (position.X > Util.ScreenWidth - scaledTexture.width / 2)
                {
                    position.X = Util.ScreenWidth - scaledTexture.width / 2;
                }
                if (position.Y < 0 + scaledTexture.width / 2)
                {
                    position.Y = 0 + scaledTexture.width / 2;
                }
                if (position.Y > Util.ScreenHeight - scaledTexture.height / 2)
                {
                    position.Y = Util.ScreenHeight - scaledTexture.height / 2;
                }
                #endregion
                #region Suck Action
                if (currentState.Buttons.A == ButtonState.Pressed && previousState.Buttons.A == ButtonState.Released)
                {
                    color = Color.Green;
                }
                if (currentState.Buttons.B == ButtonState.Pressed && previousState.Buttons.B == ButtonState.Released)
                {
                    color = Color.Red;
                }
                if (currentState.Buttons.Y == ButtonState.Pressed && previousState.Buttons.Y == ButtonState.Released)
                {
                    color = Color.Yellow;
                }
                if (currentState.Buttons.X == ButtonState.Pressed && previousState.Buttons.X == ButtonState.Released)
                {
                    color = Color.Blue;
                }
                if (currentState.IsButtonDown(Buttons.A) || currentState.IsButtonDown(Buttons.B) || currentState.IsButtonDown(Buttons.X) || currentState.IsButtonDown(Buttons.Y))
                {
                    if (!buttonPressed)
                    {
                        suckAction.Start(gameTime);
                    }
                    else
                    {
                        suckAction.Update(gameTime);
                    }
                    buttonPressed = true;
                }
                else
                {
                    buttonPressed = false;
                    suckAction.Stop();
                }


                #endregion

                previousState = currentState;
            }
        }