class RubyFighter::Controls

Constants

PLAYER1
PLAYER2

Public Class Methods

new(window, player, num) click to toggle source
# File lib/ruby_fighter/controls.rb, line 20
def initialize(window, player, num)
  @window = window
  @player = player
  @keys   = [PLAYER1, PLAYER2][num-1]
end

Public Instance Methods

button_down(key) click to toggle source
# File lib/ruby_fighter/controls.rb, line 33
def button_down(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) click to toggle source
# File lib/ruby_fighter/controls.rb, line 42
def button_up(key)
  @player.idle!
end
update(left, right) click to toggle source
# 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

Private Instance Methods

matching_action() click to toggle source
# File lib/ruby_fighter/controls.rb, line 48
def matching_action
  @keys.each do |key, action|
    if @window.button_down? key
      return action
    end
  end
end