#define scr_rotWandering // Move rot around randomly but do not allow them to walk through obstacles { if(!place_snapped(4, 4)) exit; // Take point at four directions and see if collision or if outside room up = place_free(x, y-22); left = place_free(x-22, y); right = place_free(x+22, y); down = place_free(x, y+22) && y + 22 < room_height - 100; // All collision detection at +/- 16 (to get out of sprite) +/- 6 if(vspeed == 0) { // Rot moving horizontally only if(hspeed > 0) { // Rot moving right so should not go left unless at dead end if(!right && !up && !down) { // Can't go forward, up or down so must go left direction += 180; // Turn around exit; } while (true) { if(right && random(3) < 1) // Clear in front so keep moving exit; if(up && random(3) < 1) { // Clear up so turn upwards direction = 90; exit; } if(down && random(3) < 1) { // Clear to down so turn downwards direction = 270; exit; } } } if(hspeed < 0) { // Rot moving left so should not go right unless at dead end if(!left && !up && !down) { // Can't go forward, up or down so must go right direction += 180; // Turn around exit; } while (true) { if(left && random(3) < 1) // Clear in front so keep moving exit; if(up && random(3) < 1) { // Clear up so turn upwards direction = 90; exit; } if(down && random(3) < 1) { // Clear down so turn downwards direction = 270; exit; } } } } else { // Rot moving vertically only if(vspeed > 0) { // Rot moving down so should not go up unless at dead end if(!down && !right && !left) { // Can't go forward, right or left so must go up direction += 180; // Turn around exit; } while (true) { if(down && random(3) < 1) // Clear in front so keep moving exit; if(right && random(3) < 1) { // Clear to right so turn right direction = 0; exit; } if(left && random(3) < 1) { // Clear left so turn left direction = 180; exit; } } } if(vspeed < 0) { // Rot moving up so should not go down unless at dead end if(!up && !right && !left) { // Can't go forward, right or left so must go down direction += 180; // Turn around exit; } while (true) { if(up && random(3) < 1) // Clear in front so keep moving exit; if(right && random(3) < 1) { // Clear to right so turn right direction = 0; exit; } if(left && random(3) < 1) { // Clear to left so turn left direction = 180; exit; } } } } }