mr_pablo Posted August 6, 2010 Share Posted August 6, 2010 Hey folks! I am looking to build a small adventure game in PHP and the key to this will be a 3x3 (or possibly bigger) grids of squares, with the user situated in the centre. I therefore need to be able to figure out the co-ords of the surrounding squares. Presumably I will need to define the size of the master grid, then using the co-ords of the current square (defined from a database containing the users location), calculate the co-ords for the surrounding 8 grid squares. Has anyone had any experience with this? Where should I start? (Maths isn't my strong point tbh, but I can pick things up quickly) Thanks in advance! EDIT - in case it wasn't too clear, the "world map" would be something like 1000x1000 squares, but the player can only see the 3x3 grid at there location. Quote Link to comment Share on other sites More sharing options...
xangelo Posted August 6, 2010 Share Posted August 6, 2010 The method I'm presenting can be fairly complex if you want it to be, but for the explanation I'm going to keep it simple and easily understood. The easiest way would be to create a pixel-based grid, say 10x10 to start with. Each pixel would correspond to a tile. This way you keep your map size down and aren't running to a database to pull this information. Plus, creating new maps will be a breeze. I'd say let certain colors represent certain areas. So for example lets take the following: light green: grass blue: water black: rock grey: anywhere you can walk Your map could be a randomization of any of these colors and would take up a small amount of space. You could store the map information (name,id) in a database and reference it based on your user location data. Load up the map and utilizing php GD we could first figure out the exact pixel that the user is on based on their location data (x,y). Then a 3x3 square around them would be as follows: +-----------+-----------+-----------+ | x-1,y+1 | x,y+1 | x+1,y+1 | +-----------+-----------+-----------+ | x-1,y | x,y | x+1,y | +-----------+-----------+-----------+ | x-1,y-1 | x,y-1 | x+1,y-1 | +-----------+-----------+-----------+ You simply grab the color at those pixels and translate them into the appropriate images (ie, if x-1,y-1 is black include an image of a rock). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.