Two different ways to do the same thing. The first one is faster but the second one looks more natural. Depends what your after.
sync on : sync rate 60
Hide Mouse
Type Unit
X as Float
Y as Float
Angle as Float
EndType
Player as Unit : Player.X = 50 : Player.Y = 50
Enemy as Unit : Enemy.X = 250 : Enemy.Y = 250 : Enemy.Angle=0
Global Algorithm as Integer : Algorithm=1
Do
Print "Press 1 and 2 to switch between following Functions"
Box Player.x-10,PLayer.y-10,PLayer.x+10,PLayer.y+10
Box Enemy.x-10,Enemy.y-10,Enemy.x+10,Enemy.y+10
If Upkey()=1 then Dec Player.Y
If DownKey()=1 then Inc Player.Y
If LeftKey()=1 then Dec Player.X
If RightKey()=1 then Inc Player.X
If keystate(2)=1 then Algorithm=1
If keystate(3)=1 then Algorithm=2
If Algorithm=1 then Follow1()
If Algorithm=2 then Follow2()
sync : cls
Loop
Function Follow1()
If Enemy.x<Player.x then Enemy.x=Enemy.x+0.4
If Enemy.x>Player.x then Enemy.x=Enemy.x-0.4
If Enemy.y<Player.y then Enemy.y=Enemy.y+0.4
If Enemy.y>Player.y then Enemy.y=Enemy.y-0.4
EndFunction
Function Follow2()
Local DistX as Float
Local DistY as Float
Local MoveX as Float
Local MoveY as Float
`Calculate the X and Y distance between the Two
DistX=PLayer.x-Enemy.x
DistY=Player.y-Enemy.y
`Calculate the angle the enemy has to face to point to the player
Enemy.Angle=(ATANFULL(DistY,DistX))
`Calculate the distance to move the enemy
MoveX = Cos(Enemy.Angle) * 0.4
MoveY = Sin(Enemy.Angle) * 0.4
`Move the enemy towards the player
Enemy.x = Enemy.x + MoveX
Enemy.y = Enemy.y + MoveY
EndFunction
Better to be dead, than to live your life afraid.