Пример #1
0
Файл: Snake.cs Проект: akil03/BC
    public void CheckReachedGroundPiece(GroundPiece pieceToCheck)
    {
        if (pieceToCheck.collectingSnake != null)
        {
            KillSnake(pieceToCheck.collectingSnake);
        }

        if (pieceToCheck.snakeOwener != this)
        {
            if (isCollectingNewGroundPieces == false)
            {
                isCollectingNewGroundPieces = true;
                AI.Reset();
            }
            pieceToCheck.SetCollectingSnake(this);
        }
        else
        {
            if (isCollectingNewGroundPieces)
            {
                List <GroundPiece> newOwnedGroundPieces = new List <GroundPiece> ();

                foreach (GroundPiece groundPiece in tailGroundPieces)
                {
                    newOwnedGroundPieces.Add(groundPiece);
                    groundPiece.SetSnakeOwner(this);
                }

                GroundPiece[] groundPiecesToCheck = Poly.GetGroundPiecesToCheck(this);

                foreach (GroundPiece piece in groundPiecesToCheck)
                {
                    piece.tempHasToBeChecked = true;

                    if (piece.snakeOwener != this)
                    {
                        piece.ownerIDForCheck = 1;
                    }
                    else
                    {
                        piece.ownerIDForCheck = 0;
                    }
                }

                Poly.FloodFill(groundPiecesToCheck [0], 1, 2);

                if (!isBot)
                {
                    SoundsManager.instance.Play(fillClip);
                }


                foreach (GroundPiece piece in groundPiecesToCheck)
                {
                    if (piece.ownerIDForCheck == 1)
                    {
                        newOwnedGroundPieces.Add(piece);
                        piece.SetSnakeOwner(this);
                    }

                    piece.tempHasToBeChecked = false;
                }
                scoreCount = 0;

                foreach (GroundPiece piece in newOwnedGroundPieces)
                {
                    piece.pieceWhenCollected.sr.color = spriteColor;
                    piece.ShowCollectedPiece(collectedPieceSprite);
                    scoreCount++;
                }
                scoreCount *= 50 * scoreMultiplier;

                if (!isBot)
                {
                    totalScore += scoreCount;
                    fov         = 60 + (0.02f * ownedGroundPieces.Count);
                    fov         = Mathf.Clamp(fov, 60, 80);
                    GUIManager.instance.ScorePop.OnScore(scoreCount);
                    GUIManager.instance.scoreText.text = totalScore.ToString();
                    GUIManager.instance.gameCam.DOFieldOfView(fov, 1);
                    ScoreHandler.instance.SetScore(totalScore);
                }


                if (!isBot && !isDead)
                {
                    //ScoreHandler.instance.SetScore (ownedGroundPieces.Count);
                }

                isCollectingNewGroundPieces = false;
                tailGroundPieces            = new List <GroundPiece> ();
            }
        }
    }
Пример #2
0
    private void FixedUpdate()
    {
        if (isTravelling)
        {
            rb.velocity = speed * travelDirection;
        }

        Collider[] hitColliders = Physics.OverlapSphere(transform.position - (Vector3.up / 2), 0.05f);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            GroundPiece ground = hitColliders[i].transform.GetComponent <GroundPiece>();
            if (ground && !ground.isColored)
            {
                ground.ChangeColor(solveColor);
            }
            i++;
        }

        if (nectCollisionPosition != Vector3.zero)
        {
            if (Vector3.Distance(transform.position, nectCollisionPosition) < 1)
            {
                isTravelling          = false;
                travelDirection       = Vector3.zero;
                nectCollisionPosition = Vector3.zero;
            }
        }
        if (isTravelling)
        {
            return;
        }
        if (Input.GetMouseButton(0))
        {
            swipePosCurrentFrame = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
            if (swipePosLastFrame != Vector2.zero)
            {
                currentSwipe = swipePosCurrentFrame - swipePosLastFrame;
                if (currentSwipe.sqrMagnitude < minSwipeRecoginiton)
                {
                    return;
                }
                currentSwipe.Normalize();
                //Up/Down
                if (currentSwipe.x > -.5f && currentSwipe.x < .5f)
                {
                    //go up/down
                    SetDestionation(currentSwipe.y > 0 ? Vector3.forward : Vector3.back);
                }

                if (currentSwipe.y > -.5f && currentSwipe.y < .5f)
                {
                    //go left/right
                    SetDestionation(currentSwipe.x > 0 ? Vector3.right : Vector3.left);
                }
            }
            swipePosLastFrame = swipePosCurrentFrame;
        }
        if (Input.GetMouseButtonUp(0))
        {
            swipePosLastFrame = Vector2.zero;
            currentSwipe      = Vector2.zero;
        }
    }
Пример #3
0
Файл: Snake.cs Проект: akil03/bx
    public void CheckReachedGroundPiece(GroundPiece pieceToCheck)
    {
        //		if (pieceToCheck == null)
        //			return;
        if (pieceToCheck.collectingSnake != null)
        {
            //KillSnake (pieceToCheck.collectingSnake);
            if (PhotonNetwork.inRoom && pieceToCheck.collectingSnake._networkSnake.isCollecting)
            {
                KillSnake(pieceToCheck.collectingSnake);
            }
            else
            {
                KillSnake(pieceToCheck.collectingSnake);
            }
        }
        if (pieceToCheck.snakeOwener != this)
        {
            if (isCollectingNewGroundPieces == false)
            {
                isCollectingNewGroundPieces = true;
                AI.Reset();
            }
            //if (PhotonNetwork.inRoom && isLocal)
            //{
            //    PhotonView.Get(_networkSnake.gameObject).RPC("MakeTrail", PhotonTargets.All, pieceToCheck.indexInGrid);
            //}
            //else
            pieceToCheck.SetCollectingSnake(this);
        }
        else
        {
            if (isCollectingNewGroundPieces)
            {
                //if (PhotonNetwork.inRoom && isLocal)
                //{
                //    PhotonView.Get(_networkSnake.gameObject).RPC("MakeFill", PhotonTargets.All);
                //    return;
                //}
                List <GroundPiece> newOwnedGroundPieces = new List <GroundPiece>();
                foreach (GroundPiece groundPiece in tailGroundPieces)
                {
                    newOwnedGroundPieces.Add(groundPiece);
                    groundPiece.SetSnakeOwner(this);
                    isFill = true;
                }
                GroundPiece[] groundPiecesToCheck = Poly.GetGroundPiecesToCheck(this);
                foreach (GroundPiece piece in groundPiecesToCheck)
                {
                    piece.tempHasToBeChecked = true;

                    if (piece.snakeOwener != this)
                    {
                        piece.ownerIDForCheck = 1;
                    }
                    else
                    {
                        piece.ownerIDForCheck = 0;
                    }
                }
                Poly.FloodFill(groundPiecesToCheck[0], 1, 2);

                foreach (GroundPiece piece in groundPiecesToCheck)
                {
                    if (piece.ownerIDForCheck == 1)
                    {
                        newOwnedGroundPieces.Add(piece);
                        piece.SetSnakeOwner(this);
                        isFill = true;
                    }
                    piece.tempHasToBeChecked = false;
                }

                foreach (GroundPiece piece in newOwnedGroundPieces)
                {
                    piece.pieceWhenCollected.sr.color = spriteColor;
                    piece.ShowCollectedPiece(collectedPieceSprite);
                    energy += 0.025f;
                }

                if (!isBot)
                {
                    ScoreHandler.instance.SetScore(ownedGroundPieces.Count);
                }

                isCollectingNewGroundPieces = false;
                tailGroundPieces            = new List <GroundPiece>();
            }
        }

        if (PhotonNetwork.inRoom)
        {
            _networkSnake.isCollecting = isCollectingNewGroundPieces;
        }


        if (isFill && !isBot)
        {
            isFill = false;
            SoundsManager.instance.Play(FillSound);
        }
    }
Пример #4
0
    private void FixedUpdate()
    {
        if (isMoving)
        {
            rb.velocity = speed * travelDirection;
        }

        Collider[] hitColliders = Physics.OverlapSphere(transform.position - (Vector3.up / 2), 0.05f);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            GroundPiece ground = hitColliders[i].transform.GetComponent <GroundPiece>();
            if (ground && !ground.isColored)
            {
                ground.ChangeColor(solveColor);
            }
            i++;
        }

        if (nextCollisionPosition != Vector3.zero)
        {
            if (Vector3.Distance(transform.position, nextCollisionPosition) < 1)
            {
                isMoving              = false;
                travelDirection       = Vector3.zero;           ///shouldnt be moving anymore
                nextCollisionPosition = Vector3.zero;
            }
        }
        if (isMoving)
        {
            return;
        }
        if (Input.GetMouseButton(0))            //either with finger or mouse on screen
        {
            swipePositionCurrentFrame = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

            if (swipePositionLastFrame != Vector2.zero)
            {
                currentSwipe = swipePositionCurrentFrame - swipePositionLastFrame;
                if (currentSwipe.sqrMagnitude < minSwipeRecognition)
                {
                    return;
                }
                currentSwipe.Normalize();                               //getting the direction not the distance	up left right down etc.
                if (currentSwipe.x > -0.5f && currentSwipe.x < 0.5)
                {
                    //GO UP/DOWN
                    SetDestination(currentSwipe.y > 0 ? Vector3.forward : Vector3.back);
                }
                if (currentSwipe.y > -0.5f && currentSwipe.y < 0.5)
                {
                    //Go left/right
                    SetDestination(currentSwipe.x > 0 ? Vector3.right: Vector3.left);
                }
            }
            swipePositionLastFrame = swipePositionCurrentFrame;
        }
        if (Input.GetMouseButtonUp(0))
        {
            swipePositionLastFrame = Vector2.zero;
            currentSwipe           = Vector2.zero;
        }
    }
Пример #5
0
Файл: Poly.cs Проект: akil03/BC
    public static bool CheckIfCanGoInDirection(GroundPiece groundPieceToCheck, Vector3 dir, Snake snake)
    {
        bool canGoInDirection = false;

        if (dir == Vector3.up)
        {
            try {
                SetReachableBlocks(groundPieceToCheck.GroundPieceOnNorth(), snake);
            } catch {
            }
        }


        if (dir == -Vector3.up)
        {
            try {
                SetReachableBlocks(groundPieceToCheck.GroundPieceOnSouth(), snake);
            } catch {
            }
        }

        if (dir == Vector3.right)
        {
            try {
                SetReachableBlocks(groundPieceToCheck.GroundPieceOnEst(), snake);
            } catch {
            }
        }

        if (dir == -Vector3.right)
        {
            try {
                SetReachableBlocks(groundPieceToCheck.GroundPieceOnOvest(), snake);
            } catch {
            }
        }


        foreach (GroundPiece piece in GroundSpawner.instance.rows[1].groundPieces)
        {
            if (piece.tempReachableState == true && piece.collectingSnake != snake)
            {
                canGoInDirection = true;
            }
        }

        foreach (GroundPiece piece in GroundSpawner.instance.rows[GroundSpawner.instance.rows.Length - 2].groundPieces)
        {
            if (piece.tempReachableState == true && piece.collectingSnake != snake)
            {
                canGoInDirection = true;
            }
        }



        foreach (GroundPiece piece in GroundSpawner.instance.columns[1].groundPieces)
        {
            if (piece.tempReachableState == true && piece.collectingSnake != snake)
            {
                canGoInDirection = true;
            }
        }

        foreach (GroundPiece piece in GroundSpawner.instance.columns[GroundSpawner.instance.columns.Length - 2].groundPieces)
        {
            if (piece.tempReachableState == true && piece.collectingSnake != snake)
            {
                canGoInDirection = true;
            }
        }


        foreach (GroundPiece piece in GroundSpawner.instance.spawnedGroundPieces)
        {
            piece.tempReachableState = false;
        }

        return(canGoInDirection);
    }
Пример #6
0
    private void FixedUpdate()
    {
        // Set the balls speed when it should travel
        if (isTraveling)
        {
            rb.velocity = travelDirection * speed;
        }

        // Paint the ground
        Collider[] hitColliders = Physics.OverlapSphere(transform.position - (Vector3.up / 2), .05f);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            GroundPiece ground = hitColliders[i].transform.GetComponent <GroundPiece>();

            if (ground && !ground.isColored)
            {
                ground.ChangeColor(solveColor);
            }

            i++;
        }

        // Check if we have reached our destination
        if (nextCollisionPosition != Vector3.zero)
        {
            if (Vector3.Distance(transform.position, nextCollisionPosition) < 1)
            {
                isTraveling           = false;
                travelDirection       = Vector3.zero;
                nextCollisionPosition = Vector3.zero;
            }
        }

        if (isTraveling)
        {
            return;
        }

        // Swipe mechanism
        if (Input.GetMouseButton(0))
        {
            // Where is the mouse now?
            swipePosCurrentFrame = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

            if (swipePosLastFrame != Vector2.zero)
            {
                // Calculate the swipe direction
                currentSwipe = swipePosCurrentFrame - swipePosLastFrame;

                if (currentSwipe.sqrMagnitude < minSwipeRecognition) // Minium amount of swipe recognition
                {
                    return;
                }

                currentSwipe.Normalize(); // Normalize it to only get the direction not the distance (would fake the balls speed)

                // Up/Down swipe
                if (currentSwipe.x > -0.5f && currentSwipe.x < 0.5f)
                {
                    SetDestination(currentSwipe.y > 0 ? Vector3.forward : Vector3.back);
                }

                // Left/Right swipe
                if (currentSwipe.y > -0.5f && currentSwipe.y < 0.5f)
                {
                    SetDestination(currentSwipe.x > 0 ? Vector3.right : Vector3.left);
                }
            }


            swipePosLastFrame = swipePosCurrentFrame;
        }

        if (Input.GetMouseButtonUp(0))
        {
            swipePosLastFrame = Vector2.zero;
            currentSwipe      = Vector2.zero;
        }
    }
Пример #7
0
    public void Notify(GroundPiece reachedGroundPiece, bool isCollectingNewGroundPieces)
    {
        NewGroundPieceReached(reachedGroundPiece);


        if (isGoingToKillEnemySnake)
        {
            if (targetEnemySnakeToKill == null || targetEnemySnakeTailGroundPiece == null)
            { //added fix
                print("bug foix");
                isGoingToKillEnemySnake = false;
                //snake.KillSnake(snake);
                // return;
            }
            else if (targetEnemySnakeToKill != targetEnemySnakeTailGroundPiece.collectingSnake || targetEnemySnakeToKill == null)
            {
                isGoingToKillEnemySnake          = false;
                targetEnemySnakeToKill           = null;
                targetEnemySnakeTailGroundPiece  = null;
                movesBeforeReturninToOwnedPieces = 0;
            }
        }



        if (IsAnotherSnakeTailNearMe(distanceToTriggerEnemySnakeKilling, out enemyTailDirection, out targetEnemySnakeTailGroundPiece))
        {
            if (onlyKillEnemyIfPlayer)
            {
                if (!targetEnemySnakeTailGroundPiece.collectingSnake.isBot)
                {
                    targetEnemySnakeToKill  = targetEnemySnakeTailGroundPiece.collectingSnake;
                    isGoingToKillEnemySnake = true;
                }
            }
            else
            {
                targetEnemySnakeToKill  = targetEnemySnakeTailGroundPiece.collectingSnake;
                isGoingToKillEnemySnake = true;
            }
        }



        if (!isGoingToKillEnemySnake)
        {
            if (isCollectingNewGroundPieces)
            {
                if (movesBeforeReturninToOwnedPieces > 0)
                {
                    BehaviourWhenCollectingGroundPieces();
                }
                else
                {
                    BehaviourWhenReturninToOwnedGroundPieces();
                }
            }
            else
            {
                BehaviourWhenInsideOwnedGroundPieces();
            }
        }
        else
        {
            BehaviourWhenGoingToKillEnemySnake();
        }
    }
Пример #8
0
    public bool IsAnotherSnakeTailNearMe(float maxDistance, out Vector3 directionToReachEnemySnakeTail, out GroundPiece enemyTailGroundPieceToReach)
    {
        List <GroundPiece> possibleEnemyTailGroundPieces = new List <GroundPiece> ();
        List <Vector3>     possibleDirections            = new List <Vector3> ();

        directionToReachEnemySnakeTail = Vector3.zero;
        enemyTailGroundPieceToReach    = null;

        if (lastReachedGroundPiece.HasGroundPieceOnEast())
        {
            for (int i = lastReachedGroundPiece.indexInRow + 1; i < lastReachedGroundPiece.row.groundPieces.Count; i++)
            {
                GroundPiece pieceToCheck = lastReachedGroundPiece.row.groundPieces [i];

                if (Vector3.Distance(pieceToCheck.transform.position, transform.position) > maxDistance)
                {
                    break;
                }

                if (pieceToCheck.collectingSnake != null)
                {
                    if (pieceToCheck.collectingSnake == snake)
                    {
                        break;
                    }

                    if (pieceToCheck.collectingSnake != snake)
                    {
                        possibleEnemyTailGroundPieces.Add(pieceToCheck);
                        possibleDirections.Add(transform.right);
                        break;
                    }
                }
            }
        }

        if (lastReachedGroundPiece.HasGroundPieceOnOvest())
        {
            for (int i = lastReachedGroundPiece.indexInRow - 1; i > 0; i--)
            {
                GroundPiece pieceToCheck = lastReachedGroundPiece.row.groundPieces [i];

                if (Vector3.Distance(pieceToCheck.transform.position, transform.position) > maxDistance)
                {
                    break;
                }

                if (pieceToCheck.collectingSnake != null)
                {
                    if (pieceToCheck.collectingSnake == snake)
                    {
                        break;
                    }

                    if (pieceToCheck.collectingSnake != snake)
                    {
                        possibleEnemyTailGroundPieces.Add(pieceToCheck);
                        possibleDirections.Add(-transform.right);
                        break;
                    }
                }
            }
        }

        if (lastReachedGroundPiece.HasGroundPieceOnSouth())
        {
            for (int i = lastReachedGroundPiece.indexInColumn + 1; i < lastReachedGroundPiece.column.groundPieces.Count; i++)
            {
                GroundPiece pieceToCheck = lastReachedGroundPiece.column.groundPieces [i];

                if (Vector3.Distance(pieceToCheck.transform.position, transform.position) > maxDistance)
                {
                    break;
                }

                if (pieceToCheck.collectingSnake != null)
                {
                    if (pieceToCheck.collectingSnake == snake)
                    {
                        break;
                    }

                    if (pieceToCheck.collectingSnake != snake)
                    {
                        possibleEnemyTailGroundPieces.Add(pieceToCheck);
                        possibleDirections.Add(-transform.up);
                        break;
                    }
                }
            }
        }

        if (lastReachedGroundPiece.HasGroundPieceOnNorth())
        {
            for (int i = lastReachedGroundPiece.indexInColumn - 1; i > 0; i--)
            {
                GroundPiece pieceToCheck = lastReachedGroundPiece.column.groundPieces [i];

                if (Vector3.Distance(pieceToCheck.transform.position, transform.position) > maxDistance)
                {
                    break;
                }

                if (pieceToCheck.collectingSnake != null)
                {
                    if (pieceToCheck.collectingSnake == snake)
                    {
                        break;
                    }

                    if (pieceToCheck.collectingSnake != snake)
                    {
                        possibleEnemyTailGroundPieces.Add(pieceToCheck);
                        possibleDirections.Add(transform.up);
                        break;
                    }
                }
            }
        }



        if (possibleDirections.Count > 0)
        {
            int nearestReachableGrounPieceIndex = 0;

            for (int i = 0; i > possibleEnemyTailGroundPieces.Count; i++)
            {
                if (Vector3.Distance(possibleEnemyTailGroundPieces [i].transform.position, transform.position) < Vector3.Distance(possibleEnemyTailGroundPieces [nearestReachableGrounPieceIndex].transform.position, transform.position))
                {
                    nearestReachableGrounPieceIndex = i;
                }
            }


            directionToReachEnemySnakeTail = possibleDirections [nearestReachableGrounPieceIndex];
            enemyTailGroundPieceToReach    = possibleEnemyTailGroundPieces [nearestReachableGrounPieceIndex];


            return(true);
        }
        else
        {
            return(false);
        }
    }
Пример #9
0
 public void NewGroundPieceReached(GroundPiece groundPiece)
 {
     lastReachedGroundPiece = groundPiece;
 }
Пример #10
0
    private void FixedUpdate()
    {
        if (isTravelling)
        {
            rb.velocity = travelDirection * speed;
        }

        Collider[] hitColliders = Physics.OverlapSphere(transform.position - (Vector3.up / 2), .05f);
        int        i            = 0;

        while (i < hitColliders.Length)
        {
            GroundPiece ground = hitColliders[i].transform.GetComponent <GroundPiece>();

            if (ground && !ground.isColored)
            {
                ground.Colored(selectedColor);
                if (ground.GetComponentInChildren <DustparticleSystem>() == null)
                {
                    return;
                }

                ground.GetComponentInChildren <DustparticleSystem>().PlayDust();
            }
            if (ground && isTravelling)
            {
                if (ground.GetComponentInChildren <DustparticleSystem>() == null)
                {
                    return;
                }
                ground.GetComponentInChildren <DustparticleSystem>().PlayDust();
            }
            //if (GameManager.singleton.levelClear)
            //{
            //    if (ground.GetComponentInChildren<DustparticleSystem>() != null)
            //        ground.GetComponentInChildren<DustparticleSystem>().PlayDust();
            //}


            i++;
        }



        if (nextCollPos != Vector3.zero)
        {
            if (Vector3.Distance(transform.position, nextCollPos) < 1)
            {
                isTravelling    = false;
                travelDirection = Vector3.zero;
                nextCollPos     = Vector3.zero;
            }
        }

        if (isTravelling)
        {
            return;
        }

        if (Input.GetMouseButton(0) && isGameStarted)
        {
            swipePosCurrentframe = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

            if (swipePosLastframe != Vector2.zero)
            {
                currentSwipe = swipePosCurrentframe - swipePosLastframe;

                if (currentSwipe.sqrMagnitude < minSwipeRecognition)
                {
                    return;
                }
                currentSwipe.Normalize();

                if (currentSwipe.x > -.5f && currentSwipe.x < .5f)
                {
                    SetDestination(currentSwipe.y > 0 ? Vector3.forward : Vector3.back);
                }
                if (currentSwipe.y > -.5f && currentSwipe.y < .5f)
                {
                    SetDestination(currentSwipe.x > 0 ? Vector3.right : Vector3.left);
                }
            }

            swipePosLastframe = swipePosCurrentframe;
        }

        if (Input.GetMouseButtonUp(0))
        {
            swipePosLastframe = Vector2.zero;
            currentSwipe      = Vector2.zero;
        }
    }
Пример #11
0
 void Awake()
 {
     enabled           = false;
     parentGroundPiece = GetComponentInParent <GroundPiece> ();
 }