BobMann wrote: So if you are only looking at a 9x9 area starting at (1,3) the server wont be trying to get data from the coordinates (45,63) or something like that.
This part confused me a bit. The example coordinates you gave were rather large, so are those in reference to the actual x and y coordinates of where they go on the screen (like the css values you would give the tiles to place them correctly on the map)? If so, the actual spatial coordinates of where you place them on the map should not even come into play anywhere near the database. That can easily be done when assembling the map on the page.
To clarify, when you say 9x9, do you mean the whole world? Or do you mean each single map on-screen is made of 9x9 tiles? Because if these are individual maps that are made-up of 9x9 tiles, and your game is made up of many of those maps, how are you going to know which map is which (the ID is unique for each tile and I am assuming the tile type says how to display the tile, which only leaves the x and y, which are needed to assemble the single map)? You would have to add 2 more columns, a GlobalX and a GlobalY column, in that case (this would essentially turn the X and Y coordinates you already have into
Local coordinates). Then your SQL query would pull all tiles with, for example, "WHERE GlobalX = 2 AND GlobalY = 4" for the world map at (2, 4). Then you would end up with an array of all of the 9x9 map tiles that make up the world map at coordinates (2,4), and you could then use the nested FOR loops mentioned above to actually put them into place on the screen.
To actually get each tile placed at the correct place, you would take the Local coordinates of each map tile, run them through a nested FOR loop, and inside the nested FOR loop, you would multiply their Local X and Y values by the dimensions of the tiles. For example, say your nested FOR loop is running, and the next tile up for that (2,4) map has Local coordinates of [5, 3]. That is, it is the 5th column 3rd row tile of this specific map. And say each tile is 64x64 pixels. That means the tile's Local X and Y values would be multiplied by 64, giving you "Left: 320px, Top: 192px" (assuming the map starts at 0,0, which is probably not the case meaning you would have to hardcode in offsets to get the map in the right place).
And then of course it would not be that hard to deal with players moving from map to map, since if they go North, you subtract 1 from the GlobalY, if they go East, you add one to GlobalX, etc., to get the correct world map.
That is a pretty simple map setup there, but yet is fairly flexible. It also allows you to get all the tiles for each map in only 1 query. Hope it helps!
