samples/13_path_finding_algorithms/09_tower_defense/app/main.rb
# Moves object to target at speed
Moves object to target at speed
Moves object to target at speed
def move object, target, speed = 1
  if target.is_a? Hash
    object[:x] += copy_sign(speed, target[:x] - object[:x])
    object[:y] += copy_sign(speed, target[:y] - object[:y])
  else
    object[:x] += copy_sign(speed, target.x - object[:x])
    object[:y] += copy_sign(speed, target.y - object[:y])
  end
end
def move object , target , speed = 1 if target . is_a? Hash object [ :x ] += copy_sign ( speed , target [ :x ] - object [ :x ] ) object [ :y ] += copy_sign ( speed , target [ :y ] - object [ :y ] ) else object [ :x ] += copy_sign ( speed , target . x - object [ :x ] ) object [ :y ] += copy_sign ( speed , target . y - object [ :y ] ) end end
Moves object to target at speed
Moves object to target at speed
object
target
speed