SHARE
TWEET

Untitled

marlosgama Apr 14th, 2020 379 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def to_direction(start_x, start_y, target_x, target_y)
  2.   #radians = Math.atan2(target_x - start_x, target_y - start_y)
  3.   sx = start_x - target_x
  4.   sy = start_y - target_y
  5.   if sx != 0 && sy != 0
  6.     return sx > 0 ? 4 : 6, sy > 0 ? 8 : 2
  7.   elsif sx != 0
  8.     return sx > 0 ? 4 : 6
  9.   elsif sy != 0
  10.     return sy > 0 ? 8 : 2
  11.   end
  12. end
  13.  
  14. # cima (8)
  15. p to_direction(2, 1, 2, 0)
  16. # baixo (2)
  17. p to_direction(2, 1, 2, 3)
  18. # esquerda (4)
  19. p to_direction(2, 1, 0, 1)
  20. # direita (6)
  21. p to_direction(2, 1, 3, 1)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top