Class: Dopairb::Scenes::FailureScene

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

Overview

Shared bits for error scenes: red tint on the input, big glitching title.

Direct Known Subclasses

Clash, Crack, Snap, Spotlight

Instance Attribute Summary

Attributes inherited from Dopairb::Scene

#ctx, #event

Instance Method Summary collapse

Methods inherited from Dopairb::Scene

#alt?, #depth, #done?, #impact_at, #initialize, #mega?, #paint, #sub_bits, #sub_line, #total_length, #w

Constructor Details

This class inherits a constructor from Dopairb::Scene

Instance Method Details

#bell? ⇒ Boolean

Returns:

  • (Boolean)


10
# File 'lib/dopairb/scenes/failure.rb', line 10

def bell? = true

#big? ⇒ Boolean

Returns:

  • (Boolean)


7
# File 'lib/dopairb/scenes/failure.rb', line 7

def big? = true

#detail_text ⇒ Object



63
64
65
66
67
68
# File 'lib/dopairb/scenes/failure.rb', line 63

def detail_text
  bits = [event.info[:class_name]]
  bits << "x#{event.streak} in a row" if event.streak > 1
  bits << "combo reset (#{event.info[:broken_combo]})" if event.info[:broken_combo].to_i >= 3
  bits.join("   ")
end

#draw(c, t) ⇒ Object



40
41
42
43
# File 'lib/dopairb/scenes/failure.rb', line 40

def draw(c, t)
  draw_title(c, t)
  draw_detail(c, t)
end

#draw_detail(c, t) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/dopairb/scenes/failure.rb', line 70

def draw_detail(c, t)
  return if t < 0.15
  txt = detail_text
  n = (txt.size * Fx.phase(t, 0.15, 0.45)).round
  y = @scale ? 6 : 1
  c.put_center(y, txt[0, n], [255, 170, 170], bold: true)
end

#draw_title(c, t) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/dopairb/scenes/failure.rb', line 45

def draw_title(c, t)
  if ctx.config.flash != :off && t < 0.1
    c.tint_bg([160, 0, 20], 0.6 * (1 - t / 0.1), 0, 0, @w, height)
  end
  if @scale
    glitch = t < 0.35 ? 0.35 * (1 - t / 0.35) : 0.0
    tear = (t * 17).floor
    fn = lambda do |rx, ry, _f|
      flick = ((rx * 3 + ry * 5 + tear) % 11).zero? && t < 0.4
      flick ? [255, 255, 255] : Color.ramp(palette, 0.15 + ry * 0.12)
    end
    x = (@w - Font.width(title, scale: @scale)) / 2
    Fx.big_text(c, title, x, 0, fn, scale: @scale, glitch: glitch, rng: @rng)
  else
    c.put(1, 0, title.chars.join(" "), Color.ramp(palette, 0.2), bold: true)
  end
end

#draw_top(c, t) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/dopairb/scenes/failure.rb', line 27

def draw_top(c, t)
  return nil if t > 0.45
  k = 1 - Fx.phase(t, 0.1, 0.45)
  ox = t < 0.2 ? (@rng.rand(5) - 2) : 0
  ctx.input.plain.each_with_index do |r, y|
    c.put(ox, y, r, Color.mix([220, 220, 225], [255, 70, 80], k), bold: k > 0.5)
  end
  mark_top(c, t)
  true
end

#flash_at ⇒ Object



23
# File 'lib/dopairb/scenes/failure.rb', line 23

def flash_at = 0.0

#height ⇒ Object



21
# File 'lib/dopairb/scenes/failure.rb', line 21

def height = @scale ? 7 : 2

#length ⇒ Object



22
# File 'lib/dopairb/scenes/failure.rb', line 22

def length = 0.85

#mark_top(_c, _t) ⇒ Object



38
# File 'lib/dopairb/scenes/failure.rb', line 38

def mark_top(_c, _t); end

#palette ⇒ Object



13
# File 'lib/dopairb/scenes/failure.rb', line 13

def palette = Color::BLOOD

#pre ⇒ Object



9
# File 'lib/dopairb/scenes/failure.rb', line 9

def pre = 0.0

#setup ⇒ Object



16
17
18
19
# File 'lib/dopairb/scenes/failure.rb', line 16

def setup
  @scale = best_scale(title)
  @scale = 1 if @scale == 2 && Font.width(title, scale: 2) > @w * 0.7
end

#sfx ⇒ Object



14
# File 'lib/dopairb/scenes/failure.rb', line 14

def sfx = :error

#shake(t) ⇒ Object



25
# File 'lib/dopairb/scenes/failure.rb', line 25

def shake(t) = t < 0.22 ? ((@rng.rand * 2 - 1) * 3 * (1 - t / 0.22)).round : 0

#title ⇒ Object



12
# File 'lib/dopairb/scenes/failure.rb', line 12

def title = "FAILED"

#top? ⇒ Boolean

Returns:

  • (Boolean)


8
# File 'lib/dopairb/scenes/failure.rb', line 8

def top? = !ctx.input.nil?

#trail ⇒ Object



78
79
80
81
82
# File 'lib/dopairb/scenes/failure.rb', line 78

def trail
  s = "#{Term.glyph('✖', 'x')} #{title}"
  s << "  x#{event.streak}" if event.streak > 1
  paint(s, Color.ramp(palette, 0.25), bold: true)
end