# HG changeset patch # User ark # Date 1792614883 -7200 # Node ID a464bd43b76ce651cb90ca7561f10de003762e88 # Parent 0d40f346059c5532373e52bf45738f8bd22de93b clean documentation rewrite diff -r 0d40f346059c -r a464bd43b76c AGENTS.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/AGENTS.md Wed Oct 21 22:34:43 2026 +0200 @@ -0,0 +1,107 @@ +agent instructions +------------------ + +minor monsters is a browser tower defense game, in beta and feature +complete. expected work: fixes found in playtesting, and balance tweaks. +README.md has the overview. + +what to read +------------ + +load only the document the task needs. each is self-contained. + +- rules or behaviour of the game: doc/game.md +- build, config layout, runtime structure, debug switches: + doc/architecture.md +- changing or debugging an algorithm, layout or input detail: + doc/implementation.md, then the code +- sprites, masks, screens, sound events: doc/art.md +- balance tweaks or the balance tools: doc/balancing.md +- open items: doc/roadmap.md + +sources of truth +---------------- + +- config/game.toml holds every tuning value. the docs refer to its + sections and do not repeat its numbers. where a doc and the config + disagree, the config is right +- the code is right about behaviour. when a doc disagrees with the code, + say so; do not change the code to match the doc without asking +- when a change alters behaviour described in a doc, update that doc in + the same change. keep doc and config comments free of values that + repeat the config + +files +----- + +- never edit www/, dist/ or temp/. they are generated and ignored by + mercurial. files with a "generated by" header line are build output +- game/ holds the hand-written game files. the build copies them to www/; + a change shows in the browser only after a build +- art/ holds supplied files. only the cutting scripts write there + +code conventions +---------------- + +- javascript: no libraries, no modules, no build step for code. plain + script tags in the order of game/index.html, one global namespace MM, + "use strict" inside each module, var and function declarations as in + the existing files. the page must keep working from file://, so no + fetch(), no canvas pixel reads +- data the game needs from images is prepared by tools/build.py +- python: 3.11 or later. the build uses the standard library and pillow + only; numpy and matplotlib are for tools/balance.py alone +- comments are lower case prose, as in the existing files. the docs for + human readers, README.md and doc/, use normal capitalisation: capital + letters at the start of sentences, headings and list items, and for + names and abbreviations such as HTML or Python. code names, files and + config keys keep their spelling +- a new sprite has to be added to SPRITES in tools/build.py. a new sound + event needs an entry in [sound.event]; a recording with variants also an + entry in VARIANTS in tools/cut_sounds.py + +commands +-------- + + python3 tools/build.py # build into www/ + python3 tools/build.py --force # rerun every step + python3 tools/build.py --release # no debug code + tools/make_dist.sh # release tarball in dist/ + node tools/simulate.js # scripted players on the real game logic + python3 tools/balance.py # balance estimate, needs numpy, matplotlib + python3 tools/balance.py --draft 2 # wave lists drafted for map2 + +the build prints checks and warnings per map; read them after a change to +the config or the masks. temp/preview/ has map previews with routes and +placement grid, and towers.png with tower angles and pivots. + +for balance changes: edit config/game.toml, build, run tools/simulate.js +and compare temp/preview/simulate.txt with the targets in +doc/balancing.md. + +screenshots +----------- + +firefox's own --screenshot captures before the game has drawn. use +ff_screenshot (in $PATH), which drives headless firefox and waits before +capturing. `ff_screenshot -h` lists its options. + + ff_screenshot -w 1024,768 -s 2 file://$PWD/www/index.html temp/splash.png + +-w sets the viewport, -s the wait after loading. the game state is not +reachable from outside, so other screens are reached by tapping: -J runs +javascript after the wait, -S waits again before capturing. a pointer +event sent to the canvas is a tap at that position in css pixels. a fresh +firefox profile has no stored settings, so the splash screen first shows +the sound button over the play button. this taps it, and the play button +a second later, at 1024 x 768: + + ff_screenshot -w 1024,768 -s 2 -S 3 -J 'function tap() { + document.getElementById("game").dispatchEvent(new PointerEvent( + "pointerdown", {clientX: 497, clientY: 560, bubbles: true})) } + tap(); setTimeout(tap, 1000)' \ + file://$PWD/www/index.html temp/play.png + +the debug switches in [debug] (start map and wave, unlimited coins, no +heart loss, overlays) help to reach a state quickly. a release build +leaves them out. diff -r 0d40f346059c -r a464bd43b76c README.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/README.md Wed Oct 21 22:34:43 2026 +0200 @@ -0,0 +1,33 @@ +Minor Monsters +-------------- + +A tower defense game by M.A. and J.A. Juszczyk, with hand-drawn art and +voice recordings for sound. Monsters hop along a path across four maps; +the player builds, upgrades and sells four kinds of towers to stop them. +It is a static HTML page with plain JavaScript and runs in desktop and +mobile browsers. The address of the game's web page is set in [links] in +config/game.toml. + +Build and run: + + python3 tools/build.py # needs python 3.11 or later and pillow + +Then open www/index.html in a browser, from disk or through any static +web server. + +Release tarball for the web server: + + tools/make_dist.sh + +Documentation, in doc/: + +- game.md: the rules of the game as implemented +- architecture.md: directory layout, build, config, runtime +- implementation.md: algorithms and constants, for changing the code +- art.md: the drawings, scans, masks and sound recordings +- balancing.md: how the numbers are tuned, tools/balance.py and + tools/simulate.js +- roadmap.md: status and open items + +AGENTS.md has instructions for language model agents working on the +project. diff -r 0d40f346059c -r a464bd43b76c config/game.toml --- a/config/game.toml Tue Oct 20 19:54:56 2026 +0200 +++ b/config/game.toml Wed Oct 21 22:34:43 2026 +0200 @@ -1,27 +1,19 @@ # game settings. tools/build.py checks this file and writes www/data/config.js. # # units: distances in map pixels (pixels of the map image as scanned), times -# in seconds, speeds in map pixels per second. -# -# source markers, as in doc/balance.md: -# notes from the original design notes or drawing sheet, decided -# decided decided after the notes were written -# guess a starting value for playtesting, expected to change -# derived calculated from other values -# proto chosen while building the prototype, not in the docs -# (see "prototype notes" in doc/roadmap.md) +# in seconds, speeds in map pixels per second. doc/architecture.md lists +# the sections. [scale] -map = 1.0 # notes -sprite = 0.25 # notes ("maps scaled approx 400%"), towers, monsters, projectiles -coin = 0.4 # guess, 0.25 makes them about 10 pixels -hp_bar = 0.25 # guess +map = 1.0 +sprite = 0.25 # towers, monsters, projectiles +coin = 0.4 +hp_bar = 0.25 -# monsters. coins are set apart from hp (decided): regular monsters drop -# 0.10 to 0.20 coins per hp, bosses 0.2. -# hit_radius is a share of the scaled sprite's smaller side. +# monsters: hp, coins dropped on death, speed. boss marks the boss of a +# map, b0 for map0 and so on. [monster.m0] hp = 5 @@ -103,7 +95,7 @@ # level 1 and level 5; the build fills in the levels between in equal steps, # rounded to whole numbers when both ends are whole. cost is the price of # building (level 1) or of upgrading to that level. attack_time is the time -# between attacks, the same at every level (decided). projectile_speed 0 +# between attacks, the same at every level. projectile_speed 0 # means a melee tower: each attack damages every monster in range. damage # may be left out for a tower that only slows. @@ -181,7 +173,7 @@ speeds = [1, 2, 4] -# sound events (doc/sound.md). the recordings come from art/sounds/, named +# sound events (doc/art.md, sound). the recordings come from art/sounds/, named # after the event. per event: volume is a share of full volume. min_interval # is the least time between two plays; plays in between are dropped. beep is # the placeholder for an event without a recording, as notes of [frequency in @@ -190,7 +182,7 @@ enabled = true # until the player switches sound on or off in the game volume = 0.8 # base for all sounds beep_wave = "square" -music_fade = 0.4 # seconds the splash screen music takes to fade out. proto +music_fade = 0.4 # seconds the splash screen music takes to fade out [sound.event] t0_attack = { volume = 0.6 } @@ -214,13 +206,12 @@ button_tap = { volume = 0.3, beep = [[1000, 0.02]] } map_won = { volume = 1.0 } map_lost = { volume = 1.0 } -intro = { volume = 1.0 } # splash screen music, looped. proto +intro = { volume = 1.0 } # splash screen music, looped -# sprite drawing direction (art.md): angle the drawing points to as drawn, -# 0 right, -90 up. sprites not listed do not turn. set by hand, the towers -# checked in temp/preview/towers.png. -# adjusted by hand. +# sprite drawing direction (doc/art.md): angle the drawing points to as +# drawn, 0 right, -90 up. sprites not listed do not turn. set by hand, the +# towers checked in temp/preview/towers.png. [art.angle] t1 = -2 t1_2 = -3 @@ -242,12 +233,8 @@ p3 = -45 # rotation point as a share of the trimmed image's width and height, for -# sprites that do not turn around their centre (art.md). proto, checked in -# temp/preview/towers.png. t1: the centre of the base square measured on -# source_sheet_2 cutouts. t2: the middle of the rows at least 60 % as wide as -# the widest row, which leaves out the barrel. t3: the centroid of the shape -# with parts narrower than 41 pixels removed. -# adjusted by hand. +# sprites that do not turn around their centre (doc/art.md): the middle of +# the tower's body. set by hand, checked in temp/preview/towers.png. [art.pivot] t1 = [0.37, 0.5] t1_2 = [0.30, 0.5] @@ -267,18 +254,17 @@ # where the button of each screen sits on the screen's drawing: the top left # corner of the separate button image, in pixels of the trimmed drawing. -# proto, found by matching the button image against the drawing. [art.screen] splash = [479, 463] map_won = [210, 225] game_lost = [172, 230] game_won = [373, 383] # the logo and help buttons beside the play button on the splash screen: -# top left corner and height, in pixels of the trimmed splash drawing. proto +# top left corner and height, in pixels of the trimmed splash drawing splash_logo = [119, 463, 164] splash_help = [896, 463, 164] # the email address on the help popup, a tap on it writes a mail: top left -# corner, width and height, in pixels of the drawing. measured, with a margin +# corner, width and height, in pixels of the drawing, with a margin help_email = [690, 1505, 665, 100] @@ -315,11 +301,11 @@ starting_coins = 10 early_bonus = 0.05 wave_count = 6 -monster_share = [36, 25, 18, 12, 9] # fitted in tools/simulate.js; % of regular monsters by count, m0-m4 -wave_size = [4, 7] # fitted; regular monsters in the first and the last wave (draft, tools/balance.py) -first_wave = [1, 2, 2, 4, 5] # fitted; wave in which each monster level first appears, m0-m4 (draft) -spawn_interval = 1.0 # fitted; seconds between spawns -path_half_width = 19 # measured from the earlier masks, centre line to road edge +monster_share = [36, 25, 18, 12, 9] # draft: % of regular monsters by count, m0-m4 +wave_size = [4, 7] # draft: regular monsters in the first and the last wave +first_wave = [1, 2, 2, 4, 5] # draft: wave in which each monster first appears, m0-m4 +spawn_interval = 1.0 # seconds between spawns +path_half_width = 19 # centre line to road edge spawn_distance = 50 exit_distance = 40 @@ -359,122 +345,118 @@ spawn_distance = 50 exit_distance = 40 -# map0: drafted by tools/balance.py --draft from wave_count 6, wave_size [4, 7], -# monster_share [36, 25, 18, 12, 9], first_wave [1, 2, 2, 4, 5] +# map0 waves -[[map.0.wave]] # wave 1, 4 monsters, 20 hp, 4 coins +[[map.0.wave]] # wave 1 monsters = { m0 = 4 } -[[map.0.wave]] # wave 2, 5 monsters, 45 hp, 6 coins +[[map.0.wave]] # wave 2 monsters = { m0 = 2, m1 = 2, m2 = 1 } -[[map.0.wave]] # wave 3, 5 monsters, 45 hp, 6 coins +[[map.0.wave]] # wave 3 monsters = { m0 = 2, m1 = 2, m2 = 1 } -[[map.0.wave]] # wave 4, 6 monsters, 65 hp, 8 coins +[[map.0.wave]] # wave 4 monsters = { m0 = 2, m1 = 2, m2 = 1, m3 = 1 } -[[map.0.wave]] # wave 5, 6 monsters, 90 hp, 10 coins +[[map.0.wave]] # wave 5 monsters = { m0 = 1, m1 = 2, m2 = 1, m3 = 1, m4 = 1 } -[[map.0.wave]] # wave 6, 7 monsters, 130 hp, 14 coins + boss 30 +[[map.0.wave]] # wave 6 monsters = { m0 = 1, m1 = 1, m2 = 1, m3 = 2, m4 = 2, b0 = 1 } -# map1: drafted by tools/balance.py --draft from wave_count 8, wave_size [6, 17], -# monster_share [36, 25, 18, 12, 9], first_wave [1, 2, 3, 5, 6] +# map1 waves -[[map.1.wave]] # wave 1, 6 monsters, 30 hp, 6 coins +[[map.1.wave]] # wave 1 monsters = { m0 = 6 } -[[map.1.wave]] # wave 2, 8 monsters, 55 hp, 8 coins +[[map.1.wave]] # wave 2 monsters = { m0 = 5, m1 = 3 } -[[map.1.wave]] # wave 3, 9 monsters, 80 hp, 11 coins +[[map.1.wave]] # wave 3 monsters = { m0 = 4, m1 = 3, m2 = 2 } -[[map.1.wave]] # wave 4, 11 monsters, 105 hp, 14 coins +[[map.1.wave]] # wave 4 monsters = { m0 = 4, m1 = 4, m2 = 3 } -[[map.1.wave]] # wave 5, 12 monsters, 135 hp, 17 coins +[[map.1.wave]] # wave 5 monsters = { m0 = 4, m1 = 3, m2 = 3, m3 = 2 } -[[map.1.wave]] # wave 6, 14 monsters, 210 hp, 24 coins +[[map.1.wave]] # wave 6 monsters = { m0 = 3, m1 = 3, m2 = 3, m3 = 3, m4 = 2 } -[[map.1.wave]] # wave 7, 15 monsters, 240 hp, 27 coins +[[map.1.wave]] # wave 7 monsters = { m0 = 3, m1 = 3, m2 = 3, m3 = 3, m4 = 3 } -[[map.1.wave]] # wave 8, 17 monsters, 290 hp, 32 coins + boss 50 +[[map.1.wave]] # wave 8 monsters = { m0 = 3, m1 = 3, m2 = 3, m3 = 4, m4 = 4, b1 = 1 } -# map2: drafted by tools/balance.py --draft from wave_count 10, wave_size [10, 36], -# monster_share [39, 26, 17, 11, 7], first_wave [1, 2, 4, 6, 8] +# map2 waves -[[map.2.wave]] # wave 1, 10 monsters, 50 hp, 10 coins +[[map.2.wave]] # wave 1 monsters = { m0 = 10 } -[[map.2.wave]] # wave 2, 13 monsters, 85 hp, 13 coins +[[map.2.wave]] # wave 2 monsters = { m0 = 9, m1 = 4 } -[[map.2.wave]] # wave 3, 16 monsters, 110 hp, 16 coins +[[map.2.wave]] # wave 3 monsters = { m0 = 10, m1 = 6 } -[[map.2.wave]] # wave 4, 19 monsters, 160 hp, 22 coins +[[map.2.wave]] # wave 4 monsters = { m0 = 9, m1 = 7, m2 = 3 } -[[map.2.wave]] # wave 5, 22 monsters, 195 hp, 27 coins +[[map.2.wave]] # wave 5 monsters = { m0 = 10, m1 = 7, m2 = 5 } -[[map.2.wave]] # wave 6, 24 monsters, 250 hp, 32 coins +[[map.2.wave]] # wave 6 monsters = { m0 = 9, m1 = 7, m2 = 5, m3 = 3 } -[[map.2.wave]] # wave 7, 27 monsters, 305 hp, 38 coins +[[map.2.wave]] # wave 7 monsters = { m0 = 9, m1 = 7, m2 = 6, m3 = 5 } -[[map.2.wave]] # wave 8, 30 monsters, 410 hp, 48 coins +[[map.2.wave]] # wave 8 monsters = { m0 = 8, m1 = 7, m2 = 6, m3 = 6, m4 = 3 } -[[map.2.wave]] # wave 9, 33 monsters, 485 hp, 56 coins +[[map.2.wave]] # wave 9 monsters = { m0 = 8, m1 = 7, m2 = 7, m3 = 6, m4 = 5 } -[[map.2.wave]] # wave 10, 36 monsters, 565 hp, 64 coins + boss 70 +[[map.2.wave]] # wave 10 monsters = { m0 = 8, m1 = 7, m2 = 7, m3 = 7, m4 = 7, b2 = 1 } -# map3: drafted by tools/balance.py --draft from wave_count 12, wave_size [5, 16], -# monster_share [52, 26, 13, 6, 3], first_wave [1, 2, 4, 6, 9] +# map3 waves -[[map.3.wave]] # wave 1, 5 monsters, 25 hp, 5 coins +[[map.3.wave]] # wave 1 monsters = { m0 = 5 } -[[map.3.wave]] # wave 2, 6 monsters, 35 hp, 6 coins +[[map.3.wave]] # wave 2 monsters = { m0 = 5, m1 = 1 } -[[map.3.wave]] # wave 3, 7 monsters, 45 hp, 7 coins +[[map.3.wave]] # wave 3 monsters = { m0 = 5, m1 = 2 } -[[map.3.wave]] # wave 4, 8 monsters, 60 hp, 9 coins +[[map.3.wave]] # wave 4 monsters = { m0 = 5, m1 = 2, m2 = 1 } -[[map.3.wave]] # wave 5, 9 monsters, 70 hp, 10 coins +[[map.3.wave]] # wave 5 monsters = { m0 = 5, m1 = 3, m2 = 1 } -[[map.3.wave]] # wave 6, 10 monsters, 85 hp, 12 coins +[[map.3.wave]] # wave 6 monsters = { m0 = 5, m1 = 3, m2 = 2 } -[[map.3.wave]] # wave 7, 11 monsters, 105 hp, 14 coins +[[map.3.wave]] # wave 7 monsters = { m0 = 5, m1 = 3, m2 = 2, m3 = 1 } -[[map.3.wave]] # wave 8, 12 monsters, 110 hp, 15 coins +[[map.3.wave]] # wave 8 monsters = { m0 = 6, m1 = 3, m2 = 2, m3 = 1 } -[[map.3.wave]] # wave 9, 13 monsters, 120 hp, 16 coins +[[map.3.wave]] # wave 9 monsters = { m0 = 6, m1 = 4, m2 = 2, m3 = 1 } -[[map.3.wave]] # wave 10, 14 monsters, 150 hp, 19 coins +[[map.3.wave]] # wave 10 monsters = { m0 = 6, m1 = 4, m2 = 2, m3 = 1, m4 = 1 } -[[map.3.wave]] # wave 11, 15 monsters, 170 hp, 21 coins +[[map.3.wave]] # wave 11 monsters = { m0 = 6, m1 = 4, m2 = 2, m3 = 2, m4 = 1 } -[[map.3.wave]] # wave 12, 16 monsters, 185 hp, 23 coins + boss 100 +[[map.3.wave]] # wave 12 monsters = { m0 = 6, m1 = 4, m2 = 3, m3 = 2, m4 = 1, b3 = 1 } diff -r 0d40f346059c -r a464bd43b76c doc/architecture.md --- a/doc/architecture.md Tue Oct 20 19:54:56 2026 +0200 +++ b/doc/architecture.md Wed Oct 21 22:34:43 2026 +0200 @@ -1,372 +1,239 @@ -architecture +Architecture ------------ -the game is a static html page with plain javascript, drawn on a 2d canvas. it -uses no javascript libraries. a python build script prepares everything that -can be calculated in advance: processed images, map data, route data and the -config. it writes them to www/, together with a copy of the hand-written game -files from game/. www/ is the runnable game. it is not kept in the repository, -so the game has to be built before it can be run. +The game is a static HTML page with plain JavaScript, drawn on a 2D canvas. +It uses no JavaScript libraries. A Python build script prepares everything +that can be calculated in advance: processed images, map data, route data, +embedded sounds and the config. It writes them to www/, together with a +copy of the hand-written game files from game/. The www/ directory is the +runnable game. It is not kept in the repository, so the game has to be +built before it can be run. -this is a plan; nothing is implemented yet. +The details of the algorithms and their constants are in implementation.md. -directory layout +Directory layout ---------------- -proposed: - - art/ drawings as supplied: scans, masks, sprites + art/ drawings and recordings as supplied, and files cut from them + art_sources/ the scans the drawings were cut from + digits/ digits cut from digits.png (tools/cut_digits.py) sound_sources/ voice recordings as supplied sounds/ sounds cut from the recordings (tools/cut_sounds.py) - config/ hand-edited game settings (toml) - game.toml numbers from balance.md, waves, debug switches - tools/ python build scripts + config/ + game.toml every game setting, the wave lists, debug switches + doc/ documentation game/ hand-written game files index.html style.css js/ game code - doc/ design and technical notes - www/ the built game, opened as www/index.html (generated, ignored) + tools/ build, cutting, balancing and release scripts + www/ the built game (generated, ignored) index.html copied from game/, as are style.css and js/ assets/ processed images - data/ maps.js, sounds.js, config.js - dist/ tarballs for distribution (ignored) - temp/ scratch files, build previews (ignored) - -generated files carry a header line saying so and naming the script that made -them. - - -running the game ----------------- - -- desktop: open www/index.html directly from disk, or serve the directory - with any static web server -- tablet: tablets cannot easily open local html files, so the game is served - over http, from a computer on the home network or from a web host. the - tarball in dist/ is meant for that -- an optional later step makes it installable to the home screen (web app - manifest, offline cache). that requires https - -opening the page from disk (file://) limits what the browser allows. chrome -blocks javascript modules, fetch() and reading pixels back from a canvas -there. so: + data/ config.js, maps.js, sounds.js + dist/ release tarballs (ignored) + temp/ build cache and previews (ignored) + build/maps.json route and placement data of the last build + preview/ preview images, balance and simulation reports -- scripts are loaded with plain script tags in a fixed order, and share one - global namespace object -- data files are javascript files that assign to that object, not json files -- the game never reads mask pixels; the build turns the masks into data -- images are loaded with image elements, which works from disk -- recorded sounds are embedded by the build as base64 data in a javascript - file, so they can be decoded without fetch() - - -screenshots ------------ - -firefox's own --screenshot captures at the load event. the game loads its -images and draws its first frame after that, so the capture shows an empty -page. the ff_screenshot script (in $PATH, ~/bin/ff_screenshot) drives -headless firefox over marionette and waits before capturing: - - ff_screenshot -w 1024,768 -s 2 file://$PWD/www/index.html temp/splash.png - --w sets the viewport, -s the wait after loading. the game state is not -reachable from outside, so other screens are reached by tapping: -J runs -javascript after the wait, and -S waits again before capturing. a pointer -event sent to the canvas counts as a tap at that position in css pixels. -a fresh firefox profile has no stored settings, so the splash screen first -shows the sound button over the play button (sound.md). this taps it, and -the play button a second later, at 1024 x 768: - - ff_screenshot -w 1024,768 -s 2 -S 3 -J 'function tap() { - document.getElementById("game").dispatchEvent(new PointerEvent( - "pointerdown", {clientX: 497, clientY: 560, bubbles: true})) } - tap(); setTimeout(tap, 1000)' \ - file://$PWD/www/index.html temp/play.png - -`ff_screenshot -h` lists the other options. +Generated files have a header line saying so and naming the script that +made them. -build ------ +Running and deploying +--------------------- -one command, `python3 tools/build.py`, runs all steps. each step skips its work -when its inputs have not changed. requires python 3.11 or later (for the -built-in toml reader) and pillow. numpy is optional, if the pure python image -steps turn out too slow. - -tools/cut_sheet.py, tools/cut_digits.py and tools/cut_sounds.py are run by -hand and write to art/. -cut_sounds.py also needs ffmpeg with mp3 support, so the build itself does not -depend on it. see sound.md. - -steps: +- Local: build, then open www/index.html from disk, or serve www/ with any + static web server +- Server: `tools/make_dist.sh` runs a release build and packs www/ into + dist/minor_monsters_VERSION.tar.gz, which unpacks into a directory + minor_monsters. That directory is what the web server serves -1. sprites: trim transparent edges, write to www/assets/. this covers the - icons, buttons and screens, and the digits from art/digits/ as - digit_NAME_N. make the hp bar variants: the empty part, and the blue bars - for slowed monsters (art.md) -2. tower levels: t0-t3 are level 1. split each t*p strip into four images, - levels 2-5. fill the inside of the outline with white (flood fill from - outside, everything not reached is inside), trim, write as t0_2..t0_5 and - so on. see art.md -3. maps: copy the map images, possibly converted to a smaller format -4. masks: for each map - - classify pixels as path, entrance, exit or free by their exact colour. - masks must have hard edges: a pixel that is neither fully transparent - nor opaque pure red, blue or green stops the build (art.md) - - extract routes, see below - - write a placement grid: cells where a tower footprint fits next to the - road, within the limits in balance.md. the red path in the mask is the - centre line of the road; the road's half width is set per map -5. sounds: embed art/sounds/*.mp3 as base64 in www/data/sounds.js, - grouped by event -6. config: read config/game.toml, check it, write www/data/config.js -7. checks: print a summary per map (routes with length and turning, monster - counts, coins and hp per map against the target) and warn on problems -8. previews: draw each map with its routes, entrances, exits and placement - grid into temp/preview/, for checking without starting the game. towers.png - shows the tower levels, each turned by its drawing direction to face up, - with its pivot and footprint -9. game files: copy the files in game/ to www/. a file is copied when its - time or size differs from the copy. files no longer in game/ are removed - from www/, apart from www/assets/ and www/data/. a release build writes - www/js/debug.js empty +The page also runs from disk (file://), where Chrome blocks JavaScript +modules, fetch() and reading pixels back from a canvas. So: -a watch mode (`tools/build.py --watch`) reruns the build when a file in -config/, art/, art/sounds/ or game/ changes. tuning then means: edit the toml, -save, reload the browser. the same goes for changes to the game code: they -show in www/ only after the build has copied them. - -`tools/build.py --release` leaves the debug code out: it writes -www/js/debug.js empty and leaves [debug] out of config.js. the game then -runs as with every debug switch off. - -`tools/make_dist.sh` runs a release build and packs www/ into -dist/minor_monsters_VERSION.tar.gz, which unpacks into a directory -minor_monsters. the version comes from `tools/get_version.sh -f`: the -latest tag, with a timestamp appended when the working directory is not -clean or not at the tagged revision. `--debug` builds with the debug code -in place of a release build. www/ keeps the build the script made, so a -plain build afterwards brings the debug code back. +- Scripts are loaded with plain script tags in a fixed order, and share one + global namespace object, MM +- Data files are JavaScript files that assign to MM, not JSON files +- The game never reads mask pixels; the build turns the masks into data +- Images are loaded with image elements +- Sounds are embedded as base64 in a JavaScript file, so they can be + decoded without fetch() -balance tools -------------- - -tools/balance.py estimates, map by map and wave by wave, whether the coins -a map pays buy enough firepower (balance.md, balancing). it is run by hand -after a build: it reads config/game.toml, and the routes and placement grid -from temp/build/maps.json. it only calculates and leaves the images alone. -it writes tables and charts (numpy, matplotlib) to temp/preview/: +Build +----- -- balance.txt: value per coin for every tower and level; per map the - coverage of each tower's range, and per wave the coins on hand, the - damage rate both demands need and the coins the naive and greedy players - need to hold the wave -- balance_value.png: value per coin by tower level -- balance_map0.png to balance_map3.png: coins per wave, and the surplus at - the last wave and the hearts left against a wave size factor. the factor - scales the number of regular monsters in every wave; the coins they drop - follow - -`tools/balance.py --draft` prints wave lists made from the draft numbers in -each map's section of the config (balance.md, waves), as toml to paste over -the map's [[map.N.wave]] lists. `--draft 2` does map2 only. below each map -it prints what the calculation makes of the drafted lists. nothing is -written in this mode. - -tools/build.py does not count balance.py as one of its inputs, so changing -it does not rebuild the game. - -tools/simulate.js checks the calculation by playing the real game logic -with scripted players. it is run by hand with node after a build: +`python3 tools/build.py` runs all steps. It needs Python 3.11 or later, for +the built-in TOML reader, and Pillow. A step is skipped when its outputs +are newer than its inputs and the build scripts; `--force` runs every step. - node tools/simulate.js - node tools/simulate.js --maps 2 --players naive,naive_t0 --seeds 10 - -it loads www/data/config.js, www/data/maps.js and the logic files util.js, -assets.js, map.js, monster.js, tower.js, projectile.js, wave.js and -game.js, as the browser would, with window set to the global object. -render.js, ui.js, input.js, debug.js and main.js are left out, so the -debug switches have no effect. MM.audio is the only stub; assets.js loads -unchanged, since sprite sizes come from the config and images are only -loaded by main.js. +1. Sprites: trim transparent edges and write to www/assets/. This covers + monsters, towers, projectiles, coins, HP bars, icons, buttons, screens + and the digits, written as digit_NAME_N. The HP bars also get an empty + variant and blue variants for slowed monsters +2. Tower levels: split each t*p strip into levels 2 to 5, fill the inside + of each outline with white, trim, and write t0_2 to t3_5 +3. Maps: write the map scans as JPEG +4. Masks: classify the mask pixels, extract the routes and write the + placement grid to www/data/maps.js. The result is also kept in + temp/build/maps.json, for the later steps and the balance tools. This + step also reruns when the placement settings or a map's road and spawn + settings change +5. Sounds: embed art/sounds/*.mp3 in www/data/sounds.js, grouped by event +6. Config: check config/game.toml, fill in the tower values for every + level, add the size of every sprite, and write www/data/config.js +7. Checks: print per map its routes with length, turning and walk times, + the monster counts and shares, the coins and hit points of its waves, and + the early start bonus for skipping every break. Warn on problems, such as + a wave count that does not match the lists, or a boss missing from the + last wave +8. Previews: write temp/preview/mapN.png with routes, entrances, exits and + placement grid, mapN_routes.png for maps with several routes, and + towers.png with every tower level, its rotation point and footprint +9. Game files: copy the files in game/ to www/ when their time or size + differs. Files no longer in game/ are removed from www/, apart from + www/assets/ and www/data/ -the game advances in steps of 1/60 s, as in the browser; game speed plays -no part. each run has its own seed, passed to the game. the players build, -upgrade and start waves through the game's own functions (shop choice, -preview, build, tower selection, upgrade, early start), so placement rules -and prices are the game's. the players and their rules are listed at the -top of the file; naive and greedy follow balance.md, balancing, and pick -cells as tools/balance.py does, from the placement grid in maps.js. +Options: + +- `--watch` reruns the build when a file in art/, art/sounds/, art/digits/, + config/ or game/, or a build script, changes. Changes to the game code + show in www/ only after the build has copied them +- `--release` writes www/js/debug.js empty and leaves [debug] out of + config.js. The game then runs as with every debug switch off -the coins a wave needs are measured by playing that wave alone from an -empty map with the first purchases of the player's list, and searching -for the fewest that lose no heart. every wave starts on an empty map in -the game, so this matches the wave in a full run, apart from towers -bought during the wave. +`tools/make_dist.sh` takes its version from `tools/get_version.sh -f`: the +latest Mercurial tag, with a timestamp appended when the working directory +is not clean or not at the tagged revision. `--debug` packs a build with +the debug code. The www/ directory keeps the build the script made, so a +plain build afterwards brings the debug code back. + +Scripts run by hand, not by the build: -it writes temp/preview/simulate.txt (per map and player: maps won, hearts -left, coins on hand and the surplus at the start of the last wave, hearts -lost per wave) and temp/preview/simulate.json, which tools/balance.py reads -for the hits per t0 attack. `--need all` measures the coins needed for -every wave, `--waves` takes wave lists from a json file in place of the -config's, for trying drafts without a build. +- tools/cut_sheet.py cuts the monster, tower, projectile and HP bar + sprites from a drawing sheet into art/ (art.md) +- tools/cut_digits.py cuts art/digits.png into art/digits/ +- tools/cut_sounds.py cuts the recordings into art/sounds/. It needs FFmpeg + with MP3 support, which the build does not +- tools/balance.py and tools/simulate.js estimate and test the balance of + the game (balancing.md) -routes +Config ------ -a route is a list of points from an entrance to an exit. a map has one or -more routes. a monster picks a route at spawn (weights in balance.md) and -follows it to the end. this handles the branches on map1 and map2 without -junction logic at runtime. +The file config/game.toml holds every game setting. The build checks it and +turns it into www/data/config.js. There is no in-game editor: values are +changed in the file and the game is rebuilt. Units are map pixels (pixels +of the map scan), seconds, and map pixels per second. -extraction in the build: +Sections: -1. thin the path pixels to a one-pixel centre line (skeleton) -2. turn the skeleton into a graph of junctions and segments, and drop short - dead ends left by uneven strokes -3. find the graph nodes nearest to each entrance and exit blob -4. list every path through the graph from an entrance to an exit that visits - no junction twice -5. smooth each route and reduce it to a few points per bend -6. record length and turning for each route +- [scale]: drawing scale of maps, sprites, coins and HP bars +- [monster.*]: hit points, coins and speed of each monster; boss marks + the bosses +- [animation], [movement]: hops, puffs, and the spread of monsters on the + road +- [route_preference]: the route weights (game.md, routes) +- [tower.*], [tower_rules]: tower values at level 1 and level 5, attack + time, projectile, slow, sell refund +- [placement]: where towers may stand +- [waves], [hearts], [coins], [controls]: breaks, heart costs, flying + coins, game speeds +- [sound], [sound.event]: volume, the minimum time between two plays, and + a placeholder beep per event +- [art.angle], [art.pivot], [art.screen]: drawing direction and rotation + point of turning sprites, and where buttons sit on the screen drawings + (art.md) +- [links]: the logo's web page and the email address of the help popup +- [debug]: debug switches +- [map.N]: per map the starting coins, early start bonus, spawn interval, + road half width, distances from spawn and exit points, the draft numbers + for tools/balance.py, and the wave lists [[map.N.wave]] -map0 and map3 give one route each. map1 and map2 give several; map2 may give -more than wanted. where the automatic result is wrong, the mask is redrawn. +Debug switches, all off by default: -the game walks a monster along the route's centre line, by distance, and -draws it beside the line. the offset is set per monster at spawn -(balance.md, monsters) and needs no route data from the build. when a map -loads, each route works out the sideways direction at its points and how far -an offset may go on the inside of each bend. towers rank monsters by their -distance along the centre line, so the offset does not change the order. +- Start coins, unlimited coins, no heart loss +- Start map and wave. The start map counts as the first map: the play + button starts it, and a lost map returns to it. Only that map starts at + the start wave +- Show routes, placement grid, tower ranges, hit areas +- Frame time and entity counts on screen +- A fixed random seed; 0 picks a new one per map + +The file js/debug.js holds the code for all of them. It replaces functions +of the game and the UI, and render.js calls it to draw over the map image +and over the monsters. The start-up in main.js takes the start map, wave +and seed from it. +In a release build the file is empty and none of this is left. -config ------- - -config/game.toml holds every number in balance.md, the wave lists, and debug -switches. the build converts it into www/data/config.js. toml allows comments, -so each value can carry its source note (guess, decided). - -wave format: - - [[map.0.wave]] - monsters = { m0 = 5, m1 = 1, m2 = 1, b0 = 1 } - -a wave lists how many of each monster it holds. when the wave starts, the -boss spawns first: it is the slowest monster and the others overtake it. the -rest follow one per spawn interval, each drawn at random from the monsters -left in the wave. the spawn interval is set per map. the boss is in the last -wave. - -debug switches, all off by default: - -- start coins override, unlimited coins -- start at a given map and wave. that map counts as the first map: the play - button starts it, and a lost map returns to it -- no heart loss -- show routes, placement grid, tower ranges, hit areas -- on-screen frame time and entity counts -- a fixed random seed - -js/debug.js holds the code for all of them. it replaces functions of the -game and the top bar drawing, and render.js calls it to draw over the map -image and over the monsters. main.js takes the start map, wave and seed -from it. without it, as in a release build, nothing of this is left. - -there is no in-game config editor: values are changed in the toml file. - - -runtime +Runtime ------- -script files, in load order: +Script files, in load order: data/config.js generated settings data/maps.js generated map data data/sounds.js generated sound data - js/util.js vector maths, random numbers, easing + js/util.js vector maths, seeded random numbers, easing js/storage.js settings kept in the browser - js/assets.js image loading, sprite table - js/audio.js recorded sounds, placeholder beeps for the other events, - splash screen music - js/map.js placement lookup, snapping, route sampling - js/monster.js movement along a route, hops, slow, hp - js/tower.js targeting, attacks, upgrade, sell - js/projectile.js - js/wave.js wave timing, countdown, early start bonus - js/game.js game state, rules, win and loss - js/render.js drawing - js/ui.js top bar, shop, tower menu, screens + js/assets.js image loading, sprite drawing with angle and pivot + js/audio.js recordings, placeholder beeps, splash screen music + js/map.js routes and sideways offsets, placement lookup, snapping, + t0 spike sides, route weights + js/monster.js movement along a route, hops, slows + js/tower.js targeting, attacks, upgrade cost, refund + js/projectile.js flight to the target, damage, p2 freeze splash + js/wave.js breaks, spawning, early start bonus + js/game.js game state and rules: coins, hearts, building, upgrade, + sell, win and loss + js/render.js drawing of the map and everything on it + js/ui.js layout, top bar, shop, tower menu, screens, help popup js/input.js pointer events js/debug.js debug switches, empty in a release build - js/main.js start-up and main loop - -game loop: + js/main.js start-up, screen flow and main loop -- the simulation advances in fixed steps of 1/60 s. drawing happens once per - browser frame and is independent of it -- game speed 2x runs two simulation steps per frame -- pause stops the simulation; drawing and the top bar buttons continue -- a frame that takes too long runs at most a few steps and drops the rest, so - the game slows down rather than freezing after the tab was in the background - -state: +Game loop: -- game state is plain objects: monsters, towers, projectiles, coins in flight, - wave state, coins, hearts. rendering reads it and does not change it -- random numbers come from one seeded generator, so a run can be repeated with - the same seed when chasing a bug - -display: +- The simulation advances in fixed steps of 1/60 s, driven by the + browser's frame clock. Drawing happens once per frame +- Game speed n runs n times as many steps per frame +- Pause stops the simulation; drawing and the top bar buttons go on +- A long frame runs at most a few steps per speed step and drops the rest, + so the game slows down rather than freezing after the tab was in the + background -- the canvas fills the window. the map is scaled to fit and centred, with - borders where the shapes differ -- the canvas resolution follows the device pixel ratio, so drawings stay sharp - on high-resolution screens -- layout: top bar with coins, hearts, wave, countdown, sound, speed, pause - and help. on a narrow screen the buttons move to a second row under the - counters. the tower shop sits on the right in landscape and at the bottom in portrait -- buttons are at least 48 css pixels for touch +State: -input: +- The game state is plain objects: monsters, towers, projectiles, coins in + flight, puffs, freeze splashes, wave state, coins and hearts. Rendering + reads it and does not change it +- The game's random numbers come from one seeded generator, so a run can + be repeated with the same seed. Sound variants use Math.random, so sound + does not change a run -- pointer events cover mouse and touch alike -- nothing relies on hover; selection and confirmation are by tap. with a - mouse, hover enlarges the screen buttons and shows the pointer cursor over - any button -- buttons and tower selection act when the pointer goes down. placing - follows the pointer until it is let go, and building happens then -- the page blocks browser zoom and scroll gestures on the canvas +Display: -placement: +- The canvas fills the window. The map is scaled to fit the area left by + the top bar and the shop, and centred +- The canvas resolution follows the device pixel ratio +- Buttons are at least 48 CSS pixels for touch -- the build's placement grid marks every cell where a tower may stand -- while the pointer is down, the game searches outward from it for the - nearest legal cell that keeps the minimum distance to other towers, within - the snap radius. where there is none, the preview stays where it was -- t0 checks once, at placement, which of its four sides face the path, and - only draws spikes on those +Input: -persistence: +- Pointer events cover mouse and touch alike +- Buttons and tower selection act when the pointer goes down. Placing + follows the pointer until it is let go. The logo and the email address + act on release, as some browsers open a page or a mail only then +- The page blocks browser zoom, scroll, double tap and context menu + gestures on the canvas -- nothing is stored for now. maps are played in order and a lost map goes - back to the first map, so there is no progress to keep. a reload starts at - the splash screen with a fresh game -- settings, so far only sound on or off, are stored by js/storage.js. it - wraps localStorage, and one entry holds them -- all access is wrapped so the game still runs when storage is unavailable, - for example in private browsing; settings are then not kept -- the entry carries a version number for later format changes +Persistence: - -not planned ------------ - -- in-browser editors or tuning panels +- Game progress is not stored. Settings, so far only sound on or off, are + kept by js/storage.js in one localStorage entry with a format version +- All access is wrapped, so the game still runs when storage is + unavailable, for example in private browsing; settings are then not kept diff -r 0d40f346059c -r a464bd43b76c doc/art.md --- a/doc/art.md Tue Oct 20 19:54:56 2026 +0200 +++ b/doc/art.md Wed Oct 21 22:34:43 2026 +0200 @@ -1,187 +1,186 @@ -art assets ----------- +Art and sound +------------- -b0-b3: boss monsters for each map level -c0-c3: coin variants -hpb: hp bar for bosses -hpm: hp bar for monsters -m0-m4: monster progression -map0-map3: map level art. maps are to be scaled approx 400% -map*mask: map level definitions, blue: monster entrance, red: path centre line, green: exit -p0-p3: projectiles for defense towers -t0-t3: defense towers -t*p: defense towers upgrade progression -art_sources/: the scans the drawings were cut from -art_sources/source_sheet.jpg: the original drawing sheet with all sprites, maps, damage -values, monster and boss coins, and starting coins per map. map numbers on the -sheet start at 1 (M1-M4 are map0-map3) -art_sources/source_sheet_2.jpg: the same sheet with the sprite outlines inked in black, and - monster hp and tower costs added. m*, b*, t*, t*p, p* and the hp bars are - cut from it by tools/cut_sheet.py +All drawings and voice recordings come from the artist. Files in art/ +stay as supplied, apart from the files the cutting scripts write there. +The build writes processed copies to www/ (architecture.md). Drawing tips +for new items: dark outline, white or coloured inside, on white paper with +space around each item. + + +Scans +----- -splash.png: splash screen including play button -splash_play.png: play button from splash screen -map_won.png: map won screen -map_won_button.png: arrow button from map won screen -game_lost.png: map/game lost -game_lost_button.png: button from game_lost -game_won.png: game won screen, cut from art_sources/game_won.jpg -game_won_button.png: restart button from game_won, cut from the same scan -sound_on.png, sound_off.png: sound setting -speed_x1.png, speed_x2.png, speed_x4.png: speed selection buttons -play_button.png, pause_button.png: play and pause -monster_icon.png: monster/wave count icon -digits.png: sheet with all digits and a slash, in multiple variants. - tools/cut_digits.py cuts it into art/digits/ -monster_death.png: monster death puff -boss_death.png: boss death puff -upgrade_button.png, sell_button.png: upgrade and sell buttons -tower_popup.png: bubble for tower upgrade/sell popup -next_wave.png: start next wave early button -shop_bubble.png: tower shop items bubble -shop_bubble_dark.png, shop_bubble_dark2.png: selected tower shop item bubble in - 2 variants -heart.png: heart counter icon -coin_icon.png: coin counter icon -freeze.png: t2 freeze splash, drawn where p2 lands -wobbly_logo.png: logo on the splash screen, left of the play button, links to - a web page -help_splash.png: question mark on the splash screen, right of the play - button, opens the help popup -help_button.png: help button in the top bar, opens the help popup +The directory art/art_sources/ holds the scans the drawings were cut from. -notes: - - writing numbers should use digit variants. scale digits to same size in - preprocessing. - - start next wave early omit bonus coins count +- source_sheet.jpg: the original sheet with all sprites, maps, and the + first numbers for damage, coins and starting coins (history.md). Map + numbers on the sheet start at 1: M1 to M4 are map0 to map3 +- source_sheet_2.jpg: the same sheet with the sprite outlines inked in + black, and monster hit points and tower costs added. The script + tools/cut_sheet.py cuts the sprites from it +- game_won.jpg, help_info.jpg, icons.jpg, icons_and_numbers.jpg, + more_buttons.jpg, splash.jpg, upgrade_popup.jpg: scans of the screens, + icons and buttons + +On both sheets the towers t0 and t1 are swapped: the tower row runs t1, +t0, t2, t3, and the projectile row p1, p0, p2, p3. +Sprites +------- -files in art/ stay as supplied, apart from the sprites cut from a sheet and -the sounds cut from the recordings. the build (see architecture.md) writes -processed copies to www/assets/. - -attn: the source_sheet_* files have the towers t0 and t1 swapped. +| File | What | Source | +|------------|----------------------------------------|--------| +| m0-m4 | Regular monsters | cut_sheet.py | +| b0-b3 | Bosses, one per map | cut_sheet.py | +| t0-t3 | Towers, level 1 | cut_sheet.py | +| t0p-t3p | Towers, levels 2 to 5 side by side | cut_sheet.py | +| p0-p3 | Projectiles of t0 to t3 | cut_sheet.py | +| hpm, hpb | HP bars of monsters and bosses | cut_sheet.py | +| c0-c3 | Coins | Cut by hand from the first sheet | +| freeze | t2 freeze splash, drawn where p2 lands | Supplied | +| monster_death, boss_death | Death puffs | Supplied | -sound source files in art/sound_sources, all phone voice recordings, named -after their sound event (sound.md). tools/cut_sounds.py cuts them into -art/sounds/; a recording with variants gives one sound per variant: - t0_attack: t0 attack, 4 variants - t1_shot: t1 tower shot, 6 variants - t2_shot: t2 tower shot, 4 variants - t3_shot: t3 shot, 7 variants - monster_enter: monster enters map, 3 variants - monster_exit: monster reaches map exit - monster_die: monster death, 4 variants - boss_enter: boss enters map - boss_exit: boss reaches map exit - boss_die: boss death - map_won: level win - map_lost: game lost - intro: splash screen music, starts with a burp that the script cuts off +- Sprites cut by cut_sheet.py keep the sheet's scale: black outlines, + transparent outside, white paper inside, drawn colour kept (bosses, HP + bars) +- The t*p strips are cut from the same sheet as level 1, so the sizes + follow on. The build splits them and fills any inside left transparent + with white +- Level 5 of t3 is a different design from levels 1 to 4: a square with a + barrel, not a triangle +- Monsters and bosses face the viewer and are never rotated or mirrored + + +Maps and masks +-------------- + +The files map0 to map3 are the map scans, with paper edges. Each map*mask +is the mask of the same map and lines up with it pixel for pixel. + +Masks have hard edges. Every pixel is fully transparent or opaque pure +red, blue or green; the build stops on any other pixel. -state of the files ------------------- +- Red: the centre line the monsters walk, about 11 pixels wide, not the + whole road. The road's half width is set per map in the config +- Blue: monster entrances +- Green: exits + +Where the route extraction gets a map wrong, the mask is redrawn. + + +Screens, buttons and icons +-------------------------- -- t0-t3, m0-m4, b0-b3, p0-p3, hpm, hpb: cut from source_sheet_2.jpg at the - sheet's scale. black outlines, transparent outside. inside, the paper is - white and drawn colour is kept (bosses, hp bars) -- c0-c3: cut out by hand from the first sheet, transparent outside -- towers have 5 levels. t0-t3 are level 1 -- t*p: outlines of tower levels 2-5 side by side, cut from the same sheet as - level 1, so the sizes follow on. the build splits them and fills any - inside left transparent white -- on the sheet, the tower row runs t1, t0, t2, t3 and the projectile row - p1, p0, p2, p3 -- t3 level 5 is a different design from levels 1-4 (square with a barrel - instead of a triangle) -- maps: scans with paper edges. map and mask of the same number line up pixel - for pixel -- masks: hard edges, no anti-aliasing. every pixel is fully transparent or - opaque pure red, blue or green; the build stops on any other pixel. red - marks the centre line the monsters walk, about 11 pixels wide, not the - whole road. map1 has branches, map2 has two entrances and loops -- icons, buttons and screens: transparent outside, apart from splash.png, - which is opaque with white paper. the separate screen buttons are exact - crops of the buttons in their screen drawings -- art/digits/: every drawing on digits.png is one variant, named after the - character and a number (0_1, 0_2, ..., slash_1). all are scaled to the same - height, the median of the drawings, and the paper is transparent. the +| File | Use | +|--------------------------|-----| +| splash | Splash screen with title, byline and play button; opaque with white paper | +| splash_play | Play button of the splash screen | +| wobbly_logo | Logo left of the play button, opens the game's web page | +| help_splash | Question mark right of the play button, opens the help popup | +| help_info | Help popup | +| map_won, map_won_button | Map won screen and its next button | +| game_lost, game_lost_button | Game lost screen and its button | +| game_won, game_won_button | Game won screen and its restart button, cut from game_won.jpg | +| coin_icon, heart, monster_icon | Top bar counters | +| help_button | Help button in the top bar | +| play_button, pause_button | Pause button: pause while running, play while paused | +| speed_x1, speed_x2, speed_x4 | Speed button | +| sound_on, sound_off | Sound button; sound_on also on the splash screen's sound button | +| next_wave | Early start button, the countdown drawn on its right part | +| shop_bubble | Shop item | +| shop_bubble_dark, shop_bubble_dark2 | Chosen shop item, in turn | +| tower_popup | Bubble of the tower menu | +| upgrade_button, sell_button | Buttons in the tower menu | +| digits | Sheet of digits and a slash, several variants each | + +- All are transparent outside, apart from splash +- The separate screen buttons are exact crops of the buttons in their + screen drawings +- The script tools/cut_digits.py cuts digits.png into art/digits/: every + drawing is one variant, named after the character and a number (0_1, + 0_2, ..., slash_1), scaled to the median height, paper transparent. The 10, 11 and 12 on the sheet give single digits -drawing direction +Drawing direction ----------------- -turning towers and projectiles are rotated to face their target. each sprite -records which way it points as drawn, so the game can correct for it. angles -as on screen: 0 is right, -90 is up. - -the drawings are not consistent, even between levels of the same tower. the -angle of each sprite is set by hand in [art.angle] in config/game.toml. the -build draws temp/preview/towers.png with every turning tower turned to face -up, so a wrong angle shows as a barrel off the vertical guide line. the table -gives the rough direction; config/game.toml has the exact values. +Turning towers and projectiles are rotated to face their target. The +drawings are not consistent, even between levels of the same tower, so +each sprite's direction as drawn is set by hand in [art.angle]: 0 is right, +-90 is up. Sprites not listed there do not turn: t0, and p2, which is +round. The spike p0 is listed because each t0 spike is turned to point +outwards. -| sprite | points to | angle | -|---------------|-----------|-------| -| t0, all levels | does not turn | - | -| t1, all levels | right | -6 to 0 | -| t2, all levels | up | -95 to -89 | -| t3 levels 1-2 | up-right | -48 to -43 | -| t3 levels 3-4 | right, a little up | -15 | -| t3 level 5 | up | -88 | -| p0 | up | -90 | -| p1 | right (nearly square, a little lopsided) | 0 | -| p2 | any (round) | - | -| p3 | up-right | -45 | +The whole tower sprite turns, base included. It turns around the centre of +the trimmed image, or around the point set in [art.pivot]; the turning +towers turn around the middle of their body. -the tower sheet does not show the projectiles. - -the whole tower sprite turns, base included; the drawings do not separate a -base from a turret. rotation is around the centre of the trimmed image unless -the config sets another point. - -monsters and bosses face the viewer and are not rotated or mirrored. +The preview temp/preview/towers.png, written by the build, shows every +turning tower turned to face up, with its pivot. A wrong angle shows as a +barrel off the vertical guide line. -hp bars +HP bars ------- -the bar is drawn cut to the share of hp left. the empty part is drawn as a -darkened copy of the bar (suggestion). hpm sits above every monster, hpb above -the boss. - -while t2 slows a monster, its bar is drawn in blue. the build makes the blue -bars from hpm and hpb by changing the colour of the green inside to blue; the -outline stays as drawn. the empty part of a blue bar is a darkened copy of the -blue bar. +The bar is drawn cut to the share of hit points left, over a darkened copy +for the empty part. The bar hpm sits above every monster, hpb above the +boss. While t2 slows a monster its bar is blue: the build makes blue +copies of both bars by changing the colour of the green inside; the +outline stays as drawn. -art still needed ----------------- - -every icon and screen in the list above is in the game. not drawn yet: +Sound +----- -- cancel or close. the game has no such button so far; a second tap on the - chosen shop item cancels it -- plus sign. the early start button no longer shows the bonus, so it is not - needed for now +The voice recordings in art/sound_sources/ were made on a phone and are +named after their event. The script tools/cut_sounds.py turns them into +game sounds in art/sounds/; a recording with variants is split into +NAME_1, NAME_2 and so on, and the game picks one at random. The output is +mono MP3, which desktop and mobile browsers play. The intro recording +loses its first 3 s, which hold a burp, and gets a short pause at its end +for the loop. + +The event name is the name of its recordings and its entry in +[sound.event], which sets its volume, an optional minimum time between two +plays, and the placeholder beep. Events without a recording play the beep. -optional: +| Event | Name | Sound | +|----------------------|-------------------|-------| +| t0 attack | t0_attack | Recorded, 4 variants | +| t1 shot | t1_shot | Recorded, 6 variants | +| t2 shot | t2_shot | Recorded, 4 variants | +| t3 shot | t3_shot | Recorded, 7 variants | +| Monster enters map | monster_enter | Recorded, 3 variants | +| Monster dies | monster_die | Recorded, 4 variants | +| Monster reaches exit | monster_exit | Recorded | +| Boss enters map | boss_enter | Recorded | +| Boss reaches exit | boss_exit | Recorded | +| Boss dies | boss_die | Recorded | +| Map won | map_won | Recorded | +| Map lost | map_lost | Recorded | +| Splash screen music | intro | Recorded, loops | +| Monster hit | monster_hit | Beep | +| Coins arrive | coins_arrive | Beep | +| Wave starts | wave_start | Beep | +| Early start bonus | early_bonus | Beep | +| Tower built | tower_built | Beep | +| Tower upgraded | tower_upgraded | Beep | +| Tower sold | tower_sold | Beep | +| Placement refused | placement_refused | Beep | +| Button tap | button_tap | Beep | -- t0 spike burst, if p0 alone does not read well as an attack -- hit puffs -- a mark for a refused placement. the game draws a red cross for now - -drawing tips for these: dark outline, white or coloured inside, on white -paper with space around each item, so the build can cut them out the same way -as the existing sprites. +The beeps are accepted as they are. -possible addition ------------------ +Optional art +------------ -if decorated areas of a map, such as the lava pools on map3, should be off -limits for towers, a fourth mask colour (for example black) could mark them. -not decided. +Not needed for the game, possible additions: + +- A t0 spike burst, if p0 alone does not read well as an attack +- Hit puffs +- A mark for a refused placement, in place of the red cross diff -r 0d40f346059c -r a464bd43b76c doc/balance.md --- a/doc/balance.md Tue Oct 20 19:54:56 2026 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,497 +0,0 @@ -balance -------- - -all game numbers in one place. the values used by the game are in the config -file (see architecture.md); this document explains them and records where each -one comes from. - -source markers: - -- notes: from the original design notes or the original drawing sheet, - decided -- decided: decided after the notes were written -- guess: a starting value for playtesting, expected to change -- derived: calculated from other values - -notes and decided values are not fixed either. they come from the original -drawing sheet and the first design rounds, made without experience in game -design, and are all open to change in balancing. - -units: distances are in map pixels, that is pixels of the map image as -scanned. times are in seconds, speeds in map pixels per second. - - -scale ------ - -| item | value | source | -|------------------------------|-------|--------| -| map images | 1.0 | notes | -| towers, monsters, projectiles | 0.25 | notes ("maps scaled approx 400%") | -| coins | 0.4 | guess, 0.25 makes them about 10 pixels | -| hp bars | 0.25 | guess | - -measured from the earlier masks, which covered the whole road (approximate, -from red area divided by path width): - -| map | size | path width | path length, all branches | -|------|---------|------------|---------------------------| -| map0 | 705x697 | 56 | 1930 | -| map1 | 663x590 | 48 | 1350 | -| map2 | 618x537 | 42 | 2075 | -| map3 | 642x459 | 52 | 905 | - -a single route on map1 or map2 is shorter than the total. exact route lengths -come from the build (see architecture.md). - - -monsters --------- - -| monster | hp | coins | coins per hp | speed | source | -|---------|----|-------|--------------|-------|--------| -| m0 | 5 | 1 | 0.20 | 35 | hp, coins: notes; speed: guess | -| m1 | 10 | 1 | 0.10 | 40 | hp: notes; coins: decided (was 2); speed: guess | -| m2 | 15 | 2 | 0.13 | 45 | hp: notes; coins: decided (was 3); speed: guess | -| m3 | 20 | 2 | 0.10 | 40 | hp: notes; coins: decided (was 4); speed: guess | -| m4 | 30 | 3 | 0.10 | 35 | hp: notes; coins: decided (was 6); speed: guess | -| b0 | 150 | 30 | 0.20 | 25 | hp: decided, 5 x the notes; coins: notes; speed: guess | -| b1 | 250 | 50 | 0.20 | 25 | as above | -| b2 | 350 | 70 | 0.20 | 25 | as above | -| b3 | 500 | 100 | 0.20 | 25 | as above | - -monster hp is the same on every map (decided). a monster that took two hits -on one map must not take four on a later one. a map gets harder through the -size of its waves and the mix of monsters. - -the notes had every monster drop 0.2 coins per hp. regular monster coins are -now set apart from hp (decided): m0 keeps 0.2, the others drop 0.10 to 0.13. -the mix of monsters then sets the coins per hp of a map. the notes gave -bosses hp equal to their coins; balancing raised it to 5 times that -(decided). - -time to walk the whole path at 35-45 speed (derived): map0 about 50 s, map3 -about 23 s. - -animation (all guesses): - -- one hop takes 0.35 s -- hop height 5 -- squash on landing 6 % (wider and flatter), stretch in the air 4 % -- idle bob 2 % -- each monster starts at a random point in its hop cycle, so a group does not - hop in step -- the death puff shows for 0.4 s - -variation between monsters, so a group does not walk in single file (all -guesses): - -- each monster's speed differs from its table speed by up to 5 % either way. - faster ones overtake slower ones -- a monster walks beside the centre line of the road, at most 0.45 of the - road half width away from it: 8.6, 7.7, 7.2 and 9.9 pixels by map -- half of that is a fixed lean to one side, chosen at spawn. the other half - wanders, with a new random value every 40 pixels along the route and a - smooth change between them -- the offset grows from 0 over the first 20 pixels of the route -- on the inside of tight bends the offset is reduced, so a monster never moves - backwards. monsters may bunch up there - - -route preference ----------------- - -on maps with several routes, a monster picks one at spawn. faster monsters -prefer longer or straighter routes, slower ones prefer shortcuts (decided). - -proposed rule (guess): - -- for each route the build calculates its length and how much it turns (sum of - direction changes along the route) -- each route gets a value between 0 and 1: the average of its length relative - to the longest route and its straightness relative to the straightest route -- each monster gets a speed factor: its speed minus the reference speed, - divided by the reference speed, limited to -1..1 -- route weight = 1 + bias * speed factor * (2 * route value - 1), at least 0.1 -- a monster at the reference speed sees all routes as equally likely -- a boss always takes the shortest route (decided) - -| parameter | value | source | -|-----------------|-------|--------| -| reference speed | 40 | guess | -| bias | 3 | guess | - -with the speeds above, m2 is the only regular monster faster than the -reference, and the effect on it is small. the speeds may need to spread out -more for the preference to be visible. - - -towers ------- - -towers have 5 levels (decided). the config sets damage, range, slow and cost -for level 1 and level 5 only. the build fills in the levels between in equal -steps, rounded to whole numbers where both ends are whole. - -the drawing sheet gives five damage values for t0 and t1, and four for t2 and -t3. level 5 of t3 continues the trend (guess). t2 does no damage (decided); -it only slows. the equal steps change -three values from the sheet: t1 level 2 from 7 to 8, t1 level 4 from 17 to 18, -and t3 level 2 from 5 to 4 (decided). - -| tower | damage by level | cost | range by level | attack every | projectile speed | source | -|-------|------------------|------|---------------------|--------------|------------------|--------| -| t0 | 5,10,15,20,25 | 5 | 60,63,66,69,72 | 1.5 s | none (melee) | damage, cost: notes; range level 1: decided (was 45); rest: guess | -| t1 | 3,8,13,18,23 | 10 | 100,104,108,112,116 | 0.7 s | 300 | damage levels 1 and 5, cost: notes; range: guess | -| t2 | none | 20 | 90,94,98,102,106 | 1.2 s | 220 | damage: decided; cost: notes; rest: guess | -| t3 | 1,4,7,10,13 | 25 | 220,230,240,250,260 | 1.3 s | 800 | damage level 1: notes; cost: decided (was 40), may go lower; rest: guess | - -the cost column is the build cost, level 1. - -rules: - -- attack speed stays the same at every level (decided). t0 is slower than the - others (decided), t1 faster than t2, t2 faster than t3 (notes) -- range grows about 4 % per level (decided "slightly", amount guessed) -- t0 damages every monster in range at once, each attack -- t2 slow: p2 bursts where it lands into a freeze splash of radius 28, - about two monsters across (decided, radius guessed). every monster the - splash touches moves at 0.60, 0.55, 0.50, 0.45, 0.40 of its speed by - level, for 2 s (guess). a new hit restarts the time. slows do not add up; - the strongest one applies -- p1, p2, p3 home in on their target. if the target dies first, the - projectile flies on to the last position and disappears (guess) -- towers aim at the monster furthest along its route (guess) - -costs: the price of building, or of the upgrade to a level. they started as -level n costs base cost x n (decided); the config sets levels 1 and 5: - -| tower | level 1 (build) | level 2 | level 3 | level 4 | level 5 | total | -|-------|-----------------|---------|---------|---------|---------|-------| -| t0 | 5 | 10 | 15 | 20 | 25 | 75 | -| t1 | 10 | 20 | 30 | 40 | 50 | 150 | -| t2 | 20 | 40 | 60 | 80 | 100 | 300 | -| t3 | 25 | 50 | 75 | 100 | 125 | 375 | - -selling refunds half of everything paid for the tower, build and upgrades, -rounded down (decided). a tower is sold whole. - -| tower | level 1 | level 2 | level 3 | level 4 | level 5 | -|-------|---------|---------|---------|---------|---------| -| t0 | 2 | 7 | 15 | 25 | 37 | -| t1 | 5 | 15 | 30 | 50 | 75 | -| t2 | 10 | 30 | 60 | 100 | 150 | -| t3 | 12 | 37 | 75 | 125 | 187 | - -damage per second against a single target, at the guessed attack times -(derived): - -| tower | level 1 | level 2 | level 3 | level 4 | level 5 | -|-------|---------|---------|---------|---------|---------| -| t0 | 3.3 | 6.7 | 10.0 | 13.3 | 16.7 | -| t1 | 4.3 | 11.4 | 18.6 | 25.7 | 32.9 | -| t3 | 0.8 | 3.1 | 5.4 | 7.7 | 10.0 | - -t3 is meant to be weaker than the other towers; its range lets it reach more -targets (decided). to keep the gap moderate, its cost went from 40 to 25 and -its attack time from 2.0 s to 1.3 s, just slower than t2 as the notes require -(decided, amount guessed). at level 1 it deals about a fifth of t1's damage per -second at two and a half times the cost. its range covers more path, roughly -three times as much on a winding map (estimate). - - -placement ---------- - -| parameter | value | source | -|--------------------------------------------|-------|--------| -| tower footprint radius | 16 | guess | -| road half width, centre line to road edge | per map: 19, 17, 16, 22 | measured from the earlier masks | -| largest gap between footprint and road edge | 14 | guess | -| space between footprint and spawn point | per map: 50 | decided | -| space between footprint and exit point | per map: 40 | decided | -| smallest distance between tower centres | 40 | decided (was 32, two footprints; towers stood too close together) | -| distance from the map edge | 16 | guess | -| snap radius, how far a tap may be from a legal position | 48 | guess | -| placement grid cell | 4 | guess | - -towers may not be placed on the entrance or exit areas. - -the spawn point is where the path leaves the blue entrance area. the space -between it and a tower footprint is one to one and a half times the average -tower size (decided). level 1 towers average about 36 pixels across at sprite -scale 0.25, so the space is 36 to 53 pixels. - -the exit point is where the path enters the green exit area. towers keep a -somewhat smaller space from it (decided), so they do not cover the building -drawn at the exit. - - -economy -------- - -| map | starting coins | -|------|----------------| -| map0 | 10 | -| map1 | 20 | -| map2 | 40 | -| map3 | 60 | - -starting coins are from the notes. the source sheet gives 50 for map3. the -notes raise it to 60 to make the step from map1 to map3 more even (10, 20, -40, 60 instead of 10, 20, 40, 50). likely to change after playtesting. - -the notes set the coins dropped per map to 10 times the starting coins. this -is no longer a target (decided): the coins a map pays follow from its waves. -the build prints, per map, the coins dropped by regular monsters and the -boss, the total with the starting coins, and the coins per hp of the regular -monsters. - -coins per map from the current wave lists (derived): - -| map | regular monsters | boss | dropped in all | with starting coins | regular hp | coins per hp | -|------|------------------|------|----------------|---------------------|------------|--------------| -| map0 | 48 | 30 | 78 | 88 | 395 | 0.12 | -| map1 | 139 | 50 | 189 | 209 | 1145 | 0.12 | -| map2 | 326 | 70 | 396 | 436 | 2615 | 0.12 | -| map3 | 157 | 100 | 257 | 317 | 1160 | 0.14 | - -early start bonuses come on top. - -all monster levels appear on all maps (decided). - - -waves ------ - -| parameter | value | source | -|------------------------------------|---------------------|--------| -| waves per map | 6, 8, 10, 12 | guess | -| break before the first wave | 40 s | guess | -| break between waves, from the last spawn of a wave | 25 s | guess ("longer", decided) | -| time between spawns | 1.0, 0.65, 0.65, 0.5 s by map | guess, fitted in the simulation | -| early start bonus, coins per second left | 0.05, 0.1, 0.2, 0.3 by map | guess (starting coins / 200) | - -the bonus is rounded down. if every break is skipped at once, the bonus adds -about 6, 17, 45 and 82 coins per map (derived). - -shape of a map's waves (decided): each wave is at least as hard as the one -before, and the last wave is the largest. the boss comes in the last wave and -spawns first. early waves are mostly m0 and m1; later waves mix monster -levels. - -the wave lists in the config are drafted by tools/balance.py -(architecture.md) from a few numbers per map, and may be edited by hand -afterwards: - -- the number of waves -- the number of regular monsters in the first and in the last wave. the waves - between grow in equal steps -- the share of each monster level in the map's regular monsters, by count -- the wave in which each monster level first appears - -each monster level gets a weight per wave that grows by one per wave from its -first wave. the weights are scaled until the wave sizes and the shares are -met, then rounded to whole monsters per wave. later waves therefore hold more -of the levels that came in late. every level keeps at least one monster. - -the draft numbers are kept in the map's section of the config, next to the -other map settings. the game does not read them. - -draft numbers, fitted in the simulation to the targets in balancing -(guess): - -| map | waves | regular monsters, first and last wave | share by count, m0-m4 | first wave of m0-m4 | -|------|-------|-----------------|---------------------|---------------| -| map0 | 6 | 4, 7 | 36, 25, 18, 12, 9 % | 1, 2, 2, 4, 5 | -| map1 | 8 | 6, 17 | 36, 25, 18, 12, 9 % | 1, 2, 3, 5, 6 | -| map2 | 10 | 10, 36 | 39, 26, 17, 11, 7 % | 1, 2, 4, 6, 8 | -| map3 | 12 | 5, 16 | 52, 26, 13, 6, 3 % | 1, 2, 4, 6, 9 | - -resulting monster counts (derived): - -| map | m0 | m1 | m2 | m3 | m4 | regular monsters | -|------|----|----|----|----|----|------------------| -| map0 | 12 | 9 | 5 | 4 | 3 | 33 | -| map1 | 32 | 22 | 17 | 12 | 9 | 92 | -| map2 | 90 | 59 | 39 | 27 | 15 | 230 | -| map3 | 65 | 33 | 17 | 8 | 3 | 126 | - -map3 has fewer and weaker monsters than map2. its 60 starting coins already -pay for much of what the naive player needs against b3, so the waves before -may pay only about 130 coins (see balancing). - - -hearts ------- - -| parameter | value | source | -|-------------------------|-------|--------| -| hearts per map | 10 | decided | -| heart cost of a monster | 1 | decided | -| heart cost of a boss | 5 | decided | - - -coins in flight ---------------- - -| parameter | value | source | -|----------------------------------|-------|--------| -| flight time to the counter | 0.7 s | guess | -| most coin sprites for one death | 8 | guess | - -coins are added to the counter at the moment the monster dies; the flying -coins only show it (guess). the same holds for an early start bonus, whose -coins fly from the exits. this keeps the counter correct for a player who -builds right after a kill. - - -controls --------- - -| parameter | value | source | -|------------|--------|--------| -| game speeds | 1x, 2x, 4x | decided | - - -balancing ---------- - -the first values were set without a way to estimate their effect, and the -game was far too easy. two t1 towers won every map, t2 was never needed, and -many coins were left over when a map was won. the aim is a game where the -player has to think about where to place towers and which ones to build. a -player who only buys plain firepower should need nearly every coin a map -pays in order to win it. coins left over then come from better choices. - -two scripted players mark the range (decided): - -- naive: builds t1 only, on placement cells of median coverage, whenever it - can afford one. it should win with about 5 of its 10 hearts left and with - next to no coins at the start of the last wave -- greedy: builds on the best cells, and upgrades when no good cell is left. - it should win with coins to spare - -rules for changing values: - -- shop prices and starting coins stay multiples of 5. round upgrade prices - are preferred -- values the player does not see are free: hp, damage, coin drops, speeds, - attack times -- shop prices are set first. hp, damage and the wave mix are then fitted to - them -- the main control is coins per hp, set by the mix of monsters. m0 drops - 0.2 coins per hp, the other regular monsters 0.10 to 0.13. a mix with - fewer m0 pays less for the same hp -- monster hp stays the same on every map. wave size and the mix make a map - harder - -the coins of the last wave, the boss's included, arrive when the map is as -good as won. leftover coins are therefore measured at the start of the last -wave. the last wave's coins are left out of the calculation. the boss keeps -its drop as a visible reward (decided). - -the calculation goes wave by wave, not per map. at the start of each wave -the player has the starting coins, the coins dropped in earlier waves and -any early start bonus. these coins buy a certain amount of firepower. the -wave sets two demands on it: - -- throughput: the towers' damage per second has to keep up with the hp - arriving per second. the time a monster spends in range gives some buffer -- single target: the toughest monster of the wave, m4 or the boss, has to - die within its time in range - -damage is counted in whole shots. t1 at level 1 needs 2 shots for the 5 hp -of an m0, not five thirds of one. - -simplifications in tools/balance.py: - -- a tower attacks from the first monster of a wave reaching it until the - last has passed. it is idle when no monster is in range. with route - length c in range and spacing s between monsters, the share of time with - a monster in range is taken as 1 - e^(-c/s) -- for the single target demand the monster gets every tower's full - attention while in range. in the game, faster monsters overtake the - boss and draw fire away from it -- the naive player builds at the start of a wave with the coins on hand - and never starts a wave early. the greedy player always starts early and - takes the bonus. coins dropped during a wave count from the next wave -- monsters that leak cost one heart each and drop no coins, so a leaky - wave leaves less for the next one -- routes are equally likely; the route preference is left out. the boss - takes the shortest route -- towers keep their level 1 range when upgraded - -the time a monster spends in range comes from coverage: the length of route -within a tower's range, measured for every legal placement cell from the -build's route and placement data. the median cell stands for the naive -player and the best cells for the greedy one. for more than one tower, -cells are picked one after the other, each counting only route that no -earlier tower covers. maps with several routes are measured per route. - -t1 coverage at range 100 and footprint radius 16, in map pixels of route -within range, the mean over routes on maps with several. top 10 % is the -coverage the best tenth of the cells reach: - -| map | routes | legal cells | best | top 10 % | median | -|------|--------|-------------|------|----------|--------| -| map0 | 1 | 2893 | 415 | 360 | 228 | -| map1 | 3 | 2132 | 325 | 232 | 129 | -| map2 | 6 | 1857 | 276 | 195 | 111 | -| map3 | 1 | 1369 | 422 | 311 | 174 | - -route lengths: map0 2068, map1 737 to 1048, map2 722 to 1363, map3 1035. - -value per coin is damage per second divided by all coins paid for the -tower. for t1 it falls with level: 0.43, 0.38, 0.31, 0.26 and 0.22. this -is the intended trade between upgrading and building another tower. t0 at -level 1 reaches 0.67 against a single target, kills an m0 in one hit and -damages every monster in range. it may be the better buy for a naive -player than t1, so the calculation lists value per coin for every tower and -level, area damage included. the simulation measures 1.2 to 1.7 monsters -hit per t0 attack over whole runs, on median cells as on the best ones. -at that rate t0 at level 1 gives 0.8 to 1.1 against m0, two to three times -t1. - -t2 works as a time multiplier. a slow to 0.6 of the speed gives 1.67 times -the time in range for every tower covering the same stretch. this only -helps against the single target demand, so t2 needs faster monsters or -tough monsters spaced apart to pay off. it is tuned after the t1 baseline. - -tools/simulate.js (architecture.md) plays the same two players in the game -code. with the fitted waves, the two tools agree on the coins on hand at -each wave. they differ in the coins a wave needs: - -- the boss needs 5 to 20 % more in the simulation: 49, 143, 338 and 206 - coins for the naive player against 40, 130, 320 and 170 in the - calculation. faster monsters overtake the boss and draw fire away from it -- regular waves on map2 need up to 1.5 times as much. towers on median - cells cover the six routes unevenly, and monsters on a route with little - cover get through. the mean over routes hides this -- about a tenth of the shots are lost because the target died before the - projectile arrived -- route preference changes nothing: with bias 0 the results are the same, - since the speeds lie close to the reference speed -- the players in the simulation also build during a wave, with coins from - the monsters killed in it - -tools/balance.py was left as it is. the waves were fitted with the -simulation. - -with the fitted waves the naive player loses hearts to regular monsters -only in the first two or three waves. towers stay and add up. what a wave -demands, hp arriving per second, follows from the mix and the spawn -interval; wave size sets how long the wave lasts and what it pays. the boss -is the one demand that grows faster than the coins. the naive player loses -its hearts there, 5 at once, in most runs. the target of about 5 hearts -left is met on average over the seeds: the boss gets through in most runs -and dies in a few. - -order of work (decided): - -1. the calculation, tools/balance.py (architecture.md): value per coin for - every tower, the wave demands against t1 only -2. shop prices fixed, then hp, damage and waves fitted to them -3. t2 after the t1 baseline -4. a headless simulation of the real game code with the two scripted - players confirms the result diff -r 0d40f346059c -r a464bd43b76c doc/balancing.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/balancing.md Wed Oct 21 22:34:43 2026 +0200 @@ -0,0 +1,201 @@ +Balancing +--------- + +How the game's numbers are tuned, and the two tools that help with it. +The numbers themselves are in config/game.toml. This document does not +record results; run the tools for current figures. + + +Aim +--- + +The player should have to think about where to place towers and which +ones to build. A player who only buys plain firepower should need nearly +every coin a map pays to win it. Coins left over then come from better +choices. + +Two scripted players mark the range: + +- Naive: builds t1 only, at level 1, on placement cells of median + coverage, whenever it can afford one. Never starts a wave early. It + should win with about half its hearts left (HEARTS_TARGET in both + tools) and next to no coins at the start of the last wave +- Greedy: builds t1 on the best cells and upgrades when that adds more + damage per second per coin than a new tower. Starts every wave early for + the bonus. It should win with coins to spare + +A boss that gets through loses the map, so a player who wins has held the +boss. The hearts target dates from when a boss cost 5 hearts; see +roadmap.md. + +Coverage of a cell is the length of route within a tower's range from it, +the mean over the map's routes. + +The coins of the last wave, the boss's included, arrive when the map is as +good as won. Leftover coins are therefore measured at the start of the +last wave, and the last wave's coins are left out. + + +Rules for changing values +------------------------- + +- Shop prices and starting coins stay multiples of 5. Round upgrade + prices are preferred +- Values the player does not see are free: hit points, damage, coin + drops, speeds, attack times +- Shop prices are set first. Hit points, damage and the wave mix are then + fitted to them +- The main control is coins per hit point, set by the mix of monsters. The + monster m0 pays more coins per hit point than the other regular + monsters, so a mix with fewer m0 pays less for the same hit points +- Monster hit points stay the same on every map. Wave size and the mix + make a map harder +- Each wave is at least as hard as the one before, and the last wave is + the largest. Early waves are mostly m0 and m1; later waves mix levels + +Workflow: change config/game.toml, build, run tools/simulate.js and read +temp/preview/simulate.txt. The script tools/balance.py gives a faster +estimate and drafts wave lists. + + +Drafting waves +-------------- + +`python3 tools/balance.py --draft [MAP]` prints wave lists as TOML, to +paste over a map's [[map.N.wave]] lists. They are made from the draft +numbers in the map's section, which the game does not read: + +- wave_count: the number of waves +- wave_size: regular monsters in the first and in the last wave. The waves + between grow in equal steps +- monster_share: the share of each regular monster, m0 to m4, by count +- first_wave: the wave in which each regular monster first appears + +Each monster gets a weight per wave that grows by one per wave from its +first wave. The weights are scaled, in turn per wave and per monster, +until the wave sizes and the shares are met, then rounded to whole +monsters. Later waves therefore hold more of the monsters that came in +late. Every monster keeps at least one, and the boss goes into the last +wave. Below each map the tool prints what the calculation makes of the +draft, and warns about a wave with fewer hit points than the one before. +Nothing is written in this mode. The lists may be edited by hand after +pasting. + + +tools/simulate.js +----------------- + +Plays the real game logic with scripted players. Run by hand with Node +after a build: + + node tools/simulate.js + node tools/simulate.js --maps 2 --players naive,naive_t0 --seeds 10 + +It loads www/data/config.js, www/data/maps.js and the logic files util.js, +assets.js, map.js, monster.js, tower.js, projectile.js, wave.js and +game.js, as the browser would. The files render.js, ui.js, input.js, +debug.js and main.js are left out, so the debug switches have no effect. +Audio is a stub. + +- The game advances in steps of 1/60 s; game speed plays no part. Each + seed is passed to the game, so a run can be repeated +- Players buy through the game's own functions (shop choice, preview, + build, tower selection, upgrade, early start), so placement rules and + prices are the game's. They buy the moment they can afford the next + purchase, also during a wave +- Players: naive and greedy as above, naive_t0 (t0 only) and naive_mix (t1 + and t0 in turn). The list and their rules are at the top of the file +- The coins a wave needs are measured by playing that wave alone from an + empty map, with the first purchases of the player's list, and searching + for the fewest that lose no heart. By default only the last wave is + measured; `--need all` measures every wave +- `--waves FILE` takes wave lists from a JSON file in place of the + config's, for trying drafts without a build. `--config FILE` uses + another config.js. `--json` prints the results as JSON and writes + nothing + +It writes temp/preview/simulate.txt (per map and player: maps won, hearts +left, coins on hand and the surplus at the start of the last wave, hearts +lost per wave, and monsters hit per t0 attack) and +temp/preview/simulate.json, which tools/balance.py reads. + + +tools/balance.py +---------------- + +Estimates, map by map and wave by wave, whether the coins a map pays buy +enough firepower. It only calculates, against t1, and is much faster than +the simulation. Run it by hand after a build, as it reads the routes and +placement grid from temp/build/maps.json: + + python3 tools/balance.py + +It needs NumPy and Matplotlib, which the build does not. It writes to +temp/preview/: + +- balance.txt: value per coin for every tower and level; per map the + coverage of each tower's range, and per wave the coins on hand, the + damage rate the wave demands, and the coins the naive and greedy players + need to hold it; t0's value per coin with area damage +- balance_value.png: value per coin by tower level +- balance_map0.png to balance_map3.png: coins per wave, and the surplus at + the last wave and the hearts left against a wave size factor. The factor + scales the number of regular monsters in every wave; their coins follow + +Method: + +- At the start of each wave the player has the starting coins, the coins + dropped in earlier waves and, for greedy, the early start bonus. It buys + what it can in its order. Coins dropped during a wave count from the + next wave +- The wave sets two demands. Throughput: the towers' damage has to keep up + with the hit points arriving. Single target: the toughest monster of the + wave, m4 or the boss, has to die within its time in range +- Damage is counted in whole shots: a tower that needs 2 shots for a + monster spends 2 attacks on it +- A tower attacks from the first monster of a wave reaching it until the + last has passed, and is idle when no monster is in range. With route + length c in range and spacing s between monsters, the share of time with + a monster in range is taken as 1 - e^(-c/s) +- For the single target demand the monster gets every tower's full + attention while in range +- Leaked monsters cost hearts and drop no coins, so a leaky wave leaves + less for the next one +- Naive uses the median coverage of all legal cells. Greedy picks cells + one after the other, each counting only route that no earlier pick + covers. Maps with several routes are measured per route and averaged +- Value per coin is damage per second divided by all coins paid for the + tower, with whole shots against each regular monster +- The tower t0 hits several monsters per attack. Its value per coin is + multiplied by the monsters hit per attack, as measured by the simulation + when simulate.json exists, otherwise estimated from coverage and spacing + +Simplifications and limits: + +- Only t1 is considered for the wave demands. The tower t2 works as a time + multiplier (a slow to a share k of the speed gives 1/k the time in range + for every tower covering the same stretch), which helps only against the + single target demand. It is not modelled +- Routes are equally likely; the route preference is left out. The boss + takes the shortest route +- Towers keep their level 1 range when upgraded +- Towers that only slow are left out of the value per coin table + + +Where the tools differ +---------------------- + +The two tools agree on the coins on hand at each wave. They differ in the +coins a wave needs, for reasons the calculation leaves out: + +- The boss needs more in the simulation: faster monsters overtake it and + draw fire away from it +- On maps with several routes, towers on median cells cover the routes + unevenly, and monsters on a route with little cover get through. The + mean over routes hides this. It shows most on map2, with six routes +- Some shots are lost because the target died before the projectile + arrived +- The simulated players also build during a wave, with coins from the + monsters killed in it + +The waves in the config were fitted with the simulation. diff -r 0d40f346059c -r a464bd43b76c doc/game.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/game.md Wed Oct 21 22:34:43 2026 +0200 @@ -0,0 +1,227 @@ +The game +-------- + +Minor Monsters is a tower defense game by M.A. and J.A. Juszczyk. It runs +in desktop and mobile browsers, with mouse or touch. The player only +manages towers: build, upgrade, sell. Everything else, such as collecting +coins, happens on its own. The game shows icons and hand-drawn digits in +place of text. + +This document describes the rules as the game implements them. The values +are in config/game.toml; the section names below point to them. How the +code does it is in architecture.md and implementation.md. + + +Maps +---- + +There are four maps, played in order: map0 home, map1 mine entrance, map2 +mine, map3 lava depths. Each map has a mask that marks the path, its +entrances and its exits (art.md). + +- A won map leads to the next map. After the last map the game is won +- A lost map sends the player back to the first map +- There is no map selection and nothing is stored between visits. A + reload starts at the splash screen with a fresh game +- Each map starts with its own starting coins and hearts. Nothing is kept + from the map before ([map.N], [hearts]) + +The maps map0 and map3 have one route each. On map1 the path branches +into three routes. On map2 two entrances and loops give six routes. + + +Routes +------ + +A monster picks its route when it spawns and follows it to the exit. On +map2 the route also decides the entrance. + +- A boss always takes the shortest route +- Other monsters weigh the routes by their speed. Each route has a value + between 0 and 1: the average of its length relative to the longest route + and its straightness relative to the straightest one +- A monster's speed factor is its speed minus the reference speed, divided + by the reference speed, limited to -1 to 1 +- The weight of a route is 1 + bias x speed factor x (2 x route value - 1), + and at least the minimum weight ([route_preference]) + +So faster monsters prefer long or straight routes, slower ones prefer +shortcuts, and a monster at the reference speed takes every route with the +same likelihood. + + +Monsters +-------- + +The regular monsters are m0 to m4, in rising strength. The bosses are b0 +to b3, one per map: b0 comes on map0, b1 on map1 and so on. Each monster +has hit points, a coin drop and a speed ([monster.*]). A monster's hit +points are the same on every map; a map gets harder through the size and +mix of its waves. All regular monsters appear on all maps. + +- Each monster's speed differs from its configured speed by a random share + ([movement] speed_variation). Faster ones overtake slower ones +- Monsters do not walk in single file. Each walks beside the centre line + of the road, with a fixed lean to one side and a part that wanders. The + offset grows from 0 at the start of the route and is reduced on the + inside of tight bends ([movement]) +- Monsters move by small hops, with squash on landing and stretch in the + air, and a slow breathing on top ([animation]) +- An HP bar shows above every monster; the boss has its own bar. The bar + turns blue while the monster is slowed +- A dying monster leaves a puff, a larger one for a boss + + +Waves +----- + +Each map has a list of waves ([[map.N.wave]]). A wave says how many of +each monster it holds. The boss of the map is in the last wave. + +- A map starts with a break ([waves] first_break). The next wave starts + when the break runs out +- A wave spawns one monster per spawn interval ([map.N] spawn_interval). + The boss comes first, as it is the slowest; the others follow in random + order +- The break after a wave starts when its last monster has spawned + ([waves] break). Monsters of the wave may still be on the map +- The wave counter shows the current wave, and during a break the next one +- During every break, the first one included, a button starts the next + wave early. It pays a bonus: the seconds left times the map's + early_bonus rate, rounded down + + +Coins +----- + +Killing a monster pays its coin drop. The coins count at once, so a player +can build right after a kill. Coin sprites then fly from the monster to +the coin counter, at most a few per death ([coins]); each is one of the +four coin drawings, picked at random. The early start bonus counts at once +too, and its coins fly from the exits. + + +Hearts +------ + +A regular monster that reaches the exit costs hearts. A boss that reaches +it loses the map: its heart cost is all the hearts of a map ([hearts]). +At zero hearts the map is lost. The map is won when the last wave has +spawned and no monster is left on the map. + + +Towers +------ + +There are four towers, each with five levels. Damage, range, slow and cost +are set in the config for level 1 and level 5; the levels between are +filled in by equal steps ([tower.*]). The time between attacks is the same +at every level. + +- t0, melee: each attack damages every monster in range at once. It + pushes out spikes (p0) only on the sides that face the path +- t1, the standard tower: turns and shoots p1 at one monster +- t2, the freeze tower: does no damage. It turns and shoots p2, which + bursts where it lands into a freeze splash. Every monster the splash + touches is slowed to a share of its speed for a time. Slows do not add + up; the strongest one applies, and a new hit of the same strength + restarts its time. A slowed monster also hops slower +- t3, the sniper tower: turns and shoots p3. It is meant to be weaker + than t1, and its much longer range lets it reach more of the path + +Targeting: + +- A tower aims at the monster in range that is furthest along, that is, + the one with the least distance left to its exit +- Turning towers face their target at once and keep their direction when + no monster is in range +- The projectiles p1, p2 and p3 home in on their target. If the target + dies first, the projectile flies on to its last position and disappears + there without damage. A p2 still bursts there +- A new tower attacks at once + +Prices: + +- Building costs the level 1 price. Each upgrade costs the price of the + new level +- Selling refunds a share of everything paid for the tower, build and + upgrades, rounded down ([tower_rules]). A tower is always sold whole + + +Placing and managing towers +--------------------------- + +Towers stand next to the road, never on it, and not near the entrances or +exits. They keep a distance from each other and from the map edge +([placement], and per map in [map.N]). + +- The shop sits on the right in landscape and at the bottom in portrait. + A tower the player cannot afford is dimmed and cannot be chosen +- After choosing a tower, a press on the map puts a preview with its range + at the nearest legal position. The preview follows the pointer until it + is let go +- Tapping the preview builds the tower. Dragging the preview, or pressing + elsewhere and dragging, moves it again +- Where no legal position is within reach, a red cross shows briefly and + the placement refused sound plays +- The preview pulses in time with the chosen shop item. A second tap on + that item cancels the choice; building clears it +- Tapping a built tower shows its range and a bubble with upgrade and + sell, each with its price. An upgrade the player cannot afford is + dimmed. At level 5 only sell is left +- Selling takes two taps. The first arms the sell button, which then + pulses with a red glow; the second sells. Any other tap cancels it +- A tap outside the bubble closes it + + +Controls +-------- + +The top bar shows coins, hearts and the wave count. Its buttons, from the +right: help, pause, speed, sound, and during breaks the early start button +with the countdown. On a narrow screen the buttons move to a second row. + +- Pause stops the game. The shop is dimmed, and nothing can be built, + upgraded or sold. Pausing drops the shop choice and the tower selection. + The top bar buttons still work, early start included +- Speed switches between the game speeds ([controls]) +- Sound switches all sound on or off. The choice is kept in the browser. + Until the player first uses it, the config's default applies ([sound]) +- Help opens the help popup, which pauses the game. A tap anywhere closes + it and lets a game that was running go on. A tap on the email address in + the popup writes a mail ([links]) + +Nothing depends on mouse hover. With a mouse, hover only enlarges the +screen buttons and shows the pointer cursor over buttons. + + +Screens +------- + +- Splash: title, byline and play button, over the paused first map, with + music looping +- Browsers allow sound only after a tap, so on the first splash screen + after loading, a sound button covers the play button. It pulses with a + red glow; a tap starts the sound and the music and uncovers the play + button. When sound was switched off on an earlier visit there is no + sound button and no music +- Left of the play button the logo opens the game's web page ([links]), + right of it a question mark opens the help popup +- The play button fades the music out and starts play +- Map won, after every map but the last: one button, which starts the next + map +- Game won, after the last map: one button, which goes back to the splash + screen. The music plays at once there, as sound is already running +- Game lost: one button, which starts the first map + +All four screens are drawn at one scale, so the larger drawings stay +larger. The screen buttons pulse slowly as a cue to tap. + + +Sound +----- + +Game events play the voice recordings in art/sounds/, a random one where +an event has several. Events without a recording play short beeps made in +the browser. The events are listed in art.md. The map won sound waits for a +death sound still playing, the map lost sound for the last exit sound. diff -r 0d40f346059c -r a464bd43b76c doc/game_design.md --- a/doc/game_design.md Tue Oct 20 19:54:56 2026 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,171 +0,0 @@ -tower defense game design notes -------------------------------- - -numbers marked as guesses, and all speeds, ranges and timings, are collected in -balance.md. technical details are in architecture.md. - -- working title "minor monsters" -- runs as a plain html/javascript page, on desktop (mouse) and on tablets - (touch) -- the player only manages towers: build, upgrade, sell. everything else, such - as collecting coins, happens on its own -- no text in the game where an icon will do. icons, ui elements and any - remaining text are supplied as scribbles; see art.md for the list - -maps ----- - -- map levels 0-3: home, mine entrance, mine, lava depths - *mask images define play areas - monster enter from blue entrance, walk to green exit on red path - towers are placed along path -- maps are played in order. after a won map the only way on is the next map. - a lost map sends the player back to the first map. there is no map - selection. to be reviewed after playtesting -- the first map is map0, or the map set by the debug start switch - (architecture.md) -- nothing is stored in the browser for now. a reload starts again at the - splash screen with a fresh game -- coins do not carry over between maps; each map starts with its own starting - coins -- map1 and map2 have branching paths, map2 has two entrances. a monster picks - its route when it spawns: - - faster monsters prefer longer or straighter routes - - slower monsters prefer shortcuts - - otherwise all routes are equally likely - - bosses take the shortest route -- later maps have shorter paths and many more monsters - -towers ------- - -- towers: - - t0 is close range and projects spikes (p0) from all four sides - damage per tower level: 5,10,15,20 - cost 5 - melee tower: each attack damages every monster in range at once - slower attack than the other towers - spikes are only drawn on the sides that face the path - - t1 is the default generic towers, turns, shoots projectile p1 - damage: 3,7,13,17 - cost 10 - - t2 shoots projectile p2, turns, slows down monsters - slower than t1 - no damage (decided; the sheet gave 1,3,5,7). p2 bursts where it - lands into a freeze splash (freeze.png) about two monsters across, - and slows every monster in it - a slowed monster's hp bar turns blue - cost 20 - - t3 is long range sniper tower, turns, shoots p3 - slower than t2 - damage 1,5,7,10 - cost 25 (first planned as 40, lowered for balance) -- art assets for tower levels still need to be processed, contain upgrades 1-4 - for each tower -- towers have 5 levels: t0-t3 are level 1 (the base), the four drawings in - each t*p strip are levels 2-5 - the original drawing sheet gives five damage values for t0 (5,10,15,20,25) - and t1 (3,7,13,17,23), and four for t2 and t3, as above. level 5 of t3 - is guessed in balance.md. the game fills in the levels between - level 1 and level 5 in equal steps, so some values differ from the sheet -- t3 is meant to be weaker than the other towers; its range lets it reach - more targets -- towers are placed next to the path, never on it. a tap or click snaps to the - nearest legal position, so the player does not have to hit an exact spot -- placing: pick a tower in the shop, press on the map and drag. a preview - with its range follows, snapped to the nearest legal position, and stays - where the pointer is let go. tapping the preview builds the tower. - dragging the preview, or pressing elsewhere and dragging, moves it again. - changed after user testing, where players wanted to drag the preview -- the preview pulses in time with the chosen shop item. some testers took - the preview for a built tower -- tapping a built tower shows its range and the upgrade and sell buttons -- each level has its own cost: building is level 1, an upgrade costs the - price of the new level. the costs started as tower base cost * tower - level, so the first upgrade (to level 2) cost twice the base cost. - balance.md has the current values -- upgrades mainly raise damage. range grows slightly, and so does the slowing - of t2. attack speed stays the same at all levels -- selling a tower refunds half of everything paid for it: the build and all - its upgrades. a tower is always sold whole; upgrades cannot be sold one by - one - -monsters --------- - -- monsters m0-m4 are monster levels, drop 1/1/2/2/3 coins on death - hp 5/10/15/20/30, the same on every map - (the notes had 1/2/3/4/6 coins; balance.md, monsters) -- all monster levels appear on all maps, in different amounts and proportions. - low levels stay in the mix on later maps to balance the larger numbers -- monsters emulate animation with slight bobbing, squish/stretch on x and y by a - few percent; walking animation is by small hops; hops and animation may - overlap out of red path -- monsters do not walk in single file: each walks a little to the side of the - path, drifting from side to side, and at a slightly different speed -- bosses are map-specific, b0 belongs to map0 etc; boss coin drop - 30/50/70/100, boss hp 5 times that (balance.md) -- hp bars are always shown above every monster. the boss uses its own bar, also - above the boss. the bar turns blue while t2 slows the monster -- dropped coins fly to the coin counter on their own. each coin uses a random - one of c0-c3. the coins of an early start bonus fly the same way, from the - level exit - -economy and waves ------------------ - -- starting coins per map level: 10, 20, 40, 60 -- balance of monster speed vs tower fire frequency tbd, see balance.md, - balancing -- several monster waves per map with breaks between them, last wave - includes boss. the notes set the coins per map to 10 times the starting - coins; this is no longer a target (balance.md, economy) -- the break between waves counts down, and the next wave starts on its own - when it runs out. a button starts the next wave early and pays a coin bonus - based on the seconds left. this is how most tower defense games handle it -- the breaks are longer than first planned, to give time to build - -hearts ------- - -- each map starts with a number of hearts -- a monster that reaches the exit costs one heart, a boss costs more -- at zero hearts the map is lost, and play starts again at the first map -- the map is won when the last wave, including the boss, is cleared - -screens -------- - -- splash: title "minor monsters", byline "By M.A. and J.A. Juszczyk" and a - play button, drawn over the first map with the game paused. music loops - while it shows. on the first splash screen a sound button covers the play - button, as browsers allow sound only after a tap; it starts the sound - (sound.md). left of the play button a logo opens a web page in a - new tab, right of it a question mark opens the help popup -- map won, on maps before the last: one button, next, which starts the next - map -- game won, after the last map: one button, restart, which goes back to the - splash screen -- map lost: one button, which starts the first map -- all screens are drawn at one scale, so the splash and game won screens, - which are drawn larger, stay larger than map won and map lost -- the screen buttons pulse slowly as a cue to tap. with a mouse they grow - under the pointer - -controls --------- - -- pause. towers cannot be built, upgraded or sold while paused. building - during a pause was allowed at first, but it clashed with starting waves - early -- game speed 1x, 2x and 4x (decided) -- sound on and off, kept in the browser -- help, which opens the help popup -- input via pointer events, so mouse and touch work the same. no part of the - game depends on mouse hover - -sound ------ - -- voice recordings for most events, placeholder beeps generated in the - browser for the rest; see sound.md diff -r 0d40f346059c -r a464bd43b76c doc/implementation.md --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/doc/implementation.md Wed Oct 21 22:34:43 2026 +0200 @@ -0,0 +1,236 @@ +Implementation notes +-------------------- + +How the build and the game code do what game.md and architecture.md +describe, for changing or debugging the code. Tuning values are in +config/game.toml. The constants named here are set at the top of the file +or function that uses them; read the value there. + + +Images (tools/images.py, tools/build.py) +---------------------------------------- + +- Sprites are trimmed to their non-transparent pixels. Sprite sizes go into + config.js, so the game knows them before the images load +- Tower strips are split at columns without pencil, that is, without pixels + darker than INK_LUM. Runs of pencil narrower than 4 columns are specks. + The cut lies halfway between drawings. A strip must give 4 drawings +- The inside of a tower outline is filled with white: the pencil lines are + thickened by GAP_CLOSE to close gaps, the outside is flood filled from a + corner and grown back by the same amount, and everything not reached is + inside. Outside, light pixels fade from opaque at LUM_OPAQUE to + transparent at LUM_CLEAR, which removes the paper halo +- HP bars: the empty part is a copy darkened by BAR_DARKEN (hpm_empty, + hpb_empty). The blue bars have every pixel's hue set to BAR_SLOW_HUE, + which leaves the black outline as it is (hpm_slow, hpb_slow, each with + an _empty copy) +- Maps are written as JPEG at MAP_QUALITY. A map with transparent pixels + stops the build +- The sprite list of the build is SPRITES in tools/build.py. A new image + has to be added there + + +Masks and routes (tools/masks.py) +--------------------------------- + +- Pixels are classified by exact colour: transparent is free, opaque pure + red is path, blue is entrance, green is exit. Any other pixel stops the + build with its position +- The path and the entrance and exit areas are thinned to a one pixel + centre line (Zhang-Suen) and turned into a graph of junctions, line ends + and the pixel chains between them. Small loops of fewer than 8 pixels + at one junction are dropped +- The line width is the red area divided by the centre line length +- The line end nearest to each entrance and exit blob is a terminal. Dead + ends shorter than 0.8 line widths are dropped, and junctions closer than + 0.75 line widths count as one; thinning splits a wide crossing into + several junctions +- Routes are all paths from an entrance terminal to an exit terminal that + visit no junction twice. A loop that leaves a junction and comes back to + it may be walked once. Of its two directions, the one that turns less is + kept. This gives map2's three loops (the round one at the top left and + two squares at the bottom) and its six routes +- Each route is resampled at 1 pixel, smoothed twice by a moving average + with half window ROUTE_SMOOTH, and simplified to ROUTE_TOLERANCE + (Ramer-Douglas-Peucker) +- Turning is the sum of direction changes along a route, in degrees, not + per length. The route value is the average of length / longest and least + turning of the map / own turning (route_values in build.py) +- The centre line runs through the entrance and exit areas, so routes + start and end inside them. The spawn point is the first centre line + pixel outside the entrance, walking from the route start; the exit point + is found the same way from the route end + + +Placement grid (tools/masks.py) +------------------------------- + +The grid has one cell per grid_cell pixels. A cell is legal when a tower +footprint centred on it: + +- does not overlap the road: the road is a disc of footprint radius plus + the map's road half width around each centre line pixel. Centre line + pixels inside the entrance and exit areas do not count +- does not overlap the entrance and exit areas +- keeps the map's spawn_distance from each spawn point and exit_distance + from each exit point +- comes within max_gap of the road +- has its centre at least edge_distance from the map edge + +The test draws discs instead of measuring a distance for every pixel; the +result is the same. The distance between towers is checked by the game, +not the grid. + + +Main loop and movement (js/main.js, js/map.js, js/monster.js) +------------------------------------------------------------- + +- The simulation runs on the frame clock: the time since the last frame, + times the game speed, is used up in steps of STEP. At most MAX_STEPS + steps per speed step run in one frame; the rest is dropped +- A route is a polyline with cumulative distances. A monster's position is + its distance walked, turned into a point on the centre line and shifted + sideways +- Sideways offset: a fixed lean of lean x the largest offset, chosen at + spawn, plus a wandering part with a new random value every wander_step + pixels, eased between values by a cosine. The sum grows from 0 over the + first fade_in pixels. The largest offset is offset x the map's road half + width +- On the inside of a bend the offset is limited so the shifted point keeps + moving forward at no less than 1 - BEND_SHARE of the walking speed. The + limit changes by at most LIMIT_SLOPE per pixel, so monsters drift + towards the centre line before a tight bend rather than at it +- Towers rank monsters by distance left along the centre line, so the + offset does not change the order +- Hops are drawn only; monsters move at constant speed. A hop spends AIR + of its time in the air and the rest landing. The idle bob is a 1.3 s + breathing on top. Each monster starts at a random point of its hop cycle +- Monsters and towers are drawn sorted by their y position + + +Towers and effects (js/tower.js, js/projectile.js, js/game.js, js/render.js) +---------------------------------------------------------------------------- + +- A monster is in range when its centre is. Projectiles hit on coming + within the target's hit radius, hit_radius x the smaller side of its + sprite +- Each running slow keeps its own time; the strongest applies +- The freeze splash slows every monster whose hit area it touches. It is + drawn under the monsters, as freeze.png across its diameter at 85 % + opacity, and grows and fades over freeze_splash seconds +- The attack of t0 stretches each spike from under the tower until its tip + reaches the range, and back, over BURST_TIME. At rest a quarter of each + spike shows beyond the tower's edge +- Spike sides of t0: each side covers a quarter of the directions around + the tower. Route centre lines are sampled every SIDE_STEP pixels. A side + gets a spike when it holds at least SIDE_SHARE of the samples within + t0's level 5 range. With no sample in that range, only the side towards + the nearest one does. The sides are fixed when the preview is placed +- Death puffs and the freeze splash grow from 60 % to full size over the + first half of their time and fade out over the second half. Both are + dropped when the map ends +- Flying coins: one sprite per coin, at most max_sprites, started 0.05 s + apart, flying in game time on an arc that eases in towards the counter. + Early start bonus coins start at the exits in turn, within each exit's + radius. Coins in flight are dropped when the map ends; they have already + been counted + + +Layout and UI (js/ui.js) +------------------------ + +- The sizes of top bar rows, buttons, shop items, the tower menu bubble + and digits are the constants at the top of ui.js, in CSS pixels +- Each top bar counter keeps the width of a usual largest value (USUAL), + so the next one does not move. When the counters at those widths and the + buttons do not fit side by side, the buttons get a second row under the + counters. Narrower screens are not handled further +- Screens: one scale for all four drawings, so that the widest and the + tallest fit 92 % of the window width and 90 % of its height, at most 1. + Each screen's separate button image is drawn over the button in the + drawing, at the position in [art.screen]; its tap area is the button + image. The splash screen's logo and question mark are placed by top left + corner and height. Buttons pulse by 4 % over PULSE seconds; under the + mouse they are 8 % larger with a shadow +- The help popup has a scale of its own, to fit 96 % of the window. Its + tap areas are the email address ([art.screen] help_email) and the whole + window, which closes it +- The splash screen has a pale veil over the map, the other screens a dark + one. A paused game has a light veil over the map +- Numbers: the digit variant of each place depends on the digit and its + place counted from the right, so variants differ along a number but a + number keeps its look. Prices have coin_icon in front of the amount; + placed behind it, the icon would read as an extra zero +- The chosen shop item switches between shop_bubble_dark and + shop_bubble_dark2 every BUBBLE_FLIP ms. The preview grows while one + shows and shrinks while the other does, between 45 % and 80 % opacity and + 100 % and 108 % size. The range circle does not pulse +- The tower menu bubble sits above the tower, or below it when there is no + room above, kept inside the map area. Upgrade and sell each take half of + it as tap area. An armed sell button pulses by 15 % every WARN_PULSE + seconds with a red glow; there is no timeout +- The early start button draws the countdown on next_wave, without the + bonus + + +Input (js/input.js) +------------------- + +- Only the first pointer is followed while it is down; it is captured, so + a drag may leave the canvas +- A press within the footprint radius or PREVIEW_HIT CSS pixels of the + preview grabs it. Released after a move of at most DRAG_SLOP CSS pixels, + it builds the tower; a longer move drags it, keeping its offset to the + pointer +- A press or drag that never finds a legal position shows the red cross + for REFUSED_TIME where the pointer is let go +- Any button other than sell cancels an armed sell; any button outside + the tower menu closes it +- A cancelled pointer, for example taken by a system gesture, builds + nothing + + +Audio (js/audio.js) +------------------- + +- The audio context is created at start and stays suspended until + audio.start() runs in a tap: the splash screen's sound button, or the + play button. Older Safari also needs a short silent sound started in the + handler. Later pointer and touch events resume a context the browser has + suspended. For the mouse, pointerdown counts as a user interaction; for + touch, pointerup and touchend do +- A sound that cannot play at once, while audio is still locked, is + dropped, not queued +- Switching sound off mutes the output at once and stops new sounds. The + button tap sound plays after the switch, so it is heard when sound goes + on +- The min_interval setting drops plays of an event that come too soon + after the last +- Beeps are oscillator notes with the wave form beep_wave, each with a + falling envelope +- The splash music loops the event's first recording. If it is not + decoded yet, it starts once it is; on a locked context, with the unlock + + +Cutting scripts (tools/cut_*.py) +-------------------------------- + +- cut_sheet.py: one hand-set box per drawing on + art_sources/source_sheet_2.jpg, at the sheet's scale. In each box the + largest connected outline, ink darker than INK_LUM, is the drawing; other + outlines are kept only when they reach KEEP_SHARE of it and do not touch + the box border. Paper lighter than PAPER_LUM becomes white, the outside + transparent. The four levels of a t*p strip are written side by side + with STRIP_GAP empty columns, as the build expects. The files + game_won.png and game_won_button.png were cut once from + art_sources/game_won.jpg with its cut function; the scan has no boxes in + the script +- cut_digits.py: every connected stroke on digits.png darker than INK_LUM + is one character; strokes under MIN_PIXELS are specks. Rows are told + apart by the stroke centre, and the characters of each row are listed in + ROWS. All characters are scaled to the median height of the drawings +- cut_sounds.py: high-pass filter at HIGHPASS, trim to the voice (frames + within THRESHOLD_DB of the loudest), split recordings with variants at + their longest pauses (VARIANTS), fade the ends, bring every sound to the + same peak level, write mono MP3. SKIP drops the start of a recording, + LOOP_GAP adds silence after a looping sound diff -r 0d40f346059c -r a464bd43b76c doc/roadmap.md --- a/doc/roadmap.md Tue Oct 20 19:54:56 2026 +0200 +++ b/doc/roadmap.md Wed Oct 21 22:34:43 2026 +0200 @@ -1,264 +1,21 @@ -roadmap +Roadmap ------- -steps in order. each ends with something that runs and can be looked at. - -1. build basics - - directory layout, config/game.toml with the values from balance.md - - build script: sprites, tower level split and fill, map copies, - config.js - - check: the processed tower levels look right -2. maps and routes - - mask classification, placement grid, route extraction - - previews in temp/preview/ - - check: routes on all four maps follow the paths, placement grid looks - sensible -3. map and walking monsters - - index.html, main loop, scaling to the window, map drawing - - monsters walk their routes with hop animation and route preference - - check: hop and squash feel; speeds against path lengths -4. waves and hearts - - wave timing, countdown, early start and bonus, hearts, win and loss -5. towers - - shop, placement with snapping and preview, targeting, projectiles, - damage, hp bars, coin drops and flying coins - - first playable version of map0 -6. tower details - - upgrades, selling the whole tower, t0 melee - and spike sides, t2 slow with the blue hp bar, boss with its bar -7. game flow - - splash screen with title, byline and play button over the paused first - map; the play button starts the sound - - map won with next, game won after the last map with restart to the - splash screen, map lost back to the first map - - no map selection, unlocking or localStorage -8. tuning on all maps - - balance calculation, then the headless simulation to check it - (balance.md, balancing; architecture.md, balance tools) - - wave lists for maps 1-3, playtesting, balance changes in config only -9. supplied art and sound - - icons, screens and digits as the drawings arrive (art.md) - - voice recordings as they arrive (sound.md) -10. publishing - - tools/make_dist.sh, dist/ tarball of www/, hosting for tablet play -11. help page - - a hint page made from game graphics, no text where a picture will do - - the tower ranges side by side - - placing a tower: one tap puts the preview down, a second tap on it - builds - - t0 hitting several monsters with one attack - - t2 slowing a monster, with the blue hp bar - -debug switches (architecture.md) are added as each step needs them, starting -with step 3. - - -prototype notes ---------------- - -decisions taken while building steps 1-7 that the other documents do not -cover. values marked proto in config/game.toml refer to this list. - -build: +The game is in beta and feature complete. It is deployed on a web server +and runs in desktop and mobile browsers. The steps that built it are +listed in history.md. -- runs on python 3.11 or later with pillow; numpy is not used. a full build - takes about 5 s, most of it in the mask step -- a step is skipped when its outputs are newer than its inputs and the build - scripts. the mask step also reruns when the placement settings or the - per map road and spawn settings in game.toml change; it keeps its result in temp/build/maps.json for the - checks and previews -- map images are written as jpeg, quality 88. the maps have no transparency -- tower strips are split at columns without ink. ink is anything darker - than luminance 225. outline gaps of up to about 4 pixels are closed before - the fill. the white paper edge outside the outline fades to transparent -- tools/cut_sheet.py cuts the sprites out of art_sources/source_sheet_2.jpg - into art/. it - is run by hand, not by the build. one hand-set box per drawing; in each box - the largest connected outline is the drawing and other ink is dropped. - outline ink is darker than luminance 150. sprites stay at the sheet's - scale, which is the scale the first cutouts had, so [scale] is unchanged. - coins and maps are not on the inked sheet and stay as they were -- game_won.png and game_won_button.png were cut once from - art_sources/game_won.jpg with the cut function of cut_sheet.py; the scan - has no boxes in the script -- tools/cut_digits.py takes every connected stroke on digits.png as one - character. ink is darker than luminance 150, strokes under 30 pixels are - specks. rows are told apart by the stroke centre, and the characters of - each row are listed in the script. the scaled height is 66.5 pixels, the - median of the drawings -- the empty part of the hp bars is a darkened copy made by the build - (hpm_empty, hpb_empty). the blue bars for slowed monsters have the hue of - every pixel set to 220 degrees, which leaves the black outline as it is - (hpm_slow, hpb_slow, each with its _empty copy) -- sprite sizes go into config.js, so the game knows them before the images - load -- mask pixels are classified by exact colour. any pixel that is not fully - transparent and not one of the three colours stops the build -- the placement test draws discs instead of keeping a distance for every - pixel. the result is the same. the road is a disc of footprint radius plus - road half width around each centre line pixel; centre line pixels inside - the entrance and exit areas do not count. each spawn point gets a disc of - footprint radius plus spawn_distance, each exit point one of footprint - radius plus exit_distance. edge_distance applies to the tower centre -- the spawn point is the first centre line pixel outside the entrance area, - walking from the route start. the exit point is found the same way from - the route end -- the centre line runs through the entrance and exit areas, so routes start - and end inside them. dead ends shorter than 0.8 line widths are dropped. - junctions closer together than 0.75 line widths count as one. the line - width is the red area divided by the centre line length, about 11 pixels -- map2 has three loops (the round one at the top left, two squares at the - bottom). each leaves the path at a junction and comes back to the same - junction, so the rule "no junction twice" would never walk them. a route - may walk such a loop once. of its two directions, the one that turns less - is kept. map2 gives 6 routes, all kept; map1 gives 3 -- route smoothing: moving average over 17 points, applied twice, then - simplified to 0.8 pixel tolerance -- straightness for the route value is the least turning of the map's routes - divided by the route's turning. turning is the total, not per length -- the road half widths are the median distance from the centre line to the - edge of the earlier masks, which covered the whole road. map0's route is - 2068 long -- the build prints the coins dropped per map, boss included, with and - without the starting coins. the earlier check against 10 x the starting - coins is gone (balance.md, economy) -- the build prints the early start bonus for skipping every break, including - the one before the first wave: 8, 21, 53, 94. balance.md gives 6, 17, 45, - 82, which leaves that break out. the game pays the bonus before the first - wave too. to decide - -config: +Open: -- per map: [map.N] holds starting_coins, early_bonus, wave_count, the - draft numbers monster_share, wave_size and first_wave, followed by the - [[map.N.wave]] lists -- added: hit_radius in [animation] (0.4 of the monster sprite's smaller - side), min_weight in [route_preference] (the "at least 0.1" of the rule), - [art.angle] and [art.pivot]. the turning towers turn around the middle of - their body, not the middle of the image. t1: the centre of the box - measured on the cutouts. t2: the middle of the round body, found as the - rows at least 60 % as wide as the widest row. t3: an estimate, the - centroid of the shape once the barrel and star tips are removed, to adjust - by hand. temp/preview/towers.png marks them. the angles are set by hand on - the same sheet, which shows every turning tower turned to face up -- draft waves: monster counts per level from the coin shares. each level is - spread over the waves by the coin budget still open, with wave n worth n - shares. higher levels start later: m1 after 15 % of the waves, m2 35 %, m3 - 50 %, m4 65 %. spawn interval 1.0 s on maps 0 and 1, 0.8 s on map2, 0.7 s - on map3. totals: 102, 199, 398, 600 coins - -game: - -- scripts share the namespace object MM. storage.js keeps the settings in - the localStorage entry minor_monsters, as version 1 -- the simulation runs on wall clock time: at 60 frames per second, 2x gives - two steps per frame. at most 4 steps per frame and speed step; a longer - frame drops the rest -- game flow: the first map is debug.start_map, and only the first map - starts at debug.start_wave; the next maps start at wave 1. - debug.start_coins applies to every map. the splash screen pauses the - first map, and only its buttons respond. the next map starts with its break running, as - does the first map after a lost map. the splash screen has a pale veil - over the map, the other screens a dark one -- screens: the scale is the same for all four drawings, set so the widest - and the tallest fit 92 % of the window width and 90 % of its height, at - most 1. the separate button image is drawn over the button in the - drawing; [art.screen] in game.toml holds where, measured by matching the - images. its tap area is the button image. it pulses by 4 % over 1.2 s; - under the mouse it is 8 % larger with a shadow -- splash screen logo and question mark: placed by their top left corner and - height in [art.screen], and pulse like the play button. the logo opens - logo_url from [links] in a new tab when the pointer is let go over it, as - tablets allow a new tab only then. the question mark and the top bar help - button have no action until the help popup exists -- a break starts when the last monster of the wave has spawned, not when - all of them are gone. monsters of the wave may still be on the map during - the break. during a break the wave counter shows the next wave -- monsters move at constant speed; the hop is drawn only. a hop spends 80 % - of its time in the air and 20 % landing. the idle bob is a slow breathing - (1.3 s) on top of the hops, as monsters never stand still -- route choice weighs all routes of the map. on map2 this also picks the - entrance -- "furthest along" means the least distance left to the exit. a monster is in - range when its centre is. projectiles hit on reaching the target's hit - radius. a new tower attacks at once -- turning towers face their target at once and keep the last direction when - idle -- t0's attack stretches each spike from under the tower until its tip - reaches the range, and back, over 0.3 s -- t0 spike sides: each side covers a quarter of the directions around the - tower. the route centre lines are sampled every 4 pixels; a side gets a - spike when it holds at least 20 % of the samples within t0's level 5 - range. with no sample in that range, only the side towards the nearest - one gets a spike. the preview shows the same sides. on map0 about half the - placement cells give one side, most of the rest two, a few three -- t2 slow: each running slow keeps its own time, and the strongest one - applies. a slowed monster also hops slower, by the same factor -- t2 freeze splash: p2 bursts where it lands, also when its target died on - the way. it slows every monster whose hit area the splash touches. the - splash is drawn under the monsters, as freeze.png across its diameter at - 85 % opacity, and grows and fades like a death puff over 0.4 s - (freeze_splash in [animation]) -- tower menu: tapping a built tower shows the tower_popup bubble, 168 css - pixels wide, above it, or below it when there is no room above, kept - inside the map. upgrade and sell sit in it side by side, each with its - price below, and each takes half of the bubble as tap area. the upgrade - price is the cost of the next level, dimmed when it cannot be afforded; at - level 5 upgrade is left out and sell takes the whole bubble. the sell - price is the refund. selling clears the selection; upgrading keeps it. - a tap anywhere outside the bubble closes it -- selling takes two taps. the first arms it: sell_button pulses by 15 % - every 0.5 s with a red glow. the second sells. a tap anywhere else, - another button or the map, cancels it; there is no timeout -- pausing clears the shop choice, the preview and the tower selection. - while paused, presses on the map do nothing and the shop is dimmed. the - top bar buttons, early start included, still work -- placement: a press on the map puts the preview at the nearest legal - position, and the preview follows the pointer until it is let go. only - the first pointer is followed. a press within the footprint radius or 28 - css pixels of the preview grabs it: let go after moving at most 10 css - pixels, it builds; a longer move drags it, keeping its offset to the - pointer. the shop choice is cleared after building, and a second tap on - the chosen shop button cancels it. a tap on a built tower selects it and - shows its range. a press that finds no legal position shows a red cross - for 0.5 s where the pointer is let go. shop buttons the player cannot - afford are dimmed and do nothing -- the preview is drawn at 45 % to 80 % opacity and 100 % to 108 % size. it - grows while the chosen shop item shows shop_bubble_dark and shrinks while - it shows shop_bubble_dark2. the range circle does not pulse -- flying coins: one sprite per coin, at most 8, started 0.05 s apart, flying - in game time on an arc. they are dropped when the map ends. early start - bonus coins start at the exits, taking turns on a map with several, within - the exit's radius -- top bar: coin_icon, heart and monster_icon with their counters. each - counter keeps the width of a usual largest value (3, 2 and 5 - characters), so the next one does not move. when the counters at those - widths and the buttons, early start included, do not fit side by side - (below about 800 css pixels), the buttons get a second row under the - counters, right-aligned as before. the buttons run help, pause, speed, - sound and early start from the right. pause shows pause_button - while the game runs and play_button while it is paused. speed shows the - drawing of the current speed. the early - start button shows the countdown on next_wave, without the bonus. the top - bar needs about 670 css pixels of width; narrower screens are not handled -- numbers: the digit variant of each place depends on the digit and its - place counted from the right, so the variants differ along a number but a - number keeps its look. top bar digits are 28 css pixels high, prices 18, - with coin_icon in front, as behind the amount it reads as an extra zero -- shop: items are 84 x 72 css pixels, drawn on shop_bubble. the chosen - item switches between shop_bubble_dark and shop_bubble_dark2 every 0.4 s -- death puffs: at the monster's centre, at sprite scale. they grow from 60 % - to full size over the first half of their time and fade out over the - second half. they are dropped when the map ends -- debug switches: all from architecture.md. start_coins -1 means the map's own value, seed 0 a new seed per - run. the debug tower ranges are drawn under the towers -- sound: the sound button over the splash screen's play button starts the - sound, or the play button when sound is switched off (sound.md); taps - before it leave sound off. later pointer and touch events resume audio - if the browser has suspended it. switching sound off mutes the output at - once and stops new sounds; the button tap is played after switching, so - it is heard when sound goes on. beeps use a square wave. variants are picked with Math.random, not the seeded - generator, so sound does not change a repeated run. a sound that cannot be - played at once (audio still locked) is dropped, not queued -- towers at scale 0.25 are small: t1 level 1 is about 43 x 30 map pixels. - worth a look with the hop and squash check of step 3 +- Playtesting, and fixes for the problems it finds +- Balance tweaks, in config/game.toml only (balancing.md) +- Restate the balance targets now that a boss that gets through loses the + map. HEARTS_TARGET in tools/balance.py and tools/simulate.js and the aim + in balancing.md date from when it cost 5 hearts +- The early start bonus is also paid before the first wave. Whether it + should be is undecided +- Screens too narrow for the counters and the buttons in two top bar rows + are not handled +- Optional: make the game installable to the home screen (web app + manifest, offline cache). This needs HTTPS +- Optional art (art.md) diff -r 0d40f346059c -r a464bd43b76c doc/sound.md --- a/doc/sound.md Tue Oct 20 19:54:56 2026 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -sound ------ - -events with a voice recording play the recording. the others play -placeholder beeps, generated in the browser (web audio oscillator, a few notes -each), until a recording arrives. - - -events ------- - -the event name is the name of its recordings and its entry in [sound.event] -in config/game.toml. - -| event | name | notes | -|----------------------|-------------------|-------| -| t0 attack | t0_attack | recorded, 4 variants | -| t1 shot | t1_shot | recorded, 6 variants | -| t2 shot | t2_shot | recorded, 4 variants | -| t3 shot | t3_shot | recorded, 7 variants | -| monster hit | monster_hit | frequent; keep short or play only some of them | -| monster enters map | monster_enter | recorded, 3 variants. every monster for now; to playtest | -| monster dies | monster_die | recorded, 4 variants | -| monster reaches exit | monster_exit | recorded. a heart is lost | -| boss appears | boss_enter | recorded | -| boss reaches exit | boss_exit | recorded | -| boss dies | boss_die | recorded | -| coins arrive | coins_arrive | at most one per short interval | -| wave starts | wave_start | | -| early start bonus | early_bonus | | -| tower built | tower_built | | -| tower upgraded | tower_upgraded | | -| tower sold | tower_sold | | -| placement refused | placement_refused | no legal spot within reach | -| button tap | button_tap | | -| map won | map_won | recorded | -| map lost | map_lost | recorded | -| splash screen music | intro | recorded, loops while the splash screen shows | - -several recordings per event are allowed; the game picks one at random. - -the map won sound waits until a boss or monster death sound still playing has -ended, and map lost waits for the last exit sound. the boss wave may not stay -the end of a map, so boss_die and map_won are separate sounds. - -per event, the config sets a volume, an optional least time between two -plays (plays in between are dropped) and the placeholder beep. - - -recordings ----------- - -- recorded on any device, supplied in any common format -- art/sound_sources/ holds the recordings as supplied, named after the event. - a recording may hold several variants with pauses between them -- tools/cut_sounds.py turns them into game sounds in art/sounds/. it is run - by hand after a recording changes, not by the build, because it needs - ffmpeg. it lists the number of variants per recording and splits those - recordings at their longest pauses, into NAME_1, NAME_2 and so on. it - trims silence, filters low rumble, fades the ends and brings every sound to - the same peak level. the output is mono mp3, which desktop browsers and - tablets (including safari) play -- the script can drop the start of a recording up to a set time, and add a - pause of silence after a sound that loops. intro loses its first 3 s, - which hold a burp before the music, and gets 0.3 s of silence at the end -- the build embeds art/sounds/ as base64 in www/data/sounds.js. see - architecture.md for why - -browsers only play sound after the first user interaction. on the first -splash screen after loading, a sound button covers the play button. it -pulses with a red glow, like an armed sell button. tapping it starts the -sound and the intro music, and uncovers the play button. when sound was -switched off in an earlier visit, there is no sound button: the play button -shows at once and starts the sound as before, and there is no music. - -the intro loops until the play button is tapped, then fades out over the -music_fade setting in [sound]. the splash screen that follows a won game -plays the intro at once, as sound is already running. - -the sound button in the top bar switches sound on and off. the choice is -stored in the browser (architecture.md, persistence). until the player first -uses it, the enabled setting in [sound] applies. diff -r 0d40f346059c -r a464bd43b76c game/index.html --- a/game/index.html Tue Oct 20 19:54:56 2026 +0200 +++ b/game/index.html Wed Oct 21 22:34:43 2026 +0200 @@ -3,7 +3,7 @@ -minor monsters +Minor Monsters diff -r 0d40f346059c -r a464bd43b76c game/js/game.js --- a/game/js/game.js Tue Oct 20 19:54:56 2026 +0200 +++ b/game/js/game.js Wed Oct 21 22:34:43 2026 +0200 @@ -151,7 +151,7 @@ m.alive = false; MM.audio.play(m.boss ? "boss_die" : "monster_die"); this.puffs.push({ x: m.x, y: m.y, boss: m.boss, t: 0 }); - // coins count at once; the flying coins only show it (balance.md) + // coins count at once; the flying coins only show it (game.md, coins) this.coins += m.coins; var n = Math.min(m.coins, cfg.coins.max_sprites); for (var i = 0; i < n; i++) { diff -r 0d40f346059c -r a464bd43b76c game/js/map.js --- a/game/js/map.js Tue Oct 20 19:54:56 2026 +0200 +++ b/game/js/map.js Wed Oct 21 22:34:43 2026 +0200 @@ -205,8 +205,7 @@ }); }; - // route weights for a monster of the given speed (balance.md, route - // preference) + // route weights for a monster of the given speed (game.md, routes) GameMap.prototype.routeWeights = function (speed) { var rp = cfg.route_preference; var f = MM.util.clamp((speed - rp.reference_speed) / rp.reference_speed, -1, 1); diff -r 0d40f346059c -r a464bd43b76c tools/balance.py --- a/tools/balance.py Tue Oct 20 19:54:56 2026 +0200 +++ b/tools/balance.py Wed Oct 21 22:34:43 2026 +0200 @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """ estimate, map by map and wave by wave, whether the coins a map pays buy -enough firepower (doc/balance.md, balancing). reads config/game.toml and the +enough firepower (doc/balancing.md). reads config/game.toml and the routes and placement grid of the last build, temp/build/maps.json. writes temp/preview/balance.txt and the charts temp/preview/balance_*.png. @@ -163,6 +163,8 @@ self.duration = (self.count - 1) * interval self.spacing = self.speed * interval self.tough = max(reg, key=lambda k: k[1]) + # heart cost of a regular monster and of the boss getting through + self.heart_cost = (cfg["hearts"]["monster"], cfg["hearts"]["boss"]) self.reg = reg def shots(self, damage): @@ -193,7 +195,7 @@ leak = max(0.0, wave.hp - cap) killed = 1 - leak / wave.hp out = {"leak": leak, "tough": tough, "boss": boss} - out["hearts"] = leak / (wave.hp / wave.count) + out["hearts"] = leak / (wave.hp / wave.count) * wave.heart_cost[0] out["coins"] = wave.coins * killed boss_ok = True if wave.boss: @@ -201,7 +203,7 @@ if boss_ok: out["coins"] += wave.boss[3] else: - out["hearts"] += 5 + out["hearts"] += wave.heart_cost[1] out["holds"] = leak < 1e-9 and boss_ok return out @@ -349,21 +351,11 @@ return waves -def draft_toml(cfg, m, waves): - """the drafted waves as toml lines, each wave with its count, hp and coins.""" - c = cfg["map"][str(m)] - mons = cfg["monster"] - lines = [f"# map{m}: drafted by tools/balance.py --draft from wave_count {c['wave_count']}," - f" wave_size {c['wave_size']},", - f"# monster_share {c['monster_share']}, first_wave {c['first_wave']}", ""] +def draft_toml(m, waves): + """the drafted waves as toml lines, each wave marked with its number.""" + lines = [f"# map{m} waves", ""] for w, wave in enumerate(waves, start=1): - reg = {k: v for k, v in wave.items() if not mons[k].get("boss")} - boss = [k for k in wave if mons[k].get("boss")] - hp = sum(v * mons[k]["hp"] for k, v in reg.items()) - coins = sum(v * mons[k]["coins"] for k, v in reg.items()) - extra = "".join(f" + boss {mons[k]['coins']}" for k in boss) - lines += [f"[[map.{m}.wave]] # wave {w}, {sum(reg.values())} monsters, {hp} hp," - f" {coins} coins{extra}", + lines += [f"[[map.{m}.wave]] # wave {w}", "monsters = { " + ", ".join(f"{k} = {v}" for k, v in wave.items()) + " }", ""] return lines @@ -420,7 +412,7 @@ waves = map_waves(cfg, m, f) n, g = play(naive, waves, start, bon, at), play(greedy, waves, start, bon, at) scan.append({"f": f, "naive": n, "greedy": g}) - out = {"m": m, "cov": cov, "bcov": bcov, "cells": cells, "routes": len(mc.routes), + out = {"m": m, "hearts": cfg["hearts"]["per_map"], "cov": cov, "bcov": bcov, "cells": cells, "routes": len(mc.routes), "lengths": mc.lengths, "spacing": spacing, "waves": waves1, "bonus": bon, "naive": play(naive, waves1, start, bon, at), "greedy": play(greedy, waves1, start, bon, at), "scan": scan, "coverage": {}} @@ -440,15 +432,15 @@ return sum(r["res"]["hearts"] for r in rows) -def factors_at_target(scan): +def factors_at_target(scan, per_map): """ the wave size factors at which naive ends with HEARTS_TARGET hearts or - fewer, as a list of (lowest, highest) ranges of neighbouring scan + fewer, of per_map, as a list of (lowest, highest) ranges of neighbouring scan points. larger waves also pay more coins, so there may be several. """ out = [] for i, s in enumerate(scan): - if hearts_lost(s["naive"]) < 10 - HEARTS_TARGET: + if hearts_lost(s["naive"]) < per_map - HEARTS_TARGET: continue if out and out[-1][2] == i - 1: out[-1] = (out[-1][0], s["f"], i) @@ -462,11 +454,14 @@ def value_table(cfg, towers): regular = sorted(k for k, v in cfg["monster"].items() if not v.get("boss")) lines = ["value per coin: hp killed per second per coin paid for the tower,", - "whole shots per monster. t0 counts one monster per attack.", ""] + "whole shots per monster. t0 counts one monster per attack. towers", + "that only slow are left out.", ""] head = f"{'tower':6}{'level':>6}{'damage':>8}{'range':>7}{'paid':>6}{'dps':>7}{'dps/coin':>10}" head += "".join(f"{'vs ' + k:>8}" for k in regular) lines.append(head) for tid, t in towers.items(): + if "damage" not in t: + continue paid = 0 for lv in range(len(t["damage"])): d, at = t["damage"][lv], t["attack_time"] @@ -539,8 +534,8 @@ "have to kill (throughput, median cell). single: damage the toughest", "monster takes from the naive towers while in range, against its hp.", "budget: coins on hand plus coins spent. need: coins of the purchases", - "that hold the wave. lost: hearts lost, leaks by throughput plus 5 for", - "a boss.", "", + "that hold the wave. lost: hearts lost, leaks by throughput plus the", + "boss's heart cost if it gets through.", "", f"{'wave':>4}{'count':>6}{'hp':>6}{'coins':>6}{'need/s':>8}{'single':>12}" f" naive{'budget':>8}{'need':>6}{'lost':>6} greedy{'budget':>8}{'need':>6}{'lost':>6}"] med = float(np.median(a["cov"])) @@ -556,7 +551,7 @@ f" {n['budget']:>8.0f}{need(n):>6}{n['res']['hearts']:>6.1f}" f" {g['budget']:>8.0f}{need(g):>6}{g['res']['hearts']:>6.1f}") one = next(s for s in a["scan"] if s["f"] == 1.0) - target = factors_at_target(a["scan"]) + target = factors_at_target(a["scan"], a["hearts"]) fmt = lambda v: "-" if v is None else f"{v:.0f}" lines += ["", f"wave size factor 1: naive loses {hearts_lost(one['naive']):.1f} hearts," f" surplus at the last wave {fmt(surplus(one['naive']))}; greedy loses {hearts_lost(one['greedy']):.1f}," @@ -614,9 +609,10 @@ style(ax, "hearts left at the end", "wave size factor", "hearts") ax.axhline(HEARTS_TARGET, color=INK2, linewidth=1, linestyle="--") ax.text(f[-1], HEARTS_TARGET + 0.2, "target, naive", color=INK2, fontsize=8, ha="right") - line(ax, f, [max(0, 10 - hearts_lost(s["naive"])) for s in a["scan"]], 1, "naive", markevery=10) - line(ax, f, [max(0, 10 - hearts_lost(s["greedy"])) for s in a["scan"]], 2, "greedy", markevery=10) - ax.set_ylim(-0.3, 10.5) + h = a["hearts"] + line(ax, f, [max(0, h - hearts_lost(s["naive"])) for s in a["scan"]], 1, "naive", markevery=10) + line(ax, f, [max(0, h - hearts_lost(s["greedy"])) for s in a["scan"]], 2, "greedy", markevery=10) + ax.set_ylim(-0.03 * h, 1.05 * h) legend(ax) fig.tight_layout() fig.savefig(path, dpi=110, facecolor=SURFACE) @@ -629,6 +625,8 @@ hp = cfg["monster"][mon]["hp"] style(ax, f"hp per second per coin against {mon} ({hp} hp)", "tower level", "hp/s per coin") for slot, (tid, t) in enumerate(towers.items()): + if "damage" not in t: + continue paid = np.cumsum(t["cost"]) v = [hp / (math.ceil(hp / d) * t["attack_time"]) / p for d, p in zip(t["damage"], paid)] line(ax, range(1, len(v) + 1), v, slot, tid) @@ -643,7 +641,7 @@ """print drafted wave lists as toml and what the calculation makes of them.""" for m in range(MAPS) if only is None else [only]: waves = draft_waves(cfg, m) - print("\n".join(draft_toml(cfg, m, waves))) + print("\n".join(draft_toml(m, waves))) for msg in draft_check(cfg, waves): print(f"# warning: {msg}") cfg["map"][str(m)]["wave"] = [{"monsters": w} for w in waves] diff -r 0d40f346059c -r a464bd43b76c tools/build.py --- a/tools/build.py Tue Oct 20 19:54:56 2026 +0200 +++ b/tools/build.py Wed Oct 21 22:34:43 2026 +0200 @@ -171,9 +171,9 @@ def route_values(routes): """ - fill in length, turning and value of each route (balance.md, route - preference): the average of length relative to the longest route and - straightness relative to the straightest, that is the least turning. + fill in length, turning and value of each route (doc/game.md, routes): + the average of length relative to the longest route and straightness + relative to the straightest, that is the least turning. """ for r in routes: r["length"] = masks.polyline_length(r["points"]) diff -r 0d40f346059c -r a464bd43b76c tools/cut_sounds.py --- a/tools/cut_sounds.py Tue Oct 20 19:54:56 2026 +0200 +++ b/tools/cut_sounds.py Wed Oct 21 22:34:43 2026 +0200 @@ -4,9 +4,9 @@ python3 tools/cut_sounds.py [NAME ...] without names, every recording is processed. a recording is named after its -game event (doc/sound.md). one with several variants, listed in VARIANTS, is -split into that many sounds, written as NAME_1.mp3, NAME_2.mp3 and so on; any -other recording becomes one sound, NAME.mp3. +game event (doc/art.md, sound). one with several variants, listed in +VARIANTS, is split into that many sounds, written as NAME_1.mp3, NAME_2.mp3 +and so on; any other recording becomes one sound, NAME.mp3. each sound is filtered against low rumble, trimmed to the voice with a short margin, faded in and out, brought to the same peak level and written as mono diff -r 0d40f346059c -r a464bd43b76c tools/get_version.sh --- a/tools/get_version.sh Tue Oct 20 19:54:56 2026 +0200 +++ b/tools/get_version.sh Wed Oct 21 22:34:43 2026 +0200 @@ -24,7 +24,7 @@ FORCE=1 ;; *) - echo "unrecognized option '$1'" + echo "unrecognised option '$1'" echo "$USAGE" exit 1 esac diff -r 0d40f346059c -r a464bd43b76c tools/make_dist.sh --- a/tools/make_dist.sh Tue Oct 20 19:54:56 2026 +0200 +++ b/tools/make_dist.sh Wed Oct 21 22:34:43 2026 +0200 @@ -19,7 +19,7 @@ -h|--help) echo "$USAGE"; exit 0 ;; --debug) DEBUG=1 ;; *) - echo "unrecognized option '$1'" >&2 + echo "unrecognised option '$1'" >&2 exit 1 ;; esac diff -r 0d40f346059c -r a464bd43b76c tools/simulate.js --- a/tools/simulate.js Tue Oct 20 19:54:56 2026 +0200 +++ b/tools/simulate.js Wed Oct 21 22:34:43 2026 +0200 @@ -1,8 +1,7 @@ #!/usr/bin/env node -// headless simulation of the game with scripted players (doc/balance.md, -// balancing). runs the game logic from www/ after a build: data/config.js, -// data/maps.js and the js/ files of the simulation, with MM.audio replaced -// by a stub. writes temp/preview/simulate.txt, the results as json in +// headless simulation of the game with scripted players (doc/balancing.md). +// runs the game logic from www/ after a build: data/config.js, data/maps.js +// and the js/ files of the simulation, with MM.audio replaced by a stub. writes temp/preview/simulate.txt, the results as json in // temp/preview/simulate.json (read by tools/balance.py), and prints a // summary. //