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); }
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); }
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; } } }
public void SetBlock(uint x, uint y, WorldBlock block) => _blocks[x][y] = block;