I'm rewriting a 2d tile based map creator program that I wrote a good while back. One of the features that I'm trying to implement is to know where your mouse is in relation to the map. Currently I have a point variable named currentLocation. This represents the tile that is visible at (0, 0) in relation to the map. So for example, if I have this matrix:
[00, 10, 20, 30, 40, 50]
[01, 11, 21, 31, 41, 51]
[02, 12, 22, 32, 42, 52]
[03, 13, 23, 33, 43, 53]
[04, 14, 24, 34, 43, 54]
And I move to the right one:
[10, 20, 30, 40, 50, 60]
[11, 21, 31, 41, 51, 61]
[12, 22, 32, 42, 52, 62]
[13, 23, 33, 43, 53, 63]
[14, 24, 34, 44, 53, 64]
My currentLocation variable after the move would be (1, 0).
What I've tried is this:
The reason I divide everything by 32 is because the tile size is 32x32. But what I accidentally wound up doing is just dividing the map into 32 pieces and making a redundant mess. How would I do what I'm wanting to do?
[00, 10, 20, 30, 40, 50]
[01, 11, 21, 31, 41, 51]
[02, 12, 22, 32, 42, 52]
[03, 13, 23, 33, 43, 53]
[04, 14, 24, 34, 43, 54]
And I move to the right one:
[10, 20, 30, 40, 50, 60]
[11, 21, 31, 41, 51, 61]
[12, 22, 32, 42, 52, 62]
[13, 23, 33, 43, 53, 63]
[14, 24, 34, 44, 53, 64]
My currentLocation variable after the move would be (1, 0).
What I've tried is this:
Code:
Private Function GetLocation(ByVal e As MouseEventArgs) As Point
'Get the size of the tiles there are in the visible area of the screen
'We do this by dividing the width or the height by the size of the tile's width or height
Dim tilesPerHeight As Double = Math.Floor(Me.Height + ToolStrip1.Bottom / 32)
Dim tilesPerWidth As Double = Math.Floor(Me.Width / 32)
'Get the current location of the mouse
Dim mouseLocation As Point = e.Location
'Get the tiles the mouse is currently on
'Do this by dividing the mouse location by the height or width of the tiles
Dim tempLocation As Point = New Point(CInt(Math.Ceiling(mouseLocation.X / tilesPerWidth)), CInt(Math.Ceiling(mouseLocation.Y / tilesPerHeight)))
Return tempLocation
End Function