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)


60
61
62
63
64
65
66
# File 'lib/dxruby_rp5/input.rb', line 60

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)


68
69
70
71
72
73
74
# File 'lib/dxruby_rp5/input.rb', line 68

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)


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

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

.mouse_pos_xObject Also known as: mousePosX



52
53
54
# File 'lib/dxruby_rp5/input.rb', line 52

def mouse_pos_x
  return $app.mouse_x
end

.mouse_pos_yObject Also known as: mousePosY



56
57
58
# File 'lib/dxruby_rp5/input.rb', line 56

def mouse_pos_y
  return $app.mouse_y
end

.mouse_push?(button) ⇒ Boolean Also known as: mousePush?

Returns:

  • (Boolean)


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

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

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

TODO: support joystick

Returns:

  • (Boolean)


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

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)
    return true
  end
  return false
end

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

TODO: support joystick

Returns:

  • (Boolean)


107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/dxruby_rp5/input.rb', line 107

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)
    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
# 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

  if cond.call(Processing::App::LEFT)
    res -= 1
  end
  if cond.call(Processing::App::RIGHT)
    res += 1
  end
  return res
end

.y(pad_number = 0) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dxruby_rp5/input.rb', line 34

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

  if cond.call(Processing::App::UP)
    res -= 1
  end
  if cond.call(Processing::App::DOWN)
    res += 1
  end
  return res
end