Porl123 Posted August 14, 2008 Share Posted August 14, 2008 I'm trying to make a mini-game using php and mysql, which would be an 11 by 11 grid having the player bang in the center. One where you can click on the other surrounding squares to move your character's coordinates. I've seen this done on other websites but can't think for the life of me how I'd go about creating it. ??? I don't expect to be told personally how it's done because I know that's way too much work, but any of you guys know where I can read up on it? Links would be much appreciated thanks Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 14, 2008 Share Posted August 14, 2008 My initial question is this: is the movement of your character restricted within the 11x11 grid, or is this grid only the viewable area of a larger map in which your character need always remain at the center? The approach for the motion would be different in those two scenarios, but the grid idea would be the same... Basically, think of the grid as a multi-dimensional array (very like a battleship board), where you have an x and y coordinates. Then, you can build a simple class to manage the grid itself and even a GridPoint class if you wanted, to help manage the contents of each point on the grid. Something like this should at least get you started: <?php class Grid { /** * @var array $coords; */ protected $coords; /** * @param int $x width of the grid * @param int $y height of the grid */ public function __construct($x, $y) { $this->coords = array(); for ($i = 1; $i <= $x; $i++) { for ($j = 1; $j <= $y; $j++) { // Load the positions with an empty value to be filled. $this->coords[$i][$j] = NULL; } } } public function loadPoint($x, $y, $contents) { if (!isset($this->coords[$x][$y])) { throw new Exception('Invalid coordinates provided!'); } $this->coords[$x][$y] = $contents; } public function getPoint($x, $y) { if (!isset($this->coords[$x][$y])) { throw new Exception('Invalid coordinates provided!'); } return $this->coords[$x][$y]; } } ?> Hope this is at least a good start for you. Good luck! 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.