Esempio n. 1
0
    private void ToEat()
    {
        justAte = true;
        eatedFoods++;

        //check eated foods to increase speed
        if (eatedFoods % 3 == 0)
        {
            movementTimeoutLevel = Mathf.Clamp(movementTimeoutLevel + 1, Constants.MIN_LEVEL, Constants.MAX_LEVEL);
            SetMovementTimeout(movementTimeoutLevel);
        }

        //get the last body and tail
        int       tailIndex     = snakeParts.Count - 1;
        int       lastBodyIndex = snakeParts.Count - 2;
        SnakePart tail          = snakeParts[tailIndex];
        SnakePart lastBody      = snakeParts[lastBodyIndex];

        //get position and rotation for new body part
        Vector2Int pos = Vector2Int.FloorToInt(lastBody.rb.position);
        Quaternion rot = lastBody.transform.rotation;

        //get directions for new body part
        ScriptableDirection from = snakeParts[tailIndex].currentDirection;
        ScriptableDirection to   = snakeParts[lastBodyIndex].currentDirection;

        //spawning and setting up the new body part
        SnakePart newPart = snakePool.Spawn <SnakePart> (pos, Quaternion.identity);

        newPart.currentDirection = from;
        newPart.UpdateSnakePart(pos, to, from);
        snakeParts.Insert(lastBodyIndex, newPart);
        onEetFood.Call();
    }
Esempio n. 2
0
	protected override void UpdateSnakeVisual (Vector2Int position, ScriptableDirection toDirection, ScriptableDirection fromDirection = null) {
		if (currentDirection != toDirection) {
			float angle = toDirection.Angle - Constants.SPRITES_ANGLE_OFFSET;
			//spriteRend.transform.rotation = Quaternion.Euler(Vector3.forward * angle);
			rb.MoveRotation(angle);
		}
	}
Esempio n. 3
0
    protected override void UpdateSnakeVisual(Vector2Int position, ScriptableDirection toDirection, ScriptableDirection fromDirection)
    {
        float angle;

        if (fromDirection == toDirection)
        {
            spriteRend.sprite = baseSprite;
            angle             = toDirection.Angle - Constants.SPRITES_ANGLE_OFFSET;
        }
        else
        {
            spriteRend.sprite = turnedSnakeSprite;
            angle             = GetTurnedSnakeAngle(fromDirection.Side, toDirection.Side);
        }
        //spriteRend.transform.rotation = Quaternion.Euler (Vector3.forward * angle);
        rb.MoveRotation(angle);
    }