예제 #1
0
    private static Vector3 CalculateTextScreenPositionToMiddleField(int playerId, float offset)
    {
        String fieldTagName = null;

        if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            fieldTagName = TagConstants.TAG_NAME_PLAYER_1_FIELD;
        }
        else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            fieldTagName = TagConstants.TAG_NAME_PLAYER_2_FIELD;
        }

        GameObject field = GameObject.FindGameObjectWithTag(fieldTagName);

        Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(field.transform.GetChild(0).gameObject);

        Vector3 textTargetWorldPosition = new Vector3(
            field.transform.position.x + fieldsize.x / 2
            , 0.5f
            , field.transform.position.z + fieldsize.z / 2 + offset);

        Vector3 textScreenPosition = Camera.main.WorldToScreenPoint(textTargetWorldPosition);

        return(textScreenPosition);
    }
예제 #2
0
    public static int PositionToMapValue(float position, int playerId, GameObject fieldGameObject, GameObject fieldForeSeeWindowGameObject)
    {
        int   collumn = 0;
        float gameElementsHorizontalRange = 0f;
        //Avoid bug on calculation during cast
        float intermediateCollumnCalculation = 0f;

        Vector3 gameFieldBackgroundMaxRange = ElementType.CalculateGameObjectMaxRange(fieldGameObject.transform.GetChild(0).gameObject);
        Vector3 gameFieldForeSeeWindowBackgroundMaxRange = ElementType.CalculateGameObjectMaxRange(fieldForeSeeWindowGameObject.transform.GetChild(0).gameObject);

        if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            gameElementsHorizontalRange    = gameFieldBackgroundMaxRange.x + FIELD_MARGIN - HALF_UNIT;
            intermediateCollumnCalculation = gameElementsHorizontalRange + position;
            collumn = (int)(intermediateCollumnCalculation);
        }
        else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            gameElementsHorizontalRange    = gameFieldForeSeeWindowBackgroundMaxRange.x + FIELD_MARGIN + HALF_UNIT;
            intermediateCollumnCalculation = position - gameElementsHorizontalRange;
            collumn = (int)(intermediateCollumnCalculation);
        }

        return(collumn);
    }
예제 #3
0
    private void DefineMapSize(int playerId)
    {
        Vector3 maxRange = ElementType.CalculateGameObjectMaxRange(GameField.transform.GetChild(0).gameObject);

        //Initialise the position matrix for the game elements [lines, collumns]
        this.PlayersPositionMap[playerId] = new PositionMapElement[Mathf.RoundToInt(maxRange.z), Mathf.RoundToInt(maxRange.x)];
    }
예제 #4
0
    private void PrepareGameFieldForOnePlayerMode(out GameObject playerField, out GameObject playerForeseeWindow)
    {
        float   fieldPositionX         = 0f;
        float   foreseeWindowPositionX = 0f;
        Vector3 foreseeWindowSize      = ElementType.CalculateGameObjectMaxRange(ForeseeWindow.transform.GetChild(0).gameObject);

        String fieldTagName = null;

        fieldPositionX         = 0f;
        foreseeWindowPositionX = (foreseeWindowSize.x / 2) * -1;
        fieldTagName           = TagConstants.TAG_NAME_PLAYER_1_FIELD;

        Vector3 fieldPosition = new Vector3(
            fieldPositionX
            , GameField.transform.position.y
            , GameField.transform.position.z
            );
        Vector3 foreseeWindowPosition = new Vector3(
            foreseeWindowPositionX
            , ForeseeWindow.transform.position.y
            , ForeseeWindow.transform.position.z
            );

        this.InstantiateFieldElements(out playerField, out playerForeseeWindow, fieldTagName, fieldPosition, foreseeWindowPosition);
    }
예제 #5
0
    private void CreatePositionMap(int playerId)
    {
        Vector3 maxRange = ElementType.CalculateGameObjectMaxRange(GameField.transform.GetChild(0).gameObject);

        for (int k = 0; k < Mathf.RoundToInt(maxRange.z); k++)
        {
            for (int l = 0; l < Mathf.RoundToInt(maxRange.x); l++)
            {
                this.PlayersPositionMap[playerId][k, l] = new PositionMapElement(false);
            }
        }
    }
예제 #6
0
    private void ManageGameFieldObject(GameObject piece, int playerId, Quaternion randomInstanciationRotation, List <Material> randomPieceColor)
    {
        PieceMetadatas pieceMetadatas = PieceUtils.FetchPieceMetadataScript(piece);

        float positionCorrection = 0f;

        if (pieceMetadatas.IsExcentered)
        {
            positionCorrection = 0.5f;
        }

        GameObject field = this.PlayersField[playerId];

        Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(field.transform.transform.GetChild(0).gameObject);

        Vector3 instantiatePosition = new Vector3(
            fieldsize.x / 2 + field.transform.position.x - 0.5f + positionCorrection
            , 0.5f
            , fieldsize.z + field.transform.position.z - 1.5f);

        GameObject instanciatedPiece = Instantiate(piece, instantiatePosition, randomInstanciationRotation);


        PieceController genericController = null;

        if (ApplicationUtils.IsTypeComputer(playerId))
        {
            genericController = PieceUtils.FetchPieceComputerPieceControllerScript(instanciatedPiece);
        }
        else
        {
            genericController = PieceUtils.FetchPiecePlayerPieceControllerScript(instanciatedPiece);
        }

        genericController.enabled = true;
        genericController.OwnerId = playerId;
        genericController.Field   = field;

        for (int i = 0; i < randomPieceColor.Count; i++)
        {
            instanciatedPiece.transform.GetChild(i).GetComponent <MeshRenderer>().material = randomPieceColor[i];
        }

        PieceMetadatas instanciatedPieceMetadataScript = PieceUtils.FetchPieceMetadataScript(instanciatedPiece);

        instanciatedPieceMetadataScript.IsPieceReady = true;

        //Update parent piece name and the children too thank to the pieceId
        this.UpdatePiecesName(instanciatedPiece);
        this.UpdatePieceChildrenTagName(playerId, instanciatedPiece);
        this.playersCurrentGamePiece[playerId] = instanciatedPiece;
    }
예제 #7
0
    private void SetUpScoreElementsForTwoPlayerMode(int playerId)
    {
        float scoreXposition  = 0f;
        float pointsXposition = 0f;

        String scoreTextTagName = null;
        String pointTextTagName = null;
        String fieldTagName     = null;

        if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            scoreTextTagName = TagConstants.TAG_NAME_PLAYER_1_SCORE_TEXT;
            pointTextTagName = TagConstants.TAG_NAME_PLAYER_1_POINTS_TEXT;
            fieldTagName     = TagConstants.TAG_NAME_PLAYER_1_FIELD;
        }
        else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            scoreTextTagName = TagConstants.TAG_NAME_PLAYER_2_SCORE_TEXT;
            pointTextTagName = TagConstants.TAG_NAME_PLAYER_2_POINTS_TEXT;
            fieldTagName     = TagConstants.TAG_NAME_PLAYER_2_FIELD;
        }

        Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(GameObject.FindGameObjectWithTag(fieldTagName).transform.GetChild(0).gameObject);

        Vector3 foreseeWindowSize = ElementType.CalculateGameObjectMaxRange(GameObject.FindGameObjectWithTag(TagConstants.TAG_NAME_FORESEE_WINDOW).transform.GetChild(0).gameObject);

        if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            scoreXposition  = (foreseeWindowSize.x / 2 + fieldsize.x + GameFieldUtils.FIELD_MARGIN) * -1;
            pointsXposition = (GameFieldUtils.FIELD_MARGIN + fieldsize.x / 2) * -1;
        }
        else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            scoreXposition  = foreseeWindowSize.x / 2 + GameFieldUtils.FIELD_MARGIN;
            pointsXposition = GameFieldUtils.FIELD_MARGIN + foreseeWindowSize.x + fieldsize.x / 2;
        }

        Vector3 scorePosition = new Vector3(
            scoreXposition
            , 0.5f
            , fieldsize.z / 2
            );

        Vector3 pointsPosition = new Vector3(
            pointsXposition
            , 0.5f
            , Vector3.zero.z
            );

        this.InstantiateScoreElementsOnField(playerId, scoreTextTagName, pointTextTagName, scorePosition, pointsPosition);
    }
예제 #8
0
    public static float MapValueToPosition(int mapValue, int playerId, GameObject fieldGameObject, GameObject fieldForeSeeWindowGameObject)
    {
        float position = 0;

        if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            position = -1 * (ElementType.CalculateGameObjectMaxRange(fieldGameObject.transform.GetChild(0).gameObject).x - mapValue + FIELD_MARGIN - 0.5f);
        }
        else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            position = mapValue + ElementType.CalculateGameObjectMaxRange(fieldForeSeeWindowGameObject.transform.GetChild(0).gameObject).x + FIELD_MARGIN + 0.5f;
        }

        return(position);
    }
예제 #9
0
    private void BuildFieldGrid(int playerId)
    {
        GameObject fieldBackground = this.PlayersField[playerId].transform.GetChild(0).gameObject;

        Vector3 maxRange = ElementType.CalculateGameObjectMaxRange(fieldBackground);

        //Calcul the halfsize of the field
        maxRange.x *= 0.5f;
        maxRange.y *= 0.5f;
        maxRange.z *= 0.5f;

        Vector3 minRange = new Vector3(maxRange.x * -1, maxRange.y * -1, maxRange.z * -1);


        for (float i = minRange.x + fieldBackground.transform.position.x; i < maxRange.x + fieldBackground.transform.position.x; i++)
        {
            Vector3    objectPosition = new Vector3(0f, 0f, 0f);
            GameObject line           = Instantiate(verticalLine, objectPosition, Quaternion.identity);

            Vector3 lineVerticePosition1 = new Vector3(i, 0.5f, maxRange.z + fieldBackground.transform.position.z);

            Vector3 lineVerticePosition2 = new Vector3(i, 0.5f, minRange.z + fieldBackground.transform.position.z);

            LineRenderer lineRenderer = line.GetComponent <LineRenderer>();

            lineRenderer.SetPosition(0, lineVerticePosition1);
            lineRenderer.SetPosition(1, lineVerticePosition2);
        }

        for (float i = minRange.z + fieldBackground.transform.position.z; i < maxRange.z + fieldBackground.transform.position.z; i++)
        {
            Vector3    objectPosition = Vector3.zero;
            GameObject line           = Instantiate(horizontalLine, objectPosition, Quaternion.identity);

            Vector3 lineVerticePosition1 = new Vector3(maxRange.x + fieldBackground.transform.position.x, 0.5f, i);

            Vector3 lineVerticePosition2 = new Vector3(minRange.x + fieldBackground.transform.position.x, 0.5f, i);

            LineRenderer lineRenderer = line.GetComponent <LineRenderer>();

            lineRenderer.SetPosition(0, lineVerticePosition1);
            lineRenderer.SetPosition(1, lineVerticePosition2);
        }
    }
예제 #10
0
    private void PrepareGameFieldForTwoPlayerMode(int playerId, out GameObject playerField, out GameObject playerForeseeWindow)
    {
        float fieldPositionX         = 0f;
        float foreseeWindowPositionX = 0f;

        Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(GameField.transform.GetChild(0).gameObject);

        Vector3 foreseeWindowSize = ElementType.CalculateGameObjectMaxRange(ForeseeWindow.transform.GetChild(0).gameObject);

        String fieldTagName = null;

        if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            fieldPositionX         = (fieldsize.x + GameFieldUtils.FIELD_MARGIN) * -1;
            foreseeWindowPositionX = (GameFieldUtils.FIELD_MARGIN + fieldsize.x + foreseeWindowSize.x / 2) * -1;
            fieldTagName           = TagConstants.TAG_NAME_PLAYER_1_FIELD;
        }
        else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            fieldPositionX         = foreseeWindowSize.x + GameFieldUtils.FIELD_MARGIN;
            foreseeWindowPositionX = GameFieldUtils.FIELD_MARGIN + foreseeWindowSize.x / 2;
            fieldTagName           = TagConstants.TAG_NAME_PLAYER_2_FIELD;
        }

        Vector3 fieldPosition = new Vector3(
            fieldPositionX
            , GameField.transform.position.y
            , GameField.transform.position.z
            );
        Vector3 foreseeWindowPosition = new Vector3(
            foreseeWindowPositionX
            , ForeseeWindow.transform.position.y
            , ForeseeWindow.transform.position.z
            );

        this.InstantiateFieldElements(out playerField, out playerForeseeWindow, fieldTagName, fieldPosition, foreseeWindowPosition);
    }
예제 #11
0
    public void DisplayEarnedPoints(int nbLine, int lineId, int playerId)
    {
        float  pointsXposition = 0f;
        String fieldTagName    = null;

        if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            fieldTagName = TagConstants.TAG_NAME_PLAYER_1_FIELD;
        }
        else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            fieldTagName = TagConstants.TAG_NAME_PLAYER_2_FIELD;
        }

        Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(GameObject.FindGameObjectWithTag(fieldTagName).transform.GetChild(0).gameObject);

        Vector3 foreseeWindowSize = ElementType.CalculateGameObjectMaxRange(GameObject.FindGameObjectWithTag(TagConstants.TAG_NAME_FORESEE_WINDOW).transform.GetChild(0).gameObject);

        if (playerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            pointsXposition = (GameFieldUtils.FIELD_MARGIN + fieldsize.x / 2) * -1;
        }
        else if (playerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            pointsXposition = GameFieldUtils.FIELD_MARGIN + foreseeWindowSize.x + fieldsize.x / 2;
        }

        //Pieces line destroyed position calculation
        Vector3 lineWorldPosition = new Vector3(pointsXposition, 0.5f, lineId + 0.5f);
        //Calculate the text position depending on the destroyed line position
        Vector3       textPosition      = Camera.main.WorldToScreenPoint(lineWorldPosition);
        RectTransform textRectTransform = this.PlayersPointText[playerId].GetComponent <RectTransform>();

        textRectTransform.position = textPosition;
        this.PlayersPointText[playerId].gameObject.SetActive(true);
        this.PlayersPointText[playerId].text = "+ " + this.GetTotalEarnedPoint(nbLine);
    }
예제 #12
0
    private Vector3 CalculateFireWorkPosition(int winnerId, float offset)
    {
        String fieldTagName = null;

        if (winnerId == (int)PlayerEnum.PlayerId.PLAYER_1)
        {
            fieldTagName = TagConstants.TAG_NAME_PLAYER_1_FIELD;
        }
        else if (winnerId == (int)PlayerEnum.PlayerId.PLAYER_2)
        {
            fieldTagName = TagConstants.TAG_NAME_PLAYER_2_FIELD;
        }

        GameObject field = GameObject.FindGameObjectWithTag(fieldTagName);

        Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(field.transform.GetChild(0).gameObject);

        Vector3 fireworksTargetWorldPosition = new Vector3(
            field.transform.position.x + fieldsize.x / 2
            , 0.5f
            , field.transform.position.z + fieldsize.z / 2 + offset);

        return(fireworksTargetWorldPosition);
    }
예제 #13
0
    private void SetUpScoreElementsForOnePlayerMode(int playerId)
    {
        float scoreXposition  = 0f;
        float pointsXposition = 0f;

        String scoreTextTagName = null;
        String pointTextTagName = null;
        String fieldTagName     = null;

        scoreTextTagName = TagConstants.TAG_NAME_PLAYER_1_SCORE_TEXT;
        pointTextTagName = TagConstants.TAG_NAME_PLAYER_1_POINTS_TEXT;
        fieldTagName     = TagConstants.TAG_NAME_PLAYER_1_FIELD;

        Vector3 fieldsize = ElementType.CalculateGameObjectMaxRange(GameObject.FindGameObjectWithTag(fieldTagName).transform.GetChild(0).gameObject);

        Vector3 foreseeWindowSize = ElementType.CalculateGameObjectMaxRange(GameObject.FindGameObjectWithTag(TagConstants.TAG_NAME_FORESEE_WINDOW).transform.GetChild(0).gameObject);


        scoreXposition  = (foreseeWindowSize.x / 2) * -1;
        pointsXposition = GameObject.FindGameObjectWithTag(fieldTagName).transform.position.x + (fieldsize.x / 2);


        Vector3 scorePosition = new Vector3(
            scoreXposition
            , 0.5f
            , fieldsize.z / 2
            );

        Vector3 pointsPosition = new Vector3(
            pointsXposition
            , 0.5f
            , Vector3.zero.z
            );

        this.InstantiateScoreElementsOnField(playerId, scoreTextTagName, pointTextTagName, scorePosition, pointsPosition);
    }