Beispiel #1
0
        public bool TryGetBlock(uint x, uint y, out WorldBlock result)
        {
            if (x.InRange(0, Width) &&
                y.InRange(0, Height))
            {
                result = GetBlock(x, y);
                return(true);
            }

            result = default;
            return(false);
        }
Beispiel #2
0
        public bool TrySetBlock(uint x, uint y, WorldBlock block)
        {
            if (x.InRange(0, Width) &&
                y.InRange(0, Height))
            {
                if (GetBlock(x, y).Id != block.Id)
                {
                    SetBlock(x, y, block);
                }
                else
                {
                    return(false);
                }
                return(true);
            }

            return(false);
        }
Beispiel #3
0
        public World(uint width, uint height, WorldColor color)
        {
            Width  = width;
            Height = height;
            Color  = color;

            // jagged arrays are more performance then their [,] counterparts
            _blocks = new WorldBlock[width][];

            for (var x = 0; x < width; x++)
            {
                _blocks[x] = new WorldBlock[height];
                for (var y = 0; y < height; y++)
                {
                    var b = new WorldBlock();

                    _blocks[x][y] = b;
                }
            }
        }
Beispiel #4
0
 public void SetBlock(uint x, uint y, WorldBlock block) => _blocks[x][y] = block;