Class: RubyFighter::Controls
- Inherits:
-
Object
- Object
- RubyFighter::Controls
- Defined in:
- lib/ruby_fighter/controls.rb
Constant Summary collapse
- PLAYER1 =
{ 'a' => :left, 'd' => :right, 'q' => :block, 'e' => :punch, 'r' => :kick }
- PLAYER2 =
{ 'k' => :left, ';' => :right, 'i' => :block, 'p' => :punch, '[' => :kick }
Instance Method Summary collapse
- #button_down(key) ⇒ Object
- #button_up(key) ⇒ Object
-
#initialize(window, player, num) ⇒ Controls
constructor
A new instance of Controls.
- #update(left, right) ⇒ Object
Constructor Details
Instance Method Details
#button_down(key) ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/ruby_fighter/controls.rb', line 33 def (key) case @keys[key] when :left, :right then @player.walking! when :block then @player.blocking! when :punch then @player.punch! when :kick then @player.kick! end end |
#button_up(key) ⇒ Object
42 43 44 |
# File 'lib/ruby_fighter/controls.rb', line 42 def (key) @player.idle! end |
#update(left, right) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ruby_fighter/controls.rb', line 26 def update(left, right) case matching_action when :left then @player.move_left if @player.left > left when :right then @player.move_right if @player.right < right end end |