So I am struggling with some logic for collision detection in my game.
I have a grid of tiles(images), all representative of a value in a 2D array, so the location of tile N would be (column m, row n). Each tiles dimensions are set by (windowDimensions/numberOfTiles).
I have a moveable sprite, that is the same dimensions as the tile images, however, this sprite moves to (x,y) pixel locations (to move smoothly).
I am looking for suggestions to find the grid location of the moveable sprite using its (x,y) pixel coordinates in the window.
All suggestions welcome,
Regards,
Jack Hunt
Divide
xandybytileWidthandtileHeight, and then either take the floor or ceiling of the result (depending on what you want).