public override void HandleInput(InputState input)
        {
            PlayerIndex player;

            if (selectionMode == 0)
            {
                if (input.CurrentKeyboardStates[0].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Left) ||
                   input.CurrentKeyboardStates[0].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.A) ||
                    input.CurrentGamePadStates[0].ThumbSticks.Left.X<-0.2f ||
                    input.CurrentGamePadStates[0].DPad.Left == ButtonState.Pressed)
                {
                    switch (selectedColor)
                    {
                        case 0:
                            if (carColor.R > 25) carColor.R -= 2;
                            break;
                        case 1:
                            if (carColor.G > 25) carColor.G -= 2;
                            break;
                        case 2:
                            if (carColor.B > 25) carColor.B -= 2;
                            break;
                    }

                }
                if (input.CurrentKeyboardStates[0].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Right) ||
                   input.CurrentKeyboardStates[0].IsKeyDown(Microsoft.Xna.Framework.Input.Keys.D) ||
                    input.CurrentGamePadStates[0].ThumbSticks.Left.X > 0.2f ||
                    input.CurrentGamePadStates[0].DPad.Right == ButtonState.Pressed)
                {
                    switch (selectedColor)
                    {
                        case 0:
                            if (carColor.R < 255) carColor.R += 2;
                            break;
                        case 1:
                            if (carColor.G < 255) carColor.G += 2;
                            break;
                        case 2:
                            if (carColor.B < 255) carColor.B += 2;
                            break;
                    }
                }

                if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Up, null, out player) ||
                   input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.W, null, out player) ||
                    input.IsMenuUp(null))
                {
                    selectedColor--;
                    if (selectedColor == -1) selectedColor = 2;
                }
                if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Down, null, out player) ||
                   input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.S, null, out player) ||
                    input.IsMenuDown(null))
                {
                    selectedColor++;
                    if (selectedColor == 3) selectedColor = 0;
                }

                if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Enter, null, out player) ||
                   input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Space, null, out player) ||
                    input.IsMenuSelect(null, out player))
                {
                    AudioController.PlaySFX("select", 0.5f, 0f, 0f);
                    selectionMode = 1;
                    LoadTracks(selectedCup);
                }

                if (input.MouseLeftClick)
                {
                    if(rightRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        AudioController.PlaySFX("select", 0.5f, 0f, 0f);
                        selectionMode = 1;
                        LoadTracks(selectedCup);
                    }

                    if (leftRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        AudioController.StopMusic();
                        LoadingScreen.Load(ScreenManager, false, null, new MainMenuScreen());
                    }

                }

                if (input.MouseDragging)
                {
                    if (redRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        carColor.R = (byte)MathHelper.Clamp((25f + (230f / 400f) * ((input.CurrentMouseState.X - (float)redRect.Left))), 25f, 255f);
                        selectedColor = 0;
                    }
                    if (greenRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        carColor.G = (byte)MathHelper.Clamp((25f + (230f / 400f) * ((input.CurrentMouseState.X - (float)greenRect.Left))), 25f, 255f);
                        selectedColor = 1;
                    }
                    if (blueRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        carColor.B = (byte)MathHelper.Clamp((25f + (230f / 400f) * ((input.CurrentMouseState.X - (float)blueRect.Left))), 25f, 255f);
                        selectedColor = 2;
                    }
                }

            #if WINRT || WINDOWS_PHONE || TOUCH
                foreach (GestureSample gest in input.Gestures)
                {
                    if (gest.GestureType == GestureType.HorizontalDrag)
                    {
                        if (redRect.Contains(new Point((int)gest.Position.X, (int)gest.Position.Y)))
                        {
                            carColor.R = (byte)MathHelper.Clamp((25f + (230f / 400f) * ((gest.Position.X - (float)redRect.Left))), 25f, 255f);
                            selectedColor = 0;
                        }
                        if (greenRect.Contains(new Point((int)gest.Position.X, (int)gest.Position.Y)))
                        {
                            carColor.G = (byte)MathHelper.Clamp((25f + (230f / 400f) * ((gest.Position.X - (float)greenRect.Left))), 25f, 255f);
                            selectedColor = 1;
                        }
                        if (blueRect.Contains(new Point((int)gest.Position.X, (int)gest.Position.Y)))
                        {
                            carColor.B = (byte)MathHelper.Clamp((25f + (230f / 400f) * ((gest.Position.X - (float)blueRect.Left))), 25f, 255f);
                            selectedColor = 2;
                        }
                    }
                }

                if (input.TapGesture != null)
                {
            #if WINDOWS_PHONE
                    if (rightRect.Contains(new Point((int)input.TapGesture.Value.Position.Y, ScreenManager.Viewport.Height - (int)input.TapGesture.Value.Position.X)))
            #else
                    if (rightRect.Contains(new Point((int)input.TapGesture.Value.Position.X, (int)input.TapGesture.Value.Position.Y)))
            #endif
                    {
                        AudioController.PlaySFX("select", 0.5f, 0f, 0f);
                        selectionMode = 1;
                        LoadTracks(selectedCup);
                    }

            #if WINDOWS_PHONE
                    if (leftRect.Contains(new Point((int)input.TapGesture.Value.Position.Y, ScreenManager.Viewport.Height - (int)input.TapGesture.Value.Position.X)))
            #else
                    if (leftRect.Contains(new Point((int)input.TapGesture.Value.Position.X, (int)input.TapGesture.Value.Position.Y)))
            #endif
                    {
                        AudioController.StopMusic();
                        LoadingScreen.Load(ScreenManager, false, null, new MainMenuScreen());
                    }
                }

            #endif
                if (input.IsMenuCancel(null, out player))
                {
                    AudioController.StopMusic();
                    LoadingScreen.Load(ScreenManager, false, null, new MainMenuScreen());
                }
            }
            else
            {
                if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Escape, null, out player) ||
                   input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Back, null, out player) ||
                    input.IsMenuCancel(null, out player))
                {
                    selectionMode = 0;
                }

                if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Left, null, out player) ||
                   input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.A, null, out player) ||
                    (input.CurrentGamePadStates[0].ThumbSticks.Left.X<-0.2f && input.LastGamePadStates[0].ThumbSticks.Left.X>=-0.2f) ||
                    input.CurrentGamePadStates[0].DPad.Left == ButtonState.Pressed && input.LastGamePadStates[0].DPad.Left != ButtonState.Pressed)
                {
                    selectedCup--;
                    if (selectedCup == -1) selectedCup = 0;
                    else LoadTracks(selectedCup);
                }
                if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Right, null, out player) ||
                   input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.D, null, out player) ||
                    (input.CurrentGamePadStates[0].ThumbSticks.Left.X > 0.2f && input.LastGamePadStates[0].ThumbSticks.Left.X <= 0.2f) ||
                    input.CurrentGamePadStates[0].DPad.Right == ButtonState.Pressed && input.LastGamePadStates[0].DPad.Right != ButtonState.Pressed)
                {
                    selectedCup++;
                    if (selectedCup == Cups.Count) selectedCup = Cups.Count-1;
                    else LoadTracks(selectedCup);
                }

                if (input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Enter, null, out player) ||
                   input.IsNewKeyPress(Microsoft.Xna.Framework.Input.Keys.Space, null, out player) ||
                    input.IsMenuSelect(null, out player))
                {
                    AudioController.PlaySFX("select", 0.5f, 0f, 0f);
                    ExitScreen();
                    //
                }

                if (input.MouseLeftClick)
                {
                    if (rightRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        AudioController.PlaySFX("select", 0.5f, 0f, 0f);
                        ExitScreen();
                    }

                    if (leftRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        selectionMode = 0;
                    }

                    if (leftCupRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        selectedCup--;
                        if (selectedCup == -1) selectedCup = 0;
                        else LoadTracks(selectedCup);
                    }

                    if (rightCupRect.Contains(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y)))
                    {
                        selectedCup++;
                        if (selectedCup == Cups.Count) selectedCup = Cups.Count - 1;
                        else LoadTracks(selectedCup);
                    }
                }

            #if WINRT || WINDOWS_PHONE || TOUCH

                foreach (GestureSample gest in input.Gestures)
                {
                    if (gest.GestureType == GestureType.Flick)
                    {

                            if (gest.Delta.X > 0f)
                            {
                                selectedCup--;
                                if (selectedCup == -1) selectedCup = 0;
                                else LoadTracks(selectedCup);
                            }

                            if (gest.Delta.X < 0f)
                            {
                                selectedCup++;
                                if (selectedCup == Cups.Count) selectedCup = Cups.Count - 1;
                                else LoadTracks(selectedCup);
                            }

                    }
                }

                if (input.TapGesture != null)
                {
            #if WINDOWS_PHONE
                    if (rightRect.Contains(new Point((int)input.TapGesture.Value.Position.Y, ScreenManager.Viewport.Height - (int)input.TapGesture.Value.Position.X)))
            #else
                    if (rightRect.Contains(new Point((int)input.TapGesture.Value.Position.X, (int)input.TapGesture.Value.Position.Y)))
            #endif
                    {
                        AudioController.PlaySFX("select", 0.5f, 0f, 0f);
                        ExitScreen();
                    }

            #if WINDOWS_PHONE
                    if (leftRect.Contains(new Point((int)input.TapGesture.Value.Position.Y, ScreenManager.Viewport.Height - (int)input.TapGesture.Value.Position.X)))
            #else
                    if (leftRect.Contains(new Point((int)input.TapGesture.Value.Position.X, (int)input.TapGesture.Value.Position.Y)))
            #endif
                    {
                        selectionMode = 0;
                    }

            #if WINDOWS_PHONE
                    if (rightCupRect.Contains(new Point((int)input.TapGesture.Value.Position.Y, ScreenManager.Viewport.Height - (int)input.TapGesture.Value.Position.X)))
            #else
                    if (rightCupRect.Contains(new Point((int)input.TapGesture.Value.Position.X, (int)input.TapGesture.Value.Position.Y)))
            #endif
                    {
                        selectedCup++;
                        if (selectedCup == Cups.Count) selectedCup = Cups.Count - 1;
                        else LoadTracks(selectedCup);
                    }

            #if WINDOWS_PHONE
                    if (leftCupRect.Contains(new Point((int)input.TapGesture.Value.Position.Y, ScreenManager.Viewport.Height - (int)input.TapGesture.Value.Position.X)))
            #else
                    if (leftCupRect.Contains(new Point((int)input.TapGesture.Value.Position.X, (int)input.TapGesture.Value.Position.Y)))
            #endif
                    {
                        selectedCup--;
                        if (selectedCup == -1) selectedCup = 0;
                        else LoadTracks(selectedCup);
                    }
                }

            #endif
            }

            base.HandleInput(input);
        }
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            if (input.IsMenuSelect(ControllingPlayer, out playerIndex) || input.IsMenuCancel(ControllingPlayer, out playerIndex) || input.TapPosition.HasValue || input.MouseLeftClick)
            {
              //  LoadingScreen.Load(ScreenManager, false, null, new GameplayScreen(), new MainMenuScreen());
                AudioController.PlaySFX("select", 0.5f, 0f, 0f);

                if (currentScreen == 0)
                    swappingScreens = true;
                else
                {
                    AudioController.StopMusic();
                    ExitScreen();
                }
            }

            base.HandleInput(input);
        }
        /// <summary>
        /// Lets the game respond to player input. Unlike the Update method,
        /// this will only be called when the gameplay screen is active.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            if (input == null)
                throw new ArgumentNullException("input");

            // Look up inputs for the active player profile.
            int playerIndex = 0;

            KeyboardState keyboardState = input.CurrentKeyboardStates[playerIndex];
            GamePadState gamePadState = input.CurrentGamePadStates[playerIndex];

            PlayerIndex player;
            if (input.IsPauseGame(ControllingPlayer))
            {
                PauseBackgroundScreen pauseBG = new PauseBackgroundScreen();
                ScreenManager.AddScreen(pauseBG, ControllingPlayer);
                ScreenManager.AddScreen(new PauseMenuScreen(pauseBG), ControllingPlayer);
            }

            if(IsActive)
            {

                gameCars[7].ApplyThrottle(0f);
                gameCars[7].ApplyBrake(false);

                if(input.CurrentKeyboardStates[0].IsKeyDown(Keys.W) ||
                   input.CurrentKeyboardStates[0].IsKeyDown(Keys.Up))
                {
                    gameCars[7].ApplyThrottle(1f);
                }
                else gameCars[7].ApplyThrottle(0f);

                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.S) ||
                   input.CurrentKeyboardStates[0].IsKeyDown(Keys.Down))
                {
                    gameCars[7].ApplyBrake(true);
                }
                else gameCars[7].ApplyBrake(false);

                if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.A) ||
                   input.CurrentKeyboardStates[0].IsKeyDown(Keys.Left))
                {
                    if (steeringAmount > 0f) steeringAmount -= 0.015f;
                    steeringAmount -= 0.01f;
                    steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f, 0.5f);
                }
                else if (input.CurrentKeyboardStates[0].IsKeyDown(Keys.D) ||
                        input.CurrentKeyboardStates[0].IsKeyDown(Keys.Right))
                {
                    if (steeringAmount < 0f) steeringAmount += 0.015f;
                    steeringAmount += 0.01f;
                    steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f, 0.5f);
                }
                else if (input.CurrentGamePadStates[0].ThumbSticks.Left.X < -0.05f)
                {
                    if (steeringAmount > 0f) steeringAmount -= 0.015f;
                    steeringAmount -= 0.01f;
                    steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f * ((float)Math.Abs(input.CurrentGamePadStates[0].ThumbSticks.Left.X)), 0.5f);
                }
                else if (input.CurrentGamePadStates[0].ThumbSticks.Left.X > 0.05f)
                {
                    if (steeringAmount < 0f) steeringAmount += 0.015f;
                    steeringAmount += 0.01f;
                    steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f, 0.5f * ((float)Math.Abs(input.CurrentGamePadStates[0].ThumbSticks.Left.X)));
                }
                else steeringAmount = MathHelper.Lerp(steeringAmount, 0f, 0.15f);

                if (input.CurrentGamePadStates[0].Triggers.Right > 0.05f)
                {
                    gameCars[7].ApplyThrottle(input.CurrentGamePadStates[0].Triggers.Right > 0.95f ? 1f : input.CurrentGamePadStates[0].Triggers.Right);
                }
                if (input.CurrentGamePadStates[0].Triggers.Left > 0.05f)
                {
                    gameCars[7].ApplyBrake(true);
                }

            #if WINRT || WINDOWS_PHONE
                foreach(TouchLocation tl in TouchPanel.GetState())
                {
                    if (tl.State == TouchLocationState.Pressed || tl.State == TouchLocationState.Moved)
                    {
                        if(tl.Position.X> ScreenManager.Viewport.Width/2)
                            gameCars[7].ApplyThrottle(1f);
                        else
                            gameCars[7].ApplyThrottle(0f);

                        if(tl.Position.X< ScreenManager.Viewport.Width/2)
                            gameCars[7].ApplyBrake(true);
                        else
                            gameCars[7].ApplyBrake(false);
                    }
                }

                if(Math.Abs(input.AccelerometerVect.X)>0.05f)
                {
                    steeringAmount = input.AccelerometerVect.X;
                    steeringAmount = MathHelper.Clamp(steeringAmount, -0.5f, 0.5f);
                }
                //if (Math.Abs(input.AccelerometerVect.X) > 0.15f)
                //{
                //    if (input.AccelerometerVect.X > 0) gameCars[7].Steer(input.AccelerometerVect.X);
                //    if (input.AccelerometerVect.X < 0) gameCars[7].Steer(input.AccelerometerVect.X);
                //}
            #endif

                gameCars[7].Steer(steeringAmount);
            }
        }
Beispiel #4
0
 /// <summary>
 /// Allows the screen to handle user input. Unlike Update, this method
 /// is only called when the screen is active, and not when some other
 /// screen has taken the focus.
 /// </summary>
 public virtual void HandleInput(InputState input)
 {
 }
        public override void HandleInput(InputState input)
        {
            PlayerIndex pi;

            if (IsActive)
            {
                if (input.IsMenuSelect(null, out pi) || input.MouseLeftClick)
                {
                    AudioController.PlaySFX("select", 0.5f, 0f, 0f);
                    ExitScreen();
                }

            #if WINRT || WINDOWS_PHONE || TOUCH
                foreach (GestureSample gest in input.Gestures)
                {
                    if (gest.GestureType == GestureType.Tap)
                    {
                        AudioController.PlaySFX("select", 0.5f, 0f, 0f);
                        ExitScreen();
                    }
                }
            #endif
            }

            if (input.IsMenuCancel(null, out pi))
                ScreenManager.Game.Exit();

            base.HandleInput(input);
        }
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            PlayerIndex playerIndex;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (input.IsMenuSelect(ControllingPlayer, out playerIndex))
            {
                // Raise the accepted event, then exit the message box.
                if (Accepted != null)
                    Accepted(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (input.IsMenuCancel(ControllingPlayer, out playerIndex))
            {
                // Raise the cancelled event, then exit the message box.
                if (Cancelled != null)
                    Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }

            #if WINDOWS_PHONE || WINRT || TOUCH
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    // convert the position to a Point that we can test against a Rectangle
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);

                    if (okRect.Contains(tapLocation))
                    {
                        if (Accepted != null)
                            Accepted(this, new PlayerIndexEventArgs(playerIndex));

                        ExitScreen();
                    }

                    if (cancelRect.Contains(tapLocation))
                    {
                        if (Cancelled != null)
                            Cancelled(this, new PlayerIndexEventArgs(playerIndex));

                        ExitScreen();
                    }
                }
            }
            #endif
        }
Beispiel #7
0
        /// <summary>
        /// Responds to user input, changing the selected entry and accepting
        /// or cancelling the menu.
        /// </summary>
        public override void HandleInput(InputState input)
        {
            // we cancel the current menu screen if the user presses the back button
            PlayerIndex player;
            if (input.IsNewButtonPress(Buttons.Back, ControllingPlayer, out player))
            {
                OnCancel(player);
            }

            if (input.IsMenuCancel(null, out player))
            {
                OnCancel(player);
            }

            if (input.IsMenuUp(null))
                if(selectedEntry>0) selectedEntry--;

            if (input.IsMenuDown(null))
                if (selectedEntry < menuEntries.Count-1) selectedEntry++;

            if (input.IsMenuSelect(null, out player))
                OnSelectEntry(selectedEntry, PlayerIndex.One);

            #if WINDOWS_PHONE || WINRT || TOUCH
            // look for any taps that occurred and select any entries that were tapped
            foreach (GestureSample gesture in input.Gestures)
            {
                if (gesture.GestureType == GestureType.Tap)
                {
                    // convert the position to a Point that we can test against a Rectangle
                    Point tapLocation = new Point((int)gesture.Position.X, (int)gesture.Position.Y);

                    // iterate the entries to see if any were tapped
                    for (int i = 0; i < menuEntries.Count; i++)
                    {
                        MenuEntry menuEntry = menuEntries[i];

                        if (GetMenuEntryHitBounds(menuEntry).Contains(tapLocation))
                        {
                            // select the entry. since gestures are only available on Windows Phone,
                            // we can safely pass PlayerIndex.One to all entries since there is only
                            // one player on Windows Phone.
                            OnSelectEntry(i, PlayerIndex.One);
                        }
                    }
                }
            }
            #endif

            if (!ScreenManager.IsPhone)
            {
                Point mouseLocation = new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y);

                for (int i = 0; i < menuEntries.Count; i++)
                {
                    MenuEntry menuEntry = menuEntries[i];

                    if (GetMenuEntryHitBounds(menuEntry).Contains(mouseLocation))
                    {
                        selectedEntry = i;

                        // Mouse left click?
                        if (input.CurrentMouseState.LeftButton == ButtonState.Released && input.LastMouseState.LeftButton == ButtonState.Pressed)
                        {
                            // select the entry. since gestures are only available on Windows Phone,
                            // we can safely pass PlayerIndex.One to all entries since there is only
                            // one player on Windows Phone.
                            OnSelectEntry(i, PlayerIndex.One);
                        }
                    }
                }
            }
        }