samples/02_input_basics/04_mouse_rect_to_rect/app/main.rb
def tick args
  tick_instructions args, "Sample app shows how to determine if two rectangles intersect."
  x = 460

  args.outputs.labels << small_label(args, x, 3, "Click anywhere on the screen")
  # red_box = [460, 250, 355, 90, 170, 0, 0]
  # args.outputs.borders << red_box

  # args.state.box_collision_one and args.state.box_collision_two
  # Are given values of a solid when they should be rendered
  # They are stored in game so that they do not get reset every tick
  if args.inputs.mouse.click
    if !args.state.box_collision_one
      args.state.box_collision_one = { x: args.inputs.mouse.click.point.x - 25,
                                       y: args.inputs.mouse.click.point.y - 25,
                                       w: 125, h: 125,
                                       r: 180, g: 0, b: 0, a: 180 }
    elsif !args.state.box_collision_two
      args.state.box_collision_two = { x: args.inputs.mouse.click.point.x - 25,
                                       y: args.inputs.mouse.click.point.y - 25,
                                       w: 125, h: 125,
                                       r: 0, g: 0, b: 180, a: 180 }
    else
      args.state.box_collision_one = nil
      args.state.box_collision_two = nil
    end
  end

  if args.state.box_collision_one
    args.outputs.solids << args.state.box_collision_one
  end

  if args.state.box_collision_two
    args.outputs.solids << args.state.box_collision_two
  end

  if args.state.box_collision_one && args.state.box_collision_two
    if args.state.box_collision_one.intersect_rect? args.state.box_collision_two
      args.outputs.labels << small_label(args, x, 4, 'The boxes intersect.')
    else
      args.outputs.labels << small_label(args, x, 4, 'The boxes do not intersect.')
    end
  else
    args.outputs.labels << small_label(args, x, 4, '--')
  end
end
# Similarly, whether rects intersect can be found through
# rect1.intersect_rect? rect2
Similarly, whether rects intersect can be found through
rect1.intersect_rect. rect2
Similarly whether rects intersect can be found through rect1 . intersect_rect . rect2
def tick args
  tick_instructions args, "Sample app shows how to determine if two rectangles intersect."
  x = 460
  args.outputs.labels << small_label(args, x, 3, "Click anywhere on the screen")
  if args.inputs.mouse.click
    if !args.state.box_collision_one
      args.state.box_collision_one = { x: args.inputs.mouse.click.point.x - 25,
                                       y: args.inputs.mouse.click.point.y - 25,
                                       w: 125, h: 125,
                                       r: 180, g: 0, b: 0, a: 180 }
    elsif !args.state.box_collision_two
      args.state.box_collision_two = { x: args.inputs.mouse.click.point.x - 25,
                                       y: args.inputs.mouse.click.point.y - 25,
                                       w: 125, h: 125,
                                       r: 0, g: 0, b: 180, a: 180 }
    else
      args.state.box_collision_one = nil
      args.state.box_collision_two = nil
    end
  end
  if args.state.box_collision_one
    args.outputs.solids << args.state.box_collision_one
  end
  if args.state.box_collision_two
    args.outputs.solids << args.state.box_collision_two
  end
  if args.state.box_collision_one && args.state.box_collision_two
    if args.state.box_collision_one.intersect_rect? args.state.box_collision_two
      args.outputs.labels << small_label(args, x, 4, 'The boxes intersect.')
    else
      args.outputs.labels << small_label(args, x, 4, 'The boxes do not intersect.')
    end
  else
    args.outputs.labels << small_label(args, x, 4, '--')
  end
end
def tick args tick_instructions args , "Sample app shows how to determine if two rectangles intersect." x = 460 args . outputs . labels << small_label ( args , x , 3 , "Click anywhere on the screen" ) if args . inputs . mouse . click if ! args . state . box_collision_one args . state . box_collision_one = { x : args . inputs . mouse . click . point . x - 25 , y : args . inputs . mouse . click . point . y - 25 , w : 125 , h : 125 , r : 180 , g : 0 , b : 0 , a : 180 } elsif ! args . state . box_collision_two args . state . box_collision_two = { x : args . inputs . mouse . click . point . x - 25 , y : args . inputs . mouse . click . point . y - 25 , w : 125 , h : 125 , r : 0 , g : 0 , b : 180 , a : 180 } else args . state . box_collision_one = nil args . state . box_collision_two = nil end end if args . state . box_collision_one args . outputs . solids << args . state . box_collision_one end if args . state . box_collision_two args . outputs . solids << args . state . box_collision_two end if args . state . box_collision_one && args . state . box_collision_two if args . state . box_collision_one . intersect_rect? args . state . box_collision_two args . outputs . labels << small_label ( args , x , 4 , 'The boxes intersect.' ) else args . outputs . labels << small_label ( args , x , 4 , 'The boxes do not intersect.' ) end else args . outputs . labels << small_label ( args , x , 4 , '--' ) end end
Similarly, whether rects intersect can be found through
rect1.intersect_rect?
Similarly whether rects intersect can be found through rect1 . intersect_rect?
# red_box = [460, 250, 355, 90, 170, 0, 0] # args.outputs.borders << red_box # args.state.box_collision_one and args.state.box_collision_two # Are given values of a solid when they should be rendered # They are stored in game so that they do not get reset every tick
args