Exemplo n.º 1
0
 private void SetInitialAdvancing(TouchCollection touches)
 {
     if (touches.Any(t => t.State == TouchLocationState.Released))
     {
         if (touches.Any(t => t.State == TouchLocationState.Released &&
                         !(t.Position.Y >= 380 && t.Position.Y <= 480 && t.Position.X >= 700)))
         {
             AdvancingDirection = 0;
         }
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Updates the current machine state
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="currentTouch">The current touch.</param>
        /// <param name="nextState">The next state in the state machine.</param>
        /// <returns>
        /// A value indicating whether or not the state machine should advance to the next state
        /// </returns>
        public override bool Update(GameTime gameTime, TouchCollection currentTouch, out TouchStateBase nextState)
        {
            this.delayTimer += gameTime.ElapsedGameTime.Milliseconds;

            if (this.delayTimer > TouchStateMachine.Configuration.TapDelay)
            {
                TouchStateMachine.SubmitGestureEvent(new TapEventArgs(this.TapLocation, GestureTiming.Completed));
                nextState = new CooldownState();
                return(true);
            }

            var touched = currentTouch.Any();

            if (!touched && this.fingerDown)
            {
                // TODO: detect if taps are far apart and start a new tap
                nextState = new CooldownState();
                TouchStateMachine.SubmitGestureEvent(new DoubleTapEventArgs(this.TapLocation));
                return(true);
            }

            if (touched)
            {
                this.fingerDown = true;
            }

            nextState = null;
            return(false);
        }
Exemplo n.º 3
0
 private void GetJumpButtonPressed(TouchCollection touches)
 {
     JumpButtonPressed = touches.Any(t =>
                                     (t.Position.Y >= 380 && t.Position.Y <= 480 && t.Position.X >= 700) &&
                                     t.State == TouchLocationState.Pressed &&
                                     t.State != TouchLocationState.Released
                                     );
 }
        /// <summary>
        /// Updates the current machine state
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="currentTouch">The current touch.</param>
        /// <param name="nextState">The next state in the state machine.</param>
        /// <returns>
        /// A value indicating whether or not the state machine should advance to the next state
        /// </returns>
        public override bool Update(GameTime gameTime, TouchCollection currentTouch, out TouchStateBase nextState)
        {
            var touched = currentTouch.Any();

            if (touched)
            {
                nextState = new TouchedState(currentTouch);
                return(true);
            }

            nextState = null;
            return(false);
        }
Exemplo n.º 5
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)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
                return;
            }

            if (timeRemaining == 0.0f)
            {
                currentSquare = new Rectangle(_rand.Next(0, this.Window.ClientBounds.Width - _squareSize), _rand.Next(0, this.Window.ClientBounds.Height - _squareSize), _squareSize, _squareSize);
                timeRemaining = _timePerSquare;
            }

            MouseState mouse = Mouse.GetState();

            _touch = TouchPanel.GetState();
            if ((mouse.LeftButton == ButtonState.Pressed) && (currentSquare.Contains(mouse.X, mouse.Y)))
            {
                playerScore++; timeRemaining = 0.0f;

                if (playerScore % 2 == 0)
                {
                    _squareSize    -= 10;
                    _timePerSquare -= 0.1f;
                }
            }

            if (_touch.IsConnected && _touch.Any() && (currentSquare.Contains(_touch[0].Position.X, _touch[0].Position.Y)))
            {
                playerScore++; timeRemaining = 0.0f;

                if (playerScore % 15 == 0)
                {
                    _squareSize    -= 10;
                    _timePerSquare -= 0.1f;
                }
            }

            timeRemaining = MathHelper.Max(0, timeRemaining - (float)gameTime.ElapsedGameTime.TotalSeconds);

            base.Update(gameTime);
        }
        /// <summary>
        /// Updates the current machine state
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        /// <param name="currentTouch">The current touch.</param>
        /// <param name="nextState">The next state in the state machine.</param>
        /// <returns>
        /// A value indicating whether or not the state machine should advance to the next state
        /// </returns>
        public override bool Update(GameTime gameTime, TouchCollection currentTouch, out TouchStateBase nextState)
        {
            this.touchedTimer += gameTime.ElapsedGameTime.Milliseconds;

            if (this.touchedTimer > TouchStateMachine.Configuration.TouchDelay || currentTouch.Count > 1)
            {
                nextState = new GestureActiveState();
                return(true);
            }

            if (currentTouch.Any())
            {
                if (currentTouch.Count == 1)
                {
                    var prevFirst = this.previousTouch[0].Position;
                    var currFirst = currentTouch[0].Position;

                    var direction = Vector2.Normalize(currFirst - prevFirst);
                    var distance  = Vector2.Distance(currFirst, prevFirst);

                    if (distance > TouchStateMachine.Configuration.FlickDistance)
                    {
                        TouchStateMachine.SubmitGestureEvent(new FlickEventArgs(prevFirst, direction, distance));
                        nextState = new CooldownState();
                        return(true);
                    }
                }

                this.previousTouch = currentTouch;
                nextState          = null;
                return(false);
            }

            TouchStateMachine.SubmitGestureEvent(new TapEventArgs(this.previousTouch[0].Position, GestureTiming.Started));
            nextState = new TappedState(this.previousTouch[0].Position);
            return(true);
        }
Exemplo n.º 7
0
        //------------------------------------------------------------------
        public void UpdateTouch()
        {
            UpdateMouse();

            //Get the state of the touch panel
            TouchCollection touches = TouchPanel.GetState();

            // ToDo: Only first Touch?
            // Handle only first Touch
            if (!touches.Any())
            {
                return;
            }

            var first = touches.First();

            if (first.State == TouchLocationState.Pressed)
            {
                HandleTouch(first.Position);
            }

//            // Process touch locations
//            foreach (TouchLocation location in curTouches)
//            {
//                switch (location.State)
//                {
//                    case TouchLocationState.Pressed:
//                        HandleTouch (location.Position);
//                        break;
//                    case TouchLocationState.Released:
//                        break;
//                    case TouchLocationState.Moved:
//                        break;
//                }
//            }
        }
Exemplo n.º 8
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)
        {
            base.Update (gameTime);

            if (adView.BannerLoaded)
            {
                adView.Hidden = false;
            } else
            {
                adView.Hidden = true;
            }

            if (!(State == GameState.Paused)) {
                // save previous state of keyboard and gamepad to determine key/button presses
                previousGamePadState = currentGamePadState;
                previousKeyboardState = currentKeyboardState;
                previousTouches = currentTouches;

                // read current state of keyboard and gamepad and store it
                currentGamePadState = GamePad.GetState (PlayerIndex.One);
                currentKeyboardState = Keyboard.GetState ();
                currentTouches = TouchPanel.GetState ();

                // update player
                var shouldSwim = currentTouches.Any () || currentKeyboardState.IsKeyDown (Keys.Space) || currentGamePadState.IsButtonDown (Buttons.A);
                if (shouldSwim && State == GameState.Menu) {
                    State = GameState.Playing;
                } else if (shouldSwim && State == GameState.Score) {
                    shouldSwim = false;
                }

                // update player
                if (deadFromHook) {
                    player.Update (true);
                    foreach (var hook in hooks) {
                        if (hook.Collides (player.Rectangle)) {
                            hook.Update (deadFromHook);
                        }
                    }
                } else if (deadFromEnergy) {
                    player.Update (true);
                } else if (deadFromFloor) {
                    player.Update (true);
                } else {
                    player.Update (gameTime, shouldSwim, graphics.GraphicsDevice.Viewport.Height - (int)(adView.Frame.Height *3), State == GameState.Menu);
                }

                if (State != GameState.Score) {

                }

                if (State == GameState.Playing) {
                    UpdateHooks (gameTime);
                    UpdateWorms (gameTime);
                    UpdateCorals (gameTime);
                    UpdateCollision ();

                    if (score == 0 && !hasPlayedSound) {
                        hasPlayedSound = true;
                        bubbleSound.Play ();
                    }
                    else if (score != 0 && score % 3 == 0 && playSound) {
                        playSound = false;
                        bubbleSound.Play ();
                    } else {
                        if (score % 3 != 0) {
                            playSound = true;
                        }
                        bubbleSound.Dispose ();
                    }

                } else if (State == GameState.Score) {
                    UpdateGameOver (gameTime);
                    if (gameOverAnimationDuration <= gameOverTimer && Toggled ()) {
                        Reset ();
                    }
                }
            }
        }
Exemplo n.º 9
0
 bool ToggledTappped()
 {
     return(!previousTouches.Any() && currentTouches.Any());
 }
Exemplo n.º 10
0
        protected override void Update(GameTime gameTime)
        {
#if DEBUG
            // SAVE ME KEY
            if (Keyboard.GetState().IsKeyDown(Keys.F12))
            {
                Exit();
            }
#endif

            if (GameData.Instance.CurrentScreen == Screen.Ingame || GameData.Instance.CurrentScreen == Screen.Editor)
            {
                //TargetElapsedTime = TimeSpan.FromSeconds(1.0f / 500.0f);
            }
            else
            {
                TargetElapsedTime = OGTimeSpan;
#if WINDOWS
                if (!GameData.Instance.Options.Fullscreen)
                {
                    Window.IsBorderless = false;
                }
#endif
            }

            var p = Mouse.GetState(Window).Position;

            CursorLocation = new Rectangle(p, new Point(1, 1));

            if (Windows)
            {
                Click = false;
                MouseState current = Mouse.GetState();
                if (current.LeftButton == ButtonState.Pressed &&
                    OldMouseState.LeftButton == ButtonState.Released &&
                    IsActive)
                {
                    Click = true;
                }
                OldMouseState = current;
            }
            else
            {
                TouchCollection touchCollection = TouchPanel.GetState();

                var pos = new Point(0, 0);
                Click = false;
                if (touchCollection.Any())
                {
                    pos.X  = (int)touchCollection[0].Position.X;
                    pos.Y  = (int)touchCollection[0].Position.Y;
                    Click  = touchCollection[0].State == TouchLocationState.Pressed && oldtls == 0;
                    oldtls = touchCollection[0].State;
                }
                else
                {
                    oldtls = 0;
                }

                CursorLocation = new Rectangle(pos, new Point(1, 1));
            }

            GameData.Instance.Screens.Find(x => x.Name == GameData.Instance.CurrentScreen).Update(gameTime, CursorLocation, Click);
            base.Update(gameTime);
            if (GameData.Instance.Exiting)
            {
                Exit();
            }
        }
Exemplo n.º 11
0
 private bool IsTouch(TouchCollection state, Rectangle area) => state.Any((s) => area.Contains(s.Position));
Exemplo n.º 12
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            //// get all of our input states
            keyboardState = Keyboard.GetState();
            //gamePadState = GamePad.GetState(PlayerIndex.One);
            touchState         = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            if (maze.player.IsAlive == false)
            {
                if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.Any() == true)
                {
                    maze.StartRoom().StartNewLife(ScreenManager.GraphicsDevice);
                }
            }

            // Exit the game when back is pressed.
            ///// if (gamePadState.Buttons.Back == ButtonState.Pressed)
            ////// Exit();

            bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.Any();


            wasContinuePressed = continuePressed;
        }
Exemplo n.º 13
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            //// get all of our input states
            keyboardState = Keyboard.GetState();
            //gamePadState = GamePad.GetState(PlayerIndex.One);
            touchState = TouchPanel.GetState();
            accelerometerState = Accelerometer.GetState();

            if (maze.player.IsAlive == false)
            {
                if (keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.Any() == true)
                {
                    maze.StartRoom().StartNewLife(ScreenManager.GraphicsDevice);
                }
            }

            // Exit the game when back is pressed.
            ///// if (gamePadState.Buttons.Back == ButtonState.Pressed)
            ////// Exit();

            bool continuePressed = keyboardState.IsKeyDown(Keys.Space) || gamePadState.IsButtonDown(Buttons.A) || touchState.Any();

            wasContinuePressed = continuePressed;
        }