Exemple #1
0
        public void Setup()
        {
            char [,] tilemap = new char[10, 10]
            {
                { '.', '.', '.', '.', '.', '.', '.', '.', '.', '.' }, // 0
                { '.', '.', '.', '.', '#', '#', '#', '#', '#', '.' }, // 1
                { '.', '.', '.', '.', '#', '#', '#', '#', '.', '.' }, // 2
                { '.', '#', '#', '.', '#', '#', '.', '.', '.', '.' }, // 3
                { '.', '#', '#', '.', '#', '#', 'T', '.', '.', '.' }, // 4
                { '.', '#', '#', '.', '#', '#', '.', '.', '.', '.' }, // 5
                { '.', '#', '#', '.', '#', '#', '#', '#', '#', '#' }, // 6
                { '.', '.', '.', '.', '#', '#', '#', '#', '#', '.' }, // 7
                { '.', '.', '.', 'S', '#', '#', '#', '#', '#', '.' }, // 8
                { '.', '.', '.', '.', '.', '.', '.', '.', '.', '.' }, // 9
                // 0    1    2    3    4    5    6    7    8    9
            };

            grid   = new TilemapGrid(tilemap);
            start  = new TilemapCell(3, 8, 0);
            target = new TilemapCell(6, 4, 0);
        }
    public void SetNextPoint()
    {
        if (CurrentPath.Count <= 0)
        {
            return;
        }

        Vector2Int nextPoint = CurrentPath.Peek();

        if (CurrentPath.Count == 1 && !TilemapGrid.IsWalkable(nextPoint.x, nextPoint.y))
        {
            _player.Stats.ViewDirection = MoveDirection.FromNextPoint(new Vector2(nextPoint.x, nextPoint.y), _player);

            InvokeCollisionNotification(nextPoint);
            CurrentPath.Dequeue();
            return;
        }
        else
        {
            _character.Components.RealPosition.position = new Vector3(nextPoint.x, nextPoint.y, 0);
            CurrentPath.Dequeue();
        }
    }