pixelsnake 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (102) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +21 -0
  4. data/README.md +122 -0
  5. data/bin/pixelsnake +8 -0
  6. data/lib/pixelsnake/abacus.rb +102 -0
  7. data/lib/pixelsnake/app.rb +130 -0
  8. data/lib/pixelsnake/art/big_font.rb +196 -0
  9. data/lib/pixelsnake/art/heads.rb +68 -0
  10. data/lib/pixelsnake/art/small_font.rb +73 -0
  11. data/lib/pixelsnake/autopilot.rb +34 -0
  12. data/lib/pixelsnake/award.rb +67 -0
  13. data/lib/pixelsnake/board.rb +36 -0
  14. data/lib/pixelsnake/canvas.rb +189 -0
  15. data/lib/pixelsnake/choice.rb +92 -0
  16. data/lib/pixelsnake/clockwork.rb +169 -0
  17. data/lib/pixelsnake/controls.rb +26 -0
  18. data/lib/pixelsnake/countdown.rb +80 -0
  19. data/lib/pixelsnake/courtyard.rb +306 -0
  20. data/lib/pixelsnake/day.rb +23 -0
  21. data/lib/pixelsnake/death.rb +115 -0
  22. data/lib/pixelsnake/debug_overlay.rb +53 -0
  23. data/lib/pixelsnake/demo.rb +85 -0
  24. data/lib/pixelsnake/density.rb +47 -0
  25. data/lib/pixelsnake/ease.rb +27 -0
  26. data/lib/pixelsnake/fade.rb +30 -0
  27. data/lib/pixelsnake/feats.rb +86 -0
  28. data/lib/pixelsnake/fine.rb +78 -0
  29. data/lib/pixelsnake/fireflies.rb +63 -0
  30. data/lib/pixelsnake/floating_text.rb +36 -0
  31. data/lib/pixelsnake/font.rb +62 -0
  32. data/lib/pixelsnake/fruit.rb +149 -0
  33. data/lib/pixelsnake/game.rb +294 -0
  34. data/lib/pixelsnake/gear.rb +132 -0
  35. data/lib/pixelsnake/high_scores.rb +91 -0
  36. data/lib/pixelsnake/hud.rb +217 -0
  37. data/lib/pixelsnake/iris.rb +76 -0
  38. data/lib/pixelsnake/jukebox.rb +143 -0
  39. data/lib/pixelsnake/keyboard.rb +96 -0
  40. data/lib/pixelsnake/laurel.rb +76 -0
  41. data/lib/pixelsnake/leaf.rb +73 -0
  42. data/lib/pixelsnake/lettering.rb +111 -0
  43. data/lib/pixelsnake/medal.rb +29 -0
  44. data/lib/pixelsnake/medal_view.rb +428 -0
  45. data/lib/pixelsnake/menu.rb +213 -0
  46. data/lib/pixelsnake/meter.rb +108 -0
  47. data/lib/pixelsnake/metronome.rb +24 -0
  48. data/lib/pixelsnake/name.rb +22 -0
  49. data/lib/pixelsnake/name_field.rb +156 -0
  50. data/lib/pixelsnake/odometer.rb +76 -0
  51. data/lib/pixelsnake/palette.rb +64 -0
  52. data/lib/pixelsnake/panel.rb +45 -0
  53. data/lib/pixelsnake/particles.rb +188 -0
  54. data/lib/pixelsnake/piece.rb +82 -0
  55. data/lib/pixelsnake/playback.rb +22 -0
  56. data/lib/pixelsnake/preferences.rb +96 -0
  57. data/lib/pixelsnake/rare_fruit.rb +268 -0
  58. data/lib/pixelsnake/recording.rb +44 -0
  59. data/lib/pixelsnake/ribbon.rb +110 -0
  60. data/lib/pixelsnake/save_file.rb +51 -0
  61. data/lib/pixelsnake/scenes/game_over.rb +249 -0
  62. data/lib/pixelsnake/scenes/medal_case.rb +268 -0
  63. data/lib/pixelsnake/scenes/pause.rb +171 -0
  64. data/lib/pixelsnake/scenes/play.rb +326 -0
  65. data/lib/pixelsnake/scenes/scores.rb +420 -0
  66. data/lib/pixelsnake/scenes/settings.rb +344 -0
  67. data/lib/pixelsnake/scenes/size_notice.rb +38 -0
  68. data/lib/pixelsnake/scenes/statistics.rb +420 -0
  69. data/lib/pixelsnake/scenes/title.rb +152 -0
  70. data/lib/pixelsnake/screen.rb +163 -0
  71. data/lib/pixelsnake/shed.rb +40 -0
  72. data/lib/pixelsnake/skin.rb +36 -0
  73. data/lib/pixelsnake/snake.rb +53 -0
  74. data/lib/pixelsnake/snake_view.rb +393 -0
  75. data/lib/pixelsnake/sound/band.rb +354 -0
  76. data/lib/pixelsnake/sound/instruments.rb +143 -0
  77. data/lib/pixelsnake/sound/mixer.rb +60 -0
  78. data/lib/pixelsnake/sound/music.rb +15 -0
  79. data/lib/pixelsnake/sound/pulse.rb +149 -0
  80. data/lib/pixelsnake/sound/song.rb +22 -0
  81. data/lib/pixelsnake/sound/sounds.rb +225 -0
  82. data/lib/pixelsnake/sound/speaker.rb +199 -0
  83. data/lib/pixelsnake/sound/synth.rb +277 -0
  84. data/lib/pixelsnake/sound/tune.rb +145 -0
  85. data/lib/pixelsnake/sound/tunes/dusk.rb +154 -0
  86. data/lib/pixelsnake/sound/tunes/fireflies.rb +106 -0
  87. data/lib/pixelsnake/sound/tunes/jade.rb +100 -0
  88. data/lib/pixelsnake/sound/tunes/lanterns.rb +126 -0
  89. data/lib/pixelsnake/sound/tunes.rb +40 -0
  90. data/lib/pixelsnake/sprite.rb +58 -0
  91. data/lib/pixelsnake/stage.rb +95 -0
  92. data/lib/pixelsnake/stats.rb +131 -0
  93. data/lib/pixelsnake/terminal.rb +84 -0
  94. data/lib/pixelsnake/terrarium.rb +206 -0
  95. data/lib/pixelsnake/tile.rb +32 -0
  96. data/lib/pixelsnake/toolbox.rb +251 -0
  97. data/lib/pixelsnake/trophy.rb +99 -0
  98. data/lib/pixelsnake/tuft.rb +55 -0
  99. data/lib/pixelsnake/upscale.rb +60 -0
  100. data/lib/pixelsnake/version.rb +5 -0
  101. data/lib/pixelsnake.rb +143 -0
  102. metadata +146 -0
@@ -0,0 +1,420 @@
1
+ # frozen_string_literal: true
2
+
3
+ module PixelSnake
4
+ # The best games at each speed, on a panel over the dimmed courtyard. A
5
+ # small lantern marks whose table is showing and slides along the speeds
6
+ # as the player moves between them. One game at a time is chosen, a dim
7
+ # lantern glowing behind its row; the arrows, Page Up and Down and Home
8
+ # and End move it, and the table scrolls smoothly to keep it in view, as
9
+ # it does under the mouse wheel. A bar at the side shows where the table
10
+ # is and can be dragged. Enter or a click watches the chosen game again,
11
+ # if it was recorded, which a play mark beside it shows. The title drops in
12
+ # and the rows follow one after another; the best wears a crown, and the
13
+ # game just played shimmers and is chosen. Moving through the table ticks
14
+ # softly, and the lantern swishes between speeds. A golden cup stands at
15
+ # each side of the title, the two taking turns to catch the light.
16
+ #
17
+ # The table is laid out in points, but its rows are drawn in pixels a
18
+ # whole number apart, ten on the fine canvas, so the lines of a long
19
+ # table stay evenly spaced. The pointer is read against the rows and the
20
+ # bar as they were last drawn, in the same pixels.
21
+ class Scores
22
+ PANEL_X = 22
23
+ PANEL_Y = 30
24
+ PANEL_WIDTH = 192
25
+ PANEL_HEIGHT = 79
26
+ TABS_Y = PANEL_Y + 4
27
+ TAB_WIDTH = 40
28
+ TAB_GAP = 4
29
+ TABS_X = PANEL_X + (PANEL_WIDTH - 3 * TAB_WIDTH - 2 * TAB_GAP) / 2
30
+ HEADING_Y = PANEL_Y + 16
31
+ RULE_Y = PANEL_Y + 22
32
+ LIST_Y = PANEL_Y + 24
33
+ LINE = 7
34
+ FINE_LINE = 10
35
+ SHOWN = 7
36
+ BAR_X = PANEL_X + PANEL_WIDTH - 9
37
+ # Left edges, but the place and the length line up on their right.
38
+ COLUMNS = { place: PANEL_X + 22, name: PANEL_X + 28, score: PANEL_X + 94, length: PANEL_X + 140,
39
+ date: PANEL_X + 148 }.freeze
40
+ SPEEDS = { slow: "SLOW", normal: "NORMAL", fast: "FAST" }.freeze
41
+ SHIMMER = %i[cream gold amber gold].freeze
42
+ SLIDE = 0.2
43
+ WHEEL = 3
44
+ SETTLE = 20.0
45
+ ARRIVE_FROM = 20
46
+ # Between the title and each cup.
47
+ ASIDE = 10
48
+ MARK_X = PANEL_X + 5
49
+
50
+ # The table for the player's speed, or the one a game just watched is
51
+ # on, with that game chosen.
52
+ def initialize(stage, chosen: nil)
53
+ @stage = stage
54
+ @courtyard = Courtyard.new(stage.rng, hud: false)
55
+ @title = Lettering.new("HIGH SCORES")
56
+ @sparkles = Particles.new(stage.rng)
57
+ left = (App::WIDTH - @title.width) / 2 - ASIDE - Trophy::WIDTH
58
+ right = (App::WIDTH + @title.width) / 2 + ASIDE
59
+ @cups = [Trophy.new(left, PANEL_Y - 1, @sparkles, glint_from: 1.5),
60
+ Trophy.new(right, PANEL_Y - 1, @sparkles, glint_from: 3.5)]
61
+ @fireflies = Fireflies.new(stage.rng, 6)
62
+ @time = 0.0
63
+ @tab = SPEEDS.keys.index(chosen&.speed || stage.preferences.speed)
64
+ @tab_from = @tab.to_f
65
+ @switched = -SLIDE
66
+ @hovered = nil
67
+ @grab = nil
68
+ @density = Density::STANDARD
69
+ show_table(0.25, -ARRIVE_FROM, chosen)
70
+ end
71
+
72
+ def focus = [App::WIDTH / 2, App::HEIGHT / 2]
73
+
74
+ def music = @stage.preferences.song.in_the_menus
75
+
76
+ def typing? = false
77
+
78
+ def update(dt)
79
+ @time += dt
80
+ [@courtyard, *@cups, @sparkles, @fireflies].each { |part| part.update(dt) }
81
+ @scroll += (@target - @scroll) * (1 - Math.exp(-SETTLE * dt)) unless @grab
82
+ end
83
+
84
+ def draw(canvas)
85
+ @density = canvas.density
86
+ @courtyard.draw(canvas)
87
+ canvas.recolor(Palette::DARKER[2])
88
+ @cups.each { |cup| cup.draw(canvas) }
89
+ drop = ((1 - Ease.out_back(Ease.progress(@time, 0.0, 0.45))) * 30).round
90
+ @title.draw(canvas, (App::WIDTH - @title.width) / 2, PANEL_Y - @title.height - 3 - drop)
91
+ Panel.draw(canvas, PANEL_X, PANEL_Y, PANEL_WIDTH, PANEL_HEIGHT)
92
+ draw_tabs(canvas)
93
+ draw_heading(canvas)
94
+ @entries.empty? ? draw_empty(canvas) : draw_entries(canvas)
95
+ draw_bar(canvas) if last_top.positive?
96
+ @sparkles.draw(canvas)
97
+ @fireflies.draw(canvas)
98
+ end
99
+
100
+ # A key takes the bar out of the pointer's hand.
101
+ def press(action)
102
+ @grab = nil
103
+ case action
104
+ when :up then choose(@chosen - 1)
105
+ when :down then choose(@chosen + 1)
106
+ when :page_up then choose(@chosen - SHOWN)
107
+ when :page_down then choose(@chosen + SHOWN)
108
+ when :top then choose(0)
109
+ when :bottom then choose(@entries.size - 1)
110
+ when :left then switch(@tab - 1)
111
+ when :right then switch(@tab + 1)
112
+ when :confirm then watch
113
+ when :back then leave
114
+ end
115
+ end
116
+
117
+ # The pointer chooses the game it is over, the wheel scrolls, a click
118
+ # watches a game, picks a speed or works the bar, and a click off the
119
+ # panel goes back.
120
+ def point(x, y, kind)
121
+ @hovered = tab_at(x, y)
122
+ case kind
123
+ when :wheel_up then scroll_by(-WHEEL)
124
+ when :wheel_down then scroll_by(WHEEL)
125
+ when :drag then drag(y) if @grab
126
+ when :move then hover(x, y)
127
+ when :click then click(x, y)
128
+ end
129
+ end
130
+
131
+ private
132
+
133
+ def speed = SPEEDS.keys[@tab]
134
+
135
+ # Puts a speed's table up with a game chosen, the one asked for or the
136
+ # one just played if either is on it, or the best, and scrolled so it
137
+ # is in the middle of the view; the rows arrive from so far to one side.
138
+ def show_table(after, from, chosen = nil)
139
+ @entries = @stage.scores.table(speed)
140
+ @chosen = @entries.index { |entry| entry.equal?(chosen || @stage.scores.newest) } || 0
141
+ @chosen_from = @chosen.to_f
142
+ @moved = -SLIDE
143
+ @target = @scroll = (@chosen - SHOWN / 2).clamp(0, last_top).to_f
144
+ @arrived = @time + after
145
+ @arrive_from = from
146
+ end
147
+
148
+ # Moves the light to a row, scrolling just enough to keep it in view.
149
+ def choose(row)
150
+ row = row.clamp(0, [@entries.size - 1, 0].max)
151
+ return if row == @chosen || @entries.empty?
152
+
153
+ @chosen_from = chosen_row
154
+ @chosen = row
155
+ @moved = @time
156
+ @target = @target.clamp((row - SHOWN + 1).to_f, row.to_f).clamp(0.0, last_top.to_f)
157
+ @stage.speaker.play(:tick, 1)
158
+ end
159
+
160
+ # Where the light is, in rows; between two while it slides.
161
+ def chosen_row = @chosen_from + (@chosen - @chosen_from) * Ease.out_cubic(Ease.progress(@time, @moved, SLIDE / 2))
162
+
163
+ # The chosen game played again, from its recording, if it has one.
164
+ def watch
165
+ entry = @entries[@chosen]
166
+ return @stage.speaker.play(:refuse) unless entry&.replay
167
+
168
+ @stage.speaker.play(:press)
169
+ @stage.show(Play.new(@stage, watching: entry), Iris)
170
+ end
171
+
172
+ def switch(tab)
173
+ tab = tab.clamp(0, SPEEDS.size - 1)
174
+ return if tab == @tab
175
+
176
+ @tab_from = tab_row
177
+ @switched = @time
178
+ direction = tab <=> @tab
179
+ @tab = tab
180
+ @grab = nil
181
+ show_table(0.0, ARRIVE_FROM * direction)
182
+ @stage.speaker.play(:swish)
183
+ end
184
+
185
+ # The row at the top of the list when it is scrolled to the end.
186
+ def last_top = [@entries.size - SHOWN, 0].max
187
+
188
+ def scroll_by(rows)
189
+ @grab = nil
190
+ target = (@target.round + rows).clamp(0, last_top).to_f
191
+ @stage.speaker.play(:tick, 1) unless target == @target
192
+ @target = target
193
+ end
194
+
195
+ def click(x, y)
196
+ tab = tab_at(x, y)
197
+ return switch(tab) if tab
198
+ return leave unless on_panel?(x, y)
199
+
200
+ return watch_row(row_at(x, y)) if row_at(x, y)
201
+ return unless on_bar?(x, y)
202
+
203
+ _, _, top, thumb = bar(@density)
204
+ pixel = @density.at(y)
205
+ if pixel.between?(top, top + thumb - 1) then @grab = pixel - top
206
+ else scroll_by(pixel < top ? -SHOWN : SHOWN)
207
+ end
208
+ end
209
+
210
+ def on_panel?(x, y) = x.between?(PANEL_X, PANEL_X + PANEL_WIDTH - 1) && y.between?(PANEL_Y, PANEL_Y + PANEL_HEIGHT - 1)
211
+
212
+ # The pointer lets go of the bar and chooses the game it is over.
213
+ def hover(x, y)
214
+ @grab = nil
215
+ row = row_at(x, y)
216
+ choose(row) if row
217
+ end
218
+
219
+ # A click on a game chooses it and watches it.
220
+ def watch_row(row)
221
+ choose(row)
222
+ watch
223
+ end
224
+
225
+ # How many pixels down the list a point is, if it is over the list.
226
+ def down_the_list(y)
227
+ down = @density.at(y) - @density.at(LIST_Y)
228
+ down if down.between?(0, SHOWN * line(@density) - 1)
229
+ end
230
+
231
+ # The game whose row is under a point in the list, if any: the last
232
+ # row drawn with its top at or above the point.
233
+ def row_at(x, y)
234
+ down = down_the_list(y)
235
+ return unless down && x.between?(PANEL_X + 3, BAR_X - 3)
236
+
237
+ first = @scroll.floor
238
+ row = (first..first + SHOWN).reverse_each.find { |below| row_top(@density, below) <= @density.at(LIST_Y) + down }
239
+ row if row.between?(0, @entries.size - 1)
240
+ end
241
+
242
+ # The bar, with a little room either side for a hand that misses.
243
+ def on_bar?(x, y) = last_top.positive? && x.between?(BAR_X - 2, BAR_X + 4) && down_the_list(y)
244
+
245
+ # The thumb follows the pointer, and the table follows the thumb.
246
+ def drag(y)
247
+ list_top, height, _, thumb = bar(@density)
248
+ @target = @scroll = ((@density.at(y) - @grab - list_top).fdiv(height - thumb) * last_top).clamp(0.0, last_top.to_f)
249
+ end
250
+
251
+ def leave
252
+ @stage.speaker.play(:back)
253
+ @stage.show(Title.new(@stage))
254
+ end
255
+
256
+ def tab_at(x, y)
257
+ return unless y.between?(TABS_Y, TABS_Y + 8)
258
+
259
+ SPEEDS.size.times.find { |tab| x.between?(tab_x(tab), tab_x(tab) + TAB_WIDTH - 1) }
260
+ end
261
+
262
+ def tab_x(tab) = (TABS_X + tab * (TAB_WIDTH + TAB_GAP)).round
263
+
264
+ # Where the lantern is, in tabs; between two while it slides.
265
+ def tab_row = @tab_from + (@tab - @tab_from) * Ease.out_back(Ease.progress(@time, @switched, SLIDE))
266
+
267
+ # A small lantern like the HUD's behind the speed whose table is up.
268
+ def draw_tabs(canvas)
269
+ density = canvas.density
270
+ pixels = canvas.pixels
271
+ x = density.at(tab_x(tab_row))
272
+ top = density.at(TABS_Y)
273
+ width = density.at(TAB_WIDTH)
274
+ height = density.at(TABS_Y + 9) - top
275
+ pixels.fill(x, top, width, height, Palette[:ink])
276
+ pixels.fill(x, top, width - 1, height - 1, Palette[:amber])
277
+ pixels.fill(x + 1, top + 1, width - 2, height - 2, Palette[:crimson])
278
+ pixels.fill(x + 1, top + height - 2, width - 2, 1, Palette[:wine])
279
+ pixels.fill(x + width - 2, top + 1, 1, height - 2, Palette[:wine])
280
+ SPEEDS.each_value.with_index do |label, tab|
281
+ color = if tab == @tab then :gold
282
+ elsif tab == @hovered then :ash
283
+ else :steel
284
+ end
285
+ Font::SMALL.draw(canvas, label, tab_x(tab), TABS_Y + 2, Palette[color], align: :center, within: TAB_WIDTH)
286
+ end
287
+ end
288
+
289
+ def draw_heading(canvas)
290
+ small = Font::SMALL
291
+ steel = Palette[:steel]
292
+ small.draw(canvas, "NAME", COLUMNS[:name], HEADING_Y, steel)
293
+ small.draw(canvas, "SCORE", COLUMNS[:score], HEADING_Y, steel)
294
+ small.draw(canvas, "LEN", COLUMNS[:length], HEADING_Y, steel, align: :right)
295
+ small.draw(canvas, "DAY", COLUMNS[:date] + 6, HEADING_Y, steel)
296
+ canvas.fill(PANEL_X + 6, RULE_Y, PANEL_WIDTH - 12, 1, Palette[:violet])
297
+ end
298
+
299
+ # The list's rectangle in the canvas's pixels: as many lines as show,
300
+ # each a whole number of pixels tall.
301
+ def list_box(density)
302
+ [density.at(PANEL_X + 3), density.at(LIST_Y), density.at(PANEL_X + PANEL_WIDTH - 11) - density.at(PANEL_X + 3),
303
+ SHOWN * line(density)]
304
+ end
305
+
306
+ def line(density) = density.pick(LINE, FINE_LINE)
307
+
308
+ # The top of a row's line in pixels, as the table is scrolled now.
309
+ def row_top(density, row) = density.at(LIST_Y) + ((row - @scroll) * line(density)).round
310
+
311
+ def draw_entries(canvas)
312
+ density = canvas.density
313
+ pixels = canvas.pixels
314
+ first = @scroll.floor
315
+ pixels.clip(*list_box(density)) do
316
+ draw_light(pixels, density)
317
+ (first..[first + SHOWN, @entries.size - 1].min).each { |row| draw_entry(pixels, density, @entries[row], row) }
318
+ end
319
+ end
320
+
321
+ # Once the rows have come in, a dim lantern behind the chosen one, lit
322
+ # along its top, and a play mark beside it if the game can be watched.
323
+ def draw_light(canvas, density)
324
+ return if @time < @arrived + 0.2
325
+
326
+ y = row_top(density, chosen_row)
327
+ left = density.at(PANEL_X + 4)
328
+ width = density.at(BAR_X - 5) - left
329
+ canvas.fill(left, y, width, line(density), Palette[:wine])
330
+ canvas.fill(left, y, width, 1, Palette[:crimson])
331
+ return unless @entries[@chosen].replay
332
+
333
+ mark = density.pick(Choice::RIGHT, Choice::RIGHT.fine)
334
+ canvas.draw(mark, density.at(MARK_X), y + density.pick(1, 2), Palette.solid(Palette[:gold]))
335
+ end
336
+
337
+ # Each row slides in from the side a beat after the one above it. The
338
+ # game just played shimmers through the gold ramp.
339
+ def draw_entry(canvas, density, entry, row)
340
+ slot = (row - @scroll).clamp(0, SHOWN)
341
+ arrival = Ease.progress(@time, @arrived + slot * 0.05, 0.35)
342
+ return if arrival.zero?
343
+
344
+ x = ((1 - Ease.out_back(arrival)) * @arrive_from).round
345
+ y = row_top(density, row) + density.pick(1, 2)
346
+ font = density.pick(Font::SMALL, Font::SMALL.fine)
347
+ column = ->(name) { density.at(COLUMNS.fetch(name) + x) }
348
+ shimmer = Palette[SHIMMER[(@time * 8).floor % SHIMMER.size]] if entry.equal?(@stage.scores.newest)
349
+ draw_place(canvas, density, font, row, column[:place], y)
350
+ draw_name(canvas, font, entry.name, column[:name], y, shimmer)
351
+ draw_score(canvas, font, entry.score, row, column[:score], y, shimmer)
352
+ length = entry.length.to_s
353
+ font.write(canvas, length, column[:length] - font.width(length), y, shimmer || Palette[:leaf], 16)
354
+ font.write(canvas, day(entry.date), column[:date], y, shimmer || Palette[:ash], 16)
355
+ end
356
+
357
+ # The best wears the crown, the next two are silver and bronze, and
358
+ # the rest have plain numbers, standing on the right at x.
359
+ def draw_place(canvas, density, font, row, x, y)
360
+ if row.zero?
361
+ crown = density.pick(Hud::CROWN, Hud::CROWN.fine)
362
+ return canvas.draw(crown, x - crown.width, y)
363
+ end
364
+
365
+ place = (row + 1).to_s
366
+ color = { 1 => :sand, 2 => :orange }.fetch(row, :steel)
367
+ font.write(canvas, place, x - font.width(place), y, Palette[color], 16)
368
+ end
369
+
370
+ # A game from before there were names has a dash.
371
+ def draw_name(canvas, font, name, x, y, shimmer)
372
+ return font.write(canvas, "-", x, y, Palette[:steel], 16) if name.empty?
373
+
374
+ font.write(canvas, name, x, y, shimmer || Palette[:cream], 16)
375
+ end
376
+
377
+ # Five digits, the leading zeros sunk into the panel as in the HUD; a
378
+ # score of six has none to sink.
379
+ def draw_score(canvas, font, score, row, x, y, shimmer)
380
+ digits = score.to_s
381
+ zeros = "0" * [5 - digits.size, 0].max
382
+ font.write(canvas, zeros, x, y, Palette[:violet], 16) unless zeros.empty?
383
+ left = x + (zeros.empty? ? 0 : font.width(zeros) + 1)
384
+ font.write(canvas, digits, left, y, shimmer || Palette[row.zero? ? :gold : :cream], 16)
385
+ end
386
+
387
+ def draw_empty(canvas)
388
+ ["NO GAMES YET", "PLAY ONE AND IT GOES HERE"].each_with_index do |text, index|
389
+ Font::SMALL.draw(canvas, text, PANEL_X, LIST_Y + 14 + index * 9, Palette[index.zero? ? :ash : :steel],
390
+ align: :center, within: PANEL_WIDTH)
391
+ end
392
+ end
393
+
394
+ # A groove down the right of the list, with a thumb as long as the
395
+ # share of the table in view, lit while it is held.
396
+ def draw_bar(canvas)
397
+ density = canvas.density
398
+ pixels = canvas.pixels
399
+ x = density.at(BAR_X)
400
+ width = density.pick(3, 4)
401
+ list_top, height, top, thumb = bar(density)
402
+ held = !@grab.nil?
403
+ pixels.fill(x, list_top, width, height, Palette[:night])
404
+ pixels.fill(x, top, width, thumb, Palette[held ? :ash : :steel])
405
+ pixels.fill(x, top, 1, thumb, Palette[held ? :sand : :ash])
406
+ pixels.fill(x, top, width, 1, Palette[held ? :sand : :ash])
407
+ end
408
+
409
+ # The bar in a density's pixels: the groove's top and height, and the
410
+ # thumb's.
411
+ def bar(density)
412
+ height = SHOWN * line(density)
413
+ thumb = [(height * SHOWN.fdiv(@entries.size)).round, density.pick(5, 7)].max
414
+ [density.at(LIST_Y), height, density.at(LIST_Y) + ((height - thumb) * @scroll / last_top).round, thumb]
415
+ end
416
+
417
+ # The day number padded, so the months line up down the table.
418
+ def day(date) = Day.told(date).rjust(6)
419
+ end
420
+ end