Ejemplo n.º 1
0
    private Case GetNewCase(Vector2 pos, Direction.Condition newCaseDirection)
    {
        Vector2 nextPos  = pos;
        Case    nextCase = null;

        switch (newCaseDirection)
        {
        case Direction.Condition.Up:
            nextPos += Vector2.down * 0.6666667f;
            break;

        case Direction.Condition.Down:
            nextPos += Vector2.up * 0.6666667f;
            break;

        case Direction.Condition.Left:
            nextPos += Vector2.right * 0.6666667f;
            break;

        case Direction.Condition.Right:
            nextPos += Vector2.left * 0.6666667f;
            break;
        }

        //nextCase = Physics2D.OverlapPoint(nextPos).GetComponent<Case>();
        nextCase = ObjectPooler.instance.SpawnFromPool("CaseSnake", nextPos, Quaternion.identity).GetComponent <Case>();

        return(nextCase);
    }
Ejemplo n.º 2
0
    private Case GetNextCase(Vector2 pos, Direction.Condition newCaseDirection)
    {
        Vector2 nextPos  = pos;
        Case    nextCase = null;

        switch (newCaseDirection)
        {
        case Direction.Condition.Up:
            nextPos += Vector2.up * 0.6666667f;
            break;

        case Direction.Condition.Down:
            nextPos += Vector2.down * 0.6666667f;
            break;

        case Direction.Condition.Left:
            nextPos += Vector2.left * 0.6666667f;
            break;

        case Direction.Condition.Right:
            nextPos += Vector2.right * 0.6666667f;
            break;
        }
        posi = nextPos;
        //print(body[0].pos + " ; " + posi);
        //print(Physics2D.OverlapPoint(nextPos).GetComponent<Case>().caseType);
        if (Physics2D.OverlapPoint(nextPos))
        {
            nextCase = Physics2D.OverlapPoint(nextPos).GetComponent <Case>();
        }


        //print(nextCase);
        return(nextCase);
    }
Ejemplo n.º 3
0
    private void AvancerUneCase(Direction.Condition directionDuMouvement)
    {
        Case nouvelleCase = GetNextCase(body[0].pos, directionDuMouvement);


        Vector2 casePrécédente = body[0].pos;

        Direction.Condition directionPrécédente = bodyDirections[0];


        Vector2 casePrécédenteAvantTranslation;

        Direction.Condition directionPrécédenteAvantTranslation;


        body[0].transform.position = body[0].pos = nouvelleCase.pos;
        bodyDirections[0]          = directionDuMouvement;
        body[0].ChangerCaseConfiguration();

        for (int i = 1; i < body.Count; i++)
        {
            casePrécédenteAvantTranslation      = body[i].pos;
            directionPrécédenteAvantTranslation = bodyDirections[i];


            body[i].transform.position = body[i].pos = casePrécédente;
            bodyDirections[i]          = directionPrécédente;
            body[i].ChangerCaseConfiguration();

            casePrécédente      = casePrécédenteAvantTranslation;
            directionPrécédente = directionPrécédenteAvantTranslation;
        }
    }
Ejemplo n.º 4
0
    private Direction.Condition GetDirectionFromInput()
    {
        float horizontal = Input.GetAxisRaw("Joystick" + id + "Horizontal");
        float vertical   = Input.GetAxisRaw("Joystick" + id + "Vertical");

        float inputToUse = 0f;
        bool  useHorizontal;

        if (Mathf.Abs(horizontal) > Mathf.Abs(vertical))
        {
            inputToUse    = horizontal;
            useHorizontal = true;
        }
        else
        {
            inputToUse    = vertical;
            useHorizontal = false;
        }

        Direction.Condition nouvelleDirection = Direction.Condition.Up;

        if (Mathf.Approximately(inputToUse, 0f))
        {
            return(bodyDirections[0]);
        }
        else
        {
            switch (inputToUse)
            {
            case -1f:
                nouvelleDirection = (useHorizontal) ? Direction.Condition.Left : Direction.Condition.Down;
                break;

            case 1f:
                nouvelleDirection = (useHorizontal) ? Direction.Condition.Right : Direction.Condition.Up;
                break;

            default:
                return(bodyDirections[0]);
            }
        }

        switch (nouvelleDirection)
        {
        case Direction.Condition.Up:
            return((bodyDirections[0] == Direction.Condition.Down) ? bodyDirections[0] : nouvelleDirection);

        case Direction.Condition.Down:
            return((bodyDirections[0] == Direction.Condition.Up) ? bodyDirections[0] : nouvelleDirection);

        case Direction.Condition.Left:
            return((bodyDirections[0] == Direction.Condition.Right) ? bodyDirections[0] : nouvelleDirection);

        case Direction.Condition.Right:
            return((bodyDirections[0] == Direction.Condition.Left) ? bodyDirections[0] : nouvelleDirection);

        default:
            return(bodyDirections[0]);
        }
    }
Ejemplo n.º 5
0
    private void AjouterNouvelleCaseAuCorps(Direction.Condition newCaseDirection)
    {
        body.Add(GetNewCase(body[body.Count - 1].pos, newCaseDirection));

        body[body.Count - 1].caseType = Case.CaseType.Snake;
        body[body.Count - 1].ChangerCaseConfiguration();

        bodyDirections.Add(newCaseDirection);
    }
Ejemplo n.º 6
0
    public AnimName GetSnakeHeadConfiguration(Case @case)
    {
        bool  caseHasBeenFound = false;
        Snake joueur           = null;

        Direction.Condition orientationDeLaCase = Direction.Condition.Up;

        while (!caseHasBeenFound)
        {
            for (int i = 0; i < snakeJ1.body.Count; i++)
            {
                if (snakeJ1.body.Contains(@case))
                {
                    caseHasBeenFound    = true;
                    orientationDeLaCase = snakeJ1.bodyDirections[0];
                    joueur = snakeJ1;
                    break;
                }

                if (snakeJ2.body.Contains(@case))
                {
                    caseHasBeenFound    = true;
                    orientationDeLaCase = snakeJ2.bodyDirections[0];
                    joueur = snakeJ2;
                    break;
                }
            }
        }

        if (caseHasBeenFound)
        {
            //print(joueur.name);

            AnimName[] animsToUse = joueur.id == snakeJ1.id ? animationsJ1 : animationsJ2;


            switch (orientationDeLaCase)
            {
            case Direction.Condition.Up:
                return(animsToUse[0]);

            case Direction.Condition.Down:
                return(animsToUse[1]);

            case Direction.Condition.Left:
                return(animsToUse[2]);

            case Direction.Condition.Right:
                return(animsToUse[3]);
            }
        }


        Debug.LogError("Erreur : La configuration n'a pas été trouvée.");
        return(null);
    }
Ejemplo n.º 7
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);
        }
    }