annotate doc/architecture.md @ 33:767970d80214

Added tag 0.10.0 for changeset 85d23328a215
author ark
date 2026-10-20 18:39 +0200
parents 85d23328a215
children a464bd43b76c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
1 architecture
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
2 ------------
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
3
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
4 the game is a static html page with plain javascript, drawn on a 2d canvas. it
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
5 uses no javascript libraries. a python build script prepares everything that
fe680946164b reorganised repo
ark
parents: 14
diff changeset
6 can be calculated in advance: processed images, map data, route data and the
fe680946164b reorganised repo
ark
parents: 14
diff changeset
7 config. it writes them to www/, together with a copy of the hand-written game
fe680946164b reorganised repo
ark
parents: 14
diff changeset
8 files from game/. www/ is the runnable game. it is not kept in the repository,
fe680946164b reorganised repo
ark
parents: 14
diff changeset
9 so the game has to be built before it can be run.
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
10
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
11 this is a plan; nothing is implemented yet.
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
12
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
13
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
14 directory layout
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
15 ----------------
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
16
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
17 proposed:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
18
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
19 art/ drawings as supplied: scans, masks, sprites
4
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
20 sound_sources/ voice recordings as supplied
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
21 sounds/ sounds cut from the recordings (tools/cut_sounds.py)
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
22 config/ hand-edited game settings (toml)
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
23 game.toml numbers from balance.md, waves, debug switches
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
24 tools/ python build scripts
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
25 game/ hand-written game files
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
26 index.html
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
27 style.css
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
28 js/ game code
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
29 doc/ design and technical notes
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
30 www/ the built game, opened as www/index.html (generated, ignored)
fe680946164b reorganised repo
ark
parents: 14
diff changeset
31 index.html copied from game/, as are style.css and js/
fe680946164b reorganised repo
ark
parents: 14
diff changeset
32 assets/ processed images
fe680946164b reorganised repo
ark
parents: 14
diff changeset
33 data/ maps.js, sounds.js, config.js
27
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
34 dist/ tarballs for distribution (ignored)
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
35 temp/ scratch files, build previews (ignored)
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
36
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
37 generated files carry a header line saying so and naming the script that made
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
38 them.
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
39
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
40
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
41 running the game
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
42 ----------------
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
43
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
44 - desktop: open www/index.html directly from disk, or serve the directory
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
45 with any static web server
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
46 - tablet: tablets cannot easily open local html files, so the game is served
27
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
47 over http, from a computer on the home network or from a web host. the
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
48 tarball in dist/ is meant for that
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
49 - an optional later step makes it installable to the home screen (web app
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
50 manifest, offline cache). that requires https
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
51
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
52 opening the page from disk (file://) limits what the browser allows. chrome
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
53 blocks javascript modules, fetch() and reading pixels back from a canvas
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
54 there. so:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
55
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
56 - scripts are loaded with plain script tags in a fixed order, and share one
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
57 global namespace object
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
58 - data files are javascript files that assign to that object, not json files
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
59 - the game never reads mask pixels; the build turns the masks into data
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
60 - images are loaded with image elements, which works from disk
4
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
61 - recorded sounds are embedded by the build as base64 data in a javascript
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
62 file, so they can be decoded without fetch()
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
63
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
64
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
65 screenshots
910b26feca76 full game flow
ark
parents: 4
diff changeset
66 -----------
910b26feca76 full game flow
ark
parents: 4
diff changeset
67
910b26feca76 full game flow
ark
parents: 4
diff changeset
68 firefox's own --screenshot captures at the load event. the game loads its
910b26feca76 full game flow
ark
parents: 4
diff changeset
69 images and draws its first frame after that, so the capture shows an empty
910b26feca76 full game flow
ark
parents: 4
diff changeset
70 page. the ff_screenshot script (in $PATH, ~/bin/ff_screenshot) drives
910b26feca76 full game flow
ark
parents: 4
diff changeset
71 headless firefox over marionette and waits before capturing:
910b26feca76 full game flow
ark
parents: 4
diff changeset
72
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
73 ff_screenshot -w 1024,768 -s 2 file://$PWD/www/index.html temp/splash.png
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
74
910b26feca76 full game flow
ark
parents: 4
diff changeset
75 -w sets the viewport, -s the wait after loading. the game state is not
910b26feca76 full game flow
ark
parents: 4
diff changeset
76 reachable from outside, so other screens are reached by tapping: -J runs
910b26feca76 full game flow
ark
parents: 4
diff changeset
77 javascript after the wait, and -S waits again before capturing. a pointer
910b26feca76 full game flow
ark
parents: 4
diff changeset
78 event sent to the canvas counts as a tap at that position in css pixels.
32
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
79 a fresh firefox profile has no stored settings, so the splash screen first
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
80 shows the sound button over the play button (sound.md). this taps it, and
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
81 the play button a second later, at 1024 x 768:
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
82
32
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
83 ff_screenshot -w 1024,768 -s 2 -S 3 -J 'function tap() {
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
84 document.getElementById("game").dispatchEvent(new PointerEvent(
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
85 "pointerdown", {clientX: 497, clientY: 560, bubbles: true})) }
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
86 tap(); setTimeout(tap, 1000)' \
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
87 file://$PWD/www/index.html temp/play.png
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
88
910b26feca76 full game flow
ark
parents: 4
diff changeset
89 `ff_screenshot -h` lists the other options.
910b26feca76 full game flow
ark
parents: 4
diff changeset
90
910b26feca76 full game flow
ark
parents: 4
diff changeset
91
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
92 build
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
93 -----
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
94
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
95 one command, `python3 tools/build.py`, runs all steps. each step skips its work
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
96 when its inputs have not changed. requires python 3.11 or later (for the
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
97 built-in toml reader) and pillow. numpy is optional, if the pure python image
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
98 steps turn out too slow.
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
99
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
100 tools/cut_sheet.py, tools/cut_digits.py and tools/cut_sounds.py are run by
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
101 hand and write to art/.
4
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
102 cut_sounds.py also needs ffmpeg with mp3 support, so the build itself does not
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
103 depend on it. see sound.md.
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
104
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
105 steps:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
106
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
107 1. sprites: trim transparent edges, write to www/assets/. this covers the
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
108 icons, buttons and screens, and the digits from art/digits/ as
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
109 digit_NAME_N. make the hp bar variants: the empty part, and the blue bars
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
110 for slowed monsters (art.md)
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
111 2. tower levels: t0-t3 are level 1. split each t*p strip into four images,
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
112 levels 2-5. fill the inside of the outline with white (flood fill from
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
113 outside, everything not reached is inside), trim, write as t0_2..t0_5 and
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
114 so on. see art.md
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
115 3. maps: copy the map images, possibly converted to a smaller format
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
116 4. masks: for each map
9
53f015966118 map, path, tower placement adjustments
ark
parents: 8
diff changeset
117 - classify pixels as path, entrance, exit or free by their exact colour.
53f015966118 map, path, tower placement adjustments
ark
parents: 8
diff changeset
118 masks must have hard edges: a pixel that is neither fully transparent
53f015966118 map, path, tower placement adjustments
ark
parents: 8
diff changeset
119 nor opaque pure red, blue or green stops the build (art.md)
53f015966118 map, path, tower placement adjustments
ark
parents: 8
diff changeset
120 - extract routes, see below
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
121 - write a placement grid: cells where a tower footprint fits next to the
9
53f015966118 map, path, tower placement adjustments
ark
parents: 8
diff changeset
122 road, within the limits in balance.md. the red path in the mask is the
53f015966118 map, path, tower placement adjustments
ark
parents: 8
diff changeset
123 centre line of the road; the road's half width is set per map
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
124 5. sounds: embed art/sounds/*.mp3 as base64 in www/data/sounds.js,
4
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
125 grouped by event
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
126 6. config: read config/game.toml, check it, write www/data/config.js
4
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
127 7. checks: print a summary per map (routes with length and turning, monster
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
128 counts, coins and hp per map against the target) and warn on problems
4
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
129 8. previews: draw each map with its routes, entrances, exits and placement
21
fa04481563b7 doc update
ark
parents: 17
diff changeset
130 grid into temp/preview/, for checking without starting the game. towers.png
fa04481563b7 doc update
ark
parents: 17
diff changeset
131 shows the tower levels, each turned by its drawing direction to face up,
fa04481563b7 doc update
ark
parents: 17
diff changeset
132 with its pivot and footprint
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
133 9. game files: copy the files in game/ to www/. a file is copied when its
fe680946164b reorganised repo
ark
parents: 14
diff changeset
134 time or size differs from the copy. files no longer in game/ are removed
27
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
135 from www/, apart from www/assets/ and www/data/. a release build writes
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
136 www/js/debug.js empty
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
137
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
138 a watch mode (`tools/build.py --watch`) reruns the build when a file in
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
139 config/, art/, art/sounds/ or game/ changes. tuning then means: edit the toml,
fe680946164b reorganised repo
ark
parents: 14
diff changeset
140 save, reload the browser. the same goes for changes to the game code: they
fe680946164b reorganised repo
ark
parents: 14
diff changeset
141 show in www/ only after the build has copied them.
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
142
27
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
143 `tools/build.py --release` leaves the debug code out: it writes
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
144 www/js/debug.js empty and leaves [debug] out of config.js. the game then
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
145 runs as with every debug switch off.
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
146
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
147 `tools/make_dist.sh` runs a release build and packs www/ into
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
148 dist/minor_monsters_VERSION.tar.gz, which unpacks into a directory
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
149 minor_monsters. the version comes from `tools/get_version.sh -f`: the
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
150 latest tag, with a timestamp appended when the working directory is not
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
151 clean or not at the tagged revision. `--debug` builds with the debug code
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
152 in place of a release build. www/ keeps the build the script made, so a
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
153 plain build afterwards brings the debug code back.
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
154
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
155
22
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
156 balance tools
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
157 -------------
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
158
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
159 tools/balance.py estimates, map by map and wave by wave, whether the coins
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
160 a map pays buy enough firepower (balance.md, balancing). it is run by hand
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
161 after a build: it reads config/game.toml, and the routes and placement grid
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
162 from temp/build/maps.json. it only calculates and leaves the images alone.
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
163 it writes tables and charts (numpy, matplotlib) to temp/preview/:
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
164
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
165 - balance.txt: value per coin for every tower and level; per map the
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
166 coverage of each tower's range, and per wave the coins on hand, the
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
167 damage rate both demands need and the coins the naive and greedy players
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
168 need to hold the wave
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
169 - balance_value.png: value per coin by tower level
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
170 - balance_map0.png to balance_map3.png: coins per wave, and the surplus at
23
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
171 the last wave and the hearts left against a wave size factor. the factor
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
172 scales the number of regular monsters in every wave; the coins they drop
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
173 follow
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
174
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
175 `tools/balance.py --draft` prints wave lists made from the draft numbers in
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
176 each map's section of the config (balance.md, waves), as toml to paste over
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
177 the map's [[map.N.wave]] lists. `--draft 2` does map2 only. below each map
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
178 it prints what the calculation makes of the drafted lists. nothing is
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
179 written in this mode.
22
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
180
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
181 tools/build.py does not count balance.py as one of its inputs, so changing
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
182 it does not rebuild the game.
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
183
23
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
184 tools/simulate.js checks the calculation by playing the real game logic
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
185 with scripted players. it is run by hand with node after a build:
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
186
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
187 node tools/simulate.js
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
188 node tools/simulate.js --maps 2 --players naive,naive_t0 --seeds 10
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
189
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
190 it loads www/data/config.js, www/data/maps.js and the logic files util.js,
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
191 assets.js, map.js, monster.js, tower.js, projectile.js, wave.js and
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
192 game.js, as the browser would, with window set to the global object.
27
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
193 render.js, ui.js, input.js, debug.js and main.js are left out, so the
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
194 debug switches have no effect. MM.audio is the only stub; assets.js loads
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
195 unchanged, since sprite sizes come from the config and images are only
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
196 loaded by main.js.
23
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
197
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
198 the game advances in steps of 1/60 s, as in the browser; game speed plays
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
199 no part. each run has its own seed, passed to the game. the players build,
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
200 upgrade and start waves through the game's own functions (shop choice,
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
201 preview, build, tower selection, upgrade, early start), so placement rules
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
202 and prices are the game's. the players and their rules are listed at the
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
203 top of the file; naive and greedy follow balance.md, balancing, and pick
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
204 cells as tools/balance.py does, from the placement grid in maps.js.
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
205
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
206 the coins a wave needs are measured by playing that wave alone from an
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
207 empty map with the first purchases of the player's list, and searching
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
208 for the fewest that lose no heart. every wave starts on an empty map in
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
209 the game, so this matches the wave in a full run, apart from towers
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
210 bought during the wave.
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
211
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
212 it writes temp/preview/simulate.txt (per map and player: maps won, hearts
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
213 left, coins on hand and the surplus at the start of the last wave, hearts
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
214 lost per wave) and temp/preview/simulate.json, which tools/balance.py reads
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
215 for the hits per t0 attack. `--need all` measures the coins needed for
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
216 every wave, `--waves` takes wave lists from a json file in place of the
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
217 config's, for trying drafts without a build.
22
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
218
ad1b478fc4dc balancing work, docs and scripts
ark
parents: 21
diff changeset
219
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
220 routes
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
221 ------
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
222
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
223 a route is a list of points from an entrance to an exit. a map has one or
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
224 more routes. a monster picks a route at spawn (weights in balance.md) and
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
225 follows it to the end. this handles the branches on map1 and map2 without
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
226 junction logic at runtime.
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
227
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
228 extraction in the build:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
229
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
230 1. thin the path pixels to a one-pixel centre line (skeleton)
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
231 2. turn the skeleton into a graph of junctions and segments, and drop short
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
232 dead ends left by uneven strokes
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
233 3. find the graph nodes nearest to each entrance and exit blob
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
234 4. list every path through the graph from an entrance to an exit that visits
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
235 no junction twice
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
236 5. smooth each route and reduce it to a few points per bend
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
237 6. record length and turning for each route
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
238
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
239 map0 and map3 give one route each. map1 and map2 give several; map2 may give
23
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
240 more than wanted. where the automatic result is wrong, the mask is redrawn.
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
241
10
22b604680c5a adjusted monster movement to be less uniform
ark
parents: 9
diff changeset
242 the game walks a monster along the route's centre line, by distance, and
22b604680c5a adjusted monster movement to be less uniform
ark
parents: 9
diff changeset
243 draws it beside the line. the offset is set per monster at spawn
22b604680c5a adjusted monster movement to be less uniform
ark
parents: 9
diff changeset
244 (balance.md, monsters) and needs no route data from the build. when a map
22b604680c5a adjusted monster movement to be less uniform
ark
parents: 9
diff changeset
245 loads, each route works out the sideways direction at its points and how far
22b604680c5a adjusted monster movement to be less uniform
ark
parents: 9
diff changeset
246 an offset may go on the inside of each bend. towers rank monsters by their
22b604680c5a adjusted monster movement to be less uniform
ark
parents: 9
diff changeset
247 distance along the centre line, so the offset does not change the order.
22b604680c5a adjusted monster movement to be less uniform
ark
parents: 9
diff changeset
248
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
249
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
250 config
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
251 ------
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
252
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
253 config/game.toml holds every number in balance.md, the wave lists, and debug
17
fe680946164b reorganised repo
ark
parents: 14
diff changeset
254 switches. the build converts it into www/data/config.js. toml allows comments,
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
255 so each value can carry its source note (guess, decided).
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
256
14
7fda634d15ad adjustments to wave logic, tower pivot points
ark
parents: 13
diff changeset
257 wave format:
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
258
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
259 [[map.0.wave]]
14
7fda634d15ad adjustments to wave logic, tower pivot points
ark
parents: 13
diff changeset
260 monsters = { m0 = 5, m1 = 1, m2 = 1, b0 = 1 }
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
261
14
7fda634d15ad adjustments to wave logic, tower pivot points
ark
parents: 13
diff changeset
262 a wave lists how many of each monster it holds. when the wave starts, the
7fda634d15ad adjustments to wave logic, tower pivot points
ark
parents: 13
diff changeset
263 boss spawns first: it is the slowest monster and the others overtake it. the
7fda634d15ad adjustments to wave logic, tower pivot points
ark
parents: 13
diff changeset
264 rest follow one per spawn interval, each drawn at random from the monsters
7fda634d15ad adjustments to wave logic, tower pivot points
ark
parents: 13
diff changeset
265 left in the wave. the spawn interval is set per map. the boss is in the last
7fda634d15ad adjustments to wave logic, tower pivot points
ark
parents: 13
diff changeset
266 wave.
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
267
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
268 debug switches, all off by default:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
269
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
270 - start coins override, unlimited coins
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
271 - start at a given map and wave. that map counts as the first map: the play
910b26feca76 full game flow
ark
parents: 4
diff changeset
272 button starts it, and a lost map returns to it
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
273 - no heart loss
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
274 - show routes, placement grid, tower ranges, hit areas
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
275 - on-screen frame time and entity counts
27
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
276 - a fixed random seed
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
277
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
278 js/debug.js holds the code for all of them. it replaces functions of the
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
279 game and the top bar drawing, and render.js calls it to draw over the map
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
280 image and over the monsters. main.js takes the start map, wave and seed
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
281 from it. without it, as in a release build, nothing of this is left.
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
282
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
283 there is no in-game config editor: values are changed in the toml file.
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
284
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
285
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
286 runtime
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
287 -------
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
288
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
289 script files, in load order:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
290
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
291 data/config.js generated settings
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
292 data/maps.js generated map data
4
2d46729a022e sound processing and in-game sounds
ark
parents: 0
diff changeset
293 data/sounds.js generated sound data
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
294 js/util.js vector maths, random numbers, easing
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
295 js/storage.js settings kept in the browser
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
296 js/assets.js image loading, sprite table
32
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
297 js/audio.js recorded sounds, placeholder beeps for the other events,
85d23328a215 added intro music, logic for browser audio triggering on splash screen
ark
parents: 27
diff changeset
298 splash screen music
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
299 js/map.js placement lookup, snapping, route sampling
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
300 js/monster.js movement along a route, hops, slow, hp
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
301 js/tower.js targeting, attacks, upgrade, sell
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
302 js/projectile.js
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
303 js/wave.js wave timing, countdown, early start bonus
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
304 js/game.js game state, rules, win and loss
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
305 js/render.js drawing
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
306 js/ui.js top bar, shop, tower menu, screens
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
307 js/input.js pointer events
27
75deda08db90 game debug functions separated into own file; release build option, distribution script
ark
parents: 24
diff changeset
308 js/debug.js debug switches, empty in a release build
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
309 js/main.js start-up and main loop
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
310
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
311 game loop:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
312
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
313 - the simulation advances in fixed steps of 1/60 s. drawing happens once per
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
314 browser frame and is independent of it
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
315 - game speed 2x runs two simulation steps per frame
13
8df95050fc8b no more build during pause; tower popup closes on any click outside it
ark
parents: 11
diff changeset
316 - pause stops the simulation; drawing and the top bar buttons continue
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
317 - a frame that takes too long runs at most a few steps and drops the rest, so
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
318 the game slows down rather than freezing after the tab was in the background
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
319
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
320 state:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
321
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
322 - game state is plain objects: monsters, towers, projectiles, coins in flight,
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
323 wave state, coins, hearts. rendering reads it and does not change it
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
324 - random numbers come from one seeded generator, so a run can be repeated with
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
325 the same seed when chasing a bug
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
326
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
327 display:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
328
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
329 - the canvas fills the window. the map is scaled to fit and centred, with
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
330 borders where the shapes differ
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
331 - the canvas resolution follows the device pixel ratio, so drawings stay sharp
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
332 on high-resolution screens
24
3f2811aebb3d splash screen buttons, help button, info screen
ark
parents: 23
diff changeset
333 - layout: top bar with coins, hearts, wave, countdown, sound, speed, pause
3f2811aebb3d splash screen buttons, help button, info screen
ark
parents: 23
diff changeset
334 and help. on a narrow screen the buttons move to a second row under the
23
2f555a54c332 layout fixes and balancing
ark
parents: 22
diff changeset
335 counters. the tower shop sits on the right in landscape and at the bottom in portrait
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
336 - buttons are at least 48 css pixels for touch
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
337
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
338 input:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
339
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
340 - pointer events cover mouse and touch alike
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
341 - nothing relies on hover; selection and confirmation are by tap. with a
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
342 mouse, hover enlarges the screen buttons and shows the pointer cursor over
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
343 any button
11
a77857594150 adjusted tower building, added preview dragging
ark
parents: 10
diff changeset
344 - buttons and tower selection act when the pointer goes down. placing
a77857594150 adjusted tower building, added preview dragging
ark
parents: 10
diff changeset
345 follows the pointer until it is let go, and building happens then
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
346 - the page blocks browser zoom and scroll gestures on the canvas
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
347
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
348 placement:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
349
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
350 - the build's placement grid marks every cell where a tower may stand
11
a77857594150 adjusted tower building, added preview dragging
ark
parents: 10
diff changeset
351 - while the pointer is down, the game searches outward from it for the
a77857594150 adjusted tower building, added preview dragging
ark
parents: 10
diff changeset
352 nearest legal cell that keeps the minimum distance to other towers, within
a77857594150 adjusted tower building, added preview dragging
ark
parents: 10
diff changeset
353 the snap radius. where there is none, the preview stays where it was
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
354 - t0 checks once, at placement, which of its four sides face the path, and
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
355 only draws spikes on those
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
356
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
357 persistence:
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
358
6
910b26feca76 full game flow
ark
parents: 4
diff changeset
359 - nothing is stored for now. maps are played in order and a lost map goes
910b26feca76 full game flow
ark
parents: 4
diff changeset
360 back to the first map, so there is no progress to keep. a reload starts at
910b26feca76 full game flow
ark
parents: 4
diff changeset
361 the splash screen with a fresh game
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
362 - settings, so far only sound on or off, are stored by js/storage.js. it
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
363 wraps localStorage, and one entry holds them
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
364 - all access is wrapped so the game still runs when storage is unavailable,
8
2c4fed8baed9 art update, persistent sound setting, tower selling as double action
ark
parents: 6
diff changeset
365 for example in private browsing; settings are then not kept
0
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
366 - the entry carries a version number for later format changes
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
367
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
368
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
369 not planned
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
370 -----------
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
371
7af9dd4e2595 initial art and design/planning docs
ark
parents:
diff changeset
372 - in-browser editors or tuning panels