Class: RoadToRubykaigi::Fireworks
- Inherits:
-
Object
- Object
- RoadToRubykaigi::Fireworks
- Defined in:
- lib/road_to_rubykaigi/fireworks.rb
Constant Summary collapse
- START_X =
632- DEMO_START_X =
524- DURATION_SECOND =
0.1
Instance Method Summary collapse
Instance Method Details
#build_buffer(offset_x:) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/road_to_rubykaigi/fireworks.rb', line 23 def build_buffer(offset_x:) return [] if !shooting? || finished? buffer = Array.new(Map::VIEWPORT_HEIGHT) { Array.new(Map::VIEWPORT_WIDTH) { "" } } relative_x = @x - offset_x relative_y = @y current_frame.each_with_index do |row, i| row.chars.each_with_index do |character, j| next if character == " " next if (relative_x + j) > Map::VIEWPORT_WIDTH buffer[relative_y+i][relative_x+j] = character end end buffer end |
#shoot ⇒ Object
7 8 9 |
# File 'lib/road_to_rubykaigi/fireworks.rb', line 7 def shoot @shooting = true end |
#update ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/road_to_rubykaigi/fireworks.rb', line 11 def update return unless shooting? if finished? return EventDispatcher.publish(:finish) end if Time.now - @last_frame_time >= DURATION_SECOND @frame_index += 1 @last_frame_time = Time.now end end |