Class: Engine::Input

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

Class Method Summary collapse

Class Method Details

._on_key_down(key) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/engine/input.rb', line 17

def self._on_key_down(key)
  keys[key] = :down
  if key == GLFW::KEY_ESCAPE
    Engine.close
  end

  if key == GLFW::KEY_BACKSPACE
    Engine::Debugging.breakpoint { binding.pry }
    # Engine.breakpoint { debugger }
  end

  if key == GLFW::KEY_F
    Engine::Window.toggle_full_screen
  end
end

._on_key_up(key) ⇒ Object



33
34
35
# File 'lib/engine/input.rb', line 33

def self._on_key_up(key)
  keys[key] = :up
end

.key?(key) ⇒ Boolean

Returns:

  • (Boolean)


5
6
7
# File 'lib/engine/input.rb', line 5

def self.key?(key)
  keys[key] == :down || keys[key] == :held
end

.key_callback(key, action) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/engine/input.rb', line 37

def self.key_callback(key, action)
  if action == GLFW::PRESS
    _on_key_down(key)
  elsif action == GLFW::RELEASE
    _on_key_up(key)
  end
end

.key_down?(key) ⇒ Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/engine/input.rb', line 9

def self.key_down?(key)
  keys[key] == :down
end

.key_up?(key) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/engine/input.rb', line 13

def self.key_up?(key)
  keys[key] == :up
end

.update_key_statesObject



45
46
47
48
49
50
51
52
53
# File 'lib/engine/input.rb', line 45

def self.update_key_states
  keys.each do |key, state|
    if state == :down
      keys[key] = :held
    elsif state == :up
      keys.delete(key)
    end
  end
end