samples/04_physics_and_collisions/05_box_collision_2/app/main.rb
def calc_edge_collision
    # Ensures that player doesn't fall below the map
    if next_y < 0 && state.dy < 0 # if player is moving down and is about to fall (next_y) below the map's scope
      state.y = 0 # 0 is the lowest the player can be while staying on the screen
      state.dy = 0
    # Ensures player doesn't go insanely high
    elsif next_y > 720 - state.tile_size && state.dy > 0 # if player is moving up, about to exceed map's scope
      state.y = 720 - state.tile_size # if we don't subtract tile_size, we won't be able to see the player on the screen
      state.dy = 0
    end

    # Ensures that player remains in the horizontal range its supposed to
    if state.x >= 1280 - state.tile_size && state.dx > 0 # if the player is moving too far right
      state.x = 1280 - state.tile_size # farthest right the player can be while remaining in the screen's scope
      state.dx = 0
    elsif state.x <= 0 && state.dx < 0 # if the player is moving too far left
      state.x = 0 # farthest left the player can be while remaining in the screen's scope
      state.dx = 0
    end
  end
# Makes sure the player remains within the screen's dimensions.
Makes sure the player remains within the screen's dimensions.
Makes sure the player remains within the screen ' s dimensions .
def calc_edge_collision
    if next_y < 0 && state.dy < 0 
      state.y = 0 
      state.dy = 0
    elsif next_y > 720 - state.tile_size && state.dy > 0 
      state.y = 720 - state.tile_size 
      state.dy = 0
    end
    if state.x >= 1280 - state.tile_size && state.dx > 0 
      state.x = 1280 - state.tile_size 
      state.dx = 0
    elsif state.x <= 0 && state.dx < 0 
      state.x = 0 
      state.dx = 0
    end
  end
def calc_edge_collision if next_y < 0 && state . dy < 0 state . y = 0 state . dy = 0 elsif next_y > 720 - state . tile_size && state . dy > 0 state . y = 720 - state . tile_size state . dy = 0 end if state . x >= 1280 - state . tile_size && state . dx > 0 state . x = 1280 - state . tile_size state . dx = 0 elsif state . x <= 0 && state . dx < 0 state . x = 0 state . dx = 0 end end
Makes sure the player remains within the screen's dimensions.
Makes sure the player remains within the screen ' s dimensions .
# Ensures that player doesn't fall below the map # if player is moving down and is about to fall (next_y) below the map's scope # 0 is the lowest the player can be while staying on the screen # Ensures player doesn't go insanely high # if player is moving up, about to exceed map's scope # if we don't subtract tile_size, we won't be able to see the player on the screen # Ensures that player remains in the horizontal range its supposed to # if the player is moving too far right # farthest right the player can be while remaining in the screen's scope # if the player is moving too far left # farthest left the player can be while remaining in the screen's scope