Class: Dopairb::Scenes::Loading

Inherits:
Dopairb::Scene show all
Defined in:
lib/dopairb/scenes/session.rb

Overview

Shown at startup while the startup sound is being synthesized. A cat runs along a pastel progress bar; LOADING bounces; sparkles pop.

Constant Summary collapse

PASTEL =
[[255, 170, 210], [255, 205, 160], [255, 245, 170], [180, 245, 200], [170, 215, 255], [215, 185, 255]].freeze
MESSAGES =
["tuning the synthesizer", "polishing sparkles", "charging the combo meter",
"stacking fireworks", "waking up the cat"].freeze
MIN =
0.7
FINISH =
0.45

Instance Attribute Summary

Attributes inherited from Dopairb::Scene

#ctx, #event

Instance Method Summary collapse

Methods inherited from Dopairb::Scene

#alt?, #bell?, #big?, #depth, #draw_top, #flash_at, #impact_at, #mega?, #paint, #pre, #sfx, #shake, #sub_bits, #sub_line, #top?, #total_length, #trail, #w

Constructor Details

#initialize(ctx, ready) ⇒ Loading

Returns a new instance of Loading.



162
163
164
165
166
# File 'lib/dopairb/scenes/session.rb', line 162

def initialize(ctx, ready)
  @ready = ready
  @ready_at = nil
  super(ctx, nil)
end

Instance Method Details

#done?(t) ⇒ Boolean

Returns:

  • (Boolean)


177
178
179
180
181
182
183
# File 'lib/dopairb/scenes/session.rb', line 177

def done?(t)
  if @ready_at.nil? && t >= MIN && @ready.call
    @ready_at = t
    @parts.burst(@bar_x + @bar_w, 3, 40, at: t, speed: 40, life: 0.5, palette: PASTEL, gravity: 10)
  end
  @ready_at && t >= @ready_at + FINISH
end

#draw(c, t) ⇒ Object



193
194
195
196
197
198
199
200
201
202
# File 'lib/dopairb/scenes/session.rb', line 193

def draw(c, t)
  Fx.sparkles(c, t, 21, 18, palette: PASTEL.reverse)
  draw_word(c, t)
  draw_bar(c, t)
  @parts.draw(c, t)
  msg = if @ready_at then "ready!  #{Term.glyph('✦', '*')}"
        else "#{MESSAGES[(t / 0.9).to_i % MESSAGES.size]}#{'.' * ((t * 4).to_i % 4)}"
        end
  c.put(@bar_x, 5, msg, @ready_at ? [255, 240, 170] : [200, 190, 230], bold: !@ready_at.nil?)
end

#height ⇒ Object



168
# File 'lib/dopairb/scenes/session.rb', line 168

def height = 6

#length ⇒ Object

safety net; normally ends via done?



169
# File 'lib/dopairb/scenes/session.rb', line 169

def length = 8.0 # safety net; normally ends via done?

#pastel(i, t) ⇒ Object



191
# File 'lib/dopairb/scenes/session.rb', line 191

def pastel(i, t) = Color.ramp(PASTEL, ((i * 0.13 + t * 0.6) % 1.0))

#progress(t) ⇒ Object



185
186
187
188
189
# File 'lib/dopairb/scenes/session.rb', line 185

def progress(t)
  fake = 1 - Math.exp(-t / 0.9) # creeps towards 1, never gets there
  return 0.9 * fake unless @ready_at
  0.9 * fake + (1 - 0.9 * fake) * Fx.ease_out((t - @ready_at) / 0.2)
end

#setup ⇒ Object



171
172
173
174
175
# File 'lib/dopairb/scenes/session.rb', line 171

def setup
  @parts = Fx::Particles.new(@rng)
  @bar_x = 4
  @bar_w = [[@w - 12, 60].min, 16].max
end