示例#1
0
    private void FillBeerIfPourPressed(bool pourPressed)
    {
        if (pourPressed && !IsFillingBeer && !IsIdleWithBeer && !IsServing)
        {
            // pouring and has not started filling beer -> start filling beer
            BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);
            if (!IsAtCurrentBarTap)
            {
                StartCoroutine(ShiftToBarTapAndFillBeer());
            }
            else
            {
                IsFillingBeer = true;
                StartCoroutine(FillBeer());
            }

            HorizontalFlipSpriteBasedOnBool(currentTap.IsFlipped);
        }
        else if (pourPressed && IsFillingBeer && IsIdleWithBeer && !IsServing)
        {
            // pour pressed while being idle (paused filling) -> resume filling the beer
            IsIdleWithBeer = false;
            animator.SetBool("isIdleWithBeer", IsIdleWithBeer);
            StartCoroutine(FillBeer());
        }
        else if (!pourPressed && IsFillingBeer && !IsIdleWithBeer && !IsServing)
        {
            // stopped pouring in the middle of filling beer -> user becomes idle
            IsIdleWithBeer = true;
            animator.SetBool("isIdleWithBeer", IsIdleWithBeer);
        }
    }
示例#2
0
    private void CheckIfAtBarTap()
    {
        RaycastHit2D hit;
        BarTap       touchingTap = null;

        boxCollider.enabled = false;
        hit = Physics2D.Linecast(transform.position, transform.position, itemsLayer);
        boxCollider.enabled = true;

        if (hit.transform != null && hit.transform.tag == "BarTap")
        {
            touchingTap = hit.transform.GetComponent <BarTap>();
            touchingTap.IsPlayerAtTap = true;
            IsAtCurrentBarTap         = true;
        }
        else
        {
            IsAtCurrentBarTap = false;
        }

        // mark other taps as the player not being there
        List <BarTap> taps = GameManager.instance.levelManager.GetBarTaps();

        foreach (BarTap otherTap in taps)
        {
            if (touchingTap != null && touchingTap.TapIndex != otherTap.TapIndex)
            {
                otherTap.IsPlayerAtTap = false;
            }
            else if (touchingTap == null)
            {
                otherTap.IsPlayerAtTap = false;
            }
        }
    }
示例#3
0
    // Shift to next Bar Tap
    private void ShiftToNextBarTap(int yDir)
    {
        if (IsShifting)
        {
            return; // don't do anything if already shifting
        }

        // Get Next Tap Index
        int nextTapIndex = CurrentTapIndex;

        // If you are going down go to the next bar
        if (yDir < Constants.ZERO)
        {
            nextTapIndex++;
        }

        // If you go up go to the previous bar
        else if (yDir > Constants.ZERO)
        {
            nextTapIndex--;
        }


        // Get all Bars
        BarTap foundTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(nextTapIndex);
        BarTap firstTap = GameManager.instance.levelManager.GetFirstBarTap();
        BarTap lastTap  = GameManager.instance.levelManager.GetLastBarTap();

        // Is found is only found if it found a tap
        bool isFound = (foundTap != null);

        // wrap to beginning or last tap if needed
        if (!isFound && nextTapIndex < firstTap.TapIndex)
        {
            isFound      = true;
            nextTapIndex = lastTap.TapIndex;
            foundTap     = lastTap;
        }
        else if (!isFound && nextTapIndex > lastTap.TapIndex)
        {
            isFound      = true;
            nextTapIndex = firstTap.TapIndex;
            foundTap     = firstTap;
        }

        // If player is in the scene but not at the tap still Shift but also resets it's position according to where the tap is
        if (isFound && !foundTap.IsPlayerAtTap)
        {
            CurrentTapIndex = nextTapIndex;

            BoxCollider2D tapCollider = foundTap.GetComponent <BoxCollider2D>();
            Vector3       newPos      = foundTap.GetShiftPositionVector();

            StartCoroutine(DoShift(newPos));
        }
    }
示例#4
0
    private void ShiftToNextBarTap(int yDir)
    {
        if (IsShifting)
        {
            return; // don't do anything if already shifting
        }

        int nextTapIndex = CurrentTapIndex;

        if (yDir < 0)
        {
            nextTapIndex++;
        }
        else if (yDir > 0)
        {
            nextTapIndex--;
        }


        BarTap foundTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(nextTapIndex);
        BarTap firstTap = GameManager.instance.levelManager.GetFirstBarTap();
        BarTap lastTap  = GameManager.instance.levelManager.GetLastBarTap();

        bool isFound = (foundTap != null);

        // wrap to beginning or last tap if needed
        if (!isFound && nextTapIndex < firstTap.TapIndex)
        {
            isFound      = true;
            nextTapIndex = lastTap.TapIndex;
            foundTap     = lastTap;
        }
        else if (!isFound && nextTapIndex > lastTap.TapIndex)
        {
            isFound      = true;
            nextTapIndex = firstTap.TapIndex;
            foundTap     = firstTap;
        }

        if (isFound && !foundTap.IsPlayerAtTap)
        {
            CurrentTapIndex = nextTapIndex;

            BoxCollider2D tapCollider = foundTap.GetComponent <BoxCollider2D>();
            Vector3       newPos      = foundTap.GetShiftPositionVector();

            StartCoroutine(DoShift(newPos));
        }
    }
示例#5
0
    protected IEnumerator ServeBeerIfReady()
    {
        if (!servePressed || FillPercent < 100 || IsShifting)
        {
            yield break;
        }

        IsServing      = true;
        FillPercent    = 0;
        IsFillingBeer  = false;
        IsIdleWithBeer = false;

        animator.SetTrigger("playerServe");
        animator.SetBool("isServing", IsServing);
        animator.SetBool("isFillingBeer", IsFillingBeer);
        animator.SetBool("isIdleWithBeer", IsIdleWithBeer);
        animator.SetFloat("fillOffset", FillOffset);


        int beerDir = -1;

        BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);

        if (currentTap.IsFlipped)
        {
            beerDir = 1;
        }

        float beerOffsetX = 1.6f;
        float beerOffsetY = 0.7f;


        GameObject beerObj = Instantiate(BeerPrefab, transform.position + new Vector3(beerOffsetX * beerDir, beerOffsetY, 0), transform.rotation);
        Beer       beer    = beerObj.GetComponent <Beer>();

        beer.HorionztalDir = beerDir;
        beer.IsFilled      = true;
        beer.Speed         = GameManager.instance.levelManager.GetPlayerBeerSpeed();
        beer.TapIndex      = this.CurrentTapIndex;

        yield return(new WaitForSeconds(ServeDelay));

        IsServing = false;
        animator.SetBool("isServing", IsServing);
    }
示例#6
0
    private void HideCurrentTapIfFilling()
    {
        if (!IsFillingBeer && !IsIdleWithBeer)
        {
            return;
        }

        BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);

        if (currentTap.IsPlayerAtTap && !IsShifting)
        {
            currentTap.GetComponent <SpriteRenderer>().enabled = false;

            Vector3 theScale = transform.localScale;
            theScale.x           = currentTap.transform.localScale.x;
            transform.localScale = theScale;
        }
    }
示例#7
0
    private void HideCurrentTapIfFilling()
    {
        // If it isn't being filled don't go further
        if (!IsFillingBeer && !IsIdleWithBeer)
        {
            return;
        }

        // Get CurrentBarTap
        BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);

        // If Player is at the Current Tap set the CurrentTap Sprite to false
        if (currentTap.IsPlayerAtTap && !IsShifting)
        {
            currentTap.GetComponent <SpriteRenderer>().enabled = false;

            Vector3 theScale = transform.localScale;
            theScale.x           = currentTap.transform.localScale.x;
            transform.localScale = theScale;
        }
    }
示例#8
0
    // Try moving according the new Direction
    protected bool AttemptMove(int xDir, int yDir)
    {
        if (IsShifting || (xDir == Constants.ZERO && yDir == Constants.ZERO))
        {
            // don't move if shifting or no input in X or Y direction
            return(false);
        }

        if (xDir != 0 && IsFillingBeer)
        {
            // don't allow running when filling beer
            return(false);
        }

        if (IsAtCurrentBarTap && xDir != Constants.ZERO)
        {
            // don't allow player to move pass bar tap
            BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);
            if (xDir > Constants.ZERO && !currentTap.IsFlipped)
            {
                return(false);
            }

            if (xDir < Constants.ZERO && currentTap.IsFlipped)
            {
                return(false);
            }
        }

        // If you move around the scene set ydir back to his now default position
        if (xDir != Constants.ZERO)
        {
            yDir = Constants.ZERO;
        }

        RaycastHit2D hit;

        return(Move(xDir, yDir, out hit));
    }
示例#9
0
    // Fill bottle with proper functions
    private void FillBeerIfPourPressed(bool pourPressed)
    {
        // If the Pour Button is pressed and you are not filling the bottle and not being idle with the bottle and not serving
        // Get Current Bar Tap and check the Player is at that BarTap if not move to it if yes set the IsFilling bool to true and starting filling
        if (pourPressed && !IsFillingBeer && !IsIdleWithBeer && !IsServing)
        {
            // pouring and has not started filling bottle -> start filling bottle
            BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);
            if (!IsAtCurrentBarTap)
            {
                StartCoroutine(ShiftToBarTapAndFillBeer());
            }
            else
            {
                IsFillingBeer = true;
                StartCoroutine(FillBeer());
            }

            // Set CurrentTap on flipped so the other tap image will show
            HorizontalFlipSpriteBasedOnBool(currentTap.IsFlipped);
        }

        // If you were filling but stopped you can resume it only if you are still idle and set correct bool for Animator
        else if (pourPressed && IsFillingBeer && IsIdleWithBeer && !IsServing)
        {
            // pour pressed while being idle (paused filling) -> resume filling the bottle
            IsIdleWithBeer = false;
            animator.SetBool("isIdleWithBeer", IsIdleWithBeer);
            StartCoroutine(FillBeer());
        }

        // If you stop pressing the pour button it will go to idle and set correct bool for Animator
        else if (!pourPressed && IsFillingBeer && !IsIdleWithBeer && !IsServing)
        {
            // stopped pouring in the middle of filling bottle -> user becomes idle
            IsIdleWithBeer = true;
            animator.SetBool("isIdleWithBeer", IsIdleWithBeer);
        }
    }
示例#10
0
    // Start is called before the first frame update
    public void Start()
    {
        // Sets Default Values for Certain Variables
        ShiftDelay  = Constants.SHIFT_DELAY;
        ShiftSpeed  = Constants.SHIFT_SPEED;
        RunSpeed    = Constants.RUN_SPEED;
        ServeDelay  = Constants.SERVE_DELAY;
        FillSpeed   = Constants.FILL_SPEED;
        FillPercent = Constants.FILL_PERCENT;

        // Every time the Player starts it will play a "You used a life" Track
        NewLife.Play();

        // Connects to the Components
        boxCollider    = GetComponent <BoxCollider2D>();
        rBody          = GetComponent <Rigidbody2D>();
        animator       = GetComponent <Animator>();
        spriteRenderer = GetComponent <SpriteRenderer>();

        // Sets Default Values to false to prevent misbehaviour
        IsRunning         = false;
        IsShifting        = false;
        IsFacingLeft      = false;
        IsFillingBeer     = false;
        IsAtCurrentBarTap = false;

        // Sets the Animator Values according to the Default Bool Values
        IsIdleWithBeer = false;
        animator.SetBool("isIdleWithBeer", IsIdleWithBeer);

        IsFillingBeer = false;
        animator.SetBool("isFillingBeer", IsFillingBeer);

        // Get Current Bartap and set Default Position
        BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);

        rBody.transform.position = currentTap.GetShiftPositionVector();
    }
示例#11
0
    protected bool AttemptMove(int xDir, int yDir)
    {
        if (IsShifting || (xDir == 0 && yDir == 0))
        {
            // don't move if shifting or no input in X or Y direction
            return(false);
        }

        if (xDir != 0 && IsFillingBeer)
        {
            // don't allow running when filling beer
            return(false);
        }

        if (IsAtCurrentBarTap && xDir != 0)
        {
            // don't allow player to move pass bar tap
            BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);
            if (xDir > 0 && !currentTap.IsFlipped)
            {
                return(false);
            }

            if (xDir < 0 && currentTap.IsFlipped)
            {
                return(false);
            }
        }

        if (xDir != 0)
        {
            yDir = 0;
        }

        RaycastHit2D hit;

        return(Move(xDir, yDir, out hit));
    }
示例#12
0
    // Start is called before the first frame update
    protected void Start()
    {
        boxCollider    = GetComponent <BoxCollider2D>();
        rBody          = GetComponent <Rigidbody2D>();
        animator       = GetComponent <Animator>();
        spriteRenderer = GetComponent <SpriteRenderer>();

        IsRunning         = false;
        IsShifting        = false;
        IsFacingLeft      = false;
        IsFillingBeer     = false;
        IsAtCurrentBarTap = false;

        IsIdleWithBeer = false;
        animator.SetBool("isIdleWithBeer", IsIdleWithBeer);

        IsFillingBeer = false;
        animator.SetBool("isFillingBeer", IsFillingBeer);

        BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);

        rBody.transform.position = currentTap.GetShiftPositionVector();
    }
示例#13
0
    // Check if bottle is ready to serve
    protected IEnumerator ServeBeerIfReady()
    {
        // If fill percentage is less then 100% or the serve button isn't being pressed or the player is shifting then break the actiom
        if (!servePressed || FillPercent < Constants.FILL_FULL || IsShifting)
        {
            yield break;
        }

        // Play a serve sound
        Throw.Play();

        // Set the correct variables to true to get the proper animation
        IsServing = true;

        // Set the Fill Percent to 0 so the function doesn't repeat
        FillPercent = Constants.FILL_PERCENT;

        // Set the following variables to false to get the proper animation and doesn't let the stystem repeat
        IsFillingBeer  = false;
        IsIdleWithBeer = false;

        // Sets the animator variables to get correct animation
        animator.SetTrigger("playerServe");
        animator.SetBool("isServing", IsServing);
        animator.SetBool("isFillingBeer", IsFillingBeer);
        animator.SetBool("isIdleWithBeer", IsIdleWithBeer);
        animator.SetFloat("fillOffset", FillOffset);

        // Sets the Bottle Direction
        int beerDir = Constants.MIN_ONE;

        // Gets Current Bartap
        BarTap currentTap = GameManager.instance.levelManager.GetBarTapAtTapIndex(CurrentTapIndex);

        // If the Current Tap is Flipped set new Bottle direction
        if (currentTap.IsFlipped)
        {
            beerDir = Constants.ONE;
        }

        // Sets Bottle Offsets
        float beerOffsetX = Constants.BOTTLE_OFFSET_X_P;
        float beerOffsetY = Constants.BOTTLE_OFFSET_Y_P;

        // Instantiate the bottle prefab and get that component
        GameObject beerObj = Instantiate(BeerPrefab, transform.position + new Vector3(beerOffsetX * beerDir, beerOffsetY, Constants.ZERO), transform.rotation);
        Beer       beer    = beerObj.GetComponent <Beer>();

        // Set the Horizontal Direction, Correct Speed and get Current Tap and Set the IsFilled Bool to true
        beer.HorionztalDir = beerDir;
        beer.IsFilled      = true;
        beer.Speed         = GameManager.instance.levelManager.GetPlayerBeerSpeed();
        beer.TapIndex      = this.CurrentTapIndex;

        // Wait for the Serve Delay
        yield return(new WaitForSeconds(ServeDelay));

        // Set is Serving Bool to false and set the Animator Bool to current is Serving Bool
        IsServing = false;
        animator.SetBool("isServing", IsServing);
    }