Class: Badline::Joystick

Inherits:
Object
  • Object
show all
Defined in:
lib/badline/joystick.rb

Constant Summary collapse

DIRECTIONS =
{ up: 0, down: 1, left: 2, right: 3, fire: 4 }.freeze

Instance Method Summary collapse

Constructor Details

#initializeJoystick

Returns a new instance of Joystick.



7
8
9
# File 'lib/badline/joystick.rb', line 7

def initialize
  @pressed = {}
end

Instance Method Details

#port_bitsObject



19
20
21
22
23
# File 'lib/badline/joystick.rb', line 19

def port_bits
  bits = 0xff
  DIRECTIONS.each { |dir, bit| bits &= ~(1 << bit) if @pressed[dir] }
  bits
end

#press(direction) ⇒ Object



11
12
13
# File 'lib/badline/joystick.rb', line 11

def press(direction)
  @pressed[direction] = true if DIRECTIONS.key?(direction)
end

#release(direction) ⇒ Object



15
16
17
# File 'lib/badline/joystick.rb', line 15

def release(direction)
  @pressed.delete(direction)
end