Class: AGL::KB

Inherits:
Object
  • Object
show all
Defined in:
lib/minigl/global.rb

Overview

class JSHelper

Class Method Summary collapse

Class Method Details

.initializeObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/minigl/global.rb', line 43

def self.initialize
	@@keys = [
		Gosu::KbUp, Gosu::KbDown,
		Gosu::KbReturn, Gosu::KbEscape,
		Gosu::KbLeftControl, Gosu::KbRightControl,
		Gosu::KbA, Gosu::KbB, Gosu::KbC, Gosu::KbD, Gosu::KbE, Gosu::KbF,
		Gosu::KbG, Gosu::KbH, Gosu::KbI, Gosu::KbJ, Gosu::KbK, Gosu::KbL,
		Gosu::KbM, Gosu::KbN, Gosu::KbO, Gosu::KbP, Gosu::KbQ, Gosu::KbR,
		Gosu::KbS, Gosu::KbT, Gosu::KbU, Gosu::KbV, Gosu::KbW, Gosu::KbX,
		Gosu::KbY, Gosu::KbZ, Gosu::Kb1, Gosu::Kb2, Gosu::Kb3, Gosu::Kb4,
		Gosu::Kb5, Gosu::Kb6, Gosu::Kb7, Gosu::Kb8, Gosu::Kb9, Gosu::Kb0,
		Gosu::KbNumpad1, Gosu::KbNumpad2, Gosu::KbNumpad3, Gosu::KbNumpad4,
		Gosu::KbNumpad5, Gosu::KbNumpad6, Gosu::KbNumpad7, Gosu::KbNumpad8,
		Gosu::KbNumpad9, Gosu::KbNumpad0, Gosu::KbSpace, Gosu::KbBackspace,
		Gosu::KbDelete, Gosu::KbLeft, Gosu::KbRight, Gosu::KbHome,
		Gosu::KbEnd, Gosu::KbLeftShift, Gosu::KbRightShift,
		Gosu::KbBacktick, Gosu::KbMinus, Gosu::KbEqual, Gosu::KbBracketLeft,
		Gosu::KbBracketRight, Gosu::KbBackslash, Gosu::KbApostrophe,
		Gosu::KbComma, Gosu::KbPeriod, Gosu::KbSlash
	]
	@@down = []
	@@prev_down = []
	@@held_timer = {}
	@@held_interval = {}
end

.key_down?(key) ⇒ Boolean

Returns:

  • (Boolean)


100
101
102
# File 'lib/minigl/global.rb', line 100

def self.key_down? key
	@@down.index(key)
end

.key_held?(key) ⇒ Boolean

Returns:

  • (Boolean)


108
109
110
# File 'lib/minigl/global.rb', line 108

def self.key_held? key
	@@held_interval[key] == Game.kb_held_interval
end

.key_pressed?(key) ⇒ Boolean

Returns:

  • (Boolean)


96
97
98
# File 'lib/minigl/global.rb', line 96

def self.key_pressed? key
	@@prev_down.index(key).nil? and @@down.index(key)
end

.key_released?(key) ⇒ Boolean

Returns:

  • (Boolean)


104
105
106
# File 'lib/minigl/global.rb', line 104

def self.key_released? key
	@@prev_down.index(key) and @@down.index(key).nil?
end

.updateObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/minigl/global.rb', line 69

def self.update
	@@held_timer.each do |k, v|
		if v < Game.kb_held_delay; @@held_timer[k] += 1
		else
			@@held_interval[k] = 0
			@@held_timer.delete k
		end
	end
	
	@@held_interval.each do |k, v|
		if v < Game.kb_held_interval; @@held_interval[k] += 1
		else; @@held_interval[k] = 0; end
	end
	
	@@prev_down = @@down.clone
	@@down.clear
	@@keys.each do |k|
		if Game.window.button_down? k
			@@down << k
			@@held_timer[k] = 0 if @@prev_down.index(k).nil?
		elsif @@prev_down.index(k)
			@@held_timer.delete k
			@@held_interval.delete k
		end
	end
end