samples/13_path_finding_algorithms/08_a_star/app/main.rb
# When the user grabs the star and puts their cursor to the far right
# and moves up and down, the star is supposed to move along the grid as well
# Finding the cell closest to the mouse in the second grid helps with this
When the user grabs the star and puts their cursor to the far right
and moves up and down, the star is supposed to move along the grid as well
Finding the cell closest to the mouse in the second grid helps with this
When the user grabs the star and puts their cursor to the far right and moves up and down the star is supposed to move along the grid as well Finding the cell closest to the mouse in the second grid helps with this
def greedy_cell_closest_to_mouse
    x = (inputs.mouse.point.x / grid.cell_size).to_i
    y = (inputs.mouse.point.y / grid.cell_size).to_i
    x -= grid.width + 1
    x = 0 if x < 0
    y = 0 if y < 0
    x = grid.width - 1 if x > grid.width - 1
    y = grid.height - 1 if y > grid.height - 1
    [x, y]
  end
def greedy_cell_closest_to_mouse x = ( inputs . mouse . point . x / grid . cell_size ) . to_i y = ( inputs . mouse . point . y / grid . cell_size ) . to_i x -= grid . width + 1 x = 0 if x < 0 y = 0 if y < 0 x = grid . width - 1 if x > grid . width - 1 y = grid . height - 1 if y > grid . height - 1 [ x , y ] end
When the user grabs the star and puts their cursor to the far right
and moves up and down, the star is supposed to move along the grid as well
Finding the cell closest to the mouse in the second grid helps with this
When the user grabs the star and puts their cursor to the far right and moves up and down the star is supposed to move along the grid as well Finding the cell closest to the mouse in the second grid helps with this
# Closest cell grid to the mouse in the second # Translate the cell to the first grid # Bound x and y to the first grid # Return closest cell