Class: Conjuration::InputManager

Inherits:
Object
  • Object
show all
Defined in:
lib/conjuration/managers/input_manager.rb

Constant Summary collapse

LEFT_CLICK =
:left_click
RIGHT_CLICK =
:right_click
UP =
:up
LEFT =
:left
DOWN =
:down
RIGHT =
:right

Instance Method Summary collapse

Instance Method Details

#action_mapObject

Returns a hash of actions mapped to key bindings.

{ action => [key_id] }



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/conjuration/managers/input_manager.rb', line 24

def action_map
  @action_map ||= {
    LEFT_CLICK => [Gosu::MsLeft],
    RIGHT_CLICK => [Gosu::MsRight],

    UP => [Gosu::KbUp, Gosu::GpUp, Gosu::KB_W],
    LEFT => [Gosu::KbLeft, Gosu::GpLeft, Gosu::KB_A],
    DOWN => [Gosu::KbDown, Gosu::GpDown, Gosu::KB_S],
    RIGHT => [Gosu::KbRight, Gosu::GpRight, Gosu::KB_D]
  }
end

#button_down?(action) ⇒ Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/conjuration/managers/input_manager.rb', line 17

def button_down?(action)
  action_map[action]&.any? { |key_id| Gosu.button_down?(key_id) } || false
end

#input_mapObject

Returns a hash of key bindings mapped to actions.

{ key_id => action }



39
40
41
42
43
44
45
# File 'lib/conjuration/managers/input_manager.rb', line 39

def input_map
  @input_map ||= action_map.each_with_object({}) do |(action, key_ids), hash|
    key_ids.each do |key_id|
      hash[key_id] = action
    end
  end
end

#map_button(key_id) ⇒ Object



13
14
15
# File 'lib/conjuration/managers/input_manager.rb', line 13

def map_button(key_id)
  input_map[key_id]
end