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
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c2b0966aa465dcff5911c198a194d9d794bcb1c185d57d341e2d9f760752e9d3
|
|
4
|
+
data.tar.gz: b4217d7bd11f10ec12aea0377ac3ea6c77a1c533d8cd81eefaeaa6111586f159
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 2ae4ca9207a31ee8e49e5aa3ed4b1ead148935c44c51f63526f48d0f9aa011ab34b2a6ca5b5d2ac80f8be9f4ab8cd79f7c4b8f481214d77577f9cdb27b1ca06a
|
|
7
|
+
data.tar.gz: 6720dc175e101728818ebcba6c991dd77a4a3c715cb649c171f359797e58326235af85b956ce83d590f1767523122823b2d3e6823b71f8a6e436531357ac2ded
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Shayan-777
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# pixelsnake
|
|
2
|
+
|
|
3
|
+
A snake game for the terminal with pixel art graphics, sound and music. Written in Ruby, no dependencies.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+
|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
The graphics are drawn with half-block characters and 24-bit color, so each terminal cell is two pixels. Sounds and music are generated by the game itself, there are no asset files.
|
|
10
|
+
|
|
11
|
+
## Features
|
|
12
|
+
|
|
13
|
+
- Smooth movement and animations at 60 fps
|
|
14
|
+
- Sound effects and four songs to choose from
|
|
15
|
+
- Three speeds, each with its own high score table
|
|
16
|
+
- Replays: games that make the high score table are recorded and can be watched again
|
|
17
|
+
- Stats screen and 12 medals to unlock
|
|
18
|
+
- Special fruit with different effects
|
|
19
|
+
- Five snake skins
|
|
20
|
+
- Mouse support in the menus
|
|
21
|
+
- Higher resolution graphics if the terminal is big enough
|
|
22
|
+
|
|
23
|
+
## Requirements
|
|
24
|
+
|
|
25
|
+
- Ruby 3.3 or newer
|
|
26
|
+
- A truecolor terminal with at least 236x61 characters. You will probably have to make the font smaller to get there (Ctrl+minus in most terminals).
|
|
27
|
+
- Linux. I have not tested it anywhere else.
|
|
28
|
+
- PipeWire or PulseAudio if you want sound. Without it the game runs silent.
|
|
29
|
+
|
|
30
|
+
## Install
|
|
31
|
+
|
|
32
|
+
gem install pixelsnake
|
|
33
|
+
pixelsnake
|
|
34
|
+
|
|
35
|
+
Or run it straight from a checkout:
|
|
36
|
+
|
|
37
|
+
ruby bin/pixelsnake
|
|
38
|
+
|
|
39
|
+
## Controls
|
|
40
|
+
|
|
41
|
+
| Key | Action |
|
|
42
|
+
|----------------------|------------------------------------|
|
|
43
|
+
| Arrows, WASD or hjkl | Move, navigate menus |
|
|
44
|
+
| Enter or Space | Select |
|
|
45
|
+
| Esc | Back / pause / quit from the title |
|
|
46
|
+
| P | Pause |
|
|
47
|
+
| Ctrl-C | Quit |
|
|
48
|
+
| F3 | Show FPS and frame times |
|
|
49
|
+
|
|
50
|
+
The menus also work with the mouse. The game pauses when the terminal loses focus.
|
|
51
|
+
|
|
52
|
+
## Gameplay
|
|
53
|
+
|
|
54
|
+
It's snake. A few things that are specific to this version:
|
|
55
|
+
|
|
56
|
+
- Every 5 fruit the multiplier goes up by one, up to x9.
|
|
57
|
+
- Now and then a special fruit appears for a short time:
|
|
58
|
+
- **Golden fruit**: worth 5 normal ones
|
|
59
|
+
- **Plum**: removes a quarter of the snake (a third once it is 68 or longer)
|
|
60
|
+
- **Pepper**: makes the snake faster for a while, fruit counts double during that time
|
|
61
|
+
- **Pear**: makes the snake slower for a while
|
|
62
|
+
- If your score makes the table you can enter a name.
|
|
63
|
+
- In the high score table, press Enter on a game to watch it again. Left/Right change the playback speed, Space pauses, Esc goes back. Only games that were recorded have a play icon.
|
|
64
|
+
|
|
65
|
+
## Terminal size
|
|
66
|
+
|
|
67
|
+
| Terminal | Result |
|
|
68
|
+
|---------------|----------------------------------------|
|
|
69
|
+
| Below 236x61 | A message asking you to resize |
|
|
70
|
+
| 236x61 | Normal mode, 27x12 field |
|
|
71
|
+
| 252x61 | Wider field (29x12) |
|
|
72
|
+
| 354x92 | High resolution mode (1.5x the pixels) |
|
|
73
|
+
| 378x92 | High resolution with the wider field |
|
|
74
|
+
|
|
75
|
+
The game follows the terminal size while it is running. A game in progress keeps the field it was started with.
|
|
76
|
+
|
|
77
|
+

|
|
78
|
+
|
|
79
|
+
## Settings and saved files
|
|
80
|
+
|
|
81
|
+
In the settings you can change the snake skin, your name, the speed, screen shake, sound volume and the music (song and volume). "Clear records" deletes the high scores, stats and medals.
|
|
82
|
+
|
|
83
|
+
- High scores and stats: `~/.local/share/pixelsnake/` (or `$XDG_DATA_HOME/pixelsnake/`)
|
|
84
|
+
- Settings: `~/.config/pixelsnake/` (or `$XDG_CONFIG_HOME/pixelsnake/`)
|
|
85
|
+
|
|
86
|
+
## More screenshots
|
|
87
|
+
|
|
88
|
+

|
|
89
|
+
|
|
90
|
+

|
|
91
|
+
|
|
92
|
+

|
|
93
|
+
|
|
94
|
+

|
|
95
|
+
|
|
96
|
+

|
|
97
|
+
|
|
98
|
+

|
|
99
|
+
|
|
100
|
+

|
|
101
|
+
|
|
102
|
+
## Development
|
|
103
|
+
|
|
104
|
+
Run the tests with:
|
|
105
|
+
|
|
106
|
+
rake
|
|
107
|
+
|
|
108
|
+
There are a few scripts in `tools/`:
|
|
109
|
+
|
|
110
|
+
- `snap.rb` renders a scene to a PNG, for example `ruby tools/snap.rb title --at 2`. Add `--fine` for the high resolution mode and `--wide` for the wider field.
|
|
111
|
+
- `pty_check.rb` runs the game in a pseudo terminal and checks the escape sequences, resizing and that the terminal is restored on exit.
|
|
112
|
+
- `bench.rb` measures frame times.
|
|
113
|
+
- `listen.rb` plays the sound effects and songs.
|
|
114
|
+
- `monkey.rb` sends random input to the game to find crashes.
|
|
115
|
+
|
|
116
|
+
`rake build` builds the gem into `pkg/` and `rake install` installs it locally. To release a new version, bump the version in `lib/pixelsnake/version.rb`, add it to `CHANGELOG.md`, commit, and run `rake release`. That runs the tests, pushes the gem to rubygems.org and tags the commit.
|
|
117
|
+
|
|
118
|
+
Some notes on the design and the code structure are in `docs/DESIGN.md`.
|
|
119
|
+
|
|
120
|
+
## License
|
|
121
|
+
|
|
122
|
+
MIT, see [LICENSE](LICENSE).
|
data/bin/pixelsnake
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# A little brass abacus to stand beside the stats' title, its beads in
|
|
5
|
+
# the fruit's red, the snake's green and the lagoon's blue. It rises from
|
|
6
|
+
# behind the panel as the stats open, and every time it is told to
|
|
7
|
+
# count, the next bead slides across its rod against the ones counted
|
|
8
|
+
# before it, a rod at a time from the top. One that counts to the right
|
|
9
|
+
# is the same abacus seen from the other side: the light still comes
|
|
10
|
+
# from the top left.
|
|
11
|
+
class Abacus
|
|
12
|
+
WIDTH = 26
|
|
13
|
+
HEIGHT = 18
|
|
14
|
+
RODS = [4, 8, 12].freeze
|
|
15
|
+
BEADS = 4
|
|
16
|
+
BEAD = 4
|
|
17
|
+
# How far a bead travels, the gap its rod leaves free.
|
|
18
|
+
TRAVEL = 6
|
|
19
|
+
SLIDE = 0.16
|
|
20
|
+
RISE_FROM = 0.15
|
|
21
|
+
RISE = 0.5
|
|
22
|
+
BELOW = HEIGHT + 2
|
|
23
|
+
|
|
24
|
+
# Standing on the ground at y, counting toward the left or the right.
|
|
25
|
+
def initialize(x, ground, toward)
|
|
26
|
+
@x = x
|
|
27
|
+
@y = ground - HEIGHT + 1
|
|
28
|
+
@toward = toward
|
|
29
|
+
@time = 0.0
|
|
30
|
+
@counted = []
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def update(dt)
|
|
34
|
+
@time += dt
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def count
|
|
38
|
+
@counted << @time
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
# Behind the panel, so it can rise from behind it.
|
|
42
|
+
def draw(canvas)
|
|
43
|
+
below = ((1 - Ease.out_back(Ease.progress(@time, RISE_FROM, RISE))) * BELOW).round
|
|
44
|
+
canvas.draw(FRAME, @x, @y + below)
|
|
45
|
+
RODS.each_index do |rod|
|
|
46
|
+
BEADS.times { |bead| canvas.draw(LOOKS[rod], @x + bead_x(rod, bead), @y + RODS[rod] - 1 + below) }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
private
|
|
51
|
+
|
|
52
|
+
# A bead's place on its rod: at home among the beads not yet counted,
|
|
53
|
+
# across among the counted ones, or on its way between.
|
|
54
|
+
def bead_x(rod, bead)
|
|
55
|
+
counted = @counted[bead * RODS.size + rod]
|
|
56
|
+
across = counted ? Ease.out_cubic(Ease.progress(@time, counted, SLIDE)) : 0
|
|
57
|
+
home = 8 + BEAD * bead - (TRAVEL * across).round
|
|
58
|
+
@toward.negative? ? home : WIDTH - BEAD - home
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
LEGEND = {
|
|
62
|
+
"g" => :gold, "a" => :amber, "o" => :orange, "h" => :ash, "n" => :night, "R" => :red, "c" => :crimson,
|
|
63
|
+
"L" => :leaf, "F" => :fern, "J" => :jade, "f" => :foam, "l" => :lagoon, "t" => :teal
|
|
64
|
+
}.freeze
|
|
65
|
+
|
|
66
|
+
FRAME = Sprite.parse(<<~ART, LEGEND)
|
|
67
|
+
.gggggggggggggggggggggggg.
|
|
68
|
+
gaaaaaaaaaaaaaaaaaaaaaaaao
|
|
69
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
70
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
71
|
+
gahhhhhhhhhhhhhhhhhhhhhhao
|
|
72
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
73
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
74
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
75
|
+
gahhhhhhhhhhhhhhhhhhhhhhao
|
|
76
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
77
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
78
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
79
|
+
gahhhhhhhhhhhhhhhhhhhhhhao
|
|
80
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
81
|
+
gannnnnnnnnnnnnnnnnnnnnnao
|
|
82
|
+
gaaaaaaaaaaaaaaaaaaaaaaaao
|
|
83
|
+
.oooooooooooooooooooooooo.
|
|
84
|
+
.oo....................oo.
|
|
85
|
+
ART
|
|
86
|
+
|
|
87
|
+
# A bead for each rod, lit along its top left.
|
|
88
|
+
LOOKS = [<<~FRUIT, <<~SNAKE, <<~LAGOON].map { |art| Sprite.parse(art, LEGEND) }.freeze
|
|
89
|
+
.oo.
|
|
90
|
+
oRRc
|
|
91
|
+
.cc.
|
|
92
|
+
FRUIT
|
|
93
|
+
.LL.
|
|
94
|
+
LFFJ
|
|
95
|
+
.JJ.
|
|
96
|
+
SNAKE
|
|
97
|
+
.ff.
|
|
98
|
+
fllt
|
|
99
|
+
.tt.
|
|
100
|
+
LAGOON
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# Runs the game against a terminal: reads input, steps the simulation in
|
|
5
|
+
# fixed slices of time, then draws a frame and presents it, sixty times a
|
|
6
|
+
# second. It draws as finely as the terminal has room for, and as wide:
|
|
7
|
+
# with room for a column more each side, new games get them. It changes
|
|
8
|
+
# as the terminal does. While the terminal is too small even for the
|
|
9
|
+
# standard canvas it shows the size notice instead and holds the game
|
|
10
|
+
# still.
|
|
11
|
+
class App
|
|
12
|
+
WIDTH = 236
|
|
13
|
+
HEIGHT = 122
|
|
14
|
+
FRAME = 1.0 / 60
|
|
15
|
+
STEP = 1.0 / 120
|
|
16
|
+
LONGEST_CATCH_UP = 0.25
|
|
17
|
+
|
|
18
|
+
def initialize(stage)
|
|
19
|
+
@stage = stage
|
|
20
|
+
@keyboard = Keyboard.new
|
|
21
|
+
@notice = SizeNotice.new
|
|
22
|
+
@overlay = DebugOverlay.new
|
|
23
|
+
@density = nil
|
|
24
|
+
@quit = false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
# The first scene is made once the terminal has been measured, so that
|
|
28
|
+
# it is laid out for the room there is from its first frame.
|
|
29
|
+
def run(terminal)
|
|
30
|
+
@terminal = terminal
|
|
31
|
+
@screen = Screen.new(terminal)
|
|
32
|
+
fit if terminal.resized?
|
|
33
|
+
@stage.show(yield)
|
|
34
|
+
last = now
|
|
35
|
+
lag = 0.0
|
|
36
|
+
until @quit || @stage.done?
|
|
37
|
+
started = now
|
|
38
|
+
lag += [started - last, LONGEST_CATCH_UP].min
|
|
39
|
+
last = started
|
|
40
|
+
fit if terminal.resized?
|
|
41
|
+
handle(@keyboard.read(terminal.read || "", started))
|
|
42
|
+
while lag >= STEP
|
|
43
|
+
@stage.update(STEP) if @density
|
|
44
|
+
lag -= STEP
|
|
45
|
+
end
|
|
46
|
+
present
|
|
47
|
+
@overlay.record(started, now - started, @screen.bytes)
|
|
48
|
+
rest = started + FRAME - now
|
|
49
|
+
sleep(rest) if rest.positive?
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
private
|
|
54
|
+
|
|
55
|
+
def now = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
|
56
|
+
|
|
57
|
+
# The finest density the terminal has room for, if any, and the widest
|
|
58
|
+
# canvas. The origin is the cell at the top left of the scenes' frame.
|
|
59
|
+
def fit
|
|
60
|
+
columns, lines = @terminal.size
|
|
61
|
+
density = Density.fitting(columns, lines)
|
|
62
|
+
hold_still if @density && !density
|
|
63
|
+
if density
|
|
64
|
+
width = columns >= density.wide ? density.wide : density.width
|
|
65
|
+
draw_at(density, width) unless density == @density && width == @canvas.width
|
|
66
|
+
@stage.columns = Courtyard.room(@surface)
|
|
67
|
+
@origin = [(columns - width) / 2 + @canvas.origin, (lines - density.lines) / 2]
|
|
68
|
+
end
|
|
69
|
+
@density = density
|
|
70
|
+
@notice.resize(columns, lines)
|
|
71
|
+
@screen.resize(columns, lines)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# The terminal has become too small: a game pauses, and its music goes
|
|
75
|
+
# behind the door with it, though nothing is updated under the notice.
|
|
76
|
+
def hold_still
|
|
77
|
+
@stage.press(:blur)
|
|
78
|
+
@stage.play_music
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# A canvas of the density's pixels, the frame in its middle, and what
|
|
82
|
+
# the scenes draw on.
|
|
83
|
+
def draw_at(density, width)
|
|
84
|
+
@canvas = Canvas.new(width, density.height, origin: (width - density.width) / 2)
|
|
85
|
+
@surface = density.fine? ? Fine.new(@canvas) : @canvas
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def handle(keys)
|
|
89
|
+
keys.each do |key|
|
|
90
|
+
case key
|
|
91
|
+
in Mouse(column:, line:, kind:) then point(column, line, kind)
|
|
92
|
+
else press(key)
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# While a scene takes a name, letters write in it instead of steering.
|
|
98
|
+
def press(key)
|
|
99
|
+
return @stage.type(key) if @density && @stage.typing? && Controls.writes?(key)
|
|
100
|
+
|
|
101
|
+
action = Controls.action(key)
|
|
102
|
+
case action
|
|
103
|
+
when :quit then @quit = true
|
|
104
|
+
when :debug then @overlay.toggle
|
|
105
|
+
when nil then nil
|
|
106
|
+
else @stage.press(action) if @density
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
# The mouse speaks in cells; the scenes think in points. A cell holds
|
|
111
|
+
# two pixels, one above the other, so a pointer is taken to be at the
|
|
112
|
+
# lower one.
|
|
113
|
+
def point(column, line, kind)
|
|
114
|
+
return unless @density
|
|
115
|
+
|
|
116
|
+
left, top = @origin
|
|
117
|
+
@stage.point(@density.point(column - left), @density.point((line - top) * 2 + 1), kind)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def present
|
|
121
|
+
if @density
|
|
122
|
+
@stage.draw(@surface)
|
|
123
|
+
@overlay.draw(@canvas)
|
|
124
|
+
@screen.present(@canvas)
|
|
125
|
+
else
|
|
126
|
+
@screen.present(@notice.canvas)
|
|
127
|
+
end
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
end
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# Eleven pixels tall with three pixel stems, for titles, the logo and the
|
|
5
|
+
# countdown. Drawn plain here; Lettering gives it an outline, light and a
|
|
6
|
+
# shadow. On the fine canvas it is sixteen tall, every two columns and
|
|
7
|
+
# rows made three, so the stems at the sides are five wide and those in
|
|
8
|
+
# the middle four.
|
|
9
|
+
Font::BIG = Font.parse(<<~SHEET, tracking: 2, space: 5, fine: Font.parse(<<~FINE, tracking: 3, space: 7))
|
|
10
|
+
A B C D E F G
|
|
11
|
+
..#####.. #######.. ..######. #######.. ######### ######### ..######.
|
|
12
|
+
.#######. ########. .######## ########. ######### ######### .########
|
|
13
|
+
###...### ###...### ###...... ###..#### ###...... ###...... ###......
|
|
14
|
+
###...### ###...### ###...... ###...### ###...... ###...... ###......
|
|
15
|
+
###...### ########. ###...... ###...### #######.. #######.. ###..####
|
|
16
|
+
######### ########. ###...... ###...### #######.. #######.. ###..####
|
|
17
|
+
######### ###...### ###...... ###...### ###...... ###...... ###...###
|
|
18
|
+
###...### ###...### ###...... ###...### ###...... ###...... ###...###
|
|
19
|
+
###...### ###...### ###...... ###..#### ###...... ###...... ###...###
|
|
20
|
+
###...### ########. .######## ########. ######### ###...... .########
|
|
21
|
+
###...### #######.. ..######. #######.. ######### ###...... ..######.
|
|
22
|
+
|
|
23
|
+
H I J K L M N
|
|
24
|
+
###...### ####### .....### ###...### ###...... ###.....### ###...###
|
|
25
|
+
###...### ####### .....### ###..###. ###...... ####...#### ####..###
|
|
26
|
+
###...### ..###.. .....### ###.###.. ###...... #####.##### #####.###
|
|
27
|
+
###...### ..###.. .....### ######... ###...... ###.###.### #########
|
|
28
|
+
######### ..###.. .....### #####.... ###...... ###..#..### ###.#####
|
|
29
|
+
######### ..###.. .....### ######... ###...... ###.....### ###..####
|
|
30
|
+
###...### ..###.. .....### ###.###.. ###...... ###.....### ###...###
|
|
31
|
+
###...### ..###.. ###..### ###..###. ###...... ###.....### ###...###
|
|
32
|
+
###...### ..###.. ###..### ###...### ###...... ###.....### ###...###
|
|
33
|
+
###...### ####### .####### ###...### ######### ###.....### ###...###
|
|
34
|
+
###...### ####### ..#####. ###...### ######### ###.....### ###...###
|
|
35
|
+
|
|
36
|
+
O P Q R S T U
|
|
37
|
+
..#####.. #######.. ..#####.. #######.. ..######. ######### ###...###
|
|
38
|
+
.#######. ########. .#######. ########. .######## ######### ###...###
|
|
39
|
+
###...### ###...### ###...### ###...### ###...... ...###... ###...###
|
|
40
|
+
###...### ###...### ###...### ###...### ###...... ...###... ###...###
|
|
41
|
+
###...### ###...### ###...### ###...### .#######. ...###... ###...###
|
|
42
|
+
###...### ########. ###...### ########. ..####### ...###... ###...###
|
|
43
|
+
###...### #######.. ###...### #######.. ......### ...###... ###...###
|
|
44
|
+
###...### ###...... ###.##### ###.###.. ......### ...###... ###...###
|
|
45
|
+
###...### ###...... ###..###. ###..###. ......### ...###... ###...###
|
|
46
|
+
.#######. ###...... .######## ###...### ########. ...###... .#######.
|
|
47
|
+
..#####.. ###...... ..####.## ###...### .######.. ...###... ..#####..
|
|
48
|
+
|
|
49
|
+
V W X Y Z
|
|
50
|
+
###...### ###.....### ###...### ###...### #########
|
|
51
|
+
###...### ###.....### ###...### ###...### #########
|
|
52
|
+
###...### ###.....### .###.###. ###...### .....####
|
|
53
|
+
###...### ###.....### ..#####.. .###.###. ....####.
|
|
54
|
+
###...### ###.....### ...###... ..#####.. ...####..
|
|
55
|
+
.###.###. ###..#..### ...###... ...###... ..####...
|
|
56
|
+
.###.###. ###.###.### ..#####.. ...###... .####....
|
|
57
|
+
..#####.. #####.##### .###.###. ...###... ####.....
|
|
58
|
+
..#####.. ####...#### ###...### ...###... ###......
|
|
59
|
+
...###... ###.....### ###...### ...###... #########
|
|
60
|
+
...###... ###.....### ###...### ...###... #########
|
|
61
|
+
|
|
62
|
+
0 1 2 3 4 5 6
|
|
63
|
+
..#####.. ..###.. .#######. ########. ###...### ######### ..######.
|
|
64
|
+
.#######. .####.. ######### ######### ###...### ######### .#######.
|
|
65
|
+
###...### #####.. ###...### ......### ###...### ###...... ###......
|
|
66
|
+
###..#### ..###.. ......### ......### ###...### ###...... ###......
|
|
67
|
+
###.##### ..###.. ....####. ..######. ######### ########. ########.
|
|
68
|
+
#####.### ..###.. ..####... ..######. ######### ######### #########
|
|
69
|
+
####..### ..###.. .####.... ......### ......### ......### ###...###
|
|
70
|
+
###...### ..###.. ###...... ......### ......### ......### ###...###
|
|
71
|
+
###...### ..###.. ###...... ......### ......### ......### ###...###
|
|
72
|
+
.#######. ####### ######### ######### ......### ######### .#######.
|
|
73
|
+
..#####.. ####### ######### ########. ......### ########. ..#####..
|
|
74
|
+
|
|
75
|
+
7 8 9 ! ? - .
|
|
76
|
+
######### .#######. ..#####.. ### .######. ...... ...
|
|
77
|
+
######### ######### .#######. ### ######## ...... ...
|
|
78
|
+
......### ###...### ###...### ### ##....## ...... ...
|
|
79
|
+
.....###. ###...### ###...### ### ......## ...... ...
|
|
80
|
+
....###.. .#######. ###...### ### ....#### ...... ...
|
|
81
|
+
...###... .#######. ######### ### ...###.. ###### ...
|
|
82
|
+
...###... ###...### .######## ### ...###.. ###### ...
|
|
83
|
+
...###... ###...### ......### ... ........ ...... ...
|
|
84
|
+
...###... ###...### ......### ... ........ ...... ...
|
|
85
|
+
...###... ######### .#######. ### ...###.. ...... ###
|
|
86
|
+
...###... .#######. .######.. ### ...###.. ...... ###
|
|
87
|
+
SHEET
|
|
88
|
+
A B C D E F G
|
|
89
|
+
...########... ###########... ...#########.. ###########... ############## ############## ...#########..
|
|
90
|
+
..##########.. ############.. ..############ ############.. ############## ############## ..############
|
|
91
|
+
..##########.. ############.. ..############ ############.. ############## ############## ..############
|
|
92
|
+
#####....##### #####....##### #####......... #####...###### #####......... #####......... #####.........
|
|
93
|
+
#####....##### #####....##### #####......... #####....##### #####......... #####......... #####.........
|
|
94
|
+
#####....##### #####....##### #####......... #####....##### #####......... #####......... #####.........
|
|
95
|
+
#####....##### ############.. #####......... #####....##### ###########... ###########... #####...######
|
|
96
|
+
############## ############.. #####......... #####....##### ###########... ###########... #####...######
|
|
97
|
+
############## ############.. #####......... #####....##### ###########... ###########... #####...######
|
|
98
|
+
############## #####....##### #####......... #####....##### #####......... #####......... #####....#####
|
|
99
|
+
#####....##### #####....##### #####......... #####....##### #####......... #####......... #####....#####
|
|
100
|
+
#####....##### #####....##### #####......... #####....##### #####......... #####......... #####....#####
|
|
101
|
+
#####....##### #####....##### #####......... #####...###### #####......... #####......... #####....#####
|
|
102
|
+
#####....##### ############.. ..############ ############.. ############## #####......... ..############
|
|
103
|
+
#####....##### ############.. ..############ ############.. ############## #####......... ..############
|
|
104
|
+
#####....##### ###########... ...#########.. ###########... ############## #####......... ...#########..
|
|
105
|
+
|
|
106
|
+
H I J K L M N
|
|
107
|
+
#####....##### ########### .......##### #####....##### #####......... #####.......##### #####....#####
|
|
108
|
+
#####....##### ########### .......##### #####...####.. #####......... ######.....###### ######...#####
|
|
109
|
+
#####....##### ########### .......##### #####...####.. #####......... ######.....###### ######...#####
|
|
110
|
+
#####....##### ...#####... .......##### #####.#####... #####......... ########.######## ########.#####
|
|
111
|
+
#####....##### ...#####... .......##### #########..... #####......... #####.#####.##### ##############
|
|
112
|
+
#####....##### ...#####... .......##### #########..... #####......... #####.#####.##### ##############
|
|
113
|
+
############## ...#####... .......##### ########...... #####......... #####...#...##### #####.########
|
|
114
|
+
############## ...#####... .......##### #########..... #####......... #####.......##### #####...######
|
|
115
|
+
############## ...#####... .......##### #########..... #####......... #####.......##### #####...######
|
|
116
|
+
#####....##### ...#####... .......##### #####.#####... #####......... #####.......##### #####....#####
|
|
117
|
+
#####....##### ...#####... ####...##### #####...####.. #####......... #####.......##### #####....#####
|
|
118
|
+
#####....##### ...#####... ####...##### #####...####.. #####......... #####.......##### #####....#####
|
|
119
|
+
#####....##### ...#####... ####...##### #####....##### #####......... #####.......##### #####....#####
|
|
120
|
+
#####....##### ########### .########### #####....##### ############## #####.......##### #####....#####
|
|
121
|
+
#####....##### ########### .########### #####....##### ############## #####.......##### #####....#####
|
|
122
|
+
#####....##### ########### ...#######.. #####....##### ############## #####.......##### #####....#####
|
|
123
|
+
|
|
124
|
+
O P Q R S T U
|
|
125
|
+
...########... ###########... ...########... ###########... ...#########.. ############## #####....#####
|
|
126
|
+
..##########.. ############.. ..##########.. ############.. ..############ ############## #####....#####
|
|
127
|
+
..##########.. ############.. ..##########.. ############.. ..############ ############## #####....#####
|
|
128
|
+
#####....##### #####....##### #####....##### #####....##### #####......... .....####..... #####....#####
|
|
129
|
+
#####....##### #####....##### #####....##### #####....##### #####......... .....####..... #####....#####
|
|
130
|
+
#####....##### #####....##### #####....##### #####....##### #####......... .....####..... #####....#####
|
|
131
|
+
#####....##### #####....##### #####....##### #####....##### ..##########.. .....####..... #####....#####
|
|
132
|
+
#####....##### ############.. #####....##### ############.. ...########### .....####..... #####....#####
|
|
133
|
+
#####....##### ############.. #####....##### ############.. ...########### .....####..... #####....#####
|
|
134
|
+
#####....##### ###########... #####....##### ###########... .........##### .....####..... #####....#####
|
|
135
|
+
#####....##### #####......... #####.######## #####.#####... .........##### .....####..... #####....#####
|
|
136
|
+
#####....##### #####......... #####.######## #####.#####... .........##### .....####..... #####....#####
|
|
137
|
+
#####....##### #####......... #####...####.. #####...####.. .........##### .....####..... #####....#####
|
|
138
|
+
..##########.. #####......... ..############ #####....##### ############.. .....####..... ..##########..
|
|
139
|
+
..##########.. #####......... ..############ #####....##### ############.. .....####..... ..##########..
|
|
140
|
+
...########... #####......... ...######..### #####....##### ..#########... .....####..... ...########...
|
|
141
|
+
|
|
142
|
+
V W X Y Z
|
|
143
|
+
#####....##### #####.......##### #####....##### #####....##### ##############
|
|
144
|
+
#####....##### #####.......##### #####....##### #####....##### ##############
|
|
145
|
+
#####....##### #####.......##### #####....##### #####....##### ##############
|
|
146
|
+
#####....##### #####.......##### ..####..####.. #####....##### ........######
|
|
147
|
+
#####....##### #####.......##### ...########... ..####..####.. ......######..
|
|
148
|
+
#####....##### #####.......##### ...########... ..####..####.. ......######..
|
|
149
|
+
#####....##### #####.......##### .....####..... ...########... .....######...
|
|
150
|
+
..####..####.. #####...#...##### .....####..... .....####..... ...######.....
|
|
151
|
+
..####..####.. #####...#...##### .....####..... .....####..... ...######.....
|
|
152
|
+
..####..####.. #####.#####.##### ...########... .....####..... ..######......
|
|
153
|
+
...########... ########.######## ..####..####.. .....####..... ######........
|
|
154
|
+
...########... ########.######## ..####..####.. .....####..... ######........
|
|
155
|
+
...########... ######.....###### #####....##### .....####..... #####.........
|
|
156
|
+
.....####..... #####.......##### #####....##### .....####..... ##############
|
|
157
|
+
.....####..... #####.......##### #####....##### .....####..... ##############
|
|
158
|
+
.....####..... #####.......##### #####....##### .....####..... ##############
|
|
159
|
+
|
|
160
|
+
0 1 2 3 4 5 6
|
|
161
|
+
...########... ...#####... ..##########.. ############.. #####....##### ############## ...#########..
|
|
162
|
+
..##########.. .#######... ############## ############## #####....##### ############## ..##########..
|
|
163
|
+
..##########.. .#######... ############## ############## #####....##### ############## ..##########..
|
|
164
|
+
#####....##### ########... #####....##### .........##### #####....##### #####......... #####.........
|
|
165
|
+
#####...###### ...#####... .........##### .........##### #####....##### #####......... #####.........
|
|
166
|
+
#####...###### ...#####... .........##### .........##### #####....##### #####......... #####.........
|
|
167
|
+
#####.######## ...#####... ......######.. ...#########.. ############## ############.. ############..
|
|
168
|
+
########.##### ...#####... ...######..... ...#########.. ############## ############## ##############
|
|
169
|
+
########.##### ...#####... ...######..... ...#########.. ############## ############## ##############
|
|
170
|
+
######...##### ...#####... ..######...... .........##### .........##### .........##### #####....#####
|
|
171
|
+
#####....##### ...#####... #####......... .........##### .........##### .........##### #####....#####
|
|
172
|
+
#####....##### ...#####... #####......... .........##### .........##### .........##### #####....#####
|
|
173
|
+
#####....##### ...#####... #####......... .........##### .........##### .........##### #####....#####
|
|
174
|
+
..##########.. ########### ############## ############## .........##### ############## ..##########..
|
|
175
|
+
..##########.. ########### ############## ############## .........##### ############## ..##########..
|
|
176
|
+
...########... ########### ############## ############.. .........##### ############.. ...########...
|
|
177
|
+
|
|
178
|
+
7 8 9 ! ? - .
|
|
179
|
+
############## ..##########.. ...########... ##### .#########.. .......... .....
|
|
180
|
+
############## ############## ..##########.. ##### ############ .......... .....
|
|
181
|
+
############## ############## ..##########.. ##### ############ .......... .....
|
|
182
|
+
.........##### #####....##### #####....##### ##### ###......### .......... .....
|
|
183
|
+
........####.. #####....##### #####....##### ##### .........### .......... .....
|
|
184
|
+
........####.. #####....##### #####....##### ##### .........### .......... .....
|
|
185
|
+
......#####... ..##########.. #####....##### ##### ......###### .......... .....
|
|
186
|
+
.....####..... ..##########.. ############## ##### ....#####... ########## .....
|
|
187
|
+
.....####..... ..##########.. ############## ##### ....#####... ########## .....
|
|
188
|
+
.....####..... #####....##### ..############ ##### ....#####... ########## .....
|
|
189
|
+
.....####..... #####....##### .........##### ..... ............ .......... .....
|
|
190
|
+
.....####..... #####....##### .........##### ..... ............ .......... .....
|
|
191
|
+
.....####..... #####....##### .........##### ..... ............ .......... .....
|
|
192
|
+
.....####..... ############## ..##########.. ##### ....#####... .......... #####
|
|
193
|
+
.....####..... ############## ..##########.. ##### ....#####... .......... #####
|
|
194
|
+
.....####..... ..##########.. ..#########... ##### ....#####... .......... #####
|
|
195
|
+
FINE
|
|
196
|
+
end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module PixelSnake
|
|
4
|
+
# The snake's head, drawn facing right and facing left; facing down and up
|
|
5
|
+
# are their transposes. Each fills its tile, with the neck at the back
|
|
6
|
+
# matching the body's cross-section so the two join without a seam. "E"
|
|
7
|
+
# marks the top left of each eye, which the snake view fills in. The fine
|
|
8
|
+
# heads are twelve pixels square, with eyes three wide and nostrils near
|
|
9
|
+
# the snout.
|
|
10
|
+
module Heads
|
|
11
|
+
LEGEND = {
|
|
12
|
+
"d" => :deep, "p" => :pine, "j" => :jade, "f" => :fern, "l" => :leaf, "L" => :lime,
|
|
13
|
+
"E" => :gold, "e" => :gold
|
|
14
|
+
}.freeze
|
|
15
|
+
|
|
16
|
+
RIGHT = <<~ART
|
|
17
|
+
..ppp...
|
|
18
|
+
pplEep..
|
|
19
|
+
llleelp.
|
|
20
|
+
fffffffd
|
|
21
|
+
ffffffjd
|
|
22
|
+
jjjEejd.
|
|
23
|
+
ddjeed..
|
|
24
|
+
..ddd...
|
|
25
|
+
ART
|
|
26
|
+
|
|
27
|
+
LEFT = <<~ART
|
|
28
|
+
...ppp..
|
|
29
|
+
..pEelpp
|
|
30
|
+
.pleelll
|
|
31
|
+
pfffffff
|
|
32
|
+
pjffffff
|
|
33
|
+
.djEejjj
|
|
34
|
+
..deejdd
|
|
35
|
+
...ddd..
|
|
36
|
+
ART
|
|
37
|
+
|
|
38
|
+
FINE_RIGHT = <<~ART
|
|
39
|
+
....pppp....
|
|
40
|
+
pppplEeep...
|
|
41
|
+
llllleeelp..
|
|
42
|
+
llllleeellp.
|
|
43
|
+
llllllllldlp
|
|
44
|
+
fffffffffffd
|
|
45
|
+
fffffffffffd
|
|
46
|
+
jjjjjjjjjdjd
|
|
47
|
+
jjjjjEeejjd.
|
|
48
|
+
jjjjjeeejd..
|
|
49
|
+
ddddjeeed...
|
|
50
|
+
....dddd....
|
|
51
|
+
ART
|
|
52
|
+
|
|
53
|
+
FINE_LEFT = <<~ART
|
|
54
|
+
....pppp....
|
|
55
|
+
...pEeelpppp
|
|
56
|
+
..pleeelllll
|
|
57
|
+
.plleeelllll
|
|
58
|
+
pldlllllllll
|
|
59
|
+
pfffffffffff
|
|
60
|
+
pfffffffffff
|
|
61
|
+
djdjjjjjjjjj
|
|
62
|
+
.djjEeejjjjj
|
|
63
|
+
..djeeejjjjj
|
|
64
|
+
...deeejdddd
|
|
65
|
+
....dddd....
|
|
66
|
+
ART
|
|
67
|
+
end
|
|
68
|
+
end
|