Module: DXRubyRP5::Input
- Defined in:
- lib/dxruby_rp5/input.rb
Class Method Summary collapse
- .key_down?(key_code) ⇒ Boolean (also: keyDown?)
- .key_push?(key_code) ⇒ Boolean (also: keyPush?)
- .mouse_down?(button) ⇒ Boolean (also: mouseDown?)
- .mouse_pos_x ⇒ Object (also: mousePosX)
- .mouse_pos_y ⇒ Object (also: mousePosY)
- .mouse_push?(button) ⇒ Boolean (also: mousePush?)
-
.pad_down?(button_code, pad_number = 0) ⇒ Boolean
(also: padDown?)
TODO: support pad_number.
-
.pad_push?(button_code, pad_number = 0) ⇒ Boolean
(also: padPush?)
TODO: support pad_number.
- .set_repeat(wait, interval) ⇒ Object (also: setRepeat)
- .x(pad_number = 0) ⇒ Object
- .y(pad_number = 0) ⇒ Object
Class Method Details
.key_down?(key_code) ⇒ Boolean Also known as: keyDown?
62 63 64 65 66 67 68 |
# File 'lib/dxruby_rp5/input.rb', line 62 def key_down?(key_code) if @pressed_keys return @pressed_keys.include?(key_code) else return rp5_key_press?(to_rp5_key(key_code)) end end |
.key_push?(key_code) ⇒ Boolean Also known as: keyPush?
70 71 72 73 74 75 76 |
# File 'lib/dxruby_rp5/input.rb', line 70 def key_push?(key_code) if @pushed_keys return @pushed_keys.include?(key_code) else return rp5_key_press?(to_rp5_key(key_code)) end end |
.mouse_down?(button) ⇒ Boolean Also known as: mouseDown?
78 79 80 81 82 83 84 |
# File 'lib/dxruby_rp5/input.rb', line 78 def mouse_down?() if @pressed_mbuttons return @pressed_mbuttons.include?() else return rp5_mouse_down?() end end |
.mouse_pos_x ⇒ Object Also known as: mousePosX
54 55 56 |
# File 'lib/dxruby_rp5/input.rb', line 54 def mouse_pos_x return $app.mouse_x end |
.mouse_pos_y ⇒ Object Also known as: mousePosY
58 59 60 |
# File 'lib/dxruby_rp5/input.rb', line 58 def mouse_pos_y return $app.mouse_y end |
.mouse_push?(button) ⇒ Boolean Also known as: mousePush?
86 87 88 89 90 91 92 |
# File 'lib/dxruby_rp5/input.rb', line 86 def mouse_push?() if @pushed_mbuttons return @pushed_mbuttons.include?() else return rp5_mouse_down?() end end |
.pad_down?(button_code, pad_number = 0) ⇒ Boolean Also known as: padDown?
TODO: support pad_number
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/dxruby_rp5/input.rb', line 95 def pad_down?(, pad_number = 0) if == P_BUTTON0 && key_down?(K_Z) || == P_BUTTON1 && key_down?(K_X) || == P_BUTTON2 && key_down?(K_C) || == P_LEFT && key_down?(K_LEFT) || == P_RIGHT && key_down?(K_RIGHT) || == P_UP && key_down?(K_UP) || == P_DOWN && key_down?(K_DOWN) || rp5_pad_pressed?() return true end return false end |
.pad_push?(button_code, pad_number = 0) ⇒ Boolean Also known as: padPush?
TODO: support pad_number
110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/dxruby_rp5/input.rb', line 110 def pad_push?(, pad_number = 0) if == P_BUTTON0 && key_push?(K_Z) || == P_BUTTON1 && key_push?(K_X) || == P_BUTTON2 && key_push?(K_C) || == P_LEFT && key_push?(K_LEFT) || == P_RIGHT && key_push?(K_RIGHT) || == P_UP && key_push?(K_UP) || == P_DOWN && key_push?(K_DOWN) || rp5_pad_pushed?() return true end return false end |
.set_repeat(wait, interval) ⇒ Object Also known as: setRepeat
6 7 8 9 10 11 12 13 14 |
# File 'lib/dxruby_rp5/input.rb', line 6 def set_repeat(wait, interval) if wait == 0 && interval == 0 @repeat_wait = nil @repeat_interval = nil else @repeat_wait = wait @repeat_interval = interval end end |
.x(pad_number = 0) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dxruby_rp5/input.rb', line 16 def x(pad_number = 0) res = 0 if @pressed_keys cond = lambda { |key| @pressed_keys.include?(to_dxruby_key(key)) } else cond = lambda { |key| rp5_key_press?(key) } end pad_val = (:x) if cond.call(Processing::App::LEFT) || pad_val < 0 res -= 1 end if cond.call(Processing::App::RIGHT) || pad_val > 0 res += 1 end return res end |
.y(pad_number = 0) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/dxruby_rp5/input.rb', line 35 def y(pad_number = 0) res = 0 if @pressed_keys cond = lambda { |key| @pressed_keys.include?(to_dxruby_key(key)) } else cond = lambda { |key| rp5_key_press?(key) } end pad_val = (:y) if cond.call(Processing::App::UP) || pad_val < 0 res -= 1 end if cond.call(Processing::App::DOWN) || pad_val > 0 res += 1 end return res end |