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

      if state.world.any? { |loc| loc == [x, y] }  # checks if coordinates duplicate
        state.world = state.world.reject { |loc| loc == [x, y] }  # erases tile space
      else
        state.world << [x, y] # If no duplicates, adds to world collection
      end
    end

    # Sets dx to 0 if the player lets go of arrow keys.
    if inputs.keyboard.key_up.right
      state.dx = 0
    elsif inputs.keyboard.key_up.left
      state.dx = 0
    end

    # Sets dx to 3 in whatever direction the player chooses.
    if inputs.keyboard.key_held.right # if right key is pressed
      state.dx =  3
    elsif inputs.keyboard.key_held.left # if left key is pressed
      state.dx = -3
    end

    #Sets dy to 5 to make the player ~fly~ when they press the space bar
    if inputs.keyboard.key_held.space
      state.dy = 5
    end
  end
# Processes input from the user on the keyboard.
Processes input from the user on the keyboard.
Processes input from the user on the keyboard .
def process_inputs
    if inputs.mouse.down
      state.world_lookup = {}
      x, y = to_coord inputs.mouse.down.point  
      if state.world.any? { |loc| loc == [x, y] }  
        state.world = state.world.reject { |loc| loc == [x, y] }  
      else
        state.world << [x, y] 
      end
    end
    if inputs.keyboard.key_up.right
      state.dx = 0
    elsif inputs.keyboard.key_up.left
      state.dx = 0
    end
    if inputs.keyboard.key_held.right 
      state.dx =  3
    elsif inputs.keyboard.key_held.left 
      state.dx = -3
    end
    if inputs.keyboard.key_held.space
      state.dy = 5
    end
  end
def process_inputs if inputs . mouse . down state . world_lookup = { } x , y = to_coord inputs . mouse . down . point if state . world . any? { | loc | loc == [ x , y ] } state . world = state . world . reject { | loc | loc == [ x , y ] } else state . world << [ x , y ] end end if inputs . keyboard . key_up . right state . dx = 0 elsif inputs . keyboard . key_up . left state . dx = 0 end if inputs . keyboard . key_held . right state . dx = 3 elsif inputs . keyboard . key_held . left state . dx = - 3 end if inputs . keyboard . key_held . space state . dy = 5 end end
Processes input from the user on the keyboard.
Processes input from the user on the keyboard .
# gets x, y coordinates for the grid # checks if coordinates duplicate # erases tile space # If no duplicates, adds to world collection # Sets dx to 0 if the player lets go of arrow keys. # Sets dx to 3 in whatever direction the player chooses. # if right key is pressed # if left key is pressed #Sets dy to 5 to make the player ~fly~ when they press the space bar