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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE +21 -0
- data/README.md +122 -0
- data/bin/pixelsnake +8 -0
- data/lib/pixelsnake/abacus.rb +102 -0
- data/lib/pixelsnake/app.rb +130 -0
- data/lib/pixelsnake/art/big_font.rb +196 -0
- data/lib/pixelsnake/art/heads.rb +68 -0
- data/lib/pixelsnake/art/small_font.rb +73 -0
- data/lib/pixelsnake/autopilot.rb +34 -0
- data/lib/pixelsnake/award.rb +67 -0
- data/lib/pixelsnake/board.rb +36 -0
- data/lib/pixelsnake/canvas.rb +189 -0
- data/lib/pixelsnake/choice.rb +92 -0
- data/lib/pixelsnake/clockwork.rb +169 -0
- data/lib/pixelsnake/controls.rb +26 -0
- data/lib/pixelsnake/countdown.rb +80 -0
- data/lib/pixelsnake/courtyard.rb +306 -0
- data/lib/pixelsnake/day.rb +23 -0
- data/lib/pixelsnake/death.rb +115 -0
- data/lib/pixelsnake/debug_overlay.rb +53 -0
- data/lib/pixelsnake/demo.rb +85 -0
- data/lib/pixelsnake/density.rb +47 -0
- data/lib/pixelsnake/ease.rb +27 -0
- data/lib/pixelsnake/fade.rb +30 -0
- data/lib/pixelsnake/feats.rb +86 -0
- data/lib/pixelsnake/fine.rb +78 -0
- data/lib/pixelsnake/fireflies.rb +63 -0
- data/lib/pixelsnake/floating_text.rb +36 -0
- data/lib/pixelsnake/font.rb +62 -0
- data/lib/pixelsnake/fruit.rb +149 -0
- data/lib/pixelsnake/game.rb +294 -0
- data/lib/pixelsnake/gear.rb +132 -0
- data/lib/pixelsnake/high_scores.rb +91 -0
- data/lib/pixelsnake/hud.rb +217 -0
- data/lib/pixelsnake/iris.rb +76 -0
- data/lib/pixelsnake/jukebox.rb +143 -0
- data/lib/pixelsnake/keyboard.rb +96 -0
- data/lib/pixelsnake/laurel.rb +76 -0
- data/lib/pixelsnake/leaf.rb +73 -0
- data/lib/pixelsnake/lettering.rb +111 -0
- data/lib/pixelsnake/medal.rb +29 -0
- data/lib/pixelsnake/medal_view.rb +428 -0
- data/lib/pixelsnake/menu.rb +213 -0
- data/lib/pixelsnake/meter.rb +108 -0
- data/lib/pixelsnake/metronome.rb +24 -0
- data/lib/pixelsnake/name.rb +22 -0
- data/lib/pixelsnake/name_field.rb +156 -0
- data/lib/pixelsnake/odometer.rb +76 -0
- data/lib/pixelsnake/palette.rb +64 -0
- data/lib/pixelsnake/panel.rb +45 -0
- data/lib/pixelsnake/particles.rb +188 -0
- data/lib/pixelsnake/piece.rb +82 -0
- data/lib/pixelsnake/playback.rb +22 -0
- data/lib/pixelsnake/preferences.rb +96 -0
- data/lib/pixelsnake/rare_fruit.rb +268 -0
- data/lib/pixelsnake/recording.rb +44 -0
- data/lib/pixelsnake/ribbon.rb +110 -0
- data/lib/pixelsnake/save_file.rb +51 -0
- data/lib/pixelsnake/scenes/game_over.rb +249 -0
- data/lib/pixelsnake/scenes/medal_case.rb +268 -0
- data/lib/pixelsnake/scenes/pause.rb +171 -0
- data/lib/pixelsnake/scenes/play.rb +326 -0
- data/lib/pixelsnake/scenes/scores.rb +420 -0
- data/lib/pixelsnake/scenes/settings.rb +344 -0
- data/lib/pixelsnake/scenes/size_notice.rb +38 -0
- data/lib/pixelsnake/scenes/statistics.rb +420 -0
- data/lib/pixelsnake/scenes/title.rb +152 -0
- data/lib/pixelsnake/screen.rb +163 -0
- data/lib/pixelsnake/shed.rb +40 -0
- data/lib/pixelsnake/skin.rb +36 -0
- data/lib/pixelsnake/snake.rb +53 -0
- data/lib/pixelsnake/snake_view.rb +393 -0
- data/lib/pixelsnake/sound/band.rb +354 -0
- data/lib/pixelsnake/sound/instruments.rb +143 -0
- data/lib/pixelsnake/sound/mixer.rb +60 -0
- data/lib/pixelsnake/sound/music.rb +15 -0
- data/lib/pixelsnake/sound/pulse.rb +149 -0
- data/lib/pixelsnake/sound/song.rb +22 -0
- data/lib/pixelsnake/sound/sounds.rb +225 -0
- data/lib/pixelsnake/sound/speaker.rb +199 -0
- data/lib/pixelsnake/sound/synth.rb +277 -0
- data/lib/pixelsnake/sound/tune.rb +145 -0
- data/lib/pixelsnake/sound/tunes/dusk.rb +154 -0
- data/lib/pixelsnake/sound/tunes/fireflies.rb +106 -0
- data/lib/pixelsnake/sound/tunes/jade.rb +100 -0
- data/lib/pixelsnake/sound/tunes/lanterns.rb +126 -0
- data/lib/pixelsnake/sound/tunes.rb +40 -0
- data/lib/pixelsnake/sprite.rb +58 -0
- data/lib/pixelsnake/stage.rb +95 -0
- data/lib/pixelsnake/stats.rb +131 -0
- data/lib/pixelsnake/terminal.rb +84 -0
- data/lib/pixelsnake/terrarium.rb +206 -0
- data/lib/pixelsnake/tile.rb +32 -0
- data/lib/pixelsnake/toolbox.rb +251 -0
- data/lib/pixelsnake/trophy.rb +99 -0
- data/lib/pixelsnake/tuft.rb +55 -0
- data/lib/pixelsnake/upscale.rb +60 -0
- data/lib/pixelsnake/version.rb +5 -0
- data/lib/pixelsnake.rb +143 -0
- metadata +146 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# A game as it was played, so that it can be played again: the rules it
|
|
5
|
+
# was played under, the seed its dice were set to, its speed, how many
|
|
6
|
+
# columns wide its field was, and every turn the snake made, as the move
|
|
7
|
+
# it was made on and the way it went. The rules do the rest: under the
|
|
8
|
+
# same rules, with the same dice and the same turns, a game comes out the
|
|
9
|
+
# same.
|
|
10
|
+
#
|
|
11
|
+
# It is kept as text, a few letters a turn: the moves since the last
|
|
12
|
+
# turn, and U, D, L or R for the way. One made under rules the game does
|
|
13
|
+
# not know could not come out the same, so it reads as none. One kept
|
|
14
|
+
# from before fields could be wider was played on the narrower one.
|
|
15
|
+
Recording = Data.define(:rules, :seed, :speed, :turns, :columns) do
|
|
16
|
+
def self.of(game, seed)
|
|
17
|
+
new(rules: game.rules, seed:, speed: game.speed, turns: game.made_turns.dup, columns: game.board.columns)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# A recording as it was saved for a game at a speed, or nothing if it
|
|
21
|
+
# was made under rules the game does not know or is not understood.
|
|
22
|
+
def self.read(saved, speed)
|
|
23
|
+
return unless saved.is_a?(Hash) && (1..Game::RULES).cover?(saved[:rules]) && saved[:seed].is_a?(Integer)
|
|
24
|
+
return unless saved[:turns].is_a?(String) && saved[:turns].match?(/\A(\d+[UDLR])*\z/)
|
|
25
|
+
|
|
26
|
+
columns = saved.fetch(:columns, Courtyard::COLUMNS)
|
|
27
|
+
return unless [Courtyard::COLUMNS, Courtyard::WIDE].include?(columns)
|
|
28
|
+
|
|
29
|
+
move = 0
|
|
30
|
+
turns = saved[:turns].scan(/(\d+)([UDLR])/).map { |gap, letter| [move += gap.to_i, Recording::WAYS.key(letter)] }
|
|
31
|
+
new(rules: saved[:rules], seed: saved[:seed], speed:, turns:, columns:)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def saved
|
|
35
|
+
text = [[0], *turns].each_cons(2).map { |(before), (move, way)| "#{move - before}#{Recording::WAYS.fetch(way)}" }
|
|
36
|
+
{ rules:, seed:, turns: text.join, columns: }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
# The game as it began, ready to be played the same way again.
|
|
40
|
+
def game = Game.new(Board.new(columns, Courtyard::ROWS), Random.new(seed), speed:, rules:)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
Recording::WAYS = { Direction::UP => "U", Direction::DOWN => "D", Direction::LEFT => "L", Direction::RIGHT => "R" }.freeze
|
|
44
|
+
end
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# A gold banner with folded tails and a few words on it, for a moment
|
|
5
|
+
# worth marking. The ends are drawn; the middle stretches to fit the
|
|
6
|
+
# words. It is made for both canvases at once, the fine one in the fine
|
|
7
|
+
# letters with tails to match.
|
|
8
|
+
module Ribbon
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
def made(text)
|
|
12
|
+
Sprite.new(sewn(text, Font::SMALL, LEFT, MIDDLE, RIGHT, 4, 2).rows,
|
|
13
|
+
fine: sewn(text, Font::SMALL.fine, LEFT.fine, MIDDLE.fine, RIGHT.fine, 6, 3))
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# The ends, as much middle as the words and their margins need, and the
|
|
17
|
+
# words across it.
|
|
18
|
+
def sewn(text, font, left, middle, right, margin, top)
|
|
19
|
+
width = font.width(text) + margin * 2
|
|
20
|
+
canvas = Canvas.new(left.width + width + right.width, left.height, Sprite::CLEAR)
|
|
21
|
+
canvas.draw(left, 0, 0)
|
|
22
|
+
width.times { |x| canvas.draw(middle, left.width + x, 0) }
|
|
23
|
+
canvas.draw(right, left.width + width, 0)
|
|
24
|
+
font.write(canvas, text, left.width + margin, top, Palette[:wine], 16)
|
|
25
|
+
Sprite.new(canvas.rows)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
LEGEND = { "w" => :wine, "c" => :crimson, "g" => :gold, "a" => :amber, "o" => :orange }.freeze
|
|
29
|
+
|
|
30
|
+
LEFT = Sprite.parse(<<~ART, LEGEND, fine: <<~FINE)
|
|
31
|
+
....w
|
|
32
|
+
....w
|
|
33
|
+
wwwww
|
|
34
|
+
wcccw
|
|
35
|
+
.wccw
|
|
36
|
+
..wcw
|
|
37
|
+
.wccw
|
|
38
|
+
wcccw
|
|
39
|
+
wwwww
|
|
40
|
+
ART
|
|
41
|
+
......w
|
|
42
|
+
......w
|
|
43
|
+
......w
|
|
44
|
+
wwwwwww
|
|
45
|
+
wcccccw
|
|
46
|
+
.wccccw
|
|
47
|
+
..wcccw
|
|
48
|
+
...wccw
|
|
49
|
+
..wcccw
|
|
50
|
+
.wccccw
|
|
51
|
+
wcccccw
|
|
52
|
+
wcccccw
|
|
53
|
+
wwwwwww
|
|
54
|
+
FINE
|
|
55
|
+
|
|
56
|
+
MIDDLE = Sprite.parse(<<~ART, LEGEND, fine: <<~FINE)
|
|
57
|
+
w
|
|
58
|
+
g
|
|
59
|
+
a
|
|
60
|
+
a
|
|
61
|
+
a
|
|
62
|
+
a
|
|
63
|
+
a
|
|
64
|
+
o
|
|
65
|
+
w
|
|
66
|
+
ART
|
|
67
|
+
w
|
|
68
|
+
g
|
|
69
|
+
a
|
|
70
|
+
a
|
|
71
|
+
a
|
|
72
|
+
a
|
|
73
|
+
a
|
|
74
|
+
a
|
|
75
|
+
a
|
|
76
|
+
a
|
|
77
|
+
a
|
|
78
|
+
o
|
|
79
|
+
w
|
|
80
|
+
FINE
|
|
81
|
+
|
|
82
|
+
RIGHT = Sprite.parse(<<~ART, LEGEND, fine: <<~FINE)
|
|
83
|
+
w....
|
|
84
|
+
w....
|
|
85
|
+
wwwww
|
|
86
|
+
wcccw
|
|
87
|
+
wccw.
|
|
88
|
+
wcw..
|
|
89
|
+
wccw.
|
|
90
|
+
wcccw
|
|
91
|
+
wwwww
|
|
92
|
+
ART
|
|
93
|
+
w......
|
|
94
|
+
w......
|
|
95
|
+
w......
|
|
96
|
+
wwwwwww
|
|
97
|
+
wcccccw
|
|
98
|
+
wccccw.
|
|
99
|
+
wcccw..
|
|
100
|
+
wccw...
|
|
101
|
+
wcccw..
|
|
102
|
+
wccccw.
|
|
103
|
+
wcccccw
|
|
104
|
+
wcccccw
|
|
105
|
+
wwwwwww
|
|
106
|
+
FINE
|
|
107
|
+
|
|
108
|
+
private_class_method :sewn
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "json"
|
|
4
|
+
require "fileutils"
|
|
5
|
+
|
|
6
|
+
module PixelSnake
|
|
7
|
+
# A small JSON file the game keeps between runs: the scores, the stats or
|
|
8
|
+
# the settings, as a list or a table. With no file yet there is nothing
|
|
9
|
+
# in it, and the same goes for one that cannot be read or is not what
|
|
10
|
+
# the game keeps there.
|
|
11
|
+
#
|
|
12
|
+
# It is written beside the old file and renamed over it, so a crash
|
|
13
|
+
# halfway never leaves it broken, and a disk that refuses the write costs
|
|
14
|
+
# what was to be kept, not the game. A file the game could make nothing
|
|
15
|
+
# of is not written over: it is set aside first, as it may yet be mended
|
|
16
|
+
# by hand.
|
|
17
|
+
class SaveFile
|
|
18
|
+
def initialize(path, kind)
|
|
19
|
+
@path = path
|
|
20
|
+
@kind = kind
|
|
21
|
+
@spoiled = false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def read
|
|
25
|
+
kept = JSON.parse(File.read(@path), symbolize_names: true)
|
|
26
|
+
@spoiled = !kept.is_a?(@kind)
|
|
27
|
+
@spoiled ? @kind.new : kept
|
|
28
|
+
rescue Errno::ENOENT
|
|
29
|
+
@kind.new
|
|
30
|
+
rescue JSON::ParserError, SystemCallError
|
|
31
|
+
@spoiled = true
|
|
32
|
+
@kind.new
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def write(kept)
|
|
36
|
+
FileUtils.mkdir_p(File.dirname(@path))
|
|
37
|
+
set_aside if @spoiled
|
|
38
|
+
File.write("#{@path}.new", JSON.pretty_generate(kept))
|
|
39
|
+
File.rename("#{@path}.new", @path)
|
|
40
|
+
rescue SystemCallError
|
|
41
|
+
nil
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def set_aside
|
|
47
|
+
File.rename(@path, "#{@path}.broken")
|
|
48
|
+
@spoiled = false
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# After a run: the courtyard dims, the title drops in, and a panel rises
|
|
5
|
+
# with the score counting up, the best, the snake's length and its place
|
|
6
|
+
# on the table, then a choice of another go or the menu. A new best gets
|
|
7
|
+
# a ribbon, confetti, and a score that shimmers through the gold ramp.
|
|
8
|
+
# The count ticks its way up the scale, slowing as it does, and ends on
|
|
9
|
+
# a bell, or on a fanfare for a new best.
|
|
10
|
+
#
|
|
11
|
+
# A game that makes the table goes on it at once under the player's
|
|
12
|
+
# usual name. Before the choice comes up, the name is offered in a field
|
|
13
|
+
# where the buttons will be: Enter signs the game with whatever it says,
|
|
14
|
+
# and Esc goes back to the menu leaving the game as it is.
|
|
15
|
+
class GameOver
|
|
16
|
+
CHOICES = %w[AGAIN MENU].freeze
|
|
17
|
+
SOUNDS = { "AGAIN" => :start, "MENU" => :press }.freeze
|
|
18
|
+
PANEL_X = 64
|
|
19
|
+
PANEL_Y = 37
|
|
20
|
+
PANEL_WIDTH = 108
|
|
21
|
+
PANEL_HEIGHT = 79
|
|
22
|
+
PADDING = 7
|
|
23
|
+
# Rows inside the panel, counted from its top edge.
|
|
24
|
+
LABEL = 6
|
|
25
|
+
NUMBER = 13
|
|
26
|
+
DETAILS = 29
|
|
27
|
+
PLACE = 37
|
|
28
|
+
MENU = 49
|
|
29
|
+
HINT = 65
|
|
30
|
+
MENU_X = PANEL_X + PADDING + 12
|
|
31
|
+
MENU_WIDTH = PANEL_WIDTH - PADDING * 2 - 24
|
|
32
|
+
DIM = 0.3
|
|
33
|
+
COUNT_FROM = 0.55
|
|
34
|
+
COUNT = 0.8
|
|
35
|
+
TALLIES = 10
|
|
36
|
+
ASK = 1.0
|
|
37
|
+
ARRIVE = 0.4
|
|
38
|
+
SEAL = 0.3
|
|
39
|
+
# The music comes back once the count has landed and rung out.
|
|
40
|
+
MUSIC = 2.6
|
|
41
|
+
HINT_TEXT = "ENTER TO SAVE"
|
|
42
|
+
SHIMMER = %i[cream gold amber orange].freeze
|
|
43
|
+
|
|
44
|
+
# 1ST, 2ND, 3RD, 4TH, ... 11TH, 12TH, 13TH, ... 21ST.
|
|
45
|
+
def self.ordinal(number)
|
|
46
|
+
suffix = (11..13).cover?(number % 100) ? "TH" : { 1 => "ST", 2 => "ND", 3 => "RD" }.fetch(number % 10, "TH")
|
|
47
|
+
"#{number}#{suffix}"
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def initialize(stage, play, score:, length:, won: false)
|
|
51
|
+
@stage = stage
|
|
52
|
+
@play = play
|
|
53
|
+
@score = score
|
|
54
|
+
@length = length
|
|
55
|
+
preferences = stage.preferences
|
|
56
|
+
@place = stage.scores.record(name: preferences.name, score:, length:, speed: preferences.speed, replay: play.recording)
|
|
57
|
+
@best = stage.scores.best(preferences.speed)
|
|
58
|
+
@title = Lettering.new(won ? "YOU WIN" : "GAME OVER")
|
|
59
|
+
@ribbon = Ribbon.made("NEW BEST")
|
|
60
|
+
@field = NameField.new(preferences.name, width: MENU_WIDTH, speaker: stage.speaker) if @place
|
|
61
|
+
@menu = choices(ASK) unless @field
|
|
62
|
+
@confetti = Particles.new(stage.rng)
|
|
63
|
+
@numbers = {}
|
|
64
|
+
@tallied = 0
|
|
65
|
+
@signed = nil
|
|
66
|
+
@time = 0.0
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def focus = @menu ? @menu.focus : [MENU_X + MENU_WIDTH / 2, PANEL_Y + MENU + Menu::BUTTON / 2]
|
|
70
|
+
|
|
71
|
+
def music = @time >= MUSIC ? @stage.preferences.song.in_the_menus : Music::NONE
|
|
72
|
+
|
|
73
|
+
# Only once the field is up, so keys still held from the game write
|
|
74
|
+
# nothing.
|
|
75
|
+
def typing? = naming?
|
|
76
|
+
|
|
77
|
+
def type(key)
|
|
78
|
+
@field.type(key)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def update(dt)
|
|
82
|
+
@time += dt
|
|
83
|
+
[@play, @confetti, @field, @menu].each { |part| part&.update(dt) }
|
|
84
|
+
tally unless @score.zero? || @tallied == TALLIES
|
|
85
|
+
celebrate if new_best? && !@celebrated && @time >= COUNT_FROM + COUNT
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def draw(canvas)
|
|
89
|
+
@play.draw(canvas)
|
|
90
|
+
canvas.dim(Ease.progress(@time, 0.0, DIM))
|
|
91
|
+
draw_title(canvas)
|
|
92
|
+
rise = ((1 - Ease.out_back(Ease.progress(@time, 0.15, 0.5))) * 90).round
|
|
93
|
+
Panel.draw(canvas, PANEL_X, PANEL_Y + rise, PANEL_WIDTH, PANEL_HEIGHT)
|
|
94
|
+
draw_score(canvas, PANEL_Y + rise)
|
|
95
|
+
draw_details(canvas, PANEL_Y + rise)
|
|
96
|
+
draw_field(canvas) if @field && @time >= ASK && !sealed?
|
|
97
|
+
@menu.draw(canvas) if @menu && rise.zero?
|
|
98
|
+
draw_ribbon(canvas) if @celebrated
|
|
99
|
+
@confetti.draw(canvas)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Esc leads back to the title at any time, the game kept as it stands.
|
|
103
|
+
# The buttons take nothing until they have begun to come up, so keys
|
|
104
|
+
# still held from the game choose nothing unseen.
|
|
105
|
+
def press(action)
|
|
106
|
+
return leave if action == :back
|
|
107
|
+
return sign if naming? && action == :confirm
|
|
108
|
+
return unless @menu&.up?
|
|
109
|
+
|
|
110
|
+
case action
|
|
111
|
+
when :up, :left then @menu.move(-1)
|
|
112
|
+
when :down, :right then @menu.move(1)
|
|
113
|
+
when :confirm then choose
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Hovering selects a button; clicking one chooses it.
|
|
118
|
+
def point(x, y, kind)
|
|
119
|
+
choose if @menu&.up? && @menu.point(x, y) && kind == :click
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
private
|
|
123
|
+
|
|
124
|
+
def new_best? = @place == 1
|
|
125
|
+
|
|
126
|
+
def naming? = !@field.nil? && @signed.nil? && @time >= ASK
|
|
127
|
+
|
|
128
|
+
def sealed? = @signed && @time >= @signed + SEAL
|
|
129
|
+
|
|
130
|
+
def choices(delay)
|
|
131
|
+
Menu.new(CHOICES, x: MENU_X, y: PANEL_Y + MENU, width: MENU_WIDTH, speaker: @stage.speaker, delay:)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# The game takes the name, the player keeps it for next time, and the
|
|
135
|
+
# buttons come up once the field has lit.
|
|
136
|
+
def sign
|
|
137
|
+
name = Name.clean(@field.text)
|
|
138
|
+
return @field.refuse if name.empty?
|
|
139
|
+
|
|
140
|
+
@stage.scores.sign(name)
|
|
141
|
+
@stage.preferences.name = name
|
|
142
|
+
@stage.speaker.play(:sign)
|
|
143
|
+
@signed = @time
|
|
144
|
+
@menu = choices(SEAL)
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
def choose
|
|
148
|
+
@menu.press
|
|
149
|
+
@stage.speaker.play(SOUNDS.fetch(@menu.selected))
|
|
150
|
+
case @menu.selected
|
|
151
|
+
when "AGAIN" then @stage.show(Play.new(@stage), Iris)
|
|
152
|
+
when "MENU" then @stage.show(Title.new(@stage), Iris)
|
|
153
|
+
end
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
def leave
|
|
157
|
+
@stage.speaker.play(:back)
|
|
158
|
+
@stage.show(Title.new(@stage), Iris)
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
# A tick for every tenth of the way the count has rolled, each a step
|
|
162
|
+
# higher; the last is the bell, unless a fanfare is coming.
|
|
163
|
+
def tally
|
|
164
|
+
tallied = (Ease.out_cubic(Ease.progress(@time, COUNT_FROM, COUNT)) * TALLIES).floor
|
|
165
|
+
return if tallied == @tallied
|
|
166
|
+
|
|
167
|
+
@tallied = tallied
|
|
168
|
+
if tallied < TALLIES then @stage.speaker.play(:tally, tallied - 1)
|
|
169
|
+
elsif !new_best? then @stage.speaker.play(:ding)
|
|
170
|
+
end
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
def celebrate
|
|
174
|
+
@celebrated = @time
|
|
175
|
+
@confetti.confetti(70, left: 20, width: App::WIDTH - 40, top: 0)
|
|
176
|
+
@stage.speaker.play(:fanfare)
|
|
177
|
+
end
|
|
178
|
+
|
|
179
|
+
def draw_title(canvas)
|
|
180
|
+
drop = ((1 - Ease.out_back(Ease.progress(@time, 0.05, 0.45))) * 40).round
|
|
181
|
+
@title.draw(canvas, (App::WIDTH - @title.width) / 2, PANEL_Y - @title.height - 2 - drop)
|
|
182
|
+
end
|
|
183
|
+
|
|
184
|
+
# The score counts up as the panel settles, easing into its last digits.
|
|
185
|
+
def draw_score(canvas, top)
|
|
186
|
+
Font::SMALL.draw(canvas, "SCORE", 0, top + LABEL, Palette[:steel], align: :center, within: App::WIDTH)
|
|
187
|
+
shown = (@score * Ease.out_cubic(Ease.progress(@time, COUNT_FROM, COUNT))).round / 10 * 10
|
|
188
|
+
number = @numbers[shown] ||= Lettering.new(shown.to_s)
|
|
189
|
+
map = @celebrated ? SHIMMER_MAPS[(@time * 12).floor % SHIMMER_MAPS.size] : Palette::IDENTITY
|
|
190
|
+
number.draw(canvas, (App::WIDTH - number.width) / 2, top + NUMBER, map:)
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
def draw_details(canvas, top)
|
|
194
|
+
line = "BEST #{@best} LENGTH #{@length}"
|
|
195
|
+
Font::SMALL.draw(canvas, line, 0, top + DETAILS, Palette[:ash], align: :center, within: App::WIDTH)
|
|
196
|
+
return if @place.nil? || new_best?
|
|
197
|
+
|
|
198
|
+
place = "#{GameOver.ordinal(@place)} ON THE TABLE"
|
|
199
|
+
Font::SMALL.draw(canvas, place, 0, top + PLACE, Palette[:leaf], align: :center, within: App::WIDTH)
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# The field slides in like a button where the buttons will be, rimmed
|
|
203
|
+
# in amber while it takes a name and lit like a lantern for a moment
|
|
204
|
+
# once the game is signed.
|
|
205
|
+
def draw_field(canvas)
|
|
206
|
+
x = MENU_X + ((1 - Ease.out_cubic(Ease.progress(@time, ASK, ARRIVE))) * MENU_WIDTH).round
|
|
207
|
+
y = PANEL_Y + MENU
|
|
208
|
+
canvas.clip(MENU_X, y, MENU_WIDTH, PANEL_HEIGHT - MENU) do
|
|
209
|
+
draw_well(canvas, x, y)
|
|
210
|
+
@field.draw(canvas, x, y + 3, Palette[@signed ? :gold : :cream], caret: !@signed)
|
|
211
|
+
unless @signed
|
|
212
|
+
Font::SMALL.draw(canvas, HINT_TEXT, x, PANEL_Y + HINT, Palette[:steel], align: :center, within: MENU_WIDTH)
|
|
213
|
+
end
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# The field's box, a pixel for each of its edges at either density.
|
|
218
|
+
def draw_well(canvas, x, y)
|
|
219
|
+
density = canvas.density
|
|
220
|
+
left = density.at(x)
|
|
221
|
+
top = density.at(y)
|
|
222
|
+
width = density.at(x + MENU_WIDTH) - left
|
|
223
|
+
height = density.at(y + Menu::BUTTON) - top
|
|
224
|
+
rim, inside = @signed ? %i[amber crimson] : %i[amber night]
|
|
225
|
+
pixels = canvas.pixels
|
|
226
|
+
pixels.fill(left, top, width, height, Palette[rim])
|
|
227
|
+
pixels.fill(left + 1, top + 1, width - 2, height - 2, Palette[:ink])
|
|
228
|
+
pixels.fill(left + 2, top + 2, width - 4, height - 4, Palette[inside])
|
|
229
|
+
end
|
|
230
|
+
|
|
231
|
+
# The ribbon springs out from nothing to a little too big, and settles;
|
|
232
|
+
# once it has, it is the ribbon as it was made, not made again.
|
|
233
|
+
def draw_ribbon(canvas)
|
|
234
|
+
grow = Ease.out_back(Ease.progress(@time, @celebrated, 0.35))
|
|
235
|
+
return if grow <= 0.05
|
|
236
|
+
|
|
237
|
+
sprite = grow == 1.0 ? @ribbon : @ribbon.scale(grow, grow)
|
|
238
|
+
canvas.draw(sprite, (App::WIDTH - sprite.width) / 2, PANEL_Y + PLACE + 2 - sprite.height / 2)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# The gold ramp turned a step at a time, so the digits seem to shine.
|
|
242
|
+
SHIMMER_MAPS = SHIMMER.each_index.map do |turn|
|
|
243
|
+
Palette.map do |index|
|
|
244
|
+
position = SHIMMER.index(Palette::NAMES[index])
|
|
245
|
+
position ? Palette[SHIMMER[(position + turn) % SHIMMER.size]] : index
|
|
246
|
+
end
|
|
247
|
+
end.freeze
|
|
248
|
+
end
|
|
249
|
+
end
|