Ejemplo n.º 1
0
    private void Start()
    {
        if (instance != null)
        {
            Destroy(this);
            return;
        }

        instance = this;

        snakeJ1 = GameObject.Find("Snake J1").GetComponent <Snake>();
        snakeJ2 = GameObject.Find("Snake J2").GetComponent <Snake>();

        CameraMovement cameraMovement = FindObjectOfType <CameraMovement>();

        caseStartJ1 = cameraMovement.currentBiome.caseStartJ1;
        caseStartJ2 = cameraMovement.currentBiome.caseStartJ2;

        snakeJ1.body.Add(caseStartJ1);
        snakeJ1.bodyDirections.Add(Direction.Condition.Up);

        if (PlayerPrefs.GetInt("NbJoueurs") == 2)
        {
            snakeJ2.body.Add(caseStartJ2);
            snakeJ2.bodyDirections.Add(Direction.Condition.Up);
        }

        caseStartJ1.ChangerCaseConfiguration();

        if (PlayerPrefs.GetInt("NbJoueurs") == 2)
        {
            caseStartJ2.ChangerCaseConfiguration();
        }

        snakeJ1.SetupSnake();

        if (PlayerPrefs.GetInt("NbJoueurs") == 2)
        {
            snakeJ2.SetupSnake();
        }

        if (PlayerPrefs.GetInt("NbJoueurs") != 2)
        {
            Destroy(snakeJ2.gameObject);
            Destroy(caseStartJ2.gameObject);
        }


        cameraMovement.currentBiome.caseStartJ1 = null;
        cameraMovement.currentBiome.caseStartJ2 = null;
    }
Ejemplo n.º 2
0
    private void GoToNextCase(Case head, Direction.Condition directionDuMouvement)
    {
        Case nextCase = GetNextCase(head.pos, directionDuMouvement);

        if (GetNextCase(head.pos, directionDuMouvement) != null)
        {
            if ((nextCase.caseType == Case.CaseType.Obstacle && !isInvincible) ||
                nextCase.caseType == Case.CaseType.LimiteTerrain ||
                (nextCase.caseType == Case.CaseType.Snake && !isInvincible) ||
                (nextCase.caseType == Case.CaseType.SnakeHead && !isInvincible) ||
                isBeyondCamera)
            {
                print((isBeyondCamera) ? "hors champ" : "obstacle");
                isDead = true;
                ScoreManager.instance.KillPlayer(id);
            }
            else if (nextCase.caseType == Case.CaseType.Gélule)
            {
                //AvancerUneCase(directionDuMouvement);
                AvancerUneCase(bodyDirections[0]);
                AjouterNouvelleCaseAuCorps(bodyDirections[bodyDirections.Count - 1]);
                ScoreManager.instance.AddPoint(id);

                nextCase.caseType = Case.CaseType.TerrainNavigable;
                nextCase.GetComponent <SpriteRenderer>().sprite = null;
                nextCase.ChangerCaseConfiguration();
            }
            else
            {
                print("j'avance");
                AvancerUneCase(directionDuMouvement);
            }
        }
        else
        {
            print("est dans un chunk désactivé");
            isDead = true;
            ScoreManager.instance.KillPlayer(id);
        }
    }