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,344 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# The player's choices, on a panel over the dimmed courtyard beside a
|
|
5
|
+
# glass case where their snake shows them off. Up and down move between
|
|
6
|
+
# the rows; left and right step a setting back and forth, and Enter or a
|
|
7
|
+
# click steps it on. Every change is saved at once and has a sound of its
|
|
8
|
+
# own; a new volume for the sounds is heard at that volume. The name is
|
|
9
|
+
# written in place, and clearing the records, the scores, the stats and
|
|
10
|
+
# the medals with them, has to be asked for twice.
|
|
11
|
+
#
|
|
12
|
+
# The music row says which song is playing, and opens the music page in
|
|
13
|
+
# place of the list, under its own title: the songs to choose from and
|
|
14
|
+
# how loud the music is. Its way back returns to the music row.
|
|
15
|
+
class Settings
|
|
16
|
+
ROWS = ["SNAKE", "NAME", "SPEED", "SHAKE", "SOUND", "MUSIC", "CLEAR RECORDS", "BACK"].freeze
|
|
17
|
+
SPEEDS = { "SLOW" => :slow, "NORMAL" => :normal, "FAST" => :fast }.freeze
|
|
18
|
+
VOLUMES = { "OFF" => :off, "LOW" => :low, "MEDIUM" => :medium, "HIGH" => :high }.freeze
|
|
19
|
+
PANEL_X = 24
|
|
20
|
+
PANEL_Y = 24
|
|
21
|
+
PANEL_WIDTH = 188
|
|
22
|
+
PADDING = 6
|
|
23
|
+
# The rows stand a pixel closer than buttons, and nearer the top and
|
|
24
|
+
# bottom of the panel, so that eight fit between the title and the wall.
|
|
25
|
+
ROW = Menu::BUTTON - 1
|
|
26
|
+
INSET = PADDING - 1
|
|
27
|
+
ROW_WIDTH = 108
|
|
28
|
+
LIST_X = PANEL_X + PADDING
|
|
29
|
+
LIST_Y = PANEL_Y + INSET
|
|
30
|
+
LIST_HEIGHT = ROWS.size * ROW + 1
|
|
31
|
+
# The music page's fewer rows stand in the middle of the list's place.
|
|
32
|
+
JUKEBOX_Y = LIST_Y + (ROWS.size - Jukebox::ROWS.size) * ROW / 2
|
|
33
|
+
PANEL_HEIGHT = LIST_HEIGHT + INSET * 2
|
|
34
|
+
CASE_X = PANEL_X + PANEL_WIDTH - PADDING - Terrarium::WIDTH
|
|
35
|
+
CASE_Y = LIST_Y + (LIST_HEIGHT - Terrarium::HEIGHT) / 2
|
|
36
|
+
# Where a row's tool, name and value go, from the row's left edge.
|
|
37
|
+
TOOL_X = 3
|
|
38
|
+
LABEL_X = 12
|
|
39
|
+
VALUE_X = 40
|
|
40
|
+
VALUE_WIDTH = 64
|
|
41
|
+
LEFT_ARROW = 12
|
|
42
|
+
MESSAGE = 1.6
|
|
43
|
+
SAVED = 0.3
|
|
44
|
+
NOD = 0.8
|
|
45
|
+
DUST = %i[sand ash steel pewter].freeze
|
|
46
|
+
|
|
47
|
+
def initialize(stage)
|
|
48
|
+
@stage = stage
|
|
49
|
+
@preferences = stage.preferences
|
|
50
|
+
@speaker = stage.speaker
|
|
51
|
+
@courtyard = Courtyard.new(stage.rng, hud: false)
|
|
52
|
+
@title = Lettering.new("SETTINGS")
|
|
53
|
+
@music_title = Lettering.new("MUSIC")
|
|
54
|
+
@menu = settings_menu(delay: 0.2)
|
|
55
|
+
@terrarium = Terrarium.new(stage.rng, x: CASE_X, y: CASE_Y, skin: @preferences.skin, speed: @preferences.speed)
|
|
56
|
+
@choices = {
|
|
57
|
+
"SNAKE" => Choice.new(Skin::ALL.map(&:name), @preferences.skin.name),
|
|
58
|
+
"SPEED" => Choice.new(SPEEDS.keys, SPEEDS.key(@preferences.speed)),
|
|
59
|
+
"SHAKE" => Choice.new(%w[ON OFF], @preferences.shake? ? "ON" : "OFF"),
|
|
60
|
+
"SOUND" => Choice.new(VOLUMES.keys, VOLUMES.key(@preferences.volume))
|
|
61
|
+
}
|
|
62
|
+
@clockwork = Clockwork.new(PANEL_X, PANEL_Y, PANEL_WIDTH, PANEL_HEIGHT)
|
|
63
|
+
@toolbox = Toolbox.new(@preferences)
|
|
64
|
+
@dust = Particles.new(stage.rng)
|
|
65
|
+
@fireflies = Fireflies.new(stage.rng, 6)
|
|
66
|
+
@field = nil
|
|
67
|
+
@jukebox = nil
|
|
68
|
+
@asking = false
|
|
69
|
+
@said = nil
|
|
70
|
+
@named = -SAVED
|
|
71
|
+
@time = 0.0
|
|
72
|
+
@titled = 0.0
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def focus = (@jukebox || @menu).focus
|
|
76
|
+
|
|
77
|
+
def music = @stage.preferences.song.in_the_menus
|
|
78
|
+
|
|
79
|
+
def typing? = !@field.nil?
|
|
80
|
+
|
|
81
|
+
def type(key)
|
|
82
|
+
@field.type(key)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
def update(dt)
|
|
86
|
+
@time += dt
|
|
87
|
+
parts = [@courtyard, @menu, @terrarium, @clockwork, @toolbox, @dust, @fireflies, *@choices.values]
|
|
88
|
+
parts.each { |part| part.update(dt) }
|
|
89
|
+
@field&.update(dt)
|
|
90
|
+
@jukebox&.update(dt)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
def draw(canvas)
|
|
94
|
+
@courtyard.draw(canvas)
|
|
95
|
+
canvas.recolor(Palette::DARKER[2])
|
|
96
|
+
@clockwork.draw_gears(canvas)
|
|
97
|
+
title = @jukebox ? @music_title : @title
|
|
98
|
+
drop = ((1 - Ease.out_back(Ease.progress(@time, @titled, 0.45))) * 30).round
|
|
99
|
+
title.draw(canvas, (App::WIDTH - title.width) / 2, PANEL_Y - title.height - 3 - drop)
|
|
100
|
+
Panel.draw(canvas, PANEL_X, PANEL_Y, PANEL_WIDTH, PANEL_HEIGHT)
|
|
101
|
+
@clockwork.draw_screws(canvas)
|
|
102
|
+
(@jukebox || @menu).draw(canvas)
|
|
103
|
+
@terrarium.draw(canvas)
|
|
104
|
+
@dust.draw(canvas)
|
|
105
|
+
@fireflies.draw(canvas)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
def press(action)
|
|
109
|
+
return edit(action) if @field
|
|
110
|
+
return on_the_music_page { @jukebox.press(action) } if @jukebox
|
|
111
|
+
|
|
112
|
+
case action
|
|
113
|
+
when :up then move(-1)
|
|
114
|
+
when :down then move(1)
|
|
115
|
+
when :left then step(-1)
|
|
116
|
+
when :right then step(1)
|
|
117
|
+
when :confirm then choose
|
|
118
|
+
when :back then back
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Hovering selects a row and clicking works it: a click on a setting's
|
|
123
|
+
# left arrow steps it back, anywhere else on it steps it on.
|
|
124
|
+
def point(x, y, kind)
|
|
125
|
+
return if @field
|
|
126
|
+
return on_the_music_page { @jukebox.point(x, y, kind) } if @jukebox
|
|
127
|
+
|
|
128
|
+
before = @menu.selected
|
|
129
|
+
over = @menu.point(x, y)
|
|
130
|
+
@asking = false if @menu.selected != before
|
|
131
|
+
return unless over && kind == :click
|
|
132
|
+
|
|
133
|
+
@choices.key?(@menu.selected) && left_arrow?(x) ? step(-1) : choose
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
private
|
|
137
|
+
|
|
138
|
+
def settings_menu(delay: 0.0, at: 0)
|
|
139
|
+
Menu.new(ROWS, x: LIST_X, y: LIST_Y, width: ROW_WIDTH, speaker: @speaker, delay:, gap: ROW - Menu::BUTTON,
|
|
140
|
+
slots: false, at:, &method(:write_row))
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
def move(by)
|
|
144
|
+
@asking = false
|
|
145
|
+
@menu.move(by)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
def left_arrow?(x) = x.between?(LIST_X + VALUE_X - 4, LIST_X + VALUE_X + LEFT_ARROW)
|
|
149
|
+
|
|
150
|
+
# Esc takes back the question about clearing, if one is asked, before
|
|
151
|
+
# it leaves.
|
|
152
|
+
def back
|
|
153
|
+
return leave unless @asking
|
|
154
|
+
|
|
155
|
+
@asking = false
|
|
156
|
+
@speaker.play(:back)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
def choose
|
|
160
|
+
case @menu.selected
|
|
161
|
+
when "NAME" then rename
|
|
162
|
+
when "MUSIC" then open_jukebox
|
|
163
|
+
when "CLEAR RECORDS" then clear
|
|
164
|
+
when "BACK" then leave
|
|
165
|
+
else step(1)
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
def step(by)
|
|
170
|
+
return open_jukebox if @menu.selected == "MUSIC" && by.positive?
|
|
171
|
+
|
|
172
|
+
choice = @choices[@menu.selected]
|
|
173
|
+
return unless choice
|
|
174
|
+
|
|
175
|
+
choice.step(by)
|
|
176
|
+
@menu.tap
|
|
177
|
+
@clockwork.turn
|
|
178
|
+
apply(@menu.selected, choice.value)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# A new skin gleams, the speeds tick higher as they quicken, the shake
|
|
182
|
+
# jolts, and a volume plays a sound to be heard by.
|
|
183
|
+
def apply(row, value)
|
|
184
|
+
case row
|
|
185
|
+
when "SNAKE"
|
|
186
|
+
@preferences.skin = Skin.named(value)
|
|
187
|
+
@terrarium.wear(@preferences.skin)
|
|
188
|
+
@speaker.play(:gleam)
|
|
189
|
+
when "SPEED"
|
|
190
|
+
@preferences.speed = SPEEDS.fetch(value)
|
|
191
|
+
@terrarium.speed = @preferences.speed
|
|
192
|
+
@speaker.play(:tick, SPEEDS.keys.index(value))
|
|
193
|
+
when "SHAKE"
|
|
194
|
+
@preferences.shake = value == "ON"
|
|
195
|
+
@terrarium.jolt if @preferences.shake?
|
|
196
|
+
@speaker.play(@preferences.shake? ? :jolt : :click)
|
|
197
|
+
when "SOUND"
|
|
198
|
+
@preferences.volume = VOLUMES.fetch(value)
|
|
199
|
+
@speaker.play(:press)
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
# The music page takes the list's place, and its title the title's,
|
|
204
|
+
# each arriving as the settings' own did.
|
|
205
|
+
def open_jukebox
|
|
206
|
+
@menu.tap
|
|
207
|
+
@speaker.play(:press)
|
|
208
|
+
@jukebox = Jukebox.new(@preferences, @speaker, @toolbox, x: LIST_X, y: JUKEBOX_Y, width: ROW_WIDTH,
|
|
209
|
+
gap: ROW - Menu::BUTTON) { @clockwork.turn }
|
|
210
|
+
@titled = @time
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
# Whatever the music page is given to do; once it is done, the list
|
|
214
|
+
# comes back with the music row chosen.
|
|
215
|
+
def on_the_music_page
|
|
216
|
+
yield
|
|
217
|
+
return unless @jukebox.closed?
|
|
218
|
+
|
|
219
|
+
@jukebox = nil
|
|
220
|
+
@menu = settings_menu(at: ROWS.index("MUSIC"))
|
|
221
|
+
@titled = @time
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
def rename
|
|
225
|
+
@menu.tap
|
|
226
|
+
@speaker.play(:press)
|
|
227
|
+
@field = NameField.new(@preferences.name, width: VALUE_WIDTH, speaker: @speaker)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
# Enter keeps the name written, if there is one; Esc keeps the old one.
|
|
231
|
+
def edit(action)
|
|
232
|
+
case action
|
|
233
|
+
when :confirm then keep_name
|
|
234
|
+
when :back
|
|
235
|
+
@field = nil
|
|
236
|
+
@speaker.play(:back)
|
|
237
|
+
end
|
|
238
|
+
end
|
|
239
|
+
|
|
240
|
+
def keep_name
|
|
241
|
+
name = Name.clean(@field.text)
|
|
242
|
+
return @field.refuse if name.empty?
|
|
243
|
+
|
|
244
|
+
@preferences.name = name
|
|
245
|
+
@field = nil
|
|
246
|
+
@named = @time
|
|
247
|
+
@menu.tap
|
|
248
|
+
@clockwork.turn
|
|
249
|
+
@speaker.play(:sign)
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
# The first press asks; the second clears every table, the stats and the
|
|
253
|
+
# medals, and the row crumbles into dust.
|
|
254
|
+
def clear
|
|
255
|
+
@menu.tap
|
|
256
|
+
if @stage.scores.empty? && @stage.stats.empty? then nothing_to_clear
|
|
257
|
+
elsif @asking then wipe
|
|
258
|
+
else ask
|
|
259
|
+
end
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
def nothing_to_clear
|
|
263
|
+
say("NO RECORDS YET")
|
|
264
|
+
@speaker.play(:refuse)
|
|
265
|
+
end
|
|
266
|
+
|
|
267
|
+
def ask
|
|
268
|
+
@asking = true
|
|
269
|
+
@speaker.play(:ask)
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
def wipe
|
|
273
|
+
@stage.scores.clear
|
|
274
|
+
@stage.stats.clear
|
|
275
|
+
@clockwork.turn
|
|
276
|
+
@asking = false
|
|
277
|
+
say("RECORDS CLEARED")
|
|
278
|
+
x, y = @menu.focus
|
|
279
|
+
@dust.burst(x, y, DUST, count: 28, speed: 60)
|
|
280
|
+
@speaker.play(:crumble)
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
def say(message)
|
|
284
|
+
@said = [message, @time]
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def leave
|
|
288
|
+
@menu.press
|
|
289
|
+
@speaker.play(:back)
|
|
290
|
+
@stage.show(Title.new(@stage))
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
# A setting's name on the left and its value on the right, brighter
|
|
294
|
+
# than the name; the other rows say what they do in the middle.
|
|
295
|
+
def write_row(canvas, index, x, y, color)
|
|
296
|
+
row = ROWS[index]
|
|
297
|
+
chosen = row == @menu.selected
|
|
298
|
+
@toolbox.draw(canvas, row, x + TOOL_X, y, lit: chosen, writing: row == "NAME" && !@field.nil?)
|
|
299
|
+
case row
|
|
300
|
+
when *@choices.keys
|
|
301
|
+
Font::SMALL.draw(canvas, row, x + LABEL_X, y, color)
|
|
302
|
+
@choices[row].draw(canvas, x + VALUE_X, y, VALUE_WIDTH, value_color(chosen), arrows: chosen)
|
|
303
|
+
when "NAME"
|
|
304
|
+
Font::SMALL.draw(canvas, row, x + LABEL_X, y, color)
|
|
305
|
+
write_name(canvas, x + VALUE_X, y, chosen)
|
|
306
|
+
when "MUSIC"
|
|
307
|
+
Font::SMALL.draw(canvas, row, x + LABEL_X, y, color)
|
|
308
|
+
write_song(canvas, x + VALUE_X, y, chosen)
|
|
309
|
+
else
|
|
310
|
+
text = row == "CLEAR RECORDS" ? clear_label : row
|
|
311
|
+
Font::SMALL.draw(canvas, text, x, y, color, align: :center, within: ROW_WIDTH)
|
|
312
|
+
end
|
|
313
|
+
end
|
|
314
|
+
|
|
315
|
+
def value_color(chosen) = Palette[chosen ? :cream : :ash]
|
|
316
|
+
|
|
317
|
+
# The name being written, or the one kept, which shines for a moment
|
|
318
|
+
# just after it is kept.
|
|
319
|
+
def write_name(canvas, x, y, chosen)
|
|
320
|
+
return @field.draw(canvas, x, y, Palette[:cream]) if @field
|
|
321
|
+
|
|
322
|
+
name = @preferences.name
|
|
323
|
+
color = @time - @named < SAVED ? Palette[:white] : value_color(chosen)
|
|
324
|
+
Font::SMALL.draw(canvas, name, x, y, color, align: :center, within: VALUE_WIDTH)
|
|
325
|
+
end
|
|
326
|
+
|
|
327
|
+
# The song playing, or that the music is off; chosen, an arrow nods
|
|
328
|
+
# the way in to the music page.
|
|
329
|
+
def write_song(canvas, x, y, chosen)
|
|
330
|
+
text = @preferences.music == :off ? "OFF" : @preferences.song.name
|
|
331
|
+
color = value_color(chosen)
|
|
332
|
+
Font::SMALL.draw(canvas, text, x, y, color, align: :center, within: VALUE_WIDTH)
|
|
333
|
+
nod = @time % NOD < NOD / 3 ? 1 : 0
|
|
334
|
+
canvas.draw(Choice::RIGHT, x + VALUE_WIDTH - Choice::RIGHT.width + nod, y, Palette.solid(color)) if chosen
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
def clear_label
|
|
338
|
+
message, at = @said
|
|
339
|
+
return message if @said && @time - at < MESSAGE
|
|
340
|
+
|
|
341
|
+
@asking ? "SURE? PRESS AGAIN" : "CLEAR RECORDS"
|
|
342
|
+
end
|
|
343
|
+
end
|
|
344
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# Shown in whatever room the terminal has while it is smaller than the
|
|
5
|
+
# game: the snake asking for the size it needs, and the size it has now,
|
|
6
|
+
# updating as the window changes. Small enough to fit 80 × 24.
|
|
7
|
+
class SizeNotice
|
|
8
|
+
PADDING = 6
|
|
9
|
+
LINE = 8
|
|
10
|
+
ICON_ROOM = 13
|
|
11
|
+
|
|
12
|
+
attr_reader :canvas
|
|
13
|
+
|
|
14
|
+
def initialize
|
|
15
|
+
resize(App::WIDTH, App::HEIGHT / 2)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def resize(columns, lines)
|
|
19
|
+
@canvas = Canvas.new(columns.clamp(1, App::WIDTH), lines.clamp(1, App::HEIGHT / 2) * 2)
|
|
20
|
+
draw(["RESIZE TO", "#{App::WIDTH} × #{App::HEIGHT / 2}", "NOW #{columns} × #{lines}"])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
private
|
|
24
|
+
|
|
25
|
+
def draw(lines)
|
|
26
|
+
width = ICON_ROOM + lines.map { |text| Font::SMALL.width(text) }.max + PADDING * 2
|
|
27
|
+
height = lines.size * LINE + PADDING * 2 - 3
|
|
28
|
+
x = (@canvas.width - width) / 2
|
|
29
|
+
y = (@canvas.height - height) / 2
|
|
30
|
+
@canvas.clear
|
|
31
|
+
Panel.draw(@canvas, x, y, width, height)
|
|
32
|
+
SnakeView.draw_head(@canvas, Direction::RIGHT, x + PADDING, y + (height - Courtyard::TILE) / 2, look: [1, 0])
|
|
33
|
+
lines.zip(%i[ash cream amber]).each_with_index do |(text, color), index|
|
|
34
|
+
Font::SMALL.draw(@canvas, text, x + PADDING + ICON_ROOM, y + PADDING + index * LINE, Palette[color])
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|