Esempio n. 1
0
    public TileType GetTile(Vector2Int atLocation, TileDirection towards)
    {
        Vector2Int newLoc = atLocation + TileDirectionVec2.Get_V2I(towards);

        if (newLoc.x < 0 || newLoc.y < 0 || newLoc.x >= width || newLoc.y >= height)
        {
            return(TileType.NULL);
        }

        return(tiles[atLocation.x, atLocation.y]);
    }
Esempio n. 2
0
    private void HandleMoving()
    {
        Vector2 dir = TileDirectionVec2.Get_V2F(currentDirection);

        transform.position = (Vector2)transform.position + (dir * speed * Time.deltaTime);

        // check if we can go further

        Tile nextTile = levelManager.GetTile(coordinate, currentDirection);

        if (!MoveableTile(nextTile))
        {
            float distToNexTile = Vector2.Distance(transform.position, nextTile.coordinate);

            if (distToNexTile < 1f)
            {
                transform.position = new Vector3(coordinate.x, coordinate.y);
                OnBlocked?.Invoke(levelManager.GetTile(coordinate));
            }
        }
    }