Skip to content

Instantly share code, notes, and snippets.

@LinuxDoku
Created July 2, 2010 16:08
Show Gist options
  • Save LinuxDoku/461561 to your computer and use it in GitHub Desktop.
Save LinuxDoku/461561 to your computer and use it in GitHub Desktop.
<?php
// coords
$destX = 22;
$destY = 10;
$actX = 70;
$actY = 12;
// 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>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment