Esempio n. 1
0
    public static void ConfigurePlayer(GameObject player, NationalSuit suit)
    {
        if (BackgroundChooser.isSpace)
        {
            player.GetComponent <Rigidbody2D>().gravityScale = 0f;
        }

        Transform[] bodyDecorations     = new Transform[5];
        Transform[] thighDecorations    = new Transform[5];
        Transform[] shoulderDecorations = new Transform[5];


        // foreach child change the sprite color
        foreach (Transform child in player.transform)
        {
            //child is your child transform
            switch (child.name)
            {
            // HEAD
            case NationalSuit.NM_HAIR:
                child.GetComponent <SpriteRenderer> ().color = NationalSuits.HAIR_COLOR;
                break;

            case NationalSuit.NM_MOUTH:
                child.GetComponent <SpriteRenderer> ().color = NationalSuits.MOUTH_COLOR;
                break;

            case NationalSuit.NM_EAR:
            case NationalSuit.NM_EYEBROWS:
            case NationalSuit.NM_NOSE:
                child.GetComponent <SpriteRenderer> ().color = NationalSuits.getSkinColor(suit.Nation, false);
                break;

            case NationalSuit.NM_HEAD:
            case NationalSuit.NM_NECK:
            case NationalSuit.NM_KNEE_UP_1:
            case NationalSuit.NM_KNEE_UP_2:
            case NationalSuit.NM_KNEE_MIDDLE_1:
            case NationalSuit.NM_KNEE_MIDDLE_2:
            case NationalSuit.NM_KNEE_DOWN_1:
            case NationalSuit.NM_KNEE_DOWN_2:
                child.GetComponent <SpriteRenderer> ().color = NationalSuits.getSkinColor(suit.Nation, true);
                break;

            case NationalSuit.NM_COLLAR:
                child.GetComponent <SpriteRenderer> ().color = suit.NationalColors.Collar;
                break;

            case NationalSuit.NM_THIGH_UP:
                child.GetComponent <SpriteRenderer> ().color = suit.NationalColors.Pants;
                break;

            case NationalSuit.NM_THIGH_DOWN_1:
                child.GetComponent <SpriteRenderer> ().color = suit.NationalColors.Pants;
                foreach (Transform child2 in child)
                {
                    switch (child2.name)
                    {
                    case NationalSuit.NM_THIGH_DC_1_1:
                        thighDecorations [0] = child2;
                        break;
                    }
                }
                break;

            case NationalSuit.NM_THIGH_DOWN_2:
                child.GetComponent <SpriteRenderer> ().color = suit.NationalColors.Pants;
                foreach (Transform child2 in child)
                {
                    switch (child2.name)
                    {
                    case NationalSuit.NM_THIGH_DC_1_2:
                        thighDecorations [1] = child2;
                        break;
                    }
                }
                break;

            // OTHER
            case NationalSuit.NM_BODY:
                child.GetComponent <SpriteRenderer> ().color = suit.NationalColors.Jersey;
                foreach (Transform child2 in child)
                {
                    switch (child2.name)
                    {
                    case NationalSuit.NM_BODY_DC_1:
                        bodyDecorations [0] = child2;
                        break;

                    case NationalSuit.NM_BODY_DC_2:
                        bodyDecorations [1] = child2;
                        break;

                    case NationalSuit.NM_BODY_DC_3:
                        bodyDecorations [2] = child2;
                        break;

                    case NationalSuit.NM_BODY_DC_4:
                        bodyDecorations [3] = child2;
                        break;

                    case NationalSuit.NM_BODY_DC_5:
                        bodyDecorations [4] = child2;
                        break;
                    }
                }
                break;

            case NationalSuit.NM_SHOULDER:
                child.GetComponent <SpriteRenderer> ().color = suit.NationalColors.Jersey;
                foreach (Transform child2 in child)
                {
                    switch (child2.name)
                    {
                    case NationalSuit.NM_SHOULDER_DC_1:
                        shoulderDecorations [0] = child2;
                        break;

                    case NationalSuit.NM_SHOULDER_DC_2:
                        shoulderDecorations [1] = child2;
                        break;

                    case NationalSuit.NM_SHOULDER_DC_3:
                        shoulderDecorations [2] = child2;
                        break;

                    case NationalSuit.NM_SHOULDER_DC_4:
                        shoulderDecorations [3] = child2;
                        break;

                    case NationalSuit.NM_SHOULDER_DC_5:
                        shoulderDecorations [4] = child2;
                        break;

                    case NationalSuit.NM_ELBOW_UP:
                    case NationalSuit.NM_ELBOW_MIDDLE:
                    case NationalSuit.NM_ELBOW_DOWN:
                        child2.GetComponent <SpriteRenderer> ().color = NationalSuits.getSkinColor(suit.Nation, true);
                        break;
                    }
                }
                break;
            }

            int  thighDecoration, bodyDecoration, shoulderDecoration;
            byte i;

            bodyDecoration     = NationalSuits.getDecorations(suit.Nation) [0];
            shoulderDecoration = NationalSuits.getDecorations(suit.Nation) [1];
            thighDecoration    = NationalSuits.getDecorations(suit.Nation) [2];



            // disable not selected decorations
            for (i = 0; i < thighDecorations.Length; i++)
            {
                if (thighDecorations [i] == null)
                {
                    continue;
                }

                if (thighDecoration == 0)
                {
                    thighDecorations [i].gameObject.SetActive(false);
                }
                else
                {
                    thighDecorations [i].gameObject.GetComponent <SpriteRenderer> ().color = suit.NationalColors.ThighDc;
                }
            }
            for (i = 0; i < bodyDecorations.Length; i++)
            {
                if (bodyDecorations [i] == null)
                {
                    continue;
                }

                if (i != bodyDecoration - 1)
                {
                    bodyDecorations [i].gameObject.SetActive(false);
                }
                else if (bodyDecoration == 5)
                {
                    // the fifth is the german decoration, we don't change color
                }
                else
                {
                    bodyDecorations [i].gameObject.GetComponent <SpriteRenderer> ().color = suit.NationalColors.BodyDc;
                }
            }
            for (i = 0; i < shoulderDecorations.Length; i++)
            {
                if (shoulderDecorations [i] == null)
                {
                    continue;
                }

                if (i != shoulderDecoration - 1)
                {
                    shoulderDecorations [i].gameObject.SetActive(false);
                }
                else
                {
                    shoulderDecorations [i].gameObject.GetComponent <SpriteRenderer> ().color = suit.NationalColors.ShoulderDc;
                }
            }
        }
    }
Esempio n. 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);
        }
    }