Class: RTanque::Bot::Sensors

Inherits:
Struct
  • Object
show all
Defined in:
lib/rtanque/bot/sensors.rb

Overview

Sensors provide input to the Brain about the current state of the Match

They are made available to Brain via Brain#sensors

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args, &block) ⇒ Sensors

Returns a new instance of Sensors.



17
18
19
20
21
# File 'lib/rtanque/bot/sensors.rb', line 17

def initialize(*args, &block)
  super(*args)
  block.call(self) if block
  self.freeze
end

Instance Attribute Details

#gun_energyFloat (readonly)

energy of cannon. if < 0, cannot fire

Returns:

  • (Float)

    the current value of gun_energy



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def gun_energy
  @gun_energy
end

#headingRTanque::Heading (readonly)

Returns the current value of heading.

Returns:



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def heading
  @heading
end

#healthFloat (readonly)

health of bot. if == 0, dead

Returns:

  • (Float)

    the current value of health



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def health
  @health
end

#positionRTanque::Point (readonly)

Returns the current value of position.

Returns:



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def position
  @position
end

#radarEnumerator (readonly)

enumerates all bots scanned by the radar, yielding Radar::Reflection

Returns:

  • (Enumerator)

    the current value of radar



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def radar
  @radar
end

#radar_headingRTanque::Heading (readonly)

Returns the current value of radar_heading.

Returns:



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def radar_heading
  @radar_heading
end

#speedFloat (readonly)

Returns the current value of speed.

Returns:

  • (Float)

    the current value of speed



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def speed
  @speed
end

#ticksInteger (readonly)

number of ticks, starts at 0

Returns:

  • (Integer)

    the current value of ticks



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def ticks
  @ticks
end

#turret_headingRTanque::Heading (readonly)

Returns the current value of turret_heading.

Returns:



16
17
18
# File 'lib/rtanque/bot/sensors.rb', line 16

def turret_heading
  @turret_heading
end

Instance Method Details

#button_down?(button_id) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
29
30
# File 'lib/rtanque/bot/sensors.rb', line 23

def button_down?(button_id)
  if self.class.const_defined?(:Gosu)
    button_id = Gosu::Window.char_to_button_id(button_id) unless button_id.kind_of?(Integer)
    @gui_window && @gui_window.button_down?(button_id)
  else
    false
  end
end

#gui_window=(gui_window) ⇒ Object



32
33
34
# File 'lib/rtanque/bot/sensors.rb', line 32

def gui_window=(gui_window)
  @gui_window = gui_window
end