Example #1
0
    void UpdateTimer()
    {
        // decrease the seconds remained
        Game.Instance.TimeRemained -= 1;

        // less than zero seconds? let's show that there are zero seconds
        if (Game.Instance.TimeRemained < 0)
        {
            Game.Instance.TimeRemained = 0;
        }

        /* SHOW TIME */
        UpdateGuiTime();

        if (currentPlayer == PlayerEnum.LEFT)
        {
            dataSmall[0] = Constants.CODE_TIME;
            dataSmall[1] = (byte)((int)Game.Instance.TimeRemained);

            if (Game.Instance.OnlinePlay)
            {
                PlayGamesPlatform.Instance.RealTime.SendMessageToAll(true, dataSmall);
            }
            else if (Game.Instance.BluetoothPlay)
            {
                                #if UNITY_ANDROID
                SendInfoToServer(dataSmall);
#endif
            }
        }


        //TimerContent.fillAmount = (float) Game.Instance.TimeRemained / 120;

        /* GAME ENDED */

        if (Game.Instance.GameEnded == true)
        {
            if (Game.Instance.TournamentMode && !isInGoldenGoal && Game.Instance.PlayerScore01 == Game.Instance.PlayerScore02)
            {
                Game.Instance.TimeRemained = addictionalTime;
                isInGoldenGoal             = true;
                Whistle(false);

                if (PlayGamesPlatform.Instance.IsAuthenticated())
                {
                    Social.ReportProgress(Constants.ACH_GOLDEN_GOAL, 100.0f, (bool success) => {
                        // handle success or failure
                    });
                }
            }
            else
            {
                CancelInvoke("UpdateTimer");
                Game.Instance.SetGameActive(false);
                PauseButton.SetActive(false);
                PointsManager points = (currentPlayer == PlayerEnum.LEFT) ? points01 : points01;

                GameEndedExitButton.SetActive(Game.Instance.PlayerScore02 > Game.Instance.PlayerScore01);
                GameEndedNextButton.SetActive(GameEndedExitButton.activeSelf == false);


                MenuGameEnded.SetActive(true);

                foreach (Transform child in MenuGameEnded.transform)
                {
                    switch (child.name)
                    {
                    case "Points":
                        child.GetComponent <UILabel>().text = string.Format("{0}", points.AllPoints);
                        break;

                    case "Pallino1":
                        foreach (Transform child2 in child)
                        {
                            switch (child2.name)
                            {
                            case "Star1":
                                if (points.Stars < 1)
                                {
                                    child2.gameObject.SetActive(false);
                                }
                                break;
                            }
                        }

                        break;

                    case "Pallino2":
                        foreach (Transform child2 in child)
                        {
                            switch (child2.name)
                            {
                            case "Star2":
                                if (points.Stars < 2)
                                {
                                    child2.gameObject.SetActive(false);
                                }
                                break;
                            }
                        }
                        break;

                    case "Pallino3":
                        foreach (Transform child2 in child)
                        {
                            switch (child2.name)
                            {
                            case "Star3":
                                if (points.Stars < 3)
                                {
                                    child2.gameObject.SetActive(false);
                                }
                                break;
                            }
                        }
                        break;
                    }
                }

                SavedVariables.LeaderBoardPoints        += points.AllPoints;
                SavedVariables.LeaderBoardGoals         += points.Goals;
                SavedVariables.LeaderBoardPlayedMatches += 1;
                //
                bool matchWon  = false;
                bool matchEven = false;;
                bool matchLost = false;
                if (currentPlayer == PlayerEnum.LEFT)
                {
                    matchWon = Game.Instance.PlayerScore01 > Game.Instance.PlayerScore02;
                }
                else
                {
                    matchWon = Game.Instance.PlayerScore01 < Game.Instance.PlayerScore02;
                }
                matchLost = !matchWon;
                matchEven = matchWon == false && matchLost == false;
                //
                bool supremeDefense = false;
                if (currentPlayer == PlayerEnum.LEFT)
                {
                    supremeDefense = Game.Instance.PlayerScore02 < 5;
                }
                else
                {
                    supremeDefense = Game.Instance.PlayerScore01 < 5;
                }

                bool bestDefenseEver = false;
                if (currentPlayer == PlayerEnum.LEFT)
                {
                    bestDefenseEver = Game.Instance.PlayerScore02 == 0;
                }
                else
                {
                    bestDefenseEver = Game.Instance.PlayerScore01 == 0;
                }
                //
                bool supremeTactic = false;
                if (currentPlayer == PlayerEnum.LEFT)
                {
                    supremeTactic = Game.Instance.PlayerScore01 > 25;
                }
                else
                {
                    supremeTactic = Game.Instance.PlayerScore01 > 25;
                }
                //
                if (matchWon)
                {
                    SavedVariables.LeaderBoardWonMatches += 1;
                }

                if (PlayGamesPlatform.Instance.IsAuthenticated() && Game.Instance.LocalMultiPlayer == false)
                {
                    Social.ReportScore(SavedVariables.LeaderBoardPoints, Constants.LB_POINTS, (bool success) => {
                        // handle success or failure
                    });
                    Social.ReportScore(SavedVariables.LeaderBoardGoals, Constants.LB_GOALS, (bool success) => {
                        // handle success or failure
                    });
                    Social.ReportScore(SavedVariables.LeaderBoardPlayedMatches, Constants.LB_PLAYED_MATCHES, (bool success) => {
                        // handle success or failure
                    });
                    Social.ReportScore(SavedVariables.LeaderBoardWonMatches, Constants.LB_WON_MATCHES, (bool success) => {
                        // handle success or failure
                    });

                    if (Game.Instance.OnlinePlay && matchWon)
                    {
                        Social.ReportProgress(Constants.ACH_WIN_AN_ONLINE_MATCH, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }

                    if (Game.Instance.BluetoothPlay && matchWon)
                    {
                        Social.ReportProgress(Constants.ACH_WIN_A_BLUETOOTH_MATCH, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }

                    if (matchWon)
                    {
                        Social.ReportProgress(Constants.ACH_WIN_A_MATCH, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }
                    else if (matchEven)
                    {
                        Social.ReportProgress(Constants.ACH_MAKE_AN_EVEN, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }
                    else if (matchLost)
                    {
                        Social.ReportProgress(Constants.ACH_LOSE_A_MATCH, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }
                    if (supremeDefense)
                    {
                        Social.ReportProgress(Constants.ACH_SUPREME_DEFENSE, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }
                    if (bestDefenseEver)
                    {
                        Social.ReportProgress(Constants.ACH_BEST_DEFENSE_EVER, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }
                    if (supremeTactic)
                    {
                        Social.ReportProgress(Constants.ACH_SUPREME_TACTIC, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }

                    if (SavedVariables.LeaderBoardPoints >= 100000)
                    {
                        Social.ReportProgress(Constants.ACH_POINTS_100_000, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }

                    if (SavedVariables.LeaderBoardPoints >= 500000)
                    {
                        Social.ReportProgress(Constants.ACH_POINTS_500_000, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }

                    if (SavedVariables.LeaderBoardPoints >= 1000000)
                    {
                        Social.ReportProgress(Constants.ACH_POINTS_1_000_000, 100.0f, (bool success) => {
                            // handle success or failure
                        });
                    }
                }
            }
        }
    }
Example #2
0
    void Start()
    {
        isInGoldenGoal = false;
        // stop timer, but play the game
        Game.Instance.TimerActive = false;
        CancelInvoke("PrepareEnemie");
        Game.Instance.SetGameActive(true);
        // distance from the screen
        float dFromScreen = 4f;

        points01 = new PointsManager();
        points02 = new PointsManager();
        canShoot = false;
        float doorPos = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x;

        currentPlayer = PlayerEnumUtils.GetCurrentPlayer();
        offlineMatch  = Game.Instance.OnlinePlay == false && Game.Instance.BluetoothPlay == false && Game.Instance.LocalMultiPlayer == false;

        if (SavedVariables.FirstPlay)
        {
            SavedVariables.FirstPlay = false;
            tutorial.SetActive(true);
        }

        // disable some components
        MenuPause.SetActive(false);
        MenuGameEnded.SetActive(false);
        if (Game.Instance.TournamentMode)
        {
            GameEndedRowOffline.SetActive(false);
            GameEndedRowOnline.SetActive(false);
            GameEndedTournament.SetActive(true);
            RedoButton.enabled = false;
            RedoButton.SetState(UIButton.State.Disabled, true);
        }
        else if (Game.Instance.OnlinePlay || Game.Instance.BluetoothPlay)
        {
            GameEndedRowOffline.SetActive(false);
            GameEndedRowOnline.SetActive(true);
            GameEndedTournament.SetActive(false);
        }
        else if (Game.Instance.LocalPlay || Game.Instance.LocalMultiPlayer)
        {
            GameEndedRowOffline.SetActive(true);
            GameEndedRowOnline.SetActive(false);
            GameEndedTournament.SetActive(false);
        }
        Points01.enabled = false;
        Points02.enabled = false;

        if (Game.Instance.BluetoothPlay || Game.Instance.OnlinePlay)
        {
            PauseButton.SetActive(false);
        }
        else
        {
            EndMatchButton.SetActive(false);
        }

        // get the letters distance
        for (byte i = 0; i < letters.Length; i++)          // count the distance from the letter on the left
        {
            if (i == 0)
            {
                lettersDistances[i] = 0;
            }
            else
            {
                lettersDistances[i] = letters[i].transform.position.x - letters[i - 1].transform.position.x;
            }
        }

        // SET WALLS POSITION
        {
            //Move each wall to its edge location:
            topDeath.size   = new Vector2(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x * 2 * 2, 1);
            topDeath.offset = new Vector2(0, Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, 0)).y + 0.5f + dFromScreen);

            bottomDeath.size   = new Vector2(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x * 2 * 2, 1);
            bottomDeath.offset = new Vector2(0, Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0)).y - 0.5f - dFromScreen);

            leftDeath.size   = new Vector2(1, Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, 0)).y * 2 * 2);;
            leftDeath.offset = new Vector2(Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0)).x - 0.5f - dFromScreen, 0);

            rightDeath.size   = new Vector2(1, Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, 0)).y * 2 * 2);
            rightDeath.offset = new Vector2(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x + 0.5f + dFromScreen, 0);

            //Move each wind to its edge location:
            topWall.size   = new Vector2(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x * 2, 1);
            topWall.offset = new Vector2(0, Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, 0)).y + 0.5f);

            bottomWall.size   = new Vector2(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x * 2, 1);
            bottomWall.offset = new Vector2(0, Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0)).y - 0.5f);

            leftWall.size   = new Vector2(1, Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, 0)).y * 2);;
            leftWall.offset = new Vector2(Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0)).x - 0.5f, 0);

            rightWall.size   = new Vector2(1, Camera.main.ScreenToWorldPoint(new Vector3(0, Screen.height, 0)).y * 2);
            rightWall.offset = new Vector2(Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, 0, 0)).x + 0.5f, 0);
        }
        // SETUP BALL AND DOORS
        {
            // move down the referee
            Whistle(true);

            // doors

            doorLeft.transform.position  = new Vector3(-doorPos, 0, 0);
            doorRight.transform.position = new Vector3(+doorPos, 0, 0);
        }

        GameObject player01   = GameObject.Instantiate(playerBase, Vector3.zero, Quaternion.identity) as GameObject;
        GameObject player02   = GameObject.Instantiate(playerBase, Vector3.zero, Quaternion.identity) as GameObject;
        GameObject goalKeeper = GameObject.Instantiate(playerBase, Vector3.zero, Quaternion.identity) as GameObject;

        while (Game.Instance.Nation01 == Nationals.NONE)
        {
            System.Array A = System.Enum.GetValues(typeof(Nationals));
            Nationals    V = (Nationals)A.GetValue(UnityEngine.Random.Range(0, A.Length));
            Game.Instance.Nation01 = V;
        }
        while (Game.Instance.Nation02 == Nationals.NONE || Game.Instance.Nation02 == Game.Instance.Nation01)
        {
            System.Array A = System.Enum.GetValues(typeof(Nationals));
            Nationals    V = (Nationals)A.GetValue(UnityEngine.Random.Range(0, A.Length));
            Game.Instance.Nation02 = V;
        }
        Flag01.sprite2D = NationalSuits.getNationFlag(Game.Instance.Nation01);
        Flag02.sprite2D = NationalSuits.getNationFlag(Game.Instance.Nation02);

        PlayerName01.text = NationalSuits.getNationNameShort(Game.Instance.Nation01);
        PlayerName02.text = NationalSuits.getNationNameShort(Game.Instance.Nation02);
        NationalSuit nationalSuit01 = NationalSuits.getSuitForNation(Game.Instance.Nation01);
        NationalSuit nationalSuit02 = NationalSuits.getSuitForNation(Game.Instance.Nation02);
        //LifeBarContent01.color = nationalSuit01.NationalColors.Jersey;
        //LifeBarContent02.color = nationalSuit02.NationalColors.Jersey;


        // SETUP PLAYERS
        {
            // set suit colors
            PlayerConfigurer.ConfigurePlayer(player01, nationalSuit01);
            PlayerConfigurer.ConfigurePlayer(player02, nationalSuit02);
            PlayerConfigurer.ConfigurePlayer(goalKeeper, NationalSuits.getGoalKeeperSuit());
            // create many copies

            PlayerShooter.Instance.SetupPlayers(player01, player02, goalKeeper);

            Destroy(player01);
            Destroy(player02);
            Destroy(goalKeeper);
        }
    }