Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Created June 7, 2025 00:05
Show Gist options
  • Save amirrajan/b25661ea95b877e43a8498510ee3d691 to your computer and use it in GitHub Desktop.
Save amirrajan/b25661ea95b877e43a8498510ee3d691 to your computer and use it in GitHub Desktop.
two controllers, one game
class SharedKeyDown
attr :args
def inputs
@args.inputs
end
def start
inputs.controllers.any? { |c| c.key_down.start }
end
def r1
inputs.controllers.any? { |c| c.key_down.r1 }
end
def r2
inputs.controllers.any? { |c| c.key_down.r2 }
end
def a
inputs.controllers.any? { |c| c.key_down.a }
end
def b
inputs.controllers.any? { |c| c.key_down.b }
end
def select
inputs.controllers.any? { |c| c.key_down.select }
end
def left
inputs.controllers.any? { |c| c.key_down.left }
end
def right
inputs.controllers.any? { |c| c.key_down.right }
end
def up
inputs.controllers.any? { |c| c.key_down.up }
end
def down
inputs.controllers.any? { |c| c.key_down.down }
end
end
class SharedController
attr :args
def args= value
@args = value
@shared_key_down.args = value
end
def initialize
@shared_key_down = SharedKeyDown.new
end
def inputs
@args.inputs
end
def key_down
@shared_key_down
end
def left_analog_x_perc
inputs.controllers.map(&:left_analog_x_perc).sum
end
def r1
inputs.controllers.any? { |c| c.r1 }
end
def r2
inputs.controllers.any? { |c| c.r2 }
end
def l1
inputs.controllers.any? { |c| c.l1 }
end
def l2
inputs.controllers.any? { |c| c.l2 }
end
def a
inputs.controllers.any? { |c| c.a }
end
def b
inputs.controllers.any? { |c| c.b }
end
def select
inputs.controllers.any? { |c| c.select }
end
def left
inputs.controllers.any? { |c| c.left }
end
def right
inputs.controllers.any? { |c| c.right }
end
def left_right
inputs.controllers.map(&:left_right).sum
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment