Class: Bestguigui::Input

Inherits:
Object
  • Object
show all
Defined in:
lib/bestguigui/input.rb

Overview

Associe des actions nommées à un ou plusieurs boutons (clavier, manette, souris — Gosu les identifie tous par le même type d'id, donc une manette se rajoute sans rien changer d'autre).

@keys = Bestguigui::Input.new(
up:    [Gosu::KB_UP, Gosu::KB_W],
down:  [Gosu::KB_DOWN, Gosu::KB_S],
left:  [Gosu::KB_LEFT, Gosu::KB_A],
right: [Gosu::KB_RIGHT, Gosu::KB_D]
)

@keys.down?(:up) # true si une des touches liées à :up est enfoncée

Instance Method Summary collapse

Constructor Details

#initialize(bindings) ⇒ Input

Returns a new instance of Input.



15
16
17
# File 'lib/bestguigui/input.rb', line 15

def initialize(bindings)
  @bindings = bindings
end

Instance Method Details

#down?(action) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/bestguigui/input.rb', line 19

def down?(action)
  (@bindings[action] || []).any? { |key| Gosu.button_down?(key) }
end