# HG changeset patch # User ark # Date 1792364729 -7200 # Node ID 910b26feca760049ffdfd192c9d4f34c978124ed # Parent 67bf3c505145d61d9196204c2b7f1ca76bf775cd full game flow diff -r 67bf3c505145 -r 910b26feca76 config/game.toml --- a/config/game.toml Sun Oct 18 22:50:24 2026 +0200 +++ b/config/game.toml Mon Oct 19 01:05:29 2026 +0200 @@ -95,7 +95,7 @@ [tower.t0] damage = [5, 10, 15, 20, 25] # notes cost = 5 # notes -range = [45, 48, 51, 54, 57] # guess +range = [60, 63, 66, 69, 72] # level 1: decided (was 45), rest: guess attack_time = 1.5 # guess, slower than the others (decided) projectile = "p0" projectile_speed = 0 # notes (melee) @@ -127,7 +127,7 @@ projectile_speed = 800 # guess [tower_rules] -sell_refund = 0.5 # decided, half of the last purchase, rounded down +sell_refund = 0.5 # decided, half of everything paid for the tower, rounded down [placement] @@ -191,6 +191,8 @@ wave_start = { volume = 0.4, beep = [[440, 0.1], [660, 0.15]] } # guess early_bonus = { volume = 0.4, beep = [[880, 0.06], [1175, 0.06], [1760, 0.1]] } # guess tower_built = { volume = 0.4, beep = [[330, 0.05], [494, 0.08]] } # guess +tower_upgraded = { volume = 0.4, beep = [[392, 0.05], [587, 0.05], [784, 0.08]] } # guess +tower_sold = { volume = 0.4, beep = [[494, 0.05], [330, 0.08]] } # guess placement_refused = { volume = 0.4, beep = [[220, 0.12], [165, 0.18]] } # guess button_tap = { volume = 0.3, beep = [[1000, 0.02]] } # guess map_won = { volume = 1.0 } # guess diff -r 67bf3c505145 -r 910b26feca76 doc/architecture.md --- a/doc/architecture.md Sun Oct 18 22:50:24 2026 +0200 +++ b/doc/architecture.md Mon Oct 19 01:05:29 2026 +0200 @@ -61,6 +61,30 @@ 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/game/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. +this taps the play button on the splash screen at 1024 x 768: + + ff_screenshot -w 1024,768 -s 2 -S 3 -J 'document.getElementById("game") + .dispatchEvent(new PointerEvent("pointerdown", + {clientX: 512, clientY: 444, bubbles: true}))' \ + file://$PWD/game/index.html temp/play.png + +`ff_screenshot -h` lists the other options. + + build ----- @@ -75,7 +99,8 @@ steps: -1. sprites: trim transparent edges, write to game/assets/ +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) 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 @@ -150,8 +175,8 @@ debug switches, all off by default: - start coins override, unlimited coins -- start at a given map and wave -- unlock all maps +- 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 - higher game speeds @@ -171,7 +196,6 @@ js/util.js vector maths, random numbers, easing js/assets.js image loading, sprite table js/audio.js recorded sounds, placeholder beeps for the other events - js/storage.js localStorage wrapper 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 @@ -225,7 +249,11 @@ persistence: -- one localStorage entry holds unlocked maps and settings (sound on or off) +- 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 - all access is wrapped so the game still runs when storage is unavailable, for example in private browsing; progress is then not saved - the entry carries a version number for later format changes diff -r 67bf3c505145 -r 910b26feca76 doc/art.md --- a/doc/art.md Sun Oct 18 22:50:24 2026 +0200 +++ b/doc/art.md Mon Oct 19 01:05:29 2026 +0200 @@ -94,6 +94,11 @@ 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. + art still needed ---------------- @@ -113,15 +118,15 @@ - sell - cancel or close - sound on and off -- restart map -- back to map selection +- next map, on the map won screen +- restart, on the map lost and game won screens -screens: +screens (game_design.md): -- title, "minor monsters" -- map selection; small copies of the maps can serve as buttons -- locked map +- 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: @@ -134,7 +139,6 @@ - t0 spike burst, if p0 alone does not read well as an attack - hit and death puffs -- a mark on slowed monsters - a frame or background for the tower shop drawing tips for these: dark outline, white or coloured inside, on white diff -r 67bf3c505145 -r 910b26feca76 doc/balance.md --- a/doc/balance.md Sun Oct 18 22:50:24 2026 +0200 +++ b/doc/balance.md Mon Oct 19 01:05:29 2026 +0200 @@ -106,7 +106,7 @@ | tower | damage by level | cost | range by level | attack every | projectile speed | source | |-------|------------------|------|---------------------|--------------|------------------|--------| -| t0 | 5,10,15,20,25 | 5 | 45,48,51,54,57 | 1.5 s | none (melee) | damage, cost: notes; rest: guess | +| 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,7,13,17,23 | 10 | 100,104,108,112,116 | 0.7 s | 300 | as above | | t2 | 1,3,5,7,9 | 20 | 90,94,98,102,106 | 1.2 s | 220 | damage 1-4, cost: notes; rest: guess | | t3 | 1,5,7,10,13 | 25 | 220,230,240,250,260 | 1.3 s | 800 | damage 1-4: notes; cost: decided (was 40), may go lower; rest: guess | @@ -133,15 +133,16 @@ | t2 | 20 | 40 | 60 | 80 | 100 | 300 | | t3 | 25 | 50 | 75 | 100 | 125 | 375 | -selling refunds half of the last purchase, rounded down (decided). this is -low for upgraded towers: a level 5 t1 cost 150 in total and sells for 25. +selling refunds half of everything paid for the tower, build and upgrades, +rounded down (decided). a tower is sold whole. purchases made during the +current pause are refunded in full instead (see game_design.md). | tower | level 1 | level 2 | level 3 | level 4 | level 5 | |-------|---------|---------|---------|---------|---------| -| t0 | 2 | 5 | 7 | 10 | 12 | -| t1 | 5 | 10 | 15 | 20 | 25 | -| t2 | 10 | 20 | 30 | 40 | 50 | -| t3 | 12 | 25 | 37 | 50 | 62 | +| 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): diff -r 67bf3c505145 -r 910b26feca76 doc/game_design.md --- a/doc/game_design.md Sun Oct 18 22:50:24 2026 +0200 +++ b/doc/game_design.md Mon Oct 19 01:05:29 2026 +0200 @@ -19,8 +19,13 @@ *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. finishing a map unlocks the next one -- progress is stored in the browser (localStorage): unlocked maps and settings +- 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 @@ -45,6 +50,7 @@ cost 10 - t2 shoots projectile p2, turns, slows down monsters slower than t1 + a slowed monster's hp bar turns blue damage: 1,3,5,7 cost 20 - t3 is long range sniper tower, turns, shoots p3 @@ -71,11 +77,13 @@ the first upgrade (to level 2) costs twice the base cost - 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 the cost of its last purchase (the build, or - the last upgrade) - exception: a tower built and removed during the same pause, never used, - is refunded in full. the same applies to an upgrade bought and undone - during the same pause +- 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 + exception: purchases made during the current pause are refunded in full. + a tower built and sold during the same pause, never used, costs nothing. + an upgrade bought during a pause comes back in full if the tower is sold + before the game resumes; the rest of the tower sells at half monsters -------- @@ -90,7 +98,7 @@ - bosses are map-specific, b0 belongs to map0 etc; boss hp 30/50/70/100 coin drop equal to hp - hp bars are always shown above every monster. the boss uses its own bar, also - above the boss + 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 @@ -111,9 +119,22 @@ - 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 can be restarted +- 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. the play button + also starts the sound +- 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 placeholders until the drawings arrive (art.md) + controls -------- diff -r 67bf3c505145 -r 910b26feca76 doc/roadmap.md --- a/doc/roadmap.md Sun Oct 18 22:50:24 2026 +0200 +++ b/doc/roadmap.md Mon Oct 19 01:05:29 2026 +0200 @@ -25,10 +25,14 @@ damage, hp bars, coin drops and flying coins - first playable version of map0 6. tower details - - upgrades, selling with the pause refund rule, t0 melee and spike sides, - t2 slow, boss with its bar + - upgrades, selling the whole tower with the pause refund rule, t0 melee + and spike sides, t2 slow with the blue hp bar, boss with its bar 7. game flow - - title and map selection, unlocking, localStorage, restart + - 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 - wave lists for maps 1-3, playtesting, balance changes in config only 9. supplied art and sound @@ -44,7 +48,7 @@ prototype notes --------------- -decisions taken while building steps 1-5 that the other documents do not +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: @@ -66,7 +70,9 @@ 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 - the empty part of the hp bars is a darkened copy made by the build - (hpm_empty, hpb_empty) + (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 count when at least half opaque, and take the class of their @@ -117,12 +123,20 @@ game: -- scripts share the namespace object MM. storage.js is not written yet +- scripts share the namespace object MM. storage.js is not written until + there are settings to store (architecture.md, persistence) - 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 -- there is no title or map selection yet. the game starts on - debug.start_map. the won and lost screens offer a restart only +- 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 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 - 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 @@ -136,10 +150,23 @@ radius. a new tower attacks at once - turning towers face their target at once and keep the last direction when idle -- t0's melee attack is in place, since without it t0 does nothing. it draws - spikes on all four sides and pushes them out for 0.3 s. spike sides, t2 - slow, upgrades, selling and the boss bar are left for step 6; the boss uses - hpm for now +- 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 +- 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 +- 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 preview builds. 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 @@ -151,11 +178,12 @@ 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 -- debug switches: all from architecture.md except unlocking maps, which waits - for step 7. start_coins -1 means the map's own value, seed 0 a new seed per +- debug switches: all from architecture.md. start_coins -1 means the map's own value, seed 0 a new seed per run -- sound: the first pointer or touch event anywhere unlocks audio, as there - is no title screen yet. sound is switched off only in the config. beeps +- 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 generator, so sound does not change a repeated run. a sound that cannot be played at once (audio still locked) is dropped, not queued diff -r 67bf3c505145 -r 910b26feca76 doc/sound.md --- a/doc/sound.md Sun Oct 18 22:50:24 2026 +0200 +++ b/doc/sound.md Mon Oct 19 01:05:29 2026 +0200 @@ -29,8 +29,8 @@ | wave starts | wave_start | | | early start bonus | early_bonus | | | tower built | tower_built | | -| tower upgraded | tower_upgraded | not in the game yet | -| tower sold | tower_sold | not in the game yet | +| 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 | @@ -62,9 +62,9 @@ - the build embeds art/sounds/ as base64 in game/data/sounds.js. see architecture.md for why -browsers only play sound after the first user interaction. for now that is -the first tap anywhere on the game; later the first tap on the title screen. +browsers only play sound after the first user interaction. the play button on +the splash screen starts the sound. -sound can be switched off; the setting is stored with the other settings. for -now the switch is the enabled setting in [sound]; the game has no button for -it yet. +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). diff -r 67bf3c505145 -r 910b26feca76 game/assets/hpb_slow.png Binary file game/assets/hpb_slow.png has changed diff -r 67bf3c505145 -r 910b26feca76 game/assets/hpb_slow_empty.png Binary file game/assets/hpb_slow_empty.png has changed diff -r 67bf3c505145 -r 910b26feca76 game/assets/hpm_slow.png Binary file game/assets/hpm_slow.png has changed diff -r 67bf3c505145 -r 910b26feca76 game/assets/hpm_slow_empty.png Binary file game/assets/hpm_slow_empty.png has changed diff -r 67bf3c505145 -r 910b26feca76 game/data/config.js --- a/game/data/config.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/data/config.js Mon Oct 19 01:05:29 2026 +0200 @@ -82,11 +82,11 @@ ], "cost": 5, "range": [ - 45, - 48, - 51, - 54, - 57 + 60, + 63, + 66, + 69, + 72 ], "attack_time": 1.5, "projectile": "p0", @@ -298,6 +298,36 @@ ] ] }, + "tower_upgraded": { + "volume": 0.4, + "beep": [ + [ + 392, + 0.05 + ], + [ + 587, + 0.05 + ], + [ + 784, + 0.08 + ] + ] + }, + "tower_sold": { + "volume": 0.4, + "beep": [ + [ + 494, + 0.05 + ], + [ + 330, + 0.08 + ] + ] + }, "placement_refused": { "volume": 0.4, "beep": [ @@ -1528,6 +1558,14 @@ 252, 41 ], + "hpb_slow": [ + 252, + 41 + ], + "hpb_slow_empty": [ + 252, + 41 + ], "hpm": [ 127, 40 @@ -1536,6 +1574,14 @@ 127, 40 ], + "hpm_slow": [ + 127, + 40 + ], + "hpm_slow_empty": [ + 127, + 40 + ], "m0": [ 134, 118 diff -r 67bf3c505145 -r 910b26feca76 game/js/audio.js --- a/game/js/audio.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/audio.js Mon Oct 19 01:05:29 2026 +0200 @@ -11,6 +11,7 @@ var buffers = {}; // event -> decoded recordings var last = {}; // event -> audio clock time of its last play var ends = {}; // event -> audio clock time when its sounds have ended + var started = false; // create the audio context and decode the recordings. the browser keeps // the context suspended until unlock() runs in a user interaction. @@ -37,9 +38,16 @@ function () { console.error("sound not decoded:", name); }); } - // call from a pointer or touch handler: browsers start sound only there + // call from the play button's handler. sound stays off until then. + function start() { + started = true; + unlock(); + } + + // call from a pointer or touch handler: browsers start sound only there. + // does nothing before start(). function unlock() { - if (!ctx || ctx.state === "running") return; + if (!ctx || !started || ctx.state === "running") return; ctx.resume(); // older safari also needs a sound started in the handler var src = ctx.createBufferSource(); @@ -100,5 +108,5 @@ ends[name] = Math.max(ends[name] || 0, when + length); } - return { init: init, unlock: unlock, play: play }; + return { init: init, start: start, unlock: unlock, play: play }; })(); diff -r 67bf3c505145 -r 910b26feca76 game/js/game.js --- a/game/js/game.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/game.js Mon Oct 19 01:05:29 2026 +0200 @@ -1,4 +1,5 @@ -// game state and rules: coins, hearts, building, win and loss +// game state and rules: coins, hearts, building, upgrading, selling, win +// and loss window.MM = window.MM || {}; @@ -8,7 +9,8 @@ var cfg = MM.config; var dbg = cfg.debug; - function Game(mapIndex, seed) { + // firstWave counts from 1 + function Game(mapIndex, seed, firstWave) { var mc = cfg.maps[mapIndex]; this.map = new MM.GameMap(mapIndex); this.seed = seed; @@ -19,12 +21,14 @@ this.towers = []; this.projectiles = []; this.flights = []; // coins flying to the counter - this.waves = new MM.Waves(mapIndex, MM.util.clamp(dbg.start_wave - 1, 0, mc.waves.length - 1)); + this.waves = new MM.Waves(mapIndex, MM.util.clamp(firstWave - 1, 0, mc.waves.length - 1)); this.time = 0; this.paused = false; + this.pauses = 0; // number of pauses so far, for the sell refund this.speeds = cfg.controls.speeds.concat(dbg.extra_speeds); this.speedIndex = 0; this.result = null; // "won" or "lost" + this.splash = false; // splash screen shown over the paused map // player selection: shop tower type, its snapped preview, a built tower this.shop = null; this.preview = null; @@ -35,6 +39,20 @@ return this.speeds[this.speedIndex]; }; + Game.prototype.lastMap = function () { + return this.map.index === MM.maps.length - 1; + }; + + Game.prototype.togglePause = function () { + this.paused = !this.paused; + if (this.paused) this.pauses++; + }; + + // number of the current pause, 0 while the game runs + Game.prototype.pauseNumber = function () { + return this.paused ? this.pauses : 0; + }; + Game.prototype.canAfford = function (cost) { return dbg.unlimited_coins || this.coins >= cost; }; @@ -147,19 +165,49 @@ return this.build(); } this.preview = this.map.snap(x, y, this.towers); - return this.preview !== null; + if (!this.preview) return false; + // t0 draws spikes only towards the path, judged by its top level range + var def = cfg.tower[this.shop]; + if (def.projectile_speed === 0) { + this.preview.sides = this.map.facingSides(this.preview.x, this.preview.y, + def.range[def.range.length - 1]); + } + return true; }; Game.prototype.build = function () { var cost = cfg.tower[this.shop].cost; if (!this.canAfford(cost)) return false; this.pay(cost); - this.towers.push(MM.tower.create(this.shop, this.preview.x, this.preview.y)); + var pv = this.preview; + var t = MM.tower.create(this.shop, pv.x, pv.y, pv.sides); + t.paid.push({ cost: cost, pause: this.pauseNumber() }); + this.towers.push(t); MM.audio.play("tower_built"); this.shop = null; this.preview = null; return true; }; + // upgrade the selected tower by one level + Game.prototype.upgrade = function () { + var t = this.selected; + var cost = t && MM.tower.upgradeCost(t); + if (!cost || !this.canAfford(cost)) return; + this.pay(cost); + t.level++; + t.paid.push({ cost: cost, pause: this.pauseNumber() }); + MM.audio.play("tower_upgraded"); + }; + + Game.prototype.sell = function () { + var t = this.selected; + if (!t) return; + this.coins += MM.tower.refund(t, this.pauseNumber()); + this.towers.splice(this.towers.indexOf(t), 1); + this.selected = null; + MM.audio.play("tower_sold"); + }; + return Game; })(); diff -r 67bf3c505145 -r 910b26feca76 game/js/input.js --- a/game/js/input.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/input.js Mon Oct 19 01:05:29 2026 +0200 @@ -9,7 +9,8 @@ var PREVIEW_HIT = 28; var REFUSED_TIME = 500; - // app: {canvas, game(), layout(), restart(), view} + // app: {canvas, view, game(), layout(), and the screen actions play(), + // next(), retry(), restart()} function attach(app) { var c = app.canvas; c.addEventListener("pointerdown", function (e) { @@ -34,15 +35,22 @@ var game = app.game(), L = app.layout(); var b = MM.ui.hit(game, L, x, y); if (b) { + // the play button starts the sound + if (b.id === "play") MM.audio.start(); MM.audio.play("button_tap"); - if (b.id === "restart") app.restart(); - else if (b.id === "pause") game.paused = !game.paused; + if (b.id === "play") app.play(); + else if (b.id === "next") app.next(); + else if (b.id === "retry") app.retry(); + else if (b.id === "restart") app.restart(); + else if (b.id === "pause") game.togglePause(); else if (b.id === "speed") game.speedIndex = (game.speedIndex + 1) % game.speeds.length; else if (b.id === "early") game.startEarly(); else if (b.id === "shop" && game.canAfford(MM.config.tower[b.tower].cost)) game.chooseShop(b.tower); + else if (b.id === "upgrade") game.upgrade(); + else if (b.id === "sell") game.sell(); return; } - if (game.result) return; + if (game.result || game.splash) return; var mx = (x - L.ox) / L.scale, my = (y - L.oy) / L.scale; if (mx < 0 || my < 0 || mx > game.map.width || my > game.map.height) return; var hitR = Math.max(MM.config.placement.footprint_radius, PREVIEW_HIT / L.scale); diff -r 67bf3c505145 -r 910b26feca76 game/js/main.js --- a/game/js/main.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/main.js Mon Oct 19 01:05:29 2026 +0200 @@ -17,13 +17,29 @@ var L = null; var view = { dpr: 1, now: 0, refused: null, stats: { ms: 0 } }; - function newGame() { - var m = MM.util.clamp(cfg.debug.start_map, 0, MM.maps.length - 1); + // the first map is the debug start map; only it starts at the debug + // start wave + var FIRST = MM.util.clamp(cfg.debug.start_map, 0, MM.maps.length - 1); + + function startMap(m) { var seed = cfg.debug.seed || (Math.random() * 4294967296) >>> 0; - game = new MM.Game(m, seed); + game = new MM.Game(m, seed, m === FIRST ? cfg.debug.start_wave : 1); resize(); } + // the splash screen over the paused first map. the pause does not count + // for the sell refund, as nothing can be bought on the splash screen. + function splash() { + startMap(FIRST); + game.splash = true; + game.paused = true; + } + + function play() { + game.splash = false; + game.paused = false; + } + // canvas resolution follows the device pixel ratio function resize() { var w = canvas.clientWidth, h = canvas.clientHeight; @@ -73,11 +89,14 @@ view: view, game: function () { return game; }, layout: function () { return L; }, - restart: newGame + play: play, + next: function () { startMap(game.map.index + 1); }, + retry: function () { startMap(FIRST); }, + restart: splash }); MM.assets.load(function (failed) { if (failed.length) console.error("images not loaded:", failed); - newGame(); + splash(); requestAnimationFrame(frame); }); })(); diff -r 67bf3c505145 -r 910b26feca76 game/js/map.js --- a/game/js/map.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/map.js Mon Oct 19 01:05:29 2026 +0200 @@ -48,6 +48,10 @@ "use strict"; var cfg = MM.config; + // spike sides: distance between route samples, and the share of the + // samples in reach a side needs to count as facing the path + var SIDE_STEP = 4; + var SIDE_SHARE = 0.2; function GameMap(index) { var d = MM.maps[index]; @@ -94,6 +98,35 @@ return best; }; + // which sides of a tower at x, y face the path, as four booleans: up, + // right, down, left. each side covers a quarter of the directions. a side + // faces the path when it holds at least SIDE_SHARE of the route points + // within reach. with no route point in reach, only the side towards the + // nearest one does. + GameMap.prototype.facingSides = function (x, y, reach) { + var count = [0, 0, 0, 0], total = 0, nearest = Infinity, nearSide = 0; + var pt = {}; + this.routes.forEach(function (r) { + pt.seg = 1; + for (var s = 0; s <= r.length; s += SIDE_STEP) { + r.point(s, pt); + var dx = pt.x - x, dy = pt.y - y, d = Math.hypot(dx, dy); + var side = Math.abs(dx) > Math.abs(dy) ? (dx > 0 ? 1 : 3) : (dy > 0 ? 2 : 0); + if (d < nearest) { + nearest = d; + nearSide = side; + } + if (d <= reach) { + count[side]++; + total++; + } + } + }); + return count.map(function (c, i) { + return total ? c >= SIDE_SHARE * total : i === nearSide; + }); + }; + // route weights for a monster of the given speed (balance.md, route // preference). fixed weights from routes.toml take precedence. GameMap.prototype.routeWeights = function (speed) { diff -r 67bf3c505145 -r 910b26feca76 game/js/monster.js --- a/game/js/monster.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/monster.js Mon Oct 19 01:05:29 2026 +0200 @@ -1,4 +1,4 @@ -// monsters: movement along a route, hops, hp +// monsters: movement along a route, hops, slow, hp window.MM = window.MM || {}; @@ -34,16 +34,43 @@ hitRadius: cfg.animation.hit_radius * Math.min(size[0], size[1]), // start at a random point of the hop cycle, so a group does not hop in step phase: game.random(), + slows: [], // running slows, {factor, left} alive: true }; m.route.point(0, m); return m; } + // share of its speed a monster keeps: the strongest running slow + // applies, slows do not add up. 1 when not slowed. + function slowFactor(m) { + var k = 1; + for (var i = 0; i < m.slows.length; i++) k = Math.min(k, m.slows[i].factor); + return k; + } + + // slow to factor of the speed for time seconds. a new hit of the same + // strength restarts its time. + function slow(m, factor, time) { + for (var i = 0; i < m.slows.length; i++) { + if (m.slows[i].factor === factor) { + m.slows[i].left = time; + return; + } + } + m.slows.push({ factor: factor, left: time }); + } + // advance by dt seconds. returns true when the monster reached the exit. function update(m, dt) { - m.s += m.speed * dt; - m.phase = (m.phase + dt / cfg.animation.hop_time) % 1; + for (var i = m.slows.length - 1; i >= 0; i--) { + m.slows[i].left -= dt; + if (m.slows[i].left <= 0) m.slows.splice(i, 1); + } + // a slowed monster also hops slower + var k = slowFactor(m); + m.s += m.speed * k * dt; + m.phase = (m.phase + k * dt / cfg.animation.hop_time) % 1; m.route.point(m.s, m); return m.s >= m.route.length; } @@ -70,5 +97,6 @@ return { lift: lift, sx: sx * (1 - bob / 2), sy: sy * (1 + bob) }; } - return { create: create, update: update, remaining: remaining, pose: pose }; + return { create: create, update: update, remaining: remaining, pose: pose, + slow: slow, slowFactor: slowFactor }; })(); diff -r 67bf3c505145 -r 910b26feca76 game/js/projectile.js --- a/game/js/projectile.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/projectile.js Mon Oct 19 01:05:29 2026 +0200 @@ -1,4 +1,5 @@ -// projectiles: fly towards their target and damage it on arrival +// projectiles: fly towards their target and damage it on arrival, p2 also +// slows it window.MM = window.MM || {}; @@ -6,15 +7,18 @@ "use strict"; function create(tower, target, damage) { + var def = tower.def; return { - kind: tower.def.projectile, - speed: tower.def.projectile_speed, + kind: def.projectile, + speed: def.projectile_speed, x: tower.x, y: tower.y, tx: target.x, ty: target.y, target: target, damage: damage, + slow: def.slow ? def.slow[tower.level - 1] : 0, + slowTime: def.slow_time, angle: Math.atan2(target.y - tower.y, target.x - tower.x), done: false }; @@ -35,7 +39,10 @@ var step = p.speed * dt; var reach = t ? Math.max(step, t.hitRadius) : step; if (d <= reach) { - if (t) game.damage(t, p.damage); + if (t) { + if (p.slow) MM.monster.slow(t, p.slow, p.slowTime); + game.damage(t, p.damage); + } p.done = true; return; } diff -r 67bf3c505145 -r 910b26feca76 game/js/render.js --- a/game/js/render.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/render.js Mon Oct 19 01:05:29 2026 +0200 @@ -54,15 +54,21 @@ }); } - // t0 spikes: one p0 per side, pushed out during an attack + // t0 spikes: one p0 per side that faces the path. during an attack each + // spike stretches from its base under the tower until its tip reaches + // the range, and back function drawSpikes(ctx, t, scale) { var half = A.size(MM.tower.sprite(t), scale)[1] / 2; var spike = A.size("p0", scale)[1]; var k = t.burst > 0 ? Math.sin(Math.PI * (1 - t.burst / MM.tower.BURST_TIME)) : 0; - var out = half - spike * 0.25 + k * (MM.tower.range(t) - half - spike * 0.5); + // at rest a quarter of the spike shows beyond the tower's edge + var base = half - spike * 0.75; + var tip = MM.util.lerp(half + spike * 0.25, MM.tower.range(t), k); + var mid = (base + tip) / 2, stretch = (tip - base) / spike; for (var side = 0; side < 4; side++) { + if (!t.sides[side]) continue; var a = -Math.PI / 2 + side * Math.PI / 2; - A.draw(ctx, "p0", t.x + Math.cos(a) * out, t.y + Math.sin(a) * out, scale, a); + A.draw(ctx, "p0", t.x + Math.cos(a) * mid, t.y + Math.sin(a) * mid, scale, a, 1, stretch); } } @@ -88,11 +94,13 @@ ctx.drawImage(img, -m.w / 2, -m.h, m.w, m.h); ctx.restore(); - // hp bar, cut to the share of hp left over its darkened copy - var bar = A.size("hpm", cfg.scale.hp_bar); + // hp bar, cut to the share of hp left over its darkened copy. the + // boss has its own bar; a slowed monster's bar is blue + var name = (m.boss ? "hpb" : "hpm") + (MM.monster.slowFactor(m) < 1 ? "_slow" : ""); + var bar = A.size(name, cfg.scale.hp_bar); var bx = m.x - bar[0] / 2, by = m.y - m.h / 2 - pose.lift - bar[1] - 2; var share = Math.max(0, m.hp / m.maxHp); - var full = A.img("hpm"), empty = A.img("hpm_empty"); + var full = A.img(name), empty = A.img(name + "_empty"); ctx.drawImage(empty, bx, by, bar[0], bar[1]); if (share > 0) { ctx.drawImage(full, 0, 0, full.naturalWidth * share, full.naturalHeight, @@ -121,7 +129,7 @@ drawTower(ctx, t, 1); } if (game.preview) { - var pv = MM.tower.create(game.shop, game.preview.x, game.preview.y); + var pv = MM.tower.create(game.shop, game.preview.x, game.preview.y, game.preview.sides); drawRange(ctx, pv.x, pv.y, MM.tower.range(pv), s); drawTower(ctx, pv, 0.65); } diff -r 67bf3c505145 -r 910b26feca76 game/js/tower.js --- a/game/js/tower.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/tower.js Mon Oct 19 01:05:29 2026 +0200 @@ -1,4 +1,4 @@ -// towers: targeting and attacks +// towers: targeting, attacks, upgrade, sell window.MM = window.MM || {}; @@ -9,19 +9,44 @@ // how long a melee attack shows its spikes pushed out var BURST_TIME = 0.3; - function create(type, x, y) { + // sides: for t0, which sides draw spikes (map.facingSides); all four + // when left out + function create(type, x, y, sides) { return { type: type, def: cfg.tower[type], level: 1, x: x, y: y, + sides: sides || [true, true, true, true], + // purchases, {cost, pause}: pause is the number of the pause + // the purchase was made in, 0 while the game ran + paid: [], angle: -Math.PI / 2, cooldown: 0, burst: 0 }; } + // cost of the next level, null at the top level. level n costs the + // base cost x n. + function upgradeCost(t) { + return t.level < t.def.damage.length ? t.def.cost * (t.level + 1) : null; + } + + // coins back for selling the tower: half of everything paid for it, + // rounded down, except purchases made during the current pause, which + // come back in full. pause is the number of the current pause, 0 while + // the game runs. + function refund(t, pause) { + var rest = 0, full = 0; + t.paid.forEach(function (p) { + if (pause && p.pause === pause) full += p.cost; + else rest += p.cost; + }); + return Math.floor(rest * cfg.tower_rules.sell_refund) + full; + } + function sprite(t) { return t.level === 1 ? t.type : t.type + "_" + t.level; } @@ -78,5 +103,5 @@ } return { create: create, update: update, sprite: sprite, range: range, - BURST_TIME: BURST_TIME }; + upgradeCost: upgradeCost, refund: refund, BURST_TIME: BURST_TIME }; })(); diff -r 67bf3c505145 -r 910b26feca76 game/js/ui.js --- a/game/js/ui.js Sun Oct 18 22:50:24 2026 +0200 +++ b/game/js/ui.js Mon Oct 19 01:05:29 2026 +0200 @@ -1,4 +1,4 @@ -// screen layout, top bar, tower shop and end screens. icons are placeholder +// 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. window.MM = window.MM || {}; @@ -12,6 +12,7 @@ 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 INK = "#3a3530"; var PAPER = "#f6f1e6"; var FONT = "bold 22px system-ui, -apple-system, Segoe UI, sans-serif"; @@ -34,12 +35,37 @@ 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. + function towerMenu(game, L) { + var t = game.selected, a = L.area, gap = 8, out = []; + 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; + 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 }); + } + out.push({ id: "sell", x: left + MENU_BUTTON + gap, y: top, w: MENU_BUTTON, h: MENU_BUTTON }); + return out; + } + // 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) { - out.push({ id: "restart", x: L.w / 2 - 48, y: L.h / 2 + 50, w: 96, h: 96 }); + 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 }); return out; } out.push({ id: "pause", x: L.w - BUTTON - 8, y: y, w: BUTTON, h: BUTTON }); @@ -56,6 +82,7 @@ b.w = b.h = SHOP_BUTTON; out.push(b); }); + if (game.selected) out = out.concat(towerMenu(game, L)); return out; } @@ -138,6 +165,45 @@ 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 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(); + } + + 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); + } + function box(ctx, b, fill, line) { ctx.fillStyle = fill; ctx.strokeStyle = line || INK; @@ -188,7 +254,28 @@ 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); ctx.globalAlpha = 1; - } else if (b.id === "restart") { + } 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 + ""); + 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); } @@ -212,16 +299,28 @@ icon(ctx, "m0", 206, TOP / 2, 30); text(ctx, game.waves.shown() + "/" + game.waves.list.length, 226, TOP / 2); - if (!game.result) buttons(game, L).forEach(function (b) { drawButton(ctx, game, b); }); + var screen = game.splash || game.result; + if (!screen) buttons(game, L).forEach(function (b) { drawButton(ctx, game, b); }); - if (game.paused && !game.result) { + 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.result) { + 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)"; ctx.fillRect(0, 0, L.w, L.h); - if (game.result === "won") { + 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"); @@ -234,8 +333,8 @@ ctx.lineTo(L.w / 2 + 4, L.h / 2 + 22); ctx.stroke(); } - buttons(game, L).forEach(function (b) { drawButton(ctx, game, b); }); } + if (screen) buttons(game, L).forEach(function (b) { drawButton(ctx, game, b); }); if (cfg.debug.show_stats && view.stats) { var st = view.stats; diff -r 67bf3c505145 -r 910b26feca76 tools/build.py --- a/tools/build.py Sun Oct 18 22:50:24 2026 +0200 +++ b/tools/build.py Mon Oct 19 01:05:29 2026 +0200 @@ -48,8 +48,12 @@ 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"]) -# empty part of an hp bar: a darkened copy (art.md) +# 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 +BAR_SLOW_HUE = 220 +BARS = ["hpm", "hpb"] +BAR_VARIANTS = [f"{n}{v}" for n in BARS for v in ("_empty", "_slow", "_slow_empty")] MAPS = 4 MAP_QUALITY = 88 # centre line smoothing: moving average half window, simplify tolerance @@ -87,7 +91,7 @@ def step_sprites(force): inputs = [ART / f"{n}.png" for n in SPRITES] - outputs = [ASSETS / f"{n}.png" for n in SPRITES] + [ASSETS / "hpm_empty.png", ASSETS / "hpb_empty.png"] + outputs = [ASSETS / f"{n}.png" for n in SPRITES + BAR_VARIANTS] if not stale(inputs, outputs, force): print("sprites: up to date") return False @@ -95,9 +99,12 @@ for n in SPRITES: im = images.trim(Image.open(ART / f"{n}.png").convert("RGBA")) im.save(ASSETS / f"{n}.png", optimize=True) - if n in ("hpm", "hpb"): + if n in BARS: + slow = images.recolour(im, BAR_SLOW_HUE) images.darken(im, BAR_DARKEN).save(ASSETS / f"{n}_empty.png", optimize=True) - print(f"sprites: wrote {len(SPRITES)} sprites and 2 empty bars") + 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") return True diff -r 67bf3c505145 -r 910b26feca76 tools/images.py --- a/tools/images.py Sun Oct 18 22:50:24 2026 +0200 +++ b/tools/images.py Mon Oct 19 01:05:29 2026 +0200 @@ -31,6 +31,19 @@ return Image.merge("RGBA", (r, g, b, a)) +def recolour(im, hue): + """ + return a copy with every pixel's hue set to hue (degrees), saturation, + brightness and alpha unchanged. grey and black pixels stay as they are. + """ + a = im.getchannel("A") + h, s, v = im.convert("RGB").convert("HSV").split() + h = h.point(lambda _: round(hue / 360 * 255)) + out = Image.merge("HSV", (h, s, v)).convert("RGBA") + out.putalpha(a) + return out + + def split_strip(im): """ split a strip of drawings side by side at columns without pencil.