Skip to content

Instantly share code, notes, and snippets.

@LinuxDoku
Created July 6, 2010 11:00
Show Gist options
  • Save LinuxDoku/465251 to your computer and use it in GitHub Desktop.
Save LinuxDoku/465251 to your computer and use it in GitHub Desktop.
<?php
// coords
$destX = 1;
$destY = 1;
$actX = 5;
$actY = 7;
// now go to destination
while(($actX <= $destX || $actX >= $destX) && ($actY <= $destX || $actY >= $destY))
{
// calc X and Y
if($actX < $destX)
{
$actX++;
} elseif($actX > $destX)
{
$actX--;
}
if($actY < $destY)
{
$actY++;
} elseif($actY > $destY)
{
$actY--;
}
echo 'X: '.$actX.' Y: '.$actY.'<br>';
if($actX == $destX && $actY == $destY)
{
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment