samples/04_physics_and_collisions/05_box_collision_2/app/main.rb
def process_inputs_place_tile
    if inputs.mouse.down # if mouse is pressed
      state.world_lookup = {}
      x, y = to_coord inputs.mouse.down.point # gets x, y coordinates for the grid

      # Checks if any coordinates duplicate (already exist in world)
      if state.world.any? { |existing_x, existing_y, n| existing_x == x && existing_y == y }
        #erases existing tile space by rejecting them from world
        state.world = state.world.reject do |existing_x, existing_y, n|
          existing_x == x && existing_y == y
        end
      else
        state.world << [x, y, state.sprite_selected] # If no duplicates, add the sprite
      end
    end
  end
# Adds tile in the place the user holds down the mouse
Adds tile in the place the user holds down the mouse
Adds tile in the place the user holds down the mouse
def process_inputs_place_tile
    if inputs.mouse.down 
      state.world_lookup = {}
      x, y = to_coord inputs.mouse.down.point 
      if state.world.any? { |existing_x, existing_y, n| existing_x == x && existing_y == y }
        state.world = state.world.reject do |existing_x, existing_y, n|
          existing_x == x && existing_y == y
        end
      else
        state.world << [x, y, state.sprite_selected] 
      end
    end
  end
def process_inputs_place_tile if inputs . mouse . down state . world_lookup = { } x , y = to_coord inputs . mouse . down . point if state . world . any? { | existing_x , existing_y , n | existing_x == x && existing_y == y } state . world = state . world . reject do | existing_x , existing_y , n | existing_x == x && existing_y == y end else state . world << [ x , y , state . sprite_selected ] end end end
Adds tile in the place the user holds down the mouse
Adds tile in the place the user holds down the mouse
# if mouse is pressed # gets x, y coordinates for the grid # Checks if any coordinates duplicate (already exist in world) #erases existing tile space by rejecting them from world # If no duplicates, add the sprite