Class: Retrograph::Easy::ControllerManager
- Inherits:
-
Object
- Object
- Retrograph::Easy::ControllerManager
- Defined in:
- lib/retrograph/easy/controllers.rb
Constant Summary collapse
- KEYMAP =
{ SDL::Key::UP => :up, SDL::Key::DOWN => :down, SDL::Key::LEFT => :left, SDL::Key::RIGHT => :right, SDL::Key::LCTRL => :action, SDL::Key::RCTRL => :action, SDL::Key::SPACE => :fire, SDL::Key::LSHIFT => :select, SDL::Key::RSHIFT => :select, SDL::Key::TAB => :select, SDL::Key::RETURN => :menu, SDL::Key::W => :up, SDL::Key::S => :down, SDL::Key::D => :right, SDL::Key::A => :left, SDL::Key::Z => :action, SDL::Key::X => :fire, SDL::Key::L => :fire, SDL::Key::SEMICOLON => :action, SDL::Key::COLON => :action, SDL::Key::QUOTE => :select, SDL::Key::QUOTEDBL => :select, SDL::Key::PERIOD => :fire, SDL::Key::SLASH => :action, SDL::Key::KP0 => :select, SDL::Key::KP1 => :fire, SDL::Key::KP2 => :action, SDL::Key::KP3 => :select, SDL::Key::KP4 => :fire, SDL::Key::KP5 => :action, SDL::Key::KP6 => :select, SDL::Key::KP7 => :fire, SDL::Key::KP8 => :action, SDL::Key::KP9 => :select, SDL::Key::KP_DIVIDE => :fire, SDL::Key::KP_MULTIPLY => :action, SDL::Key::KP_MINUS => :select, SDL::Key::KP_PLUS => :menu, SDL::Key::KP_ENTER => :menu }
Instance Method Summary collapse
- #controllers ⇒ Object
-
#initialize ⇒ ControllerManager
constructor
A new instance of ControllerManager.
- #key_pressed(key) ⇒ Object
- #key_released(key) ⇒ Object
Constructor Details
#initialize ⇒ ControllerManager
Returns a new instance of ControllerManager.
132 133 134 135 136 |
# File 'lib/retrograph/easy/controllers.rb', line 132 def initialize @controllers = (0...2).map { Controller.new } @horizontal = @controllers.map { Rocker.new(-1, 0, 1) } @vertical = @controllers.map { Rocker.new(-1, 0, 1) } end |
Instance Method Details
#controllers ⇒ Object
138 139 140 |
# File 'lib/retrograph/easy/controllers.rb', line 138 def controllers @controllers.dup end |
#key_pressed(key) ⇒ Object
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/retrograph/easy/controllers.rb', line 142 def key_pressed(key) case KEYMAP[key] when :up @controllers[0].up_pressed = true @vertical[0].minus_pressed @controllers[0].vertical = @vertical[0].state when :down @controllers[0].down_pressed = true @vertical[0].plus_pressed @controllers[0].vertical = @vertical[0].state when :left @controllers[0].left_pressed = true @horizontal[0].minus_pressed @controllers[0].horizontal = @horizontal[0].state when :right @controllers[0].right_pressed = true @horizontal[0].plus_pressed @controllers[0].horizontal = @horizontal[0].state when :action @controllers[0].action_pressed = true when :fire @controllers[0].fire_pressed = true when :select @controllers[0].select_pressed = true when :menu @controllers[0]. = true end end |
#key_released(key) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/retrograph/easy/controllers.rb', line 171 def key_released(key) case KEYMAP[key] when :up @controllers[0].up_pressed = false @vertical[0].minus_released @controllers[0].vertical = @vertical[0].state when :down @controllers[0].down_pressed = false @vertical[0].plus_released @controllers[0].vertical = @vertical[0].state when :left @controllers[0].left_pressed = false @horizontal[0].minus_released @controllers[0].horizontal = @horizontal[0].state when :right @controllers[0].right_pressed = false @horizontal[0].plus_released @controllers[0].horizontal = @horizontal[0].state when :action @controllers[0].action_pressed = false when :fire @controllers[0].fire_pressed = false when :select @controllers[0].select_pressed = false when :menu @controllers[0]. = false end end |