First off, you should be storing all the tiles in a normal square grid. This will make tasks like this a no-brainer. The only place your tiles should actually be diamond shaped is on screen. Any selections on screen utilize a screenToWorld(x,y)
function and any world drawing uses a worldToScreen(x,y)
function. Then you can easily take your two points from the selection rectangle and convert them both with screenToWorld(x,y)
, then simply use them to step through your 2D array collecting tiles that are valid for selection.
If you're not reworking your entire coordinate system, you should at least make it consistent. Your x
coordinates are shared by two adjacent tiles, while your y
tiles are not.
See how going in the x
direction it's red(5), red(5), blue(6), blue(6), red(7), red(7)? Then in the y direction it's blue(1), red(2), blue(3), red(4)?
This means it's very difficult to even iterate over the tiles in a consistent way.