示例#1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            ScreenManager.Update(gameTime);


#if WINDOWS
            KeyBoardManager keyboard = KeyBoardManager.Instance;

            if (keyboard.IsKeyPressed(Keys.P))
            {
                using (System.IO.Stream stream = System.IO.File.Create(String.Format("ScreenShots//{0}.png", ScreenManager.MainScreen)))
                {
                    Texture2D image = ScreenManager.GetScreen(ScreenManager.MainScreen).RenderTarget;
                    image.SaveAsPng(stream, image.Width, image.Height);
                }
            }
#else
            if (ScreenManager.MainScreen != "Game")
            {
                elapsedAdRefreshTime += gameTime.ElapsedGameTime;
                if (elapsedAdRefreshTime >= adRefreshTime)
                {
                    elapsedAdRefreshTime = TimeSpan.Zero;
                    Global.LoadAds();
                }
            }
#endif

            base.Update(gameTime);
        }
示例#2
0
        private void handleInput()
        {
#if WINDOWS
            KeyBoardManager keybaord = KeyBoardManager.Instance;

            if (keybaord.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Left) && playerIndex != 0)
            {
                direction = Direction.Left;
            }
            else if (keybaord.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Right) && playerIndex != fallingLocation.Length - 1)
            {
                direction = Direction.Right;
            }
            else if (keybaord.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.LeftAlt))
            {
                debug = !debug;
            }
#else
            TouchManager touch = TouchManager.Instance;

            if (touch.TouchPoints.Count == 1 && !isTouchAlready)
            {
                isTouchAlready = true;
                foreach (var touchPoint in touch.TouchPoints)
                {
                    Vector2 tapLocationTranslation = touchPoint.Position / Scale;

                    if (tapLocationTranslation.X < RenderTarget.Width / 2)
                    {
                        direction = Direction.Left;
                    }
                    else
                    {
                        direction = Direction.Right;
                    }
                }
            }
            else if (touch.TouchPoints.Count == 0)
            {
                isTouchAlready = false;
            }
#endif



            switch (direction)
            {
            case Direction.Right:

                playerIndex++;

                if (playerIndex < 0 || playerIndex > fallingLocation.Length - 1)
                {
                    player.CurrentState = CharacterState.Idle;
                    direction           = Direction.None;
                }
                else
                {
                    player.CurrentState = CharacterState.Moving;
                    player.Effect       = SpriteEffects.FlipHorizontally;

                    if (Global.SFXEnabled)
                    {
                        rightSwipe.Play();
                        //XnaAudio.MediaPlayer.Play(rightSwipe);
                    }
                }

                break;

            case Direction.Left:

                playerIndex--;
                if (playerIndex < 0 || playerIndex > fallingLocation.Length - 1)
                {
                    player.CurrentState = CharacterState.Idle;
                    direction           = Direction.None;
                }
                else
                {
                    player.CurrentState = CharacterState.Moving;
                    player.Effect       = SpriteEffects.None;

                    if (Global.SFXEnabled)
                    {
                        leftSwipe.Play();
                        //XnaAudio.MediaPlayer.Play(leftSwipe);
                    }
                }
                break;

            default:
                //do nothing
                break;
            }
            CheckLocation();


            if (direction == Direction.Right)
            {
                player.X = fallingLocation[playerIndex].X;
            }
        }