Class: Kawaii::InputManager

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(game, bound_buttons = []) ⇒ InputManager

Returns a new instance of InputManager.



6
7
8
9
10
11
12
13
# File 'lib/kawaii/input_manager.rb', line 6

def initialize game, bound_buttons = []
	@game = game
	@buttons = []
	@bound_buttons = bound_buttons

	@old_mouse_x = 0.0
	@old_mouse_y = 0.0
end

Instance Attribute Details

#gameObject

Returns the value of attribute game.



4
5
6
# File 'lib/kawaii/input_manager.rb', line 4

def game
  @game
end

Instance Method Details

#bind(buttons = []) ⇒ Object



15
16
17
# File 'lib/kawaii/input_manager.rb', line 15

def bind buttons = []
	@bound_buttons = buttons
end

#button_clicked?(button) ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/kawaii/input_manager.rb', line 32

def button_clicked? button
	@buttons.include?(button) && !@game.button_down?(button)	
end

#button_down?(button) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/kawaii/input_manager.rb', line 28

def button_down? button
	@game.button_down?(button)	
end

#mouse_dif_xObject



48
49
50
# File 'lib/kawaii/input_manager.rb', line 48

def mouse_dif_x
	mouse_x - old_mouse_x
end

#mouse_dif_yObject



51
52
53
# File 'lib/kawaii/input_manager.rb', line 51

def mouse_dif_y
	mouse_y - old_mouse_y
end

#mouse_xObject



36
37
38
# File 'lib/kawaii/input_manager.rb', line 36

def mouse_x
	@game.mouse_x
end

#mouse_yObject



39
40
41
# File 'lib/kawaii/input_manager.rb', line 39

def mouse_y
	@game.mouse_y
end

#old_mouse_xObject



42
43
44
# File 'lib/kawaii/input_manager.rb', line 42

def old_mouse_x
	@old_mouse_x
end

#old_mouse_yObject



45
46
47
# File 'lib/kawaii/input_manager.rb', line 45

def old_mouse_y
	@old_mouse_y
end

#updateObject



19
20
21
22
23
24
25
26
# File 'lib/kawaii/input_manager.rb', line 19

def update
	@buttons.clear
	@bound_buttons.each do |btn|
		@buttons.push btn if button_down? btn
	end
	@old_mouse_x = mouse_x
	@old_mouse_y = mouse_y
end