samples/04_physics_and_collisions/01_simple/app/main.rb
def position_moving_box args
  args.state.moving_box.x += args.state.moving_box_dx * args.state.moving_box_speed
  args.state.moving_box.y += args.state.moving_box_dy * args.state.moving_box_speed

  # 1280x720 are the virtual pixels you work with (essentially 720p).
  screen_width  = 1280
  screen_height = 720

  # Position of the box is denoted by the bottom left hand corner, in
  # that case, we have to subtract the width of the box so that it stays
  # in the scene (you can try deleting the subtraction to see how it
  # impacts the box's movement).
  if args.state.moving_box.x > screen_width - args.state.moving_box_size
    args.state.moving_box_dx = -1 # moves left
  elsif args.state.moving_box.x < 0
    args.state.moving_box_dx =  1 # moves right
  end

  # Here, we're making sure the moving box remains within the vertical scope of the screen
  if args.state.moving_box.y > screen_height - args.state.moving_box_size # if the box moves too high
    args.state.moving_box_dy = -1 # moves down
  elsif args.state.moving_box.y < 0 # if the box moves too low
    args.state.moving_box_dy =  1 # moves up
  end
end
# Changes the position of the moving box on the screen by multiplying the change in x (dx) and change in y (dy) by the speed,
# and adding it to the current position.
# dx and dy are positive if the box is moving right and up, respectively
# dx and dy are negative if the box is moving left and down, respectively
Changes the position of the moving box on the screen by multiplying the change in x (dx) and change in y (dy) by the speed,
and adding it to the current position.
dx and dy are positive if the box is moving right and up, respectively
dx and dy are negative if the box is moving left and down, respectively
Changes the position of the moving box on the screen by multiplying the change in x ( dx ) and change in y ( dy ) by the speed and adding it to the current position . dx and dy are positive if the box is moving right and up respectively dx and dy are negative if the box is moving left and down respectively
def position_moving_box args
  args.state.moving_box.x += args.state.moving_box_dx * args.state.moving_box_speed
  args.state.moving_box.y += args.state.moving_box_dy * args.state.moving_box_speed
  screen_width  = 1280
  screen_height = 720
  if args.state.moving_box.x > screen_width - args.state.moving_box_size
    args.state.moving_box_dx = -1 
  elsif args.state.moving_box.x < 0
    args.state.moving_box_dx =  1 
  end
  if args.state.moving_box.y > screen_height - args.state.moving_box_size 
    args.state.moving_box_dy = -1 
  elsif args.state.moving_box.y < 0 
    args.state.moving_box_dy =  1 
  end
end
def position_moving_box args args . state . moving_box . x += args . state . moving_box_dx * args . state . moving_box_speed args . state . moving_box . y += args . state . moving_box_dy * args . state . moving_box_speed screen_width = 1280 screen_height = 720 if args . state . moving_box . x > screen_width - args . state . moving_box_size args . state . moving_box_dx = - 1 elsif args . state . moving_box . x < 0 args . state . moving_box_dx = 1 end if args . state . moving_box . y > screen_height - args . state . moving_box_size args . state . moving_box_dy = - 1 elsif args . state . moving_box . y < 0 args . state . moving_box_dy = 1 end end
Changes the position of the moving box on the screen by multiplying the change in x (dx) and change in y (dy) by the speed,
and adding it to the current position.
Changes the position of the moving box on the screen by multiplying the change in x ( dx ) and change in y ( dy ) by the speed and adding it to the current position .
# 1280x720 are the virtual pixels you work with (essentially 720p). # Position of the box is denoted by the bottom left hand corner, in # that case, we have to subtract the width of the box so that it stays # in the scene (you can try deleting the subtraction to see how it # impacts the box's movement). # moves left # moves right # Here, we're making sure the moving box remains within the vertical scope of the screen # if the box moves too high # moves down # if the box moves too low # moves up
args