def toward_enemy(speed=1)
sx = self.x - @target.screen_x
sy = self.y - @target.screen_y
r = sx.abs + sy.abs
if r<=5
self.visible=false
return
end
s = 20 * speed
rx = [s * sx.abs / r,sx.abs].min
ry = [s * sy.abs / r,sy.abs].min
rx = sx > 0 ? -rx : rx
ry = sy > 0 ? -ry : ry
self.x+=rx
self.y+=ry
end
def toward_enemy(speed=1)
sx = self.x - @target.screen_x
sy = self.y - @target.screen_y
r = sx.abs + sy.abs
if r<=5
self.visible=false
return
end
s = 20 * speed
rx = [s * sx.abs / r,sx.abs].min
ry = [s * sy.abs / r,sy.abs].min
rx = sx > 0 ? -rx : rx
ry = sy > 0 ? -ry : ry
self.x+=rx
self.y+=ry
end