I am currently working on a grid-based game map prototype. Each "tile" is 24px by 24px and the script draws out 31 x-based tiles and 21 y-based tiles for a total of 651 tiles on the screen.
The problem I'm having is that the way I have my script going, it's making a database call for every single tile that's drawn at every page refresh, meaning it's making 651 database calls to check what the tile is and the coordinates of the tile. To me this seems obscenely inefficient.
The x and y coordinates are stored in a session variable. When the user clicks one of the directional buttons below the map, it offsets the appropriate coordinate accordingly and redraws the map.
If I were to create a game based on the logic I'm using, and playing the number game let's hypothetically say I've got 100 players playing the game at any one time and they're all browsing through the map, I would have 65,100 database calls simultaneously. That can't be good for system resources.
I am not a noob when it comes to PHP/MySQL programming as I have created and launched a few different browser-based games, however, this is my first venture into generating a map and navigating around it.
The tile map can be viewed here:
http://fordserver.com/gamemap/
The actual code for this can be found here:
http://fordserver.com/gamemap/index.txt
Can anyone recommend a good way to get this running more smoothly? You'll notice that when using one of the directional buttons that the game can take quite awhile to generate the actual map, especially if you are just visiting it for the first time.
I've tried to think of different ways to use arrays and everything else, but really, the game needs to check the database for each individual tile as I plan to incorporate functions so that it shows where a specific user currently is, or a building, etc.
I appreciate any help I can get with this.
Ricky