Class: Rubots::Graphics::Beam
- Inherits:
-
Object
- Object
- Rubots::Graphics::Beam
- Defined in:
- lib/rubots/graphics/beam.rb
Constant Summary collapse
- BEAM_LENGTH =
As long as it goes out of the screen it’s good
10000- BEAM_DURATION =
For how many ticks is the beam visible
30
Instance Method Summary collapse
- #decay ⇒ Object
- #draw ⇒ Object
- #expired? ⇒ Boolean
-
#initialize(window, beam) ⇒ Beam
constructor
A new instance of Beam.
Constructor Details
#initialize(window, beam) ⇒ Beam
Returns a new instance of Beam.
7 8 9 10 11 12 13 |
# File 'lib/rubots/graphics/beam.rb', line 7 def initialize(window, beam) @beam = beam @duration = BEAM_DURATION @window = window @pew = Gosu::Sample.new(window, Assets::PEW_SOUND) @pew.play end |
Instance Method Details
#decay ⇒ Object
15 16 17 |
# File 'lib/rubots/graphics/beam.rb', line 15 def decay @duration -= 1 end |
#draw ⇒ Object
23 24 25 26 27 28 29 |
# File 'lib/rubots/graphics/beam.rb', line 23 def draw rad_angle = @beam.angle * Math::PI / 180 x_end = @beam.source_x + Math.sin(rad_angle) * BEAM_LENGTH y_end = @beam.source_y + Math.cos(rad_angle) * BEAM_LENGTH * -1 beam_color = 0xffff0000 @window.draw_line @beam.source_x, @beam.source_y, beam_color, x_end, y_end, beam_color end |
#expired? ⇒ Boolean
19 20 21 |
# File 'lib/rubots/graphics/beam.rb', line 19 def expired? @duration <= 0 end |