Advertisement
marlosgama

Untitled

Jul 17th, 2019
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.09 KB | None | 0 0
  1.   def blocked_passage?
  2.     # Retorna falso se o jogador e o alvo estiverem nas
  3.     #mesmas coordenadas x e y, pois, nesta versão do Ruby,
  4.     #o atan2 retorna um erro
  5.     return false if pos?(@target.x, @target.y)
  6.     radians = Math.atan2(@target.x - @x, @target.y - @y)
  7.     speed_x = Math.sin(radians)
  8.     speed_y = Math.cos(radians)
  9.     range_x = (@target.x - @x).abs
  10.     range_y = (@target.y - @y).abs
  11.     direction = projectile_direction
  12.     result = false
  13.     x = @x
  14.     y = @y
  15.     while true
  16.       # Soma valores decimais
  17.       x += speed_x
  18.       y += speed_y
  19.       x2 = x.to_i
  20.       y2 = y.to_i
  21.       if distance_x_from(x2).abs > range_x || distance_y_from(y2).abs > range_y
  22.         break
  23.       elsif !$game_map.valid?(x2, y2) || !map_passable?(x2, y2, direction)
  24.         result = true
  25.         break
  26.       end
  27.     end
  28.     result
  29.   end
  30.  
  31.   def projectile_direction
  32.     sx = distance_x_from(@target.x)
  33.     sy = distance_y_from(@target.y)
  34.     if sx.abs > sy.abs
  35.       direction = sx > 0 ? 4 : 6
  36.     elsif sy != 0
  37.       direction = sy > 0 ? 8 : 2
  38.     end
  39.     direction
  40.   end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement