function carscript() { global $posx, $posy, $nextPosx, $nextPosy, $DIYleftWheel, $DIYrightWheel, $prevDIYLeftWheel, $direction, $curDirection; // Car logic for boundaries // Recalculate position if ($DIYleftWheel == 1 && $prevDIYLeftWheel != $DIYleftWheel) { recalculateCoordinates(); } $prevDIYLeftWheel = $DIYleftWheel; // we are still inside the boundary. Update posx and posy and execute normal logic. $posx = $nextPosx; $posy = $nextPosy; movementLogic(); }
function carscript() { global $posx, $posy, $nextPosx, $nextPosy, $DIYleftWheel, $DIYrightWheel, $prevDIYLeftWheel, $direction; // Car logic for boundaries // Recalculate position if ($DIYleftWheel == 1 && $prevDIYLeftWheel != $DIYleftWheel) { recalculateCoordinates(); } $prevDIYLeftWheel = $DIYleftWheel; if ($nextPosx < 0 || $nextPosx > BOUNDARY_X || $nextPosy < 0 || $nextPosy > BOUNDARY_Y) { // Out of boundary. Handle same as obstacle. echo "It has to stop and rotate" . $direction . "!!"; rotateLeft(160); $direction = $direction + 160; $carIsRunning = TRUE; movementLogic(); recalculateCoordinates(); echo "Rotated... in bounds again"; } else { // we are still inside the boundary. Update posx and posy and execute normal logic. $posx = $nextPosx; $posy = $nextPosy; movementLogic(); } var_dump($posx . ' ' . $posy . ' ' . $DIYleftWheel . ' ' . $prevDIYLeftWheel); }