Coordinates, Coordinates, Coordinates

Took me quite a while to write this block of code:

(Note: You will want to compare this chuck of code with the screenshot of yesterday’s source code – otherwise it wouldn’t make sense.)

do
{
   if (abs($id - $center) < = $r['sight']) {
      $ccx = $coordx + ($id - $center);
      $ccy = $coordy;
   }
   else 
   {
	$rowadj = ($id-$center)/$sight;
	$rowadj = round ($rowadj);
	$ccy = $coordy - $rowadj;
	$newid = $id - ($rowadj*$sight);
	$ccx = $coordx + ($newid - $center);
   }
   $cellcoord = $ccx.','.$ccy;
   $content[$id] = $id.'
('.$cellcoord.')'; .....

And the end result? Now we know the coordinates of each individual cell that is displayed on screen. This means that I can soon add in events as the character traverse the “world”.

Not the cleanest code, but it will serve its purpose for now. Awesome stuff. (:

Leave a Reply

Your email address will not be published. Required fields are marked *