コード例 #1
0
        /// <summary>
        /// Input helper method provided by GameScreen.  Packages up the various input
        /// values for ease of use.  Here it checks for pausing and handles controlling
        /// the player's tank.
        /// </summary>
        /// <param name="input">The state of the gamepads</param>
        public override void HandleInput(InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (input.PauseGame)
            {
                if (gameOver == true)
                {
                    foreach (GameScreen screen in ScreenManager.GetScreens())
                    {
                        screen.ExitScreen();
                    }

                    ScreenManager.AddScreen(new BackgroundScreen());
                    ScreenManager.AddScreen(new MainMenuScreen());
                }
                else
                {
                    ScreenManager.AddScreen(new PauseMenuScreen());
                }
            }
            else
            {
                // This section handles tank movement.  We only allow one "movement" action
                // to occur at once so that touchpad devices don't get double hits.
                if (input.CurrentGamePadStates[0].DPad.Left == ButtonState.Pressed)
                {
                    player.Velocity.X = -1.0f;
                }
                else if (input.CurrentGamePadStates[0].DPad.Right == ButtonState.Pressed)
                {
                    player.Velocity.X = 1.0f;
                }
                else
                {
                    player.Velocity.X = MathHelper.Min(input.CurrentGamePadStates[0].ThumbSticks.Left.X * 2.0f, 1.0f);
                }

                // B button, or pressing on the upper half of the pad fires the weapon.
                if (input.CurrentGamePadStates[0].IsButtonDown(Buttons.B) || input.CurrentGamePadStates[0].IsButtonDown(Buttons.A) || input.CurrentGamePadStates[0].ThumbSticks.Left.Y > 0.25f)
                {
                    if (player.FireTimer <= 0.0f && player.IsAlive && !gameOver)
                    {
                        Bullet bullet = CreatePlayerBullet();
                        bullet.Position  = new Vector2((int)(player.Position.X + player.Width / 2) - bulletTexture.Width / 2, player.Position.Y - 4);
                        bullet.Velocity  = new Vector2(0, -256.0f);
                        player.FireTimer = 1.0f;
                        particles.CreatePlayerFireSmoke(player);
                        playerFired.Play();
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Input helper method provided by GameScreen.  Packages up the various input
        /// values for ease of use.  Here it checks for pausing and handles controlling
        /// the player's tank.
        /// </summary>
        /// <param name="input">The state of the gamepads</param>
        public override void HandleInput(InputState input)
        {
            if (input == null)
            {
                throw new ArgumentNullException("input");
            }

            if (input.PauseGame)
            {
                if (gameOver == true)
                {
                    MediaPlayer.Stop();

                    foreach (GameScreen screen in ScreenManager.GetScreens())
                    {
                        screen.ExitScreen();
                    }

                    ScreenManager.AddScreen(new BackgroundScreen());
                    ScreenManager.AddScreen(new MainMenuScreen());
                }
                else
                {
                    ScreenManager.AddScreen(new PauseMenuScreen());
                }
            }
            else
            {
                bool touchShoot = false;

                                #if TARGET_IPHONE_SIMULATOR
                // This section handles tank movement.  We only allow one "movement" action
                // to occur at once so that touchpad devices don't get double hits.
                player.Velocity.X = MathHelper.Min(input.CurrentGamePadStates.ThumbSticks.Left.X * 2.0f, 1.0f);
                touchShoot        = input.MenuSelect;
                                #else
                // Add the accelerometer support
                player.Velocity.X = MathHelper.Min(Accelerometer.GetState().Acceleration.X * 2.0f, 1.0f);

                // tap the screen to shoot
                foreach (TouchLocation location in input.TouchStates)
                {
                    switch (location.State)
                    {
                    case TouchLocationState.Pressed:
                        touchShoot = true;
                        break;

                    case TouchLocationState.Moved:
                        break;

                    case TouchLocationState.Released:
                        break;
                    }
                }
                                #endif



                if (touchShoot)
                {
                    //Mouse.SetPosition(0,0);
                    if (player.FireTimer <= 0.0f && player.IsAlive && !gameOver)
                    {
                        Bullet bullet = CreatePlayerBullet();
                        bullet.Position  = new Vector2((int)(player.Position.X + player.Width / 2) - bulletTexture.Width / 2, player.Position.Y - 4);
                        bullet.Velocity  = new Vector2(0, -256.0f);
                        player.FireTimer = 0.5f;
                        particles.CreatePlayerFireSmoke(player);
                        playerFired.Play();
                    }
                }
            }
        }