Exemplo n.º 1
0
    private static List <Vector3> GetPositionListForSingleChild(int playerId, List <Vector3> piecePositions, Transform[] childrenTransform, PositionMapElement[,] playerPositionMapElement, GameObject playerField, GameObject playerForSeeWindow, int mapVerticalStartPosition)
    {
        int mapSingleHorizontalPosition;

        if (ApplicationUtils.IsInMultiPlayerMode())
        {
            mapSingleHorizontalPosition = GameFieldUtils.PositionToMapValue(childrenTransform.First().position.x, playerId, playerField, playerForSeeWindow);
        }
        else
        {
            mapSingleHorizontalPosition = (int)Mathf.Round(childrenTransform.First().position.x - 0.5f);
        }

        for (int j = mapVerticalStartPosition; j >= 0; j--)
        {
            if (playerPositionMapElement[j, mapSingleHorizontalPosition].IsOccupied)
            {
                piecePositions.Add(playerPositionMapElement[j, mapSingleHorizontalPosition].CurrentMapElement.transform.position);
                break;
            }

            if (j == 0)
            {
                piecePositions.Add(new Vector3(GameFieldUtils.MapValueToPosition(mapSingleHorizontalPosition, playerId, playerField, playerForSeeWindow), 0.5f, -0.5f));
            }
        }

        return(piecePositions);
    }
Exemplo n.º 2
0
 private void SetUpScoreElements(int playerId)
 {
     if (!ApplicationUtils.IsInMultiPlayerMode())
     {
         this.SetUpScoreElementsForOnePlayerMode(playerId);
     }
     else
     {
         this.SetUpScoreElementsForTwoPlayerMode(playerId);
     }
     this.PlayersScoreText[playerId].gameObject.SetActive(true);
 }
Exemplo n.º 3
0
    private void InstantiateScoreElementsOnField(int playerId, string scoreTextTagName, string pointTextTagName, Vector3 scorePosition, Vector3 pointsPosition)
    {
        //Calculate the text position
        Vector3 scoreTextPosition  = Camera.main.WorldToScreenPoint(scorePosition);
        Vector3 pointsTextPosition = Camera.main.WorldToScreenPoint(pointsPosition);

        GameObject instantiatedPointText = Instantiate(pointTextGameObject);
        GameObject instantiatedScoreText = Instantiate(scoreTextGameObject, Vector3.zero, Quaternion.identity);

        GameObject instantiatedPointTextGameObjectChild = instantiatedPointText.transform.GetChild(0).gameObject.transform.GetChild(0).gameObject;
        GameObject instantiatedScoreTextGameObjectChild = instantiatedScoreText.transform.GetChild(0).gameObject.transform.GetChild(0).gameObject;

        instantiatedPointTextGameObjectChild.tag = pointTextTagName;
        instantiatedScoreTextGameObjectChild.tag = scoreTextTagName;

        Text pointText = instantiatedPointTextGameObjectChild.GetComponent <Text>();
        Text scoreText = instantiatedScoreTextGameObjectChild.GetComponent <Text>();

        this.PlayersScoreText.Add(playerId, scoreText);
        this.PlayersPointText.Add(playerId, pointText);
        this.playersScrore.Add(playerId, 0);

        this.PlayersScoreText[playerId].text = "Score \n" + this.playersScrore[playerId];
        this.PlayersPointText[playerId].text = "";

        RectTransform scoreTextRectTransform = this.PlayersScoreText[playerId].GetComponent <RectTransform>();

        scoreTextRectTransform.position = scoreTextPosition;

        RectTransform pointsTextRectTransform = this.PlayersPointText[playerId].GetComponent <RectTransform>();

        pointsTextRectTransform.position = pointsTextPosition;

        int scoreTextfontSize = 0;
        int pointTextfontSize = 0;

        if (!ApplicationUtils.IsInMultiPlayerMode())
        {
            scoreTextfontSize = 30;
            pointTextfontSize = 23;
        }
        else
        {
            scoreTextfontSize = 24;
            pointTextfontSize = 22;
        }

        this.PlayersScoreText[playerId].fontSize = scoreTextfontSize;
        this.PlayersPointText[playerId].fontSize = pointTextfontSize;
    }
Exemplo n.º 4
0
    private void PrepareGameField(int playerId)
    {
        GameObject playerField, playerForeseeWindow;

        if (ApplicationUtils.IsInMultiPlayerMode())
        {
            this.PrepareGameFieldForTwoPlayerMode(playerId, out playerField, out playerForeseeWindow);
        }
        else
        {
            this.PrepareGameFieldForOnePlayerMode(out playerField, out playerForeseeWindow);
        }

        this.PlayersField.Add(playerId, playerField);
        this.PlayersForeSeeWindow.Add(playerId, playerForeseeWindow);
    }
Exemplo n.º 5
0
    private void ManagePlayersFrame(int currentPlayerId)
    {
        if (!this.Restart)
        {
            if (this.playersCurrentGamePiece[currentPlayerId] != null && !this.playersDeletingLinesState[currentPlayerId])
            {
                this.FreezePiece(false, false, currentPlayerId);
            }
            else if (this.playersCurrentGamePiece[currentPlayerId] != null && this.playersDeletingLinesState[currentPlayerId])
            {
                this.FreezePiece(true, true, currentPlayerId);
            }
        }

        if (this.playersSpawnAuthorisation[currentPlayerId])
        {
            StartCoroutine(this.SpawnObjects(currentPlayerId));
            this.playersSpawnAuthorisation[currentPlayerId] = false;
        }

        if (Restart)
        {
            if (Input.GetKeyDown(KeyCode.Return))
            {
                if (!ApplicationUtils.IsInMultiPlayerMode())
                {
                    SceneManager.LoadScene(SceneConstants.SCENE_NAME_ONE_PLAYER_MODE);
                }
                else
                {
                    SceneManager.LoadScene(SceneConstants.SCENE_NAME_TWO_PLAYER_MODE);
                }
            }
            else if (Input.GetKeyDown(KeyCode.Escape))
            {
                SoundUtils.StopSound(TagConstants.TAG_NAME_ONE_PLAYER_MODE_SOUND);
                SoundUtils.StopSound(TagConstants.TAG_NAME_TWO_PLAYER_MODE_SOUND);
                Destroy(GameObject.FindGameObjectWithTag(TagConstants.TAG_NAME_SOUND_CONTROLLER));
                SceneManager.LoadScene(SceneConstants.SCENE_NAME_MAIN_MENU_SCENE);
            }
        }
    }
    private void UpdateMapDatasForObject(GameObject parentObject, GameManager gameManagerScript, int playerId)
    {
        Transform[] childrenTransform = parentObject.GetComponentsInChildren <Transform>();

        foreach (Transform childTransform in childrenTransform)
        {
            int linePosition   = (int)Math.Round(childTransform.position.z - 0.5f);
            int columnPosition = 0;

            if (ApplicationUtils.IsInMultiPlayerMode())
            {
                columnPosition = GameFieldUtils.PositionToMapValue(childTransform.position.x, playerId, gameManagerScript.PlayersField[playerId], gameManagerScript.PlayersForeSeeWindow[playerId]);
            }
            else
            {
                columnPosition = (int)Math.Round(childTransform.position.x - 0.5f);
            }

            gameManagerScript.PlayersPositionMap[playerId][linePosition, columnPosition].IsOccupied        = true;
            gameManagerScript.PlayersPositionMap[playerId][linePosition, columnPosition].CurrentMapElement = childTransform.gameObject;
            childTransform.gameObject.layer = LayerMask.NameToLayer(LayerConstants.LAYER_NAME_DESTROYABLE_PIECE);
        }
    }
    private void OnTriggerEnter(Collider other)
    {
        bool isOtherColliderHasPieceChildTag = other.CompareTag(TagConstants.TAG_NAME_PLAYER_1_PIECE_CHILD) || other.CompareTag(TagConstants.TAG_NAME_PLAYER_2_PIECE_CHILD);

        //if a piece child collide with something other than the background
        if (isOtherColliderHasPieceChildTag && this.IsCollisionAccepted())
        {
            bool            isThisColliderHasPieceChildTag   = this.CompareTag(TagConstants.TAG_NAME_PLAYER_1_PIECE_CHILD) || this.CompareTag(TagConstants.TAG_NAME_PLAYER_2_PIECE_CHILD);
            PieceController genericParentPieceMovementScript = null;

            if (other.transform.parent == null && isOtherColliderHasPieceChildTag && this.transform.parent != null && isThisColliderHasPieceChildTag)
            {
                genericParentPieceMovementScript = PieceUtils.FetchCurrentlyActivatedPieceControllerScript(this.transform.parent.gameObject);
            }
            else
            {
                GameObject otherParent = other.transform.parent != null ? other.transform.parent.gameObject : other.transform.gameObject;
                genericParentPieceMovementScript = PieceUtils.FetchCurrentlyActivatedPieceControllerScript(otherParent);
            }

            if (genericParentPieceMovementScript == null)
            {
                return;
            }

            //If the piece are moving
            if (genericParentPieceMovementScript.IsMoving)
            {
                if (this.IsContactFromBelow(other))
                {
                    Rigidbody objectColidingParentRigidBody = other.GetComponentInParent <Rigidbody>();
                    if (objectColidingParentRigidBody == null)
                    {
                        return;
                    }

                    GameObject  gameManagerObject = GameObject.FindGameObjectWithTag(TagConstants.TAG_NAME_GAME_MANAGER);
                    GameManager gameManagerScript = gameManagerObject.GetComponent <GameManager>();
                    genericParentPieceMovementScript.IsMoving = false;
                    objectColidingParentRigidBody.velocity    = Vector3.zero;
                    objectColidingParentRigidBody.isKinematic = true;

                    PieceMetadatas parentPieceMetadatasScript = objectColidingParentRigidBody.gameObject.GetComponent <PieceMetadatas>();
                    if (parentPieceMetadatasScript.IsSparkling)
                    {
                        GameObject[] effectList = GameObject.FindGameObjectsWithTag(TagConstants.TAG_NAME_SPARKLE_EFFECT);
                        foreach (GameObject effect in effectList)
                        {
                            effect.transform.parent = null;
                            Destroy(effect);
                        }

                        PieceMetadatas[] metadataScripts = objectColidingParentRigidBody.gameObject.GetComponentsInChildren <PieceMetadatas>();

                        foreach (PieceMetadatas metadataScript in metadataScripts)
                        {
                            if (metadataScript.gameObject != objectColidingParentRigidBody.gameObject)
                            {
                                metadataScript.IsSparkling = false;
                            }
                        }
                        parentPieceMetadatasScript.IsSparkling = false;
                    }

                    Instantiate(pieceFallSoundEffect, other.transform.position, Quaternion.identity);
                    this.CorrectPiecePosition(objectColidingParentRigidBody.gameObject);
                    this.UpdateMapDatasForObject(objectColidingParentRigidBody.gameObject, gameManagerScript, genericParentPieceMovementScript.OwnerId);
                    gameManagerScript.CleanUpPieceObject(objectColidingParentRigidBody.gameObject, genericParentPieceMovementScript.OwnerId);
                    gameManagerScript.DestroyObjectLines(genericParentPieceMovementScript.OwnerId);
                    //test for the game over requirements
                    if (gameManagerScript.IsGameOver(genericParentPieceMovementScript.OwnerId))
                    {
                        gameManagerScript.GameOver(genericParentPieceMovementScript.OwnerId);

                        int winnerId = genericParentPieceMovementScript.OwnerId == (int)PlayerEnum.PlayerId.PLAYER_1 ? (int)PlayerEnum.PlayerId.PLAYER_2 : (int)PlayerEnum.PlayerId.PLAYER_1;

                        if (ApplicationUtils.IsInMultiPlayerMode())
                        {
                            gameManagerScript.DeclareWinner(winnerId);
                        }
                        return;
                    }

                    if (!gameManagerScript.Restart)
                    {
                        gameManagerScript.PlayersSpawnAuthorisation[genericParentPieceMovementScript.OwnerId] = true;
                    }
                }
            }
        }
    }