<?


  $size
=41;
  
$nrd=8;

  @
$x=$_REQUEST['x']+0;
  @
$y=$_REQUEST['y']+0;
  @
$r=$_REQUEST['r']+0;
  
$r=round($r*8/360);
  
//echo $r;
  
    
function stepforward (&$x, &$y, $r) {
    switch (
$r) {
      case
0: $y++; break;
      case
1: $x++; $y++; break;
      case
2: $x++; break;
      case
3: $x++; $y--; break;
      case
4: $y--; break;
      case
5: $x--; $y--; break;
      case
6: $x--; break;
      case
7: $x--; $y++; break;
    }
  }

  @
$action=$_REQUEST['action'];
  if (
$x<1)
    
$x=1;
  if (
$y<1)
    
$y=1;
  

  if (!isset(
$x))
    
$x=1;
  if (!isset(
$y))
    
$y=1;
    
  if (
$action=='left')
    
$r--;
  if (
$action=='right')
    
$r++;
  if (
$r<0)
    
$r=$nrd-1;
  if (
$r>=$nrd)
    
$r=0;
  
$rr=$r*360/8;
  
$fx=$x;
  
$fy=$y;
  

  
  if (
$action=='forward') {
    
//step in right direction
    
stepforward ($x, $y, $r);
  };
  
  
$idx=1 + ($size*($x-1)+($y-1))*$nrd + $r;
  
$i="${idx}";
  while (
strlen($i)<4)
    
$i='0'.$i;
  
$img="/images/frame${i}.jpg";
  
  
$pos="&amp;x=${x}&amp;y=${y}&amp;r=${rr}";
  
  
$fx=$x; $fy=$y;
  
//echo "$fx $fy $r";
  
stepforward ($fx,$fy, $r);
  
//echo "<br>$fx $fy $r";
  
$idx=1 + ($size*($fx-1)+($fy-1))*$nrd + $r;
  
//echo "<br>$fx $fy $r $idx";

  
$i="${idx}";
  while (
strlen($i)<4)
    
$i='0'.$i;
  
$imgfwd="./images/frame${i}.jpg";
  
//echo $imgfwd;
  
if (file_exists($imgfwd))
    
$urlfwd="<a href=\"?action=forward${pos}\">forward</a>";
  else
    
$urlfwd='&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ';
  

?>
<html><head><title>Titan Walkround</title></head>
<body>
<a href="?action=left<?=$pos?>">left</a>
&nbsp;
<?=$urlfwd?>
&nbsp;
<a href="?action=right<?=$pos?>">right</a>
<br>
<img src="<?=$img?>">
</body>
</html>