Module: DXRubyRP5::Input

Defined in:
lib/dxruby_rp5/input.rb

Class Method Summary collapse

Class Method Details

.key_down?(key_code) ⇒ Boolean Also known as: keyDown?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


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?

Returns:

  • (Boolean)


78
79
80
81
82
83
84
# File 'lib/dxruby_rp5/input.rb', line 78

def mouse_down?(button)
  if @pressed_mbuttons
    return @pressed_mbuttons.include?(button)
  else
    return rp5_mouse_down?(button)
  end
end

.mouse_pos_xObject 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_yObject 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?

Returns:

  • (Boolean)


86
87
88
89
90
91
92
# File 'lib/dxruby_rp5/input.rb', line 86

def mouse_push?(button)
  if @pushed_mbuttons
    return @pushed_mbuttons.include?(button)
  else
    return rp5_mouse_down?(button)
  end
end

.pad_down?(button_code, pad_number = 0) ⇒ Boolean Also known as: padDown?

TODO: support pad_number

Returns:

  • (Boolean)


95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/dxruby_rp5/input.rb', line 95

def pad_down?(button_code, pad_number = 0)
  if button_code == P_BUTTON0 && key_down?(K_Z) ||
      button_code == P_BUTTON1 && key_down?(K_X) ||
      button_code == P_BUTTON2 && key_down?(K_C) ||
      button_code == P_LEFT && key_down?(K_LEFT) ||
      button_code == P_RIGHT && key_down?(K_RIGHT) ||
      button_code == P_UP && key_down?(K_UP) ||
      button_code == P_DOWN && key_down?(K_DOWN) ||
      rp5_pad_pressed?(button_code)
    return true
  end
  return false
end

.pad_push?(button_code, pad_number = 0) ⇒ Boolean Also known as: padPush?

TODO: support pad_number

Returns:

  • (Boolean)


110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/dxruby_rp5/input.rb', line 110

def pad_push?(button_code, pad_number = 0)
  if button_code == P_BUTTON0 && key_push?(K_Z) ||
      button_code == P_BUTTON1 && key_push?(K_X) ||
      button_code == P_BUTTON2 && key_push?(K_C) ||
      button_code == P_LEFT && key_push?(K_LEFT) ||
      button_code == P_RIGHT && key_push?(K_RIGHT) ||
      button_code == P_UP && key_push?(K_UP) ||
      button_code == P_DOWN && key_push?(K_DOWN) ||
      rp5_pad_pushed?(button_code)
    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 = rp5_pad_slider_value(: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 = rp5_pad_slider_value(: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