Class: ProconBypassMan::AnalogStickPosition

Inherits:
Object
  • Object
show all
Defined in:
lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(x:, y:) ⇒ AnalogStickPosition

Returns a new instance of AnalogStickPosition.



4
5
6
7
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb', line 4

def initialize(x:, y:)
  @x = x.to_i
  @y = y.to_i
end

Instance Attribute Details

#xObject

Returns the value of attribute x.



2
3
4
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb', line 2

def x
  @x
end

#yObject

Returns the value of attribute y.



2
3
4
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb', line 2

def y
  @y
end

Instance Method Details

#to_binaryObject



9
10
11
12
13
14
15
16
17
# File 'lib/procon_bypass_man/procon/value_objects/analog_stick_position.rb', line 9

def to_binary
  analog_stick_data = [
    (@x & "0xff".to_i(16)),
    ((@y << 4) & "0xf0".to_i(16)) | ((@x >> 8) & "0x0f".to_i(16)),
    (@y >> 4) & "0xff".to_i(16),
  ]
  hex = analog_stick_data.map{ |x| x.to_s(16).rjust(2, "0") }.join
  [hex].pack("H*")
end