2D arrays can actually be represented with a single 1D array.
Here’s how it works… you have width
and height
defined somewhere, then you’d create the array by multiplying these values arrayLength = width * height
.
Then, you would simply follow the indexing formula (width * row) + column
.
So, to set an element, you’d use array[width * row + col] = value
And to get an element you’d use value = array[width * row + col]