diff doc/game.md @ 36:a464bd43b76c 1.0.0

clean documentation rewrite
author ark
date 2026-10-21 22:34 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/doc/game.md	Wed Oct 21 22:34:43 2026 +0200
@@ -0,0 +1,227 @@
+The game
+--------
+
+Minor Monsters is a tower defense game by M.A. and J.A. Juszczyk. It runs
+in desktop and mobile browsers, with mouse or touch. The player only
+manages towers: build, upgrade, sell. Everything else, such as collecting
+coins, happens on its own. The game shows icons and hand-drawn digits in
+place of text.
+
+This document describes the rules as the game implements them. The values
+are in config/game.toml; the section names below point to them. How the
+code does it is in architecture.md and implementation.md.
+
+
+Maps
+----
+
+There are four maps, played in order: map0 home, map1 mine entrance, map2
+mine, map3 lava depths. Each map has a mask that marks the path, its
+entrances and its exits (art.md).
+
+- A won map leads to the next map. After the last map the game is won
+- A lost map sends the player back to the first map
+- There is no map selection and nothing is stored between visits. A
+  reload starts at the splash screen with a fresh game
+- Each map starts with its own starting coins and hearts. Nothing is kept
+  from the map before ([map.N], [hearts])
+
+The maps map0 and map3 have one route each. On map1 the path branches
+into three routes. On map2 two entrances and loops give six routes.
+
+
+Routes
+------
+
+A monster picks its route when it spawns and follows it to the exit. On
+map2 the route also decides the entrance.
+
+- A boss always takes the shortest route
+- Other monsters weigh the routes by their speed. Each route has a value
+  between 0 and 1: the average of its length relative to the longest route
+  and its straightness relative to the straightest one
+- A monster's speed factor is its speed minus the reference speed, divided
+  by the reference speed, limited to -1 to 1
+- The weight of a route is 1 + bias x speed factor x (2 x route value - 1),
+  and at least the minimum weight ([route_preference])
+
+So faster monsters prefer long or straight routes, slower ones prefer
+shortcuts, and a monster at the reference speed takes every route with the
+same likelihood.
+
+
+Monsters
+--------
+
+The regular monsters are m0 to m4, in rising strength. The bosses are b0
+to b3, one per map: b0 comes on map0, b1 on map1 and so on. Each monster
+has hit points, a coin drop and a speed ([monster.*]). A monster's hit
+points are the same on every map; a map gets harder through the size and
+mix of its waves. All regular monsters appear on all maps.
+
+- Each monster's speed differs from its configured speed by a random share
+  ([movement] speed_variation). Faster ones overtake slower ones
+- Monsters do not walk in single file. Each walks beside the centre line
+  of the road, with a fixed lean to one side and a part that wanders. The
+  offset grows from 0 at the start of the route and is reduced on the
+  inside of tight bends ([movement])
+- Monsters move by small hops, with squash on landing and stretch in the
+  air, and a slow breathing on top ([animation])
+- An HP bar shows above every monster; the boss has its own bar. The bar
+  turns blue while the monster is slowed
+- A dying monster leaves a puff, a larger one for a boss
+
+
+Waves
+-----
+
+Each map has a list of waves ([[map.N.wave]]). A wave says how many of
+each monster it holds. The boss of the map is in the last wave.
+
+- A map starts with a break ([waves] first_break). The next wave starts
+  when the break runs out
+- A wave spawns one monster per spawn interval ([map.N] spawn_interval).
+  The boss comes first, as it is the slowest; the others follow in random
+  order
+- The break after a wave starts when its last monster has spawned
+  ([waves] break). Monsters of the wave may still be on the map
+- The wave counter shows the current wave, and during a break the next one
+- During every break, the first one included, a button starts the next
+  wave early. It pays a bonus: the seconds left times the map's
+  early_bonus rate, rounded down
+
+
+Coins
+-----
+
+Killing a monster pays its coin drop. The coins count at once, so a player
+can build right after a kill. Coin sprites then fly from the monster to
+the coin counter, at most a few per death ([coins]); each is one of the
+four coin drawings, picked at random. The early start bonus counts at once
+too, and its coins fly from the exits.
+
+
+Hearts
+------
+
+A regular monster that reaches the exit costs hearts. A boss that reaches
+it loses the map: its heart cost is all the hearts of a map ([hearts]).
+At zero hearts the map is lost. The map is won when the last wave has
+spawned and no monster is left on the map.
+
+
+Towers
+------
+
+There are four towers, each with five levels. Damage, range, slow and cost
+are set in the config for level 1 and level 5; the levels between are
+filled in by equal steps ([tower.*]). The time between attacks is the same
+at every level.
+
+- t0, melee: each attack damages every monster in range at once. It
+  pushes out spikes (p0) only on the sides that face the path
+- t1, the standard tower: turns and shoots p1 at one monster
+- t2, the freeze tower: does no damage. It turns and shoots p2, which
+  bursts where it lands into a freeze splash. Every monster the splash
+  touches is slowed to a share of its speed for a time. Slows do not add
+  up; the strongest one applies, and a new hit of the same strength
+  restarts its time. A slowed monster also hops slower
+- t3, the sniper tower: turns and shoots p3. It is meant to be weaker
+  than t1, and its much longer range lets it reach more of the path
+
+Targeting:
+
+- A tower aims at the monster in range that is furthest along, that is,
+  the one with the least distance left to its exit
+- Turning towers face their target at once and keep their direction when
+  no monster is in range
+- The projectiles p1, p2 and p3 home in on their target. If the target
+  dies first, the projectile flies on to its last position and disappears
+  there without damage. A p2 still bursts there
+- A new tower attacks at once
+
+Prices:
+
+- Building costs the level 1 price. Each upgrade costs the price of the
+  new level
+- Selling refunds a share of everything paid for the tower, build and
+  upgrades, rounded down ([tower_rules]). A tower is always sold whole
+
+
+Placing and managing towers
+---------------------------
+
+Towers stand next to the road, never on it, and not near the entrances or
+exits. They keep a distance from each other and from the map edge
+([placement], and per map in [map.N]).
+
+- The shop sits on the right in landscape and at the bottom in portrait.
+  A tower the player cannot afford is dimmed and cannot be chosen
+- After choosing a tower, a press on the map puts a preview with its range
+  at the nearest legal position. The preview follows the pointer until it
+  is let go
+- Tapping the preview builds the tower. Dragging the preview, or pressing
+  elsewhere and dragging, moves it again
+- Where no legal position is within reach, a red cross shows briefly and
+  the placement refused sound plays
+- The preview pulses in time with the chosen shop item. A second tap on
+  that item cancels the choice; building clears it
+- Tapping a built tower shows its range and a bubble with upgrade and
+  sell, each with its price. An upgrade the player cannot afford is
+  dimmed. At level 5 only sell is left
+- Selling takes two taps. The first arms the sell button, which then
+  pulses with a red glow; the second sells. Any other tap cancels it
+- A tap outside the bubble closes it
+
+
+Controls
+--------
+
+The top bar shows coins, hearts and the wave count. Its buttons, from the
+right: help, pause, speed, sound, and during breaks the early start button
+with the countdown. On a narrow screen the buttons move to a second row.
+
+- Pause stops the game. The shop is dimmed, and nothing can be built,
+  upgraded or sold. Pausing drops the shop choice and the tower selection.
+  The top bar buttons still work, early start included
+- Speed switches between the game speeds ([controls])
+- Sound switches all sound on or off. The choice is kept in the browser.
+  Until the player first uses it, the config's default applies ([sound])
+- Help opens the help popup, which pauses the game. A tap anywhere closes
+  it and lets a game that was running go on. A tap on the email address in
+  the popup writes a mail ([links])
+
+Nothing depends on mouse hover. With a mouse, hover only enlarges the
+screen buttons and shows the pointer cursor over buttons.
+
+
+Screens
+-------
+
+- Splash: title, byline and play button, over the paused first map, with
+  music looping
+- Browsers allow sound only after a tap, so on the first splash screen
+  after loading, a sound button covers the play button. It pulses with a
+  red glow; a tap starts the sound and the music and uncovers the play
+  button. When sound was switched off on an earlier visit there is no
+  sound button and no music
+- Left of the play button the logo opens the game's web page ([links]),
+  right of it a question mark opens the help popup
+- The play button fades the music out and starts play
+- Map won, after every map but the last: one button, which starts the next
+  map
+- Game won, after the last map: one button, which goes back to the splash
+  screen. The music plays at once there, as sound is already running
+- Game lost: one button, which starts the first map
+
+All four screens are drawn at one scale, so the larger drawings stay
+larger. The screen buttons pulse slowly as a cue to tap.
+
+
+Sound
+-----
+
+Game events play the voice recordings in art/sounds/, a random one where
+an event has several. Events without a recording play short beeps made in
+the browser. The events are listed in art.md. The map won sound waits for a
+death sound still playing, the map lost sound for the last exit sound.