Class: GTK::Controller

Inherits:
Object show all
Includes:
DirectionalInputHelperMethods
Defined in:
dragon/controller.rb,
dragon/keys.rb,
dragon/config.rb

Defined Under Namespace

Classes: Config, Keys

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DirectionalInputHelperMethods

#directional_vector, included, #left_right, #method_missing, #up_down

Constructor Details

#initializeController

Returns a new instance of Controller.


38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'dragon/controller.rb', line 38

def initialize
  @key_down = Controller::Keys.new
  @key_up   = Controller::Keys.new
  @key_held = Controller::Keys.new
  @left_analog_x_raw = 0
  @left_analog_y_raw = 0
  @left_analog_x_perc = 0
  @left_analog_y_perc = 0
  @right_analog_x_raw = 0
  @right_analog_y_raw = 0
  @right_analog_x_perc = 0
  @right_analog_y_perc = 0
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class GTK::DirectionalInputHelperMethods

Instance Attribute Details

#key_downController::Keys (readonly)

Access to keys that have been pressed down.

Returns:


13
14
15
# File 'dragon/controller.rb', line 13

def key_down
  @key_down
end

#key_heldController::Keys (readonly)

Access to keys that have been held down.

Returns:


25
26
27
# File 'dragon/controller.rb', line 25

def key_held
  @key_held
end

#key_upController::Keys (readonly)

Access to keys that have been released up.

Returns:


19
20
21
# File 'dragon/controller.rb', line 19

def key_up
  @key_up
end

#left_analog_x_percObject

Returns the value of attribute left_analog_x_perc


28
29
30
# File 'dragon/controller.rb', line 28

def left_analog_x_perc
  @left_analog_x_perc
end

#left_analog_x_rawObject

Returns the value of attribute left_analog_x_raw


28
29
30
# File 'dragon/controller.rb', line 28

def left_analog_x_raw
  @left_analog_x_raw
end

#left_analog_y_percObject

Returns the value of attribute left_analog_y_perc


28
29
30
# File 'dragon/controller.rb', line 28

def left_analog_y_perc
  @left_analog_y_perc
end

#left_analog_y_rawObject

Returns the value of attribute left_analog_y_raw


28
29
30
# File 'dragon/controller.rb', line 28

def left_analog_y_raw
  @left_analog_y_raw
end

#right_analog_x_percObject

Returns the value of attribute right_analog_x_perc


28
29
30
# File 'dragon/controller.rb', line 28

def right_analog_x_perc
  @right_analog_x_perc
end

#right_analog_x_rawObject

Returns the value of attribute right_analog_x_raw


28
29
30
# File 'dragon/controller.rb', line 28

def right_analog_x_raw
  @right_analog_x_raw
end

#right_analog_y_percObject

Returns the value of attribute right_analog_y_perc


28
29
30
# File 'dragon/controller.rb', line 28

def right_analog_y_perc
  @right_analog_y_perc
end

#right_analog_y_rawObject

Returns the value of attribute right_analog_y_raw


28
29
30
# File 'dragon/controller.rb', line 28

def right_analog_y_raw
  @right_analog_y_raw
end

Instance Method Details

#activate_down(key) ⇒ void

This method returns an undefined value.

Activates a key into the down position.

Parameters:

  • key (Symbol)

    The key to press down.


90
91
92
93
94
# File 'dragon/controller.rb', line 90

def activate_down(key)
  key_down.activate(key)
  key_held.deactivate(key)
  key_up.deactivate(key)
end

#activate_held(key) ⇒ void

This method returns an undefined value.

Activates a key into the held down position.

Parameters:

  • key (Symbol)

    The key to hold down.


101
102
103
104
105
# File 'dragon/controller.rb', line 101

def activate_held(key)
  key_down.deactivate(key)
  key_held.activate(key) unless key_held.send(key)
  key_up.deactivate(key)
end

#activate_up(key) ⇒ void

This method returns an undefined value.

Activates a key release into the up position.

Parameters:

  • key (Symbol)

    The key release up.


113
114
115
116
117
# File 'dragon/controller.rb', line 113

def activate_up(key)
  key_down.deactivate(key)
  key_held.deactivate(key)
  key_up.activate(key)
end

#clearvoid

This method returns an undefined value.

Clear all current key presses.


63
64
65
66
67
# File 'dragon/controller.rb', line 63

def clear
  @key_down.clear
  @key_up.clear
  @key_held.clear
end

#downObject


73
74
75
# File 'dragon/controller.rb', line 73

def down
  @key_up.down || @key_held.down
end

#leftObject


77
78
79
# File 'dragon/controller.rb', line 77

def left
  @key_up.left || @key_held.left
end

#rightObject


81
82
83
# File 'dragon/controller.rb', line 81

def right
  @key_up.right || @key_held.right
end

#serializeObject


52
53
54
55
56
57
58
# File 'dragon/controller.rb', line 52

def serialize
  {
    key_down: @key_down.serialize,
    key_held: @key_held.serialize,
    key_up:   @key_up.serialize
  }
end

#upObject


69
70
71
# File 'dragon/controller.rb', line 69

def up
  @key_up.up || @key_held.up
end