Beispiel #1
0
    public bool MoveObject(GridObject obj, Vector2Int movement)
    {
        Vector2Int newPos = obj.position + movement;

        if (this.InBounds(newPos) && this.IsFreeTile(newPos))
        {
            tiles[obj.position.x, obj.position.y].GetComponent <GridTile>().Depopulate();
            tiles[obj.position.x + movement.x, obj.position.y + movement.y].GetComponent <GridTile>().Populate(obj);
            return(true);
        }
        else if (!this.InBounds(newPos))
        {
            obj.MovedOutOfBounds(newPos);
            return(false);
        }
        else if (this.TileByPos(newPos).accessible)
        {
            obj.BumpIntoObject(this.TileByPos(newPos).inhabitant);
            return(true);
        }
        return(false);
    }