wobblyhead hg > minor_monsters
changeset 8:2c4fed8baed9
art update, persistent sound setting, tower selling as double action
line wrap: on
line diff
--- a/config/game.toml Mon Oct 19 11:50:24 2026 +0200 +++ b/config/game.toml Mon Oct 19 13:37:52 2026 +0200 @@ -79,6 +79,7 @@ stretch = 0.04 # guess, in the air idle_bob = 0.02 # guess hit_radius = 0.4 # proto, share of the monster sprite's smaller side +death_puff = 0.4 # guess, seconds the death puff shows [route_preference] @@ -162,7 +163,7 @@ [controls] -speeds = [1, 2] # guess +speeds = [1, 2, 4] # decided # sound events (doc/sound.md). the recordings come from art/sounds/, named @@ -171,7 +172,7 @@ # the placeholder for an event without a recording, as notes of [frequency in # Hz, seconds]. [sound] -enabled = true # proto, the game has no sound switch yet +enabled = true # proto, until the player switches sound on or off in the game volume = 0.8 # guess, all sounds beep_wave = "square" # proto @@ -231,6 +232,15 @@ t1_4 = [0.35, 0.5] t1_5 = [0.27, 0.5] +# 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] + # debug switches, all off by default [debug] @@ -243,7 +253,7 @@ show_grid = false show_ranges = false show_hit_areas = false -extra_speeds = [] # added to the game speeds, for example [4, 8] +extra_speeds = [] # added to the game speeds, for example [8] show_stats = false # frame time and entity counts seed = 0 # random seed, 0 picks a new one each run
--- a/doc/architecture.md Mon Oct 19 11:50:24 2026 +0200 +++ b/doc/architecture.md Mon Oct 19 13:37:52 2026 +0200 @@ -93,14 +93,17 @@ built-in toml reader) and pillow. numpy is optional, if the pure python image steps turn out too slow. -tools/cut_sheet.py and tools/cut_sounds.py are run by hand and write to art/. +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: -1. sprites: trim transparent edges, write to game/assets/. make the hp bar - variants: the empty part, and the blue bars for slowed monsters (art.md) +1. sprites: trim transparent edges, write to game/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 @@ -194,6 +197,7 @@ data/maps.js generated map data data/sounds.js generated sound data js/util.js vector maths, 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 js/map.js placement lookup, snapping, route sampling @@ -229,14 +233,17 @@ 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, pause and speed. the +- layout: top bar with coins, hearts, wave, countdown, sound, speed and + pause. the tower shop sits on the right in landscape and at the bottom in portrait - buttons are at least 48 css pixels for touch input: - pointer events cover mouse and touch alike -- nothing relies on hover; selection and confirmation are by tap +- 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 - the page blocks browser zoom and scroll gestures on the canvas placement: @@ -252,10 +259,10 @@ - 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 -- once the game has settings, such as sound on or off, js/storage.js wraps - localStorage, and one entry holds them +- 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; progress is then not saved + for example in private browsing; settings are then not kept - the entry carries a version number for later format changes
--- a/doc/art.md Mon Oct 19 11:50:24 2026 +0200 +++ b/doc/art.md Mon Oct 19 13:37:52 2026 +0200 @@ -11,10 +11,11 @@ p0-p3: projectiles for defense towers t0-t3: defense towers t*p: defense towers upgrade progression -source_sheet.jpg: the original drawing sheet with all sprites, maps, damage +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) -source_sheet_2.jpg: the same sheet with the sprite outlines inked in black, and +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 @@ -24,19 +25,21 @@ 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, needs to - be processed by a _cut script +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 -show_bubble_dark.png, shop_bubble_dark2.png: selected tower shop item bubble in +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 @@ -89,6 +92,13 @@ for pixel - masks: soft (anti-aliased) edges, colours are pure red, blue and green otherwise. 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 + 10, 11 and 12 on the sheet give single digits drawing direction @@ -133,43 +143,18 @@ art still needed ---------------- -the game uses icons instead of text. until the drawings are supplied, the game -draws simple placeholder shapes and uses a system font for numbers. - -icons for the top bar and buttons: +every icon and screen in the list above is in the game. not drawn yet: -- heart -- coin counter (could reuse c0) -- wave counter -- pause and play -- game speed 1x and 2x -- start next wave early -- upgrade -- sell -- cancel or close -- sound on and off -- next map, on the map won screen -- restart, on the map lost and game won screens - -screens (game_design.md): - -- splash: title "minor monsters", byline "By M.A. and J.A. Juszczyk", play - button. it is drawn over the paused first map -- map won -- game won, after the last map -- map lost - -numbers: - -- digits 0-9 for coins, hearts, wave, countdown and prices, in one consistent - size -- plus sign, for the early start bonus +- 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 optional: - t0 spike burst, if p0 alone does not read well as an attack -- hit and death puffs -- a frame or background for the tower shop +- 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
--- a/doc/balance.md Mon Oct 19 11:50:24 2026 +0200 +++ b/doc/balance.md Mon Oct 19 13:37:52 2026 +0200 @@ -68,6 +68,7 @@ - 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 route preference @@ -265,4 +266,4 @@ | parameter | value | source | |------------|--------|--------| -| game speeds | 1x, 2x | guess | +| game speeds | 1x, 2x, 4x | decided |
--- a/doc/game_design.md Mon Oct 19 11:50:24 2026 +0200 +++ b/doc/game_design.md Mon Oct 19 13:37:52 2026 +0200 @@ -133,13 +133,17 @@ - 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 placeholders until the drawings arrive (art.md) +- 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, with building, upgrading and selling allowed while paused -- game speed 1x and 2x (suggestion) +- game speed 1x, 2x and 4x (decided) +- sound on and off, kept in the browser - input via pointer events, so mouse and touch work the same. no part of the game depends on mouse hover
--- a/doc/roadmap.md Mon Oct 19 11:50:24 2026 +0200 +++ b/doc/roadmap.md Mon Oct 19 13:37:52 2026 +0200 @@ -63,12 +63,21 @@ - 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 source_sheet_2.jpg into art/. it +- 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 @@ -123,8 +132,8 @@ game: -- scripts share the namespace object MM. storage.js is not written until - there are settings to store (architecture.md, persistence) +- 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 @@ -133,10 +142,14 @@ debug.start_coins applies to every map. the splash screen pauses the first map without counting the pause for the sell refund, and only its play button responds. the next map starts with its break running, as - does the first map after a lost map. the screens use placeholders: a - pale veil with the title and byline in the system font, a play - triangle, one star for a won map and three for the game, a broken heart - for a lost map, an arrow for next and a circular arrow for restart + 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 - a break starts when all monsters of the wave are gone, killed or escaped, not when the last one has spawned. during a break the wave counter shows the next wave @@ -160,11 +173,16 @@ 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 -- tower menu: tapping a built tower shows an upgrade and a sell button above - it, or below it when there is no room above, kept inside the map. the - upgrade button shows the cost of the next level and is dimmed when it - cannot be afforded; at level 5 it is left out. the sell button shows the - refund. selling clears the selection; upgrading keeps it +- 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 +- 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 - the pause refund counts pauses: each purchase records the pause it was made in. a purchase made during the current pause is refunded in full - placement: a tap within the footprint radius or 28 css pixels of the @@ -174,17 +192,29 @@ the player cannot afford are dimmed and do nothing - 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 -- placeholder icons: c0 for coins, m0 for waves, a drawn heart, one triangle - per game speed step (digits for debug speeds), a skip icon with countdown - and bonus for the early start. the top bar needs about 500 css pixels of - width; narrower screens are not handled +- 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. pause shows pause_button + while the game runs and play_button while it is paused. speed shows the + drawing of the current speed; debug speeds show their number. 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 - sound: the play button on the splash screen starts the sound; taps before it leave sound off. later pointer and touch events resume audio - if the browser has suspended it. sound is switched off only in the - config. beeps - use a square wave. variants are picked with Math.random, not the seeded + 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.
--- a/doc/sound.md Mon Oct 19 11:50:24 2026 +0200 +++ b/doc/sound.md Mon Oct 19 13:37:52 2026 +0200 @@ -65,6 +65,6 @@ browsers only play sound after the first user interaction. the play button on the splash screen starts the sound. -sound can be switched off. for now the switch is the enabled setting in -[sound]; the game has no button for it yet. once it has one, the setting is -stored in the browser (architecture.md, persistence). +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.
--- a/game/data/config.js Mon Oct 19 11:50:24 2026 +0200 +++ b/game/data/config.js Mon Oct 19 13:37:52 2026 +0200 @@ -64,7 +64,8 @@ "squash": 0.06, "stretch": 0.04, "idle_bob": 0.02, - "hit_radius": 0.4 + "hit_radius": 0.4, + "death_puff": 0.4 }, "route_preference": { "reference_speed": 40, @@ -193,7 +194,8 @@ "controls": { "speeds": [ 1, - 2 + 2, + 4 ] }, "sound": { @@ -399,6 +401,24 @@ 0.27, 0.5 ] + }, + "screen": { + "splash": [ + 479, + 463 + ], + "map_won": [ + 210, + 225 + ], + "game_lost": [ + 172, + 230 + ], + "game_won": [ + 373, + 383 + ] } }, "debug": { @@ -1534,6 +1554,10 @@ 135, 175 ], + "boss_death": [ + 242, + 196 + ], "c0": [ 41, 40 @@ -1550,6 +1574,182 @@ 42, 53 ], + "coin_icon": [ + 81, + 86 + ], + "digit_0_1": [ + 69, + 72 + ], + "digit_0_2": [ + 58, + 71 + ], + "digit_0_3": [ + 66, + 73 + ], + "digit_1_1": [ + 55, + 73 + ], + "digit_1_2": [ + 50, + 73 + ], + "digit_1_3": [ + 27, + 71 + ], + "digit_1_4": [ + 54, + 72 + ], + "digit_1_5": [ + 59, + 73 + ], + "digit_1_6": [ + 72, + 75 + ], + "digit_1_7": [ + 62, + 75 + ], + "digit_1_8": [ + 59, + 74 + ], + "digit_2_1": [ + 69, + 74 + ], + "digit_2_2": [ + 77, + 73 + ], + "digit_2_3": [ + 89, + 72 + ], + "digit_2_4": [ + 94, + 72 + ], + "digit_3_1": [ + 41, + 68 + ], + "digit_3_2": [ + 61, + 71 + ], + "digit_3_3": [ + 60, + 73 + ], + "digit_4_1": [ + 77, + 74 + ], + "digit_4_2": [ + 78, + 72 + ], + "digit_4_3": [ + 81, + 73 + ], + "digit_5_1": [ + 50, + 72 + ], + "digit_5_2": [ + 52, + 72 + ], + "digit_5_3": [ + 53, + 72 + ], + "digit_6_1": [ + 42, + 72 + ], + "digit_6_2": [ + 49, + 73 + ], + "digit_6_3": [ + 39, + 72 + ], + "digit_6_4": [ + 39, + 72 + ], + "digit_7_1": [ + 52, + 72 + ], + "digit_7_2": [ + 63, + 72 + ], + "digit_7_3": [ + 57, + 71 + ], + "digit_8_1": [ + 37, + 72 + ], + "digit_8_2": [ + 45, + 72 + ], + "digit_8_3": [ + 44, + 72 + ], + "digit_9_1": [ + 47, + 72 + ], + "digit_9_2": [ + 47, + 68 + ], + "digit_9_3": [ + 53, + 69 + ], + "digit_slash_1": [ + 39, + 71 + ], + "game_lost": [ + 510, + 403 + ], + "game_lost_button": [ + 161, + 129 + ], + "game_won": [ + 973, + 762 + ], + "game_won_button": [ + 369, + 348 + ], + "heart": [ + 77, + 100 + ], "hpb": [ 252, 41 @@ -1602,6 +1802,26 @@ 108, 109 ], + "map_won": [ + 611, + 444 + ], + "map_won_button": [ + 242, + 166 + ], + "monster_death": [ + 194, + 157 + ], + "monster_icon": [ + 80, + 95 + ], + "next_wave": [ + 440, + 200 + ], "p0": [ 35, 90 @@ -1618,6 +1838,58 @@ 62, 62 ], + "pause_button": [ + 118, + 133 + ], + "play_button": [ + 124, + 140 + ], + "sell_button": [ + 73, + 61 + ], + "shop_bubble": [ + 276, + 226 + ], + "shop_bubble_dark": [ + 269, + 206 + ], + "shop_bubble_dark2": [ + 257, + 226 + ], + "sound_off": [ + 172, + 158 + ], + "sound_on": [ + 172, + 168 + ], + "speed_x1": [ + 117, + 148 + ], + "speed_x2": [ + 118, + 135 + ], + "speed_x4": [ + 119, + 129 + ], + "splash": [ + 1175, + 650 + ], + "splash_play": [ + 184, + 164 + ], "t0": [ 143, 140 @@ -1697,6 +1969,14 @@ "t3_5": [ 206, 222 + ], + "tower_popup": [ + 339, + 288 + ], + "upgrade_button": [ + 94, + 85 ] } };
--- a/game/index.html Mon Oct 19 11:50:24 2026 +0200 +++ b/game/index.html Mon Oct 19 13:37:52 2026 +0200 @@ -13,6 +13,7 @@ <script src="data/maps.js"></script> <script src="data/sounds.js"></script> <script src="js/util.js"></script> +<script src="js/storage.js"></script> <script src="js/assets.js"></script> <script src="js/audio.js"></script> <script src="js/map.js"></script>
--- a/game/js/audio.js Mon Oct 19 11:50:24 2026 +0200 +++ b/game/js/audio.js Mon Oct 19 13:37:52 2026 +0200 @@ -1,5 +1,6 @@ // sound: recorded sounds from data/sounds.js, placeholder beeps for events -// without a recording +// without a recording. the player's sound on or off choice is stored with +// MM.storage; the config's enabled setting applies until the first choice. window.MM = window.MM || {}; @@ -12,15 +13,16 @@ var last = {}; // event -> audio clock time of its last play var ends = {}; // event -> audio clock time when its sounds have ended var started = false; + var on = MM.storage.get("sound", cfg.enabled); // create the audio context and decode the recordings. the browser keeps // the context suspended until unlock() runs in a user interaction. function init() { var AC = window.AudioContext || window.webkitAudioContext; - if (!AC || !cfg.enabled) return; + if (!AC) return; ctx = new AC(); master = ctx.createGain(); - master.gain.value = cfg.volume; + master.gain.value = on ? cfg.volume : 0; master.connect(ctx.destination); var sounds = MM.sounds || {}; Object.keys(sounds).forEach(function (name) { @@ -80,7 +82,7 @@ // variants are picked with Math.random, so sound does not change the // game's seeded random numbers. function play(name, after) { - if (!ctx || ctx.state !== "running") return; + if (!on || !ctx || ctx.state !== "running") return; var ev = cfg.event[name]; if (!ev) return; var now = ctx.currentTime; @@ -108,5 +110,17 @@ ends[name] = Math.max(ends[name] || 0, when + length); } - return { init: init, start: start, unlock: unlock, play: play }; + function enabled() { + return on; + } + + // switch sound on or off and store the choice. sounds already playing + // are muted at once. + function toggle() { + on = !on; + if (master) master.gain.value = on ? cfg.volume : 0; + MM.storage.set("sound", on); + } + + return { init: init, start: start, unlock: unlock, play: play, enabled: enabled, toggle: toggle }; })();
--- a/game/js/game.js Mon Oct 19 11:50:24 2026 +0200 +++ b/game/js/game.js Mon Oct 19 13:37:52 2026 +0200 @@ -21,6 +21,7 @@ this.towers = []; this.projectiles = []; this.flights = []; // coins flying to the counter + this.puffs = []; // death puffs, {x, y, boss, t} this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1)); this.time = 0; this.paused = false; @@ -33,6 +34,7 @@ this.shop = null; this.preview = null; this.selected = null; + this.sellArmed = false; // sell was tapped once and waits for the second tap } Game.prototype.speed = function () { @@ -79,6 +81,8 @@ this.monsters = this.monsters.filter(function (m) { return m.alive; }); this.projectiles = this.projectiles.filter(function (p) { return !p.done; }); this.flights.forEach(function (f) { f.t += dt; }); + this.puffs.forEach(function (p) { p.t += dt; }); + this.puffs = this.puffs.filter(function (p) { return p.t < cfg.animation.death_puff; }); var flying = this.flights.length; this.flights = this.flights.filter(function (f) { return f.t < cfg.coins.flight_time; }); if (this.flights.length < flying) MM.audio.play("coins_arrive"); @@ -92,7 +96,10 @@ MM.audio.play("map_won", ["monster_die", "boss_die"]); } // the simulation stops here; the coins in flight are counted already - if (this.result) this.flights = []; + if (this.result) { + this.flights = []; + this.puffs = []; + } }; // a monster reached the exit @@ -113,6 +120,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) this.coins += m.coins; var n = Math.min(m.coins, cfg.coins.max_sprites); @@ -153,6 +161,7 @@ // was found for a preview. Game.prototype.tapMap = function (x, y, hitRadius) { var t = this.towerAt(x, y); + this.sellArmed = false; if (t && !(this.preview && Math.hypot(this.preview.x - x, this.preview.y - y) <= hitRadius)) { this.shop = null; this.preview = null; @@ -200,9 +209,15 @@ MM.audio.play("tower_upgraded"); }; + // the first tap arms selling, the second sells Game.prototype.sell = function () { var t = this.selected; if (!t) return; + if (!this.sellArmed) { + this.sellArmed = true; + return; + } + this.sellArmed = false; this.coins += MM.tower.refund(t, this.pauseNumber()); this.towers.splice(this.towers.indexOf(t), 1); this.selected = null;
--- a/game/js/input.js Mon Oct 19 11:50:24 2026 +0200 +++ b/game/js/input.js Mon Oct 19 13:37:52 2026 +0200 @@ -1,4 +1,5 @@ -// pointer events: mouse and touch alike, nothing relies on hover +// pointer events: mouse and touch alike. hover only highlights the screen +// buttons and sets the cursor; nothing relies on it window.MM = window.MM || {}; @@ -19,6 +20,19 @@ var r = c.getBoundingClientRect(); tap(app, e.clientX - r.left, e.clientY - r.top); }); + // mouse only: the position for the hover highlight, and the pointer + // cursor over buttons + c.addEventListener("pointermove", function (e) { + if (e.pointerType !== "mouse" || !app.game()) return; + var r = c.getBoundingClientRect(); + var h = { x: e.clientX - r.left, y: e.clientY - r.top }; + app.view.hover = h; + c.style.cursor = MM.ui.hit(app.game(), app.layout(), h.x, h.y) ? "pointer" : ""; + }); + c.addEventListener("pointerleave", function () { + app.view.hover = null; + c.style.cursor = ""; + }); // browsers count only some events as a user interaction that may // start sound: pointerdown for the mouse, pointerup and touchend // for touch @@ -35,9 +49,13 @@ var game = app.game(), L = app.layout(); var b = MM.ui.hit(game, L, x, y); if (b) { - // the play button starts the sound + // the play button starts the sound. switching sound on or off + // comes first, so the tap is heard when it goes on if (b.id === "play") MM.audio.start(); + if (b.id === "sound") MM.audio.toggle(); MM.audio.play("button_tap"); + // any other button cancels an armed sell + if (b.id !== "sell") game.sellArmed = false; if (b.id === "play") app.play(); else if (b.id === "next") app.next(); else if (b.id === "retry") app.retry();
--- a/game/js/main.js Mon Oct 19 11:50:24 2026 +0200 +++ b/game/js/main.js Mon Oct 19 13:37:52 2026 +0200 @@ -15,7 +15,7 @@ var ctx = canvas.getContext("2d"); var game = null; var L = null; - var view = { dpr: 1, now: 0, refused: null, stats: { ms: 0 } }; + var view = { dpr: 1, now: 0, refused: null, hover: null, stats: { ms: 0 } }; // the first map is the debug start map; only it starts at the debug // start wave
--- a/game/js/render.js Mon Oct 19 11:50:24 2026 +0200 +++ b/game/js/render.js Mon Oct 19 13:37:52 2026 +0200 @@ -108,6 +108,17 @@ } } + // death puff: grows from 60 % to full size, and fades out over the second + // half of its time + function drawPuff(ctx, p) { + var u = p.t / cfg.animation.death_puff; + var k = MM.util.lerp(0.6, 1, MM.util.easeOut(Math.min(1, u * 2))); + var name = p.boss ? "boss_death" : "monster_death"; + ctx.globalAlpha = u < 0.5 ? 1 : 2 - 2 * u; + A.draw(ctx, name, p.x, p.y, cfg.scale.sprite, null, k, k); + ctx.globalAlpha = 1; + } + // draw the map area. L is the layout from ui.js, view holds the canvas // pixel ratio, wall clock and tap feedback. function draw(ctx, game, L, view) { @@ -136,6 +147,7 @@ game.monsters.slice().sort(function (a, b) { return a.y - b.y; }) .forEach(function (m) { drawMonster(ctx, m, game.time); }); + game.puffs.forEach(function (p) { drawPuff(ctx, p); }); if (dbg.show_hit_areas) { game.monsters.forEach(function (m) { circle(ctx, m.x, m.y, m.hitRadius, null, "rgba(255, 0, 0, 0.8)", 1 / s);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/game/js/storage.js Mon Oct 19 13:37:52 2026 +0200 @@ -0,0 +1,38 @@ +// settings kept in the browser (architecture.md, persistence). one +// localStorage entry holds all of them, with a format version. every access +// is wrapped, so the game still runs when storage is unavailable, for +// example in private browsing; settings are then not kept. + +window.MM = window.MM || {}; + +MM.storage = (function () { + "use strict"; + + var KEY = "minor_monsters"; + var VERSION = 1; + var settings = {}; + + // an entry of another version is ignored and replaced on the next set() + try { + var entry = JSON.parse(window.localStorage.getItem(KEY)); + if (entry && entry.version === VERSION && entry.settings) settings = entry.settings; + } catch (e) { + settings = {}; + } + + // the stored value of a setting, or fallback when it was never set + function get(name, fallback) { + return Object.prototype.hasOwnProperty.call(settings, name) ? settings[name] : fallback; + } + + function set(name, value) { + settings[name] = value; + try { + window.localStorage.setItem(KEY, JSON.stringify({ version: VERSION, settings: settings })); + } catch (e) { + // storage unavailable or full: the setting holds until a reload + } + } + + return { get: get, set: set }; +})();
--- a/game/js/ui.js Mon Oct 19 11:50:24 2026 +0200 +++ b/game/js/ui.js Mon Oct 19 13:37:52 2026 +0200 @@ -1,5 +1,6 @@ -// screen layout, top bar, tower shop, tower menu, splash and end screens. icons are placeholder -// shapes until the drawings arrive (art.md); numbers use a system font. +// screen layout, top bar, tower shop, tower menu, splash and end screens, +// drawn from the supplied icons and drawings (art.md). numbers use the +// hand-drawn digits. window.MM = window.MM || {}; @@ -11,12 +12,46 @@ var TOP = 60; // top bar height, css pixels var SHOP = 96; // shop width (landscape) or height (portrait) var BUTTON = 52; // top bar buttons, at least 48 for touch - var SHOP_BUTTON = 80; - var MENU_BUTTON = 64; // upgrade and sell, next to the selected tower + var SHOP_W = 84; // shop items + var SHOP_H = 72; + var POPUP_W = 168; // tower menu bubble; its height follows the drawing + var DIGIT = 28; // digit height in the top bar + var PRICE = 18; // digit height of prices + var DIGIT_GAP = 0.08; // space between digits, a share of their height + var BUBBLE_FLIP = 400; // ms between the two drawings of the chosen shop item + var PULSE = 1.2; // seconds of one pulse of a screen button + var WARN_PULSE = 0.5; // seconds of one pulse of an armed sell button var INK = "#3a3530"; var PAPER = "#f6f1e6"; var FONT = "bold 22px system-ui, -apple-system, Segoe UI, sans-serif"; var TOWERS = ["t0", "t1", "t2", "t3"]; + // each screen drawing, its separate button image and the button's action + var SCREENS = { + splash: { image: "splash_play", id: "play" }, + map_won: { image: "map_won_button", id: "next" }, + game_lost: { image: "game_lost_button", id: "retry" }, + game_won: { image: "game_won_button", id: "restart" } + }; + + // digit variants from the sprite table: character -> sprite names + var DIGITS = {}; + Object.keys(cfg.sprites).forEach(function (n) { + var m = /^digit_(\d|slash)_\d+$/.exec(n); + if (!m) return; + var ch = m[1] === "slash" ? "/" : m[1]; + (DIGITS[ch] = DIGITS[ch] || []).push(n); + }); + + // all screens share one scale, set by the largest drawing, so they keep + // the sizes of the drawings relative to each other + function screenScale(w, h) { + var mw = 0, mh = 0; + Object.keys(SCREENS).forEach(function (n) { + mw = Math.max(mw, cfg.sprites[n][0]); + mh = Math.max(mh, cfg.sprites[n][1]); + }); + return Math.min(1, 0.92 * w / mw, 0.9 * h / mh); + } // positions of everything on screen for a window of w x h css pixels function layout(w, h, map) { @@ -30,71 +65,98 @@ oy: area.y + (area.h - map.height * scale) / 2, shop: land ? { x: w - SHOP, y: TOP, w: SHOP, h: h - TOP } : { x: 0, y: h - SHOP, w: w, h: SHOP }, - coinIcon: { x: 26, y: TOP / 2, size: 28 } + coinIcon: { x: 24, y: TOP / 2, size: 32 }, + screen: screenScale(w, h) }; return L; } - // upgrade and sell buttons above the selected tower, or below it when - // there is no room above, kept inside the map area. no upgrade button - // at the top level. + // the screen shown over the map, or null during play + function screenName(game) { + if (game.splash) return "splash"; + if (game.result === "lost") return "game_lost"; + if (game.result) return game.lastMap() ? "game_won" : "map_won"; + return null; + } + + // the drawing of a screen centred in the window, and its button + function screenRects(name, L) { + var k = L.screen, s = cfg.sprites[name]; + var bs = cfg.sprites[SCREENS[name].image], at = cfg.art.screen[name]; + var p = { x: (L.w - s[0] * k) / 2, y: (L.h - s[1] * k) / 2, w: s[0] * k, h: s[1] * k }; + return { panel: p, button: { x: p.x + at[0] * k, y: p.y + at[1] * k, w: bs[0] * k, h: bs[1] * k } }; + } + + // the tower menu: a bubble above the selected tower, or below it when + // there is no room above, kept inside the map area. upgrade and sell each + // take half of the bubble; at the top level there is no upgrade and sell + // takes all of it. cx is where the button's drawing is centred. function towerMenu(game, L) { - var t = game.selected, a = L.area, gap = 8, out = []; + var t = game.selected, a = L.area, gap = 8; + var s = cfg.sprites.tower_popup, w = POPUP_W, h = POPUP_W * s[1] / s[0]; var x = L.ox + t.x * L.scale, y = L.oy + t.y * L.scale; var half = A.size(MM.tower.sprite(t), cfg.scale.sprite)[1] / 2 * L.scale + gap; - var w = 2 * MENU_BUTTON + gap; - var top = y - half - MENU_BUTTON; + var top = y - half - h; if (top < a.y + gap) top = y + half; var left = MM.util.clamp(x - w / 2, a.x + gap, a.x + a.w - w - gap); - if (MM.tower.upgradeCost(t)) { - out.push({ id: "upgrade", x: left, y: top, w: MENU_BUTTON, h: MENU_BUTTON }); + var bubble = { x: left, y: top, w: w, h: h }; + if (!MM.tower.upgradeCost(t)) { + return [{ id: "sell", x: left, y: top, w: w, h: h, cx: left + w / 2, bubble: bubble }]; } - out.push({ id: "sell", x: left + MENU_BUTTON + gap, y: top, w: MENU_BUTTON, h: MENU_BUTTON }); - return out; + return [ + { id: "upgrade", x: left, y: top, w: w / 2, h: h, cx: left + w * 0.34, bubble: bubble }, + { id: "sell", x: left + w / 2, y: top, w: w / 2, h: h, cx: left + w * 0.66, bubble: bubble } + ]; } // the buttons for the current state, each {id, x, y, w, h} function buttons(game, L) { var out = []; - var y = (TOP - BUTTON) / 2; - if (game.splash) { - out.push({ id: "play", x: L.w / 2 - 56, y: L.h / 2 + 10, w: 112, h: 112 }); - return out; - } - // map lost: back to the first map. map won: on to the next map, or - // after the last map back to the splash screen - if (game.result) { - var id = game.result === "lost" ? "retry" : game.lastMap() ? "restart" : "next"; - out.push({ id: id, x: L.w / 2 - 48, y: L.h / 2 + 50, w: 96, h: 96 }); + var name = screenName(game); + if (name) { + var b = screenRects(name, L).button; + b.id = SCREENS[name].id; + b.screen = name; + out.push(b); return out; } - out.push({ id: "pause", x: L.w - BUTTON - 8, y: y, w: BUTTON, h: BUTTON }); - out.push({ id: "speed", x: L.w - 2 * BUTTON - 16, y: y, w: BUTTON, h: BUTTON }); + // top bar, right to left + var y = (TOP - BUTTON) / 2, x = L.w - 8; + ["pause", "speed", "sound"].forEach(function (id) { + x -= BUTTON; + out.push({ id: id, x: x, y: y, w: BUTTON, h: BUTTON }); + x -= 8; + }); if (game.waves.phase === "break") { - out.push({ id: "early", x: L.w - 2 * BUTTON - 150, y: y, w: 126, h: BUTTON }); + var s = cfg.sprites.next_wave, w = BUTTON * s[0] / s[1]; + out.push({ id: "early", x: x - w, y: y, w: w, h: BUTTON }); } TOWERS.forEach(function (t, i) { - var pos = 10 + i * (SHOP_BUTTON + 10); - var b = L.land ? { x: L.shop.x + (SHOP - SHOP_BUTTON) / 2, y: L.shop.y + pos } - : { x: L.shop.x + pos, y: L.shop.y + (SHOP - SHOP_BUTTON) / 2 }; + var b = L.land ? { x: L.shop.x + (SHOP - SHOP_W) / 2, y: L.shop.y + 10 + i * (SHOP_H + 10) } + : { x: L.shop.x + 10 + i * (SHOP_W + 10), y: L.shop.y + (SHOP - SHOP_H) / 2 }; b.id = "shop"; b.tower = t; - b.w = b.h = SHOP_BUTTON; + b.w = SHOP_W; + b.h = SHOP_H; out.push(b); }); if (game.selected) out = out.concat(towerMenu(game, L)); return out; } + function inside(b, x, y) { + return x >= b.x && x < b.x + b.w && y >= b.y && y < b.y + b.h; + } + function hit(game, L, x, y) { var list = buttons(game, L); for (var i = 0; i < list.length; i++) { - var b = list[i]; - if (x >= b.x && x < b.x + b.w && y >= b.y && y < b.y + b.h) return b; + if (inside(list[i], x, y)) return list[i]; } return null; } + // system font text, for the debug stats only function text(ctx, s, x, y, align, size) { ctx.font = size ? FONT.replace("22px", size + "px") : FONT; ctx.textAlign = align || "left"; @@ -106,102 +168,52 @@ ctx.fillText(s, x, y); } - // a sprite fitted into a box of size s, centred on x, y - function icon(ctx, name, x, y, s) { - var img = A.img(name); - var k = s / Math.max(img.naturalWidth, img.naturalHeight); - var w = img.naturalWidth * k, h = img.naturalHeight * k; - ctx.drawImage(img, x - w / 2, y - h / 2, w, h); - } - - function heart(ctx, x, y, s, fill) { - ctx.beginPath(); - ctx.moveTo(x, y + s * 0.4); - ctx.bezierCurveTo(x - s * 0.6, y, x - s * 0.5, y - s * 0.5, x, y - s * 0.2); - ctx.bezierCurveTo(x + s * 0.5, y - s * 0.5, x + s * 0.6, y, x, y + s * 0.4); - ctx.fillStyle = fill; - ctx.fill(); - ctx.lineWidth = 2; - ctx.strokeStyle = INK; - ctx.stroke(); + // a sprite fitted into a box of w x h centred on x, y, keeping its shape + function fit(ctx, name, x, y, w, h) { + var s = cfg.sprites[name], k = Math.min(w / s[0], h / s[1]); + ctx.drawImage(A.img(name), x - s[0] * k / 2, y - s[1] * k / 2, s[0] * k, s[1] * k); } - function triangle(ctx, x, y, s) { - ctx.beginPath(); - ctx.moveTo(x - s * 0.35, y - s * 0.45); - ctx.lineTo(x + s * 0.45, y); - ctx.lineTo(x - s * 0.35, y + s * 0.45); - ctx.closePath(); - ctx.fill(); - } - - function star(ctx, x, y, r) { - ctx.beginPath(); - for (var i = 0; i < 10; i++) { - var a = -Math.PI / 2 + i * Math.PI / 5, rr = i % 2 ? r * 0.45 : r; - ctx.lineTo(x + Math.cos(a) * rr, y + Math.sin(a) * rr); + // the digit sprites for string s. the variant of each digit depends on + // the digit and its place counted from the right, so a number keeps its + // look while other places change. + function glyphs(s) { + var out = []; + for (var i = 0; i < s.length; i++) { + var list = DIGITS[s[i]]; + if (!list) continue; + var place = s.length - 1 - i; + out.push(list[(place * 5 + s.charCodeAt(i)) % list.length]); } - ctx.closePath(); - ctx.fillStyle = "#f2c230"; - ctx.fill(); - ctx.lineWidth = 3; - ctx.strokeStyle = INK; - ctx.stroke(); + return out; } - function restartIcon(ctx, x, y, r) { - ctx.lineWidth = 7; - ctx.strokeStyle = INK; - ctx.beginPath(); - ctx.arc(x, y, r, -Math.PI * 0.35, Math.PI * 1.45); - ctx.stroke(); - var a = -Math.PI * 0.35, tx = x + Math.cos(a) * r, ty = y + Math.sin(a) * r; - ctx.fillStyle = INK; - ctx.beginPath(); - ctx.moveTo(tx + 12, ty - 4); - ctx.lineTo(tx - 8, ty - 12); - ctx.lineTo(tx - 2, ty + 10); - ctx.closePath(); - ctx.fill(); - } - - function arrowRight(ctx, x, y, s) { - ctx.save(); - ctx.translate(x, y); - ctx.rotate(Math.PI / 2); - arrowUp(ctx, 0, 0, s); - ctx.restore(); + function numberWidth(s, h) { + var g = glyphs(s), w = 0; + g.forEach(function (n) { w += cfg.sprites[n][0] * h / cfg.sprites[n][1]; }); + return w + Math.max(0, g.length - 1) * h * DIGIT_GAP; } - function arrowUp(ctx, x, y, s) { - ctx.beginPath(); - ctx.moveTo(x, y - s * 0.5); - ctx.lineTo(x + s * 0.45, y); - ctx.lineTo(x + s * 0.17, y); - ctx.lineTo(x + s * 0.17, y + s * 0.5); - ctx.lineTo(x - s * 0.17, y + s * 0.5); - ctx.lineTo(x - s * 0.17, y); - ctx.lineTo(x - s * 0.45, y); - ctx.closePath(); - ctx.fill(); + // number s in digits of height h, vertically centred on y. align is + // "left", "center" or "right" of x. + function number(ctx, s, x, y, h, align) { + s = String(s); + var w = numberWidth(s, h); + if (align === "center") x -= w / 2; + else if (align === "right") x -= w; + glyphs(s).forEach(function (n) { + var gw = cfg.sprites[n][0] * h / cfg.sprites[n][1]; + ctx.drawImage(A.img(n), x, y - h / 2, gw, h); + x += gw + h * DIGIT_GAP; + }); } - function cross(ctx, x, y, s) { - ctx.lineWidth = 6; - ctx.lineCap = "round"; - ctx.beginPath(); - ctx.moveTo(x - s / 2, y - s / 2); - ctx.lineTo(x + s / 2, y + s / 2); - ctx.moveTo(x + s / 2, y - s / 2); - ctx.lineTo(x - s / 2, y + s / 2); - ctx.stroke(); - ctx.lineCap = "butt"; - } - - // a coin and an amount along the bottom of button b - function price(ctx, b, s) { - icon(ctx, "c0", b.x + 16, b.y + b.h - 13, 16); - text(ctx, s, b.x + 27, b.y + b.h - 12, "left", 18); + // a price, the coin icon followed by the amount, centred on x, y + function price(ctx, amount, x, y) { + var s = String(amount), coin = PRICE * 0.8, gap = 3; + var left = x - (coin + gap + numberWidth(s, PRICE)) / 2; + fit(ctx, "coin_icon", left + coin / 2, y, coin, coin); + number(ctx, s, left + coin + gap, y, PRICE, "left"); } function box(ctx, b, fill, line) { @@ -215,69 +227,76 @@ ctx.stroke(); } - function drawButton(ctx, game, b) { + // a screen's button image over the same button in the drawing. it pulses + // slowly as a cue to tap; under the mouse it is drawn larger, lifted by + // a shadow. + function screenButton(ctx, b, view) { var cx = b.x + b.w / 2, cy = b.y + b.h / 2; - if (b.id === "pause") { - box(ctx, b, game.paused ? "#ffe9a8" : PAPER); - ctx.fillStyle = INK; - if (game.paused) { - triangle(ctx, cx, cy, 26); - } else { - ctx.fillRect(cx - 10, cy - 12, 7, 24); - ctx.fillRect(cx + 3, cy - 12, 7, 24); - } + var hover = view.hover && inside(b, view.hover.x, view.hover.y); + var k = hover ? 1.08 : 1 + 0.04 * (0.5 - 0.5 * Math.cos(2 * Math.PI * view.now / 1000 / PULSE)); + var w = b.w * k, h = b.h * k; + ctx.save(); + if (hover) { + ctx.shadowColor = "rgba(0, 0, 0, 0.35)"; + ctx.shadowBlur = 12; + ctx.shadowOffsetY = 3; + } + ctx.drawImage(A.img(SCREENS[b.screen].image), cx - w / 2, cy - h / 2, w, h); + ctx.restore(); + } + + function drawButton(ctx, game, b, view) { + var cx = b.x + b.w / 2, cy = b.y + b.h / 2; + if (b.screen) { + screenButton(ctx, b, view); + } else if (b.id === "pause") { + // shows what a tap does: pause while running, play while paused + fit(ctx, game.paused ? "play_button" : "pause_button", cx, cy, b.w, b.h); } else if (b.id === "speed") { - // one triangle per speed step; numbers for the debug speeds - var sp = game.speed(); - box(ctx, b, sp > 1 ? "#ffe9a8" : PAPER); - ctx.fillStyle = INK; - if (sp <= 3) { - for (var i = 0; i < sp; i++) triangle(ctx, cx + (i - (sp - 1) / 2) * 12, cy, 20); + // debug speeds have no drawing and show their number + var sp = game.speed(), name = "speed_x" + sp; + if (cfg.sprites[name]) { + fit(ctx, name, cx, cy, b.w, b.h); } else { - text(ctx, sp + "", cx, cy, "center"); + box(ctx, b, PAPER); + number(ctx, sp, cx, cy, DIGIT, "center"); } + } else if (b.id === "sound") { + fit(ctx, MM.audio.enabled() ? "sound_on" : "sound_off", cx, cy, b.w, b.h); } else if (b.id === "early") { - box(ctx, b, PAPER); - ctx.fillStyle = INK; - triangle(ctx, b.x + 20, cy, 22); - ctx.fillRect(b.x + 29, cy - 10, 4, 20); - text(ctx, Math.ceil(game.waves.left) + "", b.x + 58, cy, "center"); - var bonus = game.waves.bonus(); - if (bonus > 0) text(ctx, "+" + bonus, b.x + b.w - 6, cy, "right", 18); + // the countdown fills the empty right part of the drawing + ctx.drawImage(A.img("next_wave"), b.x, b.y, b.w, b.h); + number(ctx, Math.ceil(game.waves.left), b.x + b.w * 0.66, cy, DIGIT, "center"); } else if (b.id === "shop") { var def = cfg.tower[b.tower]; - var ok = game.canAfford(def.cost); - box(ctx, b, game.shop === b.tower ? "#ffe9a8" : PAPER, - game.shop === b.tower ? "#c08000" : INK); - ctx.globalAlpha = ok ? 1 : 0.35; - icon(ctx, b.tower, cx, b.y + 30, 46); - icon(ctx, "c0", b.x + 22, b.y + b.h - 14, 16); - text(ctx, def.cost + "", b.x + 34, b.y + b.h - 13, "left", 18); + // the chosen item's bubble switches between its two drawings + var bubble = game.shop !== b.tower ? "shop_bubble" + : Math.floor(view.now / BUBBLE_FLIP) % 2 ? "shop_bubble_dark2" : "shop_bubble_dark"; + ctx.drawImage(A.img(bubble), b.x, b.y, b.w, b.h); + ctx.globalAlpha = game.canAfford(def.cost) ? 1 : 0.35; + fit(ctx, b.tower, cx, b.y + 28, 44, 38); + price(ctx, def.cost, cx, b.y + b.h - 15); ctx.globalAlpha = 1; } else if (b.id === "upgrade") { var cost = MM.tower.upgradeCost(game.selected); - box(ctx, b, PAPER); ctx.globalAlpha = game.canAfford(cost) ? 1 : 0.35; - ctx.fillStyle = INK; - arrowUp(ctx, cx, b.y + 22, 28); - price(ctx, b, cost + ""); + fit(ctx, "upgrade_button", b.cx, b.bubble.y + b.bubble.h * 0.4, 46, 44); + price(ctx, cost, b.cx, b.bubble.y + b.bubble.h * 0.7); ctx.globalAlpha = 1; } else if (b.id === "sell") { - box(ctx, b, PAPER); - ctx.strokeStyle = "#c03030"; - cross(ctx, cx, b.y + 22, 20); - price(ctx, b, "+" + MM.tower.refund(game.selected, game.pauseNumber())); - } else if (b.id === "play") { - box(ctx, b, PAPER); - ctx.fillStyle = INK; - triangle(ctx, cx + 4, cy, 60); - } else if (b.id === "next") { - box(ctx, b, PAPER); - ctx.fillStyle = INK; - arrowRight(ctx, cx, cy, 52); - } else if (b.id === "retry" || b.id === "restart") { - box(ctx, b, PAPER); - restartIcon(ctx, cx, cy, 26); + // armed by a first tap: a fast pulse with a red glow until the + // second tap sells + var k = 1; + ctx.save(); + if (game.sellArmed) { + k = 1 + 0.15 * (0.5 - 0.5 * Math.cos(2 * Math.PI * view.now / 1000 / WARN_PULSE)); + ctx.shadowColor = "rgba(220, 30, 20, 0.9)"; + ctx.shadowBlur = 14; + } + fit(ctx, "sell_button", b.cx, b.bubble.y + b.bubble.h * 0.4, 46 * k, 44 * k); + ctx.restore(); + price(ctx, MM.tower.refund(game.selected, game.pauseNumber()), b.cx, + b.bubble.y + b.bubble.h * 0.7); } } @@ -292,49 +311,34 @@ ctx.fillRect(L.shop.x, L.shop.y, L.shop.w, L.shop.h); ctx.fillStyle = "rgba(58, 53, 48, 0.25)"; ctx.fillRect(0, TOP - 2, L.w, 2); - icon(ctx, "c0", L.coinIcon.x, L.coinIcon.y, L.coinIcon.size); - text(ctx, game.coins + "", 46, TOP / 2); - heart(ctx, 126, TOP / 2 + 2, 30, "#e03a3a"); - text(ctx, game.hearts + "", 146, TOP / 2); - icon(ctx, "m0", 206, TOP / 2, 30); - text(ctx, game.waves.shown() + "/" + game.waves.list.length, 226, TOP / 2); + // each counter takes at least the width of its widest usual value, so + // the next one does not move while the numbers change + var ic = L.coinIcon, x = ic.x - ic.size / 2; + [["coin_icon", game.coins, "000"], ["heart", game.hearts, "00"], + ["monster_icon", game.waves.shown() + "/" + game.waves.list.length, "00/00"] + ].forEach(function (c) { + var s = String(c[1]); + fit(ctx, c[0], x + ic.size / 2, TOP / 2, ic.size, ic.size); + number(ctx, s, x + ic.size + 6, TOP / 2, DIGIT, "left"); + x += ic.size + 6 + Math.max(numberWidth(s, DIGIT), numberWidth(c[2], DIGIT)) + 18; + }); - var screen = game.splash || game.result; - if (!screen) buttons(game, L).forEach(function (b) { drawButton(ctx, game, b); }); - + var screen = screenName(game); + var list = buttons(game, L); if (game.paused && !screen) { ctx.fillStyle = "rgba(255, 255, 255, 0.18)"; ctx.fillRect(L.ox, L.oy, game.map.width * L.scale, game.map.height * L.scale); } - if (game.splash) { - // title and byline, placeholders until the drawings arrive - ctx.fillStyle = "rgba(246, 241, 230, 0.55)"; - ctx.fillRect(0, 0, L.w, L.h); - text(ctx, "minor monsters", L.w / 2, L.h / 2 - 90, "center", 60); - text(ctx, "By M.A. and J.A. Juszczyk", L.w / 2, L.h / 2 - 38, "center", 24); - } else if (game.result) { - ctx.fillStyle = "rgba(40, 35, 30, 0.45)"; + if (screen) { + ctx.fillStyle = game.splash ? "rgba(246, 241, 230, 0.55)" : "rgba(40, 35, 30, 0.45)"; ctx.fillRect(0, 0, L.w, L.h); - if (game.result === "won" && game.lastMap()) { - // game won: three stars - star(ctx, L.w / 2 - 125, L.h / 2 - 15, 50); - star(ctx, L.w / 2 + 125, L.h / 2 - 15, 50); - star(ctx, L.w / 2, L.h / 2 - 45, 70); - } else if (game.result === "won") { - star(ctx, L.w / 2, L.h / 2 - 40, 70); - } else { - heart(ctx, L.w / 2, L.h / 2 - 30, 140, "#8a8a8a"); - ctx.strokeStyle = INK; - ctx.lineWidth = 5; - ctx.beginPath(); - ctx.moveTo(L.w / 2 - 6, L.h / 2 - 72); - ctx.lineTo(L.w / 2 + 10, L.h / 2 - 40); - ctx.lineTo(L.w / 2 - 10, L.h / 2 - 20); - ctx.lineTo(L.w / 2 + 4, L.h / 2 + 22); - ctx.stroke(); - } + var p = screenRects(screen, L).panel; + ctx.drawImage(A.img(screen), p.x, p.y, p.w, p.h); + } else if (game.selected) { + var bub = list[list.length - 1].bubble; + ctx.drawImage(A.img("tower_popup"), bub.x, bub.y, bub.w, bub.h); } - if (screen) buttons(game, L).forEach(function (b) { drawButton(ctx, game, b); }); + list.forEach(function (b) { drawButton(ctx, game, b, view); }); if (cfg.debug.show_stats && view.stats) { var st = view.stats;
--- a/tools/build.py Mon Oct 19 11:50:24 2026 +0200 +++ b/tools/build.py Mon Oct 19 13:37:52 2026 +0200 @@ -8,7 +8,7 @@ a step is skipped when all its outputs are newer than its inputs and the build scripts; --force runs every step. --watch reruns the build whenever a file -in art/, art/sounds/ or config/ changes. +in art/, art/sounds/, art/digits/ or config/ changes. requires python 3.11 or later and pillow. """ @@ -34,6 +34,7 @@ ROOT = Path(__file__).resolve().parent.parent ART = ROOT / "art" SOUNDS = ART / "sounds" +DIGITS = ART / "digits" CONFIG = ROOT / "config" ASSETS = ROOT / "game" / "assets" DATA = ROOT / "game" / "data" @@ -47,7 +48,14 @@ SPRITES = (["m%d" % i for i in range(5)] + ["b%d" % i for i in range(4)] + ["t%d" % i for i in range(4)] + ["p%d" % i for i in range(4)] - + ["c%d" % i for i in range(4)] + ["hpm", "hpb"]) + + ["c%d" % i for i in range(4)] + ["hpm", "hpb"] + # icons, buttons and screens (art.md) + + ["coin_icon", "heart", "monster_icon", "play_button", "pause_button", + "speed_x1", "speed_x2", "speed_x4", "sound_on", "sound_off", "next_wave", + "shop_bubble", "shop_bubble_dark", "shop_bubble_dark2", "tower_popup", + "upgrade_button", "sell_button", "monster_death", "boss_death", + "splash", "splash_play", "map_won", "map_won_button", + "game_lost", "game_lost_button", "game_won", "game_won_button"]) # hp bar variants (art.md): the empty part is a darkened copy, the bar of a # slowed monster has its colour set to this hue in degrees BAR_DARKEN = 0.35 @@ -90,12 +98,19 @@ # 1. sprites def step_sprites(force): - inputs = [ART / f"{n}.png" for n in SPRITES] - outputs = [ASSETS / f"{n}.png" for n in SPRITES + BAR_VARIANTS] + # digits cut by tools/cut_digits.py, written as digit_NAME_N + digits = sorted(DIGITS.glob("*.png")) + inputs = [ART / f"{n}.png" for n in SPRITES] + digits + [DIGITS] + outputs = ([ASSETS / f"{n}.png" for n in SPRITES + BAR_VARIANTS] + + [ASSETS / f"digit_{p.name}" for p in digits]) if not stale(inputs, outputs, force): print("sprites: up to date") return False ASSETS.mkdir(parents=True, exist_ok=True) + for p in ASSETS.glob("digit_*.png"): + p.unlink() + for p in digits: + images.trim(Image.open(p).convert("RGBA")).save(ASSETS / f"digit_{p.name}", optimize=True) for n in SPRITES: im = images.trim(Image.open(ART / f"{n}.png").convert("RGBA")) im.save(ASSETS / f"{n}.png", optimize=True) @@ -104,7 +119,8 @@ images.darken(im, BAR_DARKEN).save(ASSETS / f"{n}_empty.png", optimize=True) slow.save(ASSETS / f"{n}_slow.png", optimize=True) images.darken(slow, BAR_DARKEN).save(ASSETS / f"{n}_slow_empty.png", optimize=True) - print(f"sprites: wrote {len(SPRITES)} sprites and {len(BAR_VARIANTS)} bar variants") + print(f"sprites: wrote {len(SPRITES)} sprites, {len(BAR_VARIANTS)} bar variants" + f" and {len(digits)} digits") return True @@ -492,7 +508,8 @@ def watch(): def snapshot(): - files = list(ART.iterdir()) + list(SOUNDS.glob("*.mp3")) + list(CONFIG.iterdir()) + TOOLS + files = (list(ART.iterdir()) + list(SOUNDS.glob("*.mp3")) + list(DIGITS.glob("*.png")) + + list(CONFIG.iterdir()) + TOOLS) return {p: p.stat().st_mtime for p in files if p.is_file()} seen = None
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/cut_digits.py Mon Oct 19 13:37:52 2026 +0200 @@ -0,0 +1,110 @@ +""" +cut the digits out of art/digits.png and write them to art/digits/. + + python3 tools/cut_digits.py + +every connected stroke on the sheet is one character. the strokes are sorted +into the sheet's rows by their centre, and left to right within a row; the +characters of each row are listed below. a character drawn more than once +gives one variant per drawing, written as NAME_1.png, NAME_2.png and so on. +NAME is the digit, or "slash". + +all characters are scaled to the same height, the median height of the +drawings, so a number reads evenly whichever variants it uses. the paper +becomes transparent. +""" + +import statistics +from pathlib import Path + +from PIL import Image, ImageDraw + +ART = Path(__file__).resolve().parent.parent / "art" +SRC = ART / "digits.png" +OUT = ART / "digits" + +# ink is darker than this luminance +INK_LUM = 150 +# pixels fade from opaque at INK_LUM to transparent at this luminance +LUM_CLEAR = 245 +# smaller strokes are specks +MIN_PIXELS = 30 +# padding around each character, so the fade is not cut off +PAD = 3 + +# rows of the sheet, top to bottom: the lowest stroke centre of the row, and +# its characters left to right +ROWS = [ + (100, "0"), + (215, "987654321"), + (345, "0123456789"), + (492, "1/6123456789101112"), +] +NAMES = {"/": "slash"} + + +def strokes(lum): + """bounding boxes of the connected ink strokes of an L image.""" + ink = lum.point(lambda v: 255 if v < INK_LUM else 0) + w, h = ink.size + px = ink.load() + out = [] + for y in range(h): + for x in range(w): + if px[x, y] != 255: + continue + ImageDraw.floodfill(ink, (x, y), 100) + part = ink.point(lambda v: 255 if v == 100 else 0) + box = part.getbbox() + count = part.histogram()[255] + ImageDraw.floodfill(ink, (x, y), 50) + px = ink.load() + if count >= MIN_PIXELS: + out.append(box) + return out + + +def by_row(boxes): + """the boxes as one list per row of ROWS, left to right.""" + rows = [[] for _ in ROWS] + for box in boxes: + cy = (box[1] + box[3]) / 2 + row = next(i for i, (bottom, _) in enumerate(ROWS) if cy < bottom) + rows[row].append(box) + return [sorted(r) for r in rows] + + +def cut(sheet, lum, box, height): + """one character, faded out from the paper and scaled to height.""" + l, t, r, b = box + box = (max(0, l - PAD), max(0, t - PAD), min(sheet.width, r + PAD), min(sheet.height, b + PAD)) + alpha = lum.crop(box).point( + lambda v: max(0, min(255, (LUM_CLEAR - v) * 255 // (LUM_CLEAR - INK_LUM)))) + im = sheet.crop(box).convert("RGBA") + im.putalpha(alpha) + k = height / (b - t) + return im.resize((max(1, round(im.width * k)), max(1, round(im.height * k))), Image.LANCZOS) + + +def main(): + sheet = Image.open(SRC).convert("RGB") + lum = sheet.convert("L") + rows = by_row(strokes(lum)) + for (_, chars), boxes in zip(ROWS, rows): + if len(chars) != len(boxes): + raise SystemExit(f"row {chars}: found {len(boxes)} strokes, expected {len(chars)}") + height = statistics.median(b[3] - b[1] for r in rows for b in r) + OUT.mkdir(exist_ok=True) + for p in OUT.glob("*.png"): + p.unlink() + counts = {} + for (_, chars), boxes in zip(ROWS, rows): + for ch, box in zip(chars, boxes): + name = NAMES.get(ch, ch) + counts[name] = counts.get(name, 0) + 1 + cut(sheet, lum, box, height).save(OUT / f"{name}_{counts[name]}.png") + print(f"height {height}: " + ", ".join(f"{k} {v}" for k, v in sorted(counts.items()))) + + +if __name__ == "__main__": + main()
--- a/tools/cut_sheet.py Mon Oct 19 11:50:24 2026 +0200 +++ b/tools/cut_sheet.py Mon Oct 19 13:37:52 2026 +0200 @@ -1,7 +1,7 @@ """ cut the sprites out of a scanned drawing sheet and write them to art/. - python3 tools/cut_sheet.py art/source_sheet_2.jpg + python3 tools/cut_sheet.py art/art_sources/source_sheet_2.jpg the boxes below are set by hand for source_sheet_2.jpg, in sheet pixels, at the sheet's own scale. each box holds one drawing with an inked outline. the
