Ejemplo n.º 1
0
    /// <summary>
    /// The delegate that will respond to our touchpad's events for buying smooth moves
    /// </summary>
    /// <param name="touchEvent">The event captured by the touchpad</param>
    /// <param name="screenPosition">The screen position of the event</param>
    /// <param name="guiPosition">The GUI position of the event</param>
    /// <param name="worldPosition">The world position of the event</param>
    public void BuyNow_TouchPadDelegate(TouchPad.TOUCH_EVENT touchEvent, Vector2 screenPosition, Vector3 guiPosition, Vector3 worldPosition)
    {
        switch (touchEvent)
        {
        case TouchPad.TOUCH_EVENT.TouchDown:

            gameManager.ShowAssetStoreLink();

            break;
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// The delegate that will respond to our touchpad's events
    /// </summary>
    /// <param name="touchEvent">The event captured by the touchpad</param>
    /// <param name="screenPosition">The screen position of the event</param>
    /// <param name="guiPosition">The GUI position of the event</param>
    /// <param name="worldPosition">The world position of the event</param>
    public void TouchPadDelegate(TouchPad.TOUCH_EVENT touchEvent, Vector2 screenPosition, Vector3 guiPosition, Vector3 worldPosition)
    {
        // if showing asset store link, don't process regular touch input
        if (gameManager.BuyNow)
        {
            gameManager.BuyNow = false;
            return;
        }

        // if the game is over or the chef is picking up the weapon, then jump out
        if (gameManager.State == GameManager.STATE.GameOver || gameManager.chef.State == Chef.STATE.PickingUpWeapon)
        {
            return;
        }

        // if the game is waiting for the user to press the screen
        if (gameManager.State == GameManager.STATE.WaitingForInput)
        {
            switch (touchEvent)
            {
            case TouchPad.TOUCH_EVENT.TouchDown:

                // user pressed the screen, so now we can play

                gameManager.State = GameManager.STATE.Playing;
                return;
            }

            return;
        }

        // check the state of the chef before processing any input
        gameManager.chef.CheckState();

        switch (touchEvent)
        {
        case TouchPad.TOUCH_EVENT.TouchDown:

            // the touchpad received a touch began event,
            // so we capture and store some values

            _touchingScreen    = true;
            _touchDownTime     = Time.realtimeSinceStartup;
            _touchDownPosition = worldPosition;

            break;

        case TouchPad.TOUCH_EVENT.TouchMove:
        case TouchPad.TOUCH_EVENT.TouchStationary:

            // the touchpad received a move or stationary touch event
            // (finger / mouse is pressing the screen)

            // store the offset from the chef to the world position of the touch
            Vector3 offset = gameManager.chef.OffsetFromPosition(worldPosition);

            // make the chef face the direction of the touch
            gameManager.chef.FaceDirection(offset);

            // if the chef is not attacking and we are touching the screen
            if (gameManager.chef.State != Chef.STATE.Attacking && _touchingScreen)
            {
                // get the amount of time that has elapsed since we began the touch
                _touchTime = Time.realtimeSinceStartup - _touchDownTime;

                // if the amount of elapsed time is greater than our minimum press and hold time
                if (_touchTime >= minPressAndHoldTime)
                {
                    // if the chef is in a standing state
                    if (gameManager.chef.State == Chef.STATE.Standing)
                    {
                        // if the distance from our touch to the chef is greater than the minimum starting distance
                        if (offset.sqrMagnitude >= _minStartingDistanceSquared)
                        {
                            // make the chef run towards the touch
                            gameManager.chef.Run(offset, true);
                        }
                    }
                    else
                    {
                        // chef is not in a standing state

                        // if the distance from the touch to the chef is less than the stopping distance
                        if (offset.sqrMagnitude <= _maxStoppingDistanceSquared)
                        {
                            // make the chef stand still
                            gameManager.chef.Stand(true);
                        }
                        else
                        {
                            // chef is still farther away from the touch than the max stopping distance, so
                            // make him continue to run
                            gameManager.chef.Run(offset, false);
                        }
                    }
                }
            }
            break;

        case TouchPad.TOUCH_EVENT.TouchUp:

            // the touchpad received a touch end event

            // if the chef is not attacking and we are touching the screen
            if (gameManager.chef.State != Chef.STATE.Attacking && _touchingScreen)
            {
                // capture the time since we began touching
                _touchTime = Time.realtimeSinceStartup - _touchDownTime;

                // cache the distance of the touch from its initial position
                _touchDistanceSquared = (_touchDownPosition - worldPosition).sqrMagnitude;

                // if the touch was a tap (didn't move the touch much and didn't press very long)
                if (
                    _touchDistanceSquared <= _maxTapMoveDistanceSquared
                    &&
                    _touchTime < minPressAndHoldTime
                    )
                {
                    // make the chef attack
                    gameManager.chef.Attack(worldPosition);
                }
            }

            // we are no longer touching the screen
            _touchingScreen = false;

            // if the chef is running
            if (gameManager.chef.State == Chef.STATE.Running)
            {
                // make the chef stand still
                gameManager.chef.Stand(true);
            }

            break;
        }
    }