Here's a small diagram
O = Enemy
--> = Enemy's path
[] = block
This is how enemies walk around the block
---->O->
^ [][][][] |
| [][][][] | You get the idea.
| [][][][] |
| [][][][] |
| [][][][] V
| <------
Anyway, so I typed up some code:
{
//Make it so the enemy walks forward
if dire==0 x += 2 ;
if dire==1 y += 2 ;
if dire==2 x -= 2 ;
if dire==3 y -= 2 ;
//Check if there is an empty space in front of it
//and change the direction accordingly vvv
if dire==0 && place_free(x,y+1) { dire = 1 x -= 1 y += 1 } ;
if dire==1 && place_free(x-1,y) { dire = 2 y -= 2 x -= 1 } ;
if dire==2 && place_free(x,y-1) { dire = 3 x += 1 y -= 1 } ;
if dire==3 && place_free(x+1,y) { dire = 0 y += 1 x += 1 } ;
//Align the position around the edge of the platform ^^^
//Check if there is a wall in front of it
//and change the direction accordingly
if dire==0 && !place_free(x+2,y) {dire = 3} ;
if dire==1 && !place_free(x,y+2) {dire = 0} ;
if dire==2 && !place_free(x-2,y) {dire = 1} ;
if dire==3 && !place_free(x,y-2) {dire = 2} ;
//set the image_angle according to the direction
if dire==0 image_angle=0 ;
if dire==1 image_angle=-90 ;
if dire==2 image_angle=-180 ;
if dire==3 image_angle=-270 ;
}
However, this code makes it so the enemies fly away at the corner. I have tried changing how far the enemies align at the corners, the enemy speed, the distance for checking the floors and walls. Everything either doesn't help, or makes the problem different. By the way, this code is in the step event, and the only other event is the create which sets dire to 0.
Edited by snail man, 08 March 2012 - 09:16 PM.











