Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def blocked_passage?
- # Retorna falso se o jogador e o alvo estiverem nas
- #mesmas coordenadas x e y, pois, nesta versão do Ruby,
- #o atan2 retorna um erro
- return false if pos?(@target.x, @target.y)
- radians = Math.atan2(@target.x - @x, @target.y - @y)
- speed_x = Math.sin(radians)
- speed_y = Math.cos(radians)
- range_x = (@target.x - @x).abs
- range_y = (@target.y - @y).abs
- direction = projectile_direction
- result = false
- x = @x
- y = @y
- while true
- # Soma valores decimais
- x += speed_x
- y += speed_y
- x2 = x.to_i
- y2 = y.to_i
- if distance_x_from(x2).abs > range_x || distance_y_from(y2).abs > range_y
- break
- elsif !$game_map.valid?(x2, y2) || !map_passable?(x2, y2, direction)
- result = true
- break
- end
- end
- result
- end
- def projectile_direction
- sx = distance_x_from(@target.x)
- sy = distance_y_from(@target.y)
- if sx.abs > sy.abs
- direction = sx > 0 ? 4 : 6
- elsif sy != 0
- direction = sy > 0 ? 8 : 2
- end
- direction
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement