I have this two dimensional array of objects
private Cell[,] mapCells = new Cell[10, 10];
and I want to check if a key value pair with the coordinates x = m and y = n exists in my array.
I go for this
bool cellExists = index.x >= 0 && // check left
index.y >= 0 && // check bottom
index.x < mapCells.GetLength(0) && // check right
index.y < mapCells.GetLength(1); // check top
So with this bool I check if the cell would be on the map or outside.
Is there a more elegant way to check this?
EDIT:
When checking this I get a movement direction like
Vector2 dir = new Vector2(/* this can be
(0,1) // up
(0,-1) // down
(-1,0) // left
(1,0) // right
*/);
So I know which direction is given.
When I move right I don't need to check the left side I think.