Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 0.2.0 (unreleased)

- **Hazards (#5):** wind, falling roof tiles with a shadow first, lifts on a rope, and drawbridges, each a function of the frame count. Rooftops, The Canal, Market Square, Old Wall, and Lantern Hill have them, with new routes.
- **Level files and 5 new levels (#4):** each hand level is a file of `levels/`, which the core checks part by part, with the file and the line in an error. Rooftops, The Canal, Market Square, Old Wall, and Lantern Hill are new. `tools/solve.tcl` found a route for each, and the tests replay the 10 routes.
- **Save and continue (#3):** the save goes through `ztk::game save` in the data folder of the app, and the play page keeps it in the local storage of the browser. Continue goes to the entry that the player started last, when it is open and not done. A save of 0.1.0 is read and moved, and a save of an unknown version or a bad save gives a new game.
- **Title and pause (#2):** the title is a menu of Continue, All streets, Endless street, and Quit on a desktop. Escape, Enter, or the mark "II" pauses a level or a run, and the pause has Resume, Restart, and Title. A window that goes to the background pauses the game.
Expand Down
1 change: 1 addition & 0 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The rules and the data of the game. The core has no Tk, reads no clock, opens no
| `levels.tcl` | The check of a level file (`parseLevel`), the streets of the generator, and the facts of each entry. |
| `color.tcl` | The palette, the color math, and the themes with their rules of contrast. |
| `progress.tcl` | The best times, the stars, the open entries, and the save format. |
| `hazards.tcl` | Wind, falling tiles, lifts, and drawbridges: each one a function of the frame count. |
| `play.tcl` | The state, one frame of a hand level (`step`), the collisions, the lamps, and the events. |
| `run.tcl` | The physics of a run, the generator with its proof of each piece, and one frame of a run (`runStep`). |
| `route.tcl` | The moves of a route and its replay. |
Expand Down
78 changes: 78 additions & 0 deletions core/hazards.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# The hazards and the moving things of the hand levels. Each one is a
# function of the frame count, so a level plays the same each time.
#
# - Wind {x0 x1 force period}: a gust for the first half of each period
# pushes the hero by force pixels each frame while it is between x0
# and x1. A negative force pushes to the left.
# - Tile {x y0 period}: a roof tile falls at x once in each period. For
# the first 40 frames of the period its shadow shows on the floor. Then
# it falls from y0 at 4 pixels a frame to the floor under x. A tile
# that touches the hero puts out the flame, as the water does.
# - Lift {x0 y0 x1 y1 period}: a floor from x0 to x1 that goes from y0
# to y1 and back in each period, on a cosine. The hero on it moves
# with it.
# - Drawbridge {x0 y x1 period}: a floor that is down for the first half
# of each period and up for the second half.
#
# No Tk, no clock, no file, no random.
#
# Copyright (C) 2026 Jeremy Collins
# SPDX-License-Identifier: AGPL-3.0-or-later

proc gustOn {wind frames} {
lassign $wind x0 x1 force per
expr {$frames % int($per) < $per / 2.0}
}

# The push of the winds of the street on the hero at x y.
proc windPush {x y frames} {
set push 0
foreach w [data winds] {
lassign $w x0 x1 force
if {$x >= $x0 && $x <= $x1 && [gustOn $w $frames]} { set push [expr {$push + $force}] }
}
return $push
}

# The top of the floor under x: the top of a block, or the bottom of the
# street.
proc floorUnder {x} {
set top $::H
foreach b [data blocks] { lassign $b x0 t x1; if {$x >= $x0 && $x <= $x1} { set top [expr {min($top, $t)}] } }
return $top
}

# The state of a tile at a frame: {shadow}, {fall Y}, or {} when it is
# on the floor.
proc tileState {tile frames} {
lassign $tile x y0 per
set t [expr {$frames % int($per)}]
if {$t < 40} { return shadow }
set y [expr {$y0 + ($t - 40) * 4}]
if {$y >= [floorUnder $x]} { return {} }
list fall $y
}

# 1 when a falling tile touches the hero at x y (y is the middle of its
# body, its feet at y + 7 and its hat at y - 12).
proc tileHit {x y frames} {
foreach tl [data tiles] {
set st [tileState $tl $frames]
if {[lindex $st 0] ne "fall"} continue
set ty [lindex $st 1]
if {abs($x - [lindex $tl 0]) < 9 && $ty + 6 >= $y - 12 && $ty <= $y + 7} { return 1 }
}
return 0
}

# The top of a lift at a frame.
proc liftY {lift frames} {
lassign $lift x0 y0 x1 y1 per
expr {$y0 + ($y1 - $y0) * (1 - cos($frames * 6.283185307179586 / $per)) / 2.0}
}

# 1 when a drawbridge is down at a frame.
proc bridgeDown {bridge frames} {
lassign $bridge x0 y x1 per
expr {$frames % int($per) < $per / 2.0}
}
10 changes: 8 additions & 2 deletions core/levels.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ set W 472; set H 232
# springs boats crumbles water}: blocks {x0 top x1} that go to the
# floor, ledges {x0 y x1} that you can jump up through, lamps {x y},
# springs {x y}, boats {x0 y x1 dx frames} that swing, crumbling boards
# {x0 y x1}, and water {x0 x1}. The gate is at the right of the last
# {x0 y x1}, water {x0 x1}, and the hazards (core/hazards.tcl): winds
# {x0 x1 force period}, tiles {x y0 period}, lifts {x0 y0 x1 y1 period},
# and drawbridges {x0 y x1 period}. The gate is at the right of the last
# street.
set levels {}

# The parts of a street and the count of numbers of each part.
set partSize {blocks 3 ledges 3 lamps 2 springs 2 boats 5 crumbles 3 water 2}
set partSize {blocks 3 ledges 3 lamps 2 springs 2 boats 5 crumbles 3 water 2 winds 4 tiles 3 lifts 5 bridges 4}

# Reads the text of one level: a list of `street NAME {PART LIST ...}`.
# file and line give the place of the text for an error. Gives the level
Expand Down Expand Up @@ -51,6 +53,10 @@ proc parseLevel {name body {file level} {line 1}} {
lamps - springs { lassign $p x y; set ok [expr {$x >= 0 && $x <= $W && $y >= 0 && $y <= $H}] }
water { lassign $p x0 x1; set ok [expr {$x0 >= 0 && $x1 <= $W && $x0 < $x1}] }
boats { lassign $p x0 y x1; set ok [expr {$x0 < $x1 && $y >= 0 && $y <= $H}] }
winds { lassign $p x0 x1 force per; set ok [expr {$x0 >= 0 && $x1 <= $W && $x0 < $x1 && abs($force) <= 3 && $per >= 2}] }
tiles { lassign $p x y0 per; set ok [expr {$x >= 0 && $x <= $W && $y0 >= 0 && $y0 <= $H && $per >= 60}] }
lifts { lassign $p x0 y0 x1 y1 per; set ok [expr {$x0 >= 0 && $x1 <= $W && $x0 < $x1 && $y0 >= 0 && $y0 <= $H && $y1 >= 0 && $y1 <= $H && $per >= 2 * abs($y1 - $y0)}] }
bridges { lassign $p x0 y x1 per; set ok [expr {$x0 >= 0 && $x1 <= $W && $x0 < $x1 && $y >= 0 && $y <= $H && $per >= 2}] }
default { lassign $p x0 y x1; set ok [expr {$x0 >= 0 && $x1 <= $W && $x0 < $x1 && $y >= 0 && $y <= $H}] }
}
if {!$ok} { apply $fail "a part of $k in $sname is outside the street: $p" $sname }
Expand Down
2 changes: 1 addition & 1 deletion core/load.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Copyright (C) 2026 Jeremy Collins
# SPDX-License-Identifier: AGPL-3.0-or-later

foreach f {levels color progress play run route menu} {
foreach f {levels color progress hazards play run route menu} {
source [file join [file dirname [info script]] $f.tcl]
}
unset f
37 changes: 30 additions & 7 deletions core/play.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# physics (`step`), the collisions with blocks, ledges, boats, boards,
# and springs, the lamps, the night, and the end of a level.
#
# A level is a walk through 2 or 3 streets. Walk off the right edge to
# A level is a walk through 1 to 3 streets. Walk off the right edge to
# go to the next street. Touch a lamp to light it: each lamp pushes the
# night back. Light all the lamps of a level to open its gate.
#
Expand All @@ -20,6 +20,7 @@
# crumbshake SCENE N DX a board shakes
# crumbhide SCENE N a board breaks
# crumbshow SCENE N a board comes back
# tilehit SCENE a falling tile hit the hero
#
# app(sfx) gets the name of each sound, and app(music) the name of the
# music. The core has no random: the same inputs give the same frames.
Expand All @@ -37,7 +38,7 @@ if {![info exists app(touch)]} { set app(touch) 0 }

# The state of the game.
array set g {state title level 0 scene 0 dark 0 frames 0 shake 0 freeze 0 pick 0 clear 0 msgT 0 unlocked 1 auto 0 cam 0 paused 0 picked 0}
array set h {x 30 y 150 vx 0 vy 0 ground 1 coyote 0 buffer 0 face 1 sx 1 sy 1 step 0 spawnS 0 spawnX 30 spawnY 150 ride -1 crumble -1}
array set h {x 30 y 150 vx 0 vy 0 ground 1 coyote 0 buffer 0 face 1 sx 1 sy 1 step 0 spawnS 0 spawnX 30 spawnY 150 ride -1 crumble -1 lift -1 liftY 0}
array set hold {left 0 right 0 jump 0}
set events {}

Expand All @@ -53,7 +54,7 @@ proc say {a b} {
proc lvl {} { lindex $::levels $::g(level) 1 }
# The parts of the current street, read once when you enter it.
proc loadStreet {} {
foreach what {name blocks ledges lamps springs boats crumbles water} v [lindex [lvl] $::g(scene)] { set ::cur($what) $v }
foreach what {name blocks ledges lamps springs boats crumbles water winds tiles lifts bridges} v [lindex [lvl] $::g(scene)] { set ::cur($what) $v }
}
proc data {what} { return $::cur($what) }

Expand All @@ -63,7 +64,7 @@ proc startLevel {n} {
array set g [list state play level $n scene 0 dark 0 frames 0 shake 0 freeze 0 clear 0 msgT 120 auto $app(touch) cam 0 paused 0]
array unset lit; array unset crumb
set app(music) play
array set h {x 24 y 150 vx 0 vy 0 ground 0 coyote 0 buffer 0 face 1 sx 1 sy 1 ride -1 crumble -1}
array set h {x 24 y 150 vx 0 vy 0 ground 0 coyote 0 buffer 0 face 1 sx 1 sy 1 ride -1 crumble -1 lift -1 liftY 0}
array set h {spawnS 0 spawnX 24 spawnY 150}
enter 0 24
}
Expand Down Expand Up @@ -106,6 +107,18 @@ proc floors {} {
if {![info exists crumb($g(scene),$n)] || [lindex $crumb($g(scene),$n) 0] < 40} { lappend out [concat $cr crumble $n] }
incr n
}
set n 0
foreach lf [data lifts] {
lassign $lf x0 y0 x1
lappend out [list $x0 [liftY $lf $g(frames)] $x1 lift $n]
incr n
}
set n 0
foreach br [data bridges] {
lassign $br x0 y x1 per
if {[bridgeDown $br $g(frames)]} { lappend out [list $x0 $y $x1 bridge $n] }
incr n
}
return $out
}

Expand Down Expand Up @@ -138,7 +151,7 @@ proc step {} {
if {$h(buffer) > 0} { incr h(buffer) -1 }
if {$h(ground)} { set h(coyote) 6 } elseif {$h(coyote) > 0} { incr h(coyote) -1 }
if {$h(buffer) > 0 && $h(coyote) > 0} {
set h(vy) -6.3; set h(buffer) 0; set h(coyote) 0; set h(ground) 0; set h(ride) -1
set h(vy) -6.3; set h(buffer) 0; set h(coyote) 0; set h(ground) 0; set h(ride) -1; set h(lift) -1
set h(sx) 0.7; set h(sy) 1.35; sfx jump
burst $h(x) [expr {$h(y) + 7}] 4 #c8b8e0
}
Expand All @@ -147,7 +160,13 @@ proc step {} {
if {$h(ride) >= 0} {
foreach f [floors] { lassign $f x0 y x1 kind n; if {$kind eq "boat" && $n == $h(ride)} { set h(x) [expr {$h(x) + ($x0 - $h(rideX))}]; set h(rideX) $x0 } }
}
set h(x) [expr {$h(x) + $h(vx)}]
# Ride a lift: move up and down with it.
if {$h(lift) >= 0} {
set y [liftY [lindex [data lifts] $h(lift)] $g(frames)]
set h(y) [expr {$h(y) + ($y - $h(liftY))}]
set h(liftY) $y
}
set h(x) [expr {$h(x) + $h(vx) + [windPush $h(x) $h(y) $g(frames)]}]
# The sides of the blocks.
foreach b [data blocks] {
lassign $b x0 top x1
Expand All @@ -172,12 +191,14 @@ proc step {} {
set h(vy) 0; set h(ground) 1
set h(ride) [expr {$kind eq "boat" ? $n : -1}]
if {$kind eq "boat"} { set h(rideX) $x0 }
set h(lift) [expr {$kind eq "lift" ? $n : -1}]
if {$kind eq "lift"} { set h(liftY) $y }
if {$kind eq "crumble" && ![info exists crumb($g(scene),$n)]} { set crumb($g(scene),$n) {0} }
break
}
}
}
if {!$h(ground)} { set h(ride) -1 }
if {!$h(ground)} { set h(ride) -1; set h(lift) -1 }
# The boards break 40 frames after a step, and come back after 3 s.
foreach k [array names crumb $g(scene),*] {
set n [lindex [split $k ,] 1]
Expand All @@ -194,6 +215,8 @@ proc step {} {
set h(vy) -9.6; set h(ground) 0; set h(sx) 0.6; set h(sy) 1.5; sfx pop; burst $sx $sy 6 #a6e6b2 1
}
}
# A falling tile puts out the flame.
if {[tileHit $h(x) $h(y) $g(frames)]} { emit tilehit $g(scene); hurt; return }
# The lamps.
set k 0
foreach l [data lamps] {
Expand Down
4 changes: 4 additions & 0 deletions docs/how-to-play.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ Escape, Enter, or the mark at the top right pauses a level or a run. The pause h
| Boat | A floor that swings over the water. It moves you with it. |
| Spring | Sends you high into the air. |
| Water | Puts out the flame. |
| Wind | A gust pushes you for half of each period. Streaks show it. |
| Falling tile | A shadow shows on the floor, then a roof tile falls there. It puts out the flame. |
| Lift | A floor on a rope that goes up and down. It moves you with it. |
| Drawbridge | A floor that is down for half of each period and up for the other half. |

## Streets and stars

Expand Down
2 changes: 1 addition & 1 deletion docs/levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
| 9 | Old Wall | Gate Arch, Rampart, Watchtower | A board under an arch, a moat, and a spring to a ledge. |
| 10 | Lantern Hill | Path, Terraces, Crown | Steps, a boat and a board over the water, and the crown of the hill. |

Each level is a file of `levels/`. A file is a list of `street NAME {PART LIST ...}`, with the parts blocks, ledges, lamps, springs, boats, crumbles (boards), and water. The core checks each part when the game reads the file, and a fault gives the file and the line.
Each level is a file of `levels/`. A file is a list of `street NAME {PART LIST ...}`, with the parts blocks, ledges, lamps, springs, boats, crumbles (boards), water, winds, tiles, lifts, and bridges (drawbridges). The core checks each part when the game reads the file, and a fault gives the file and the line.

The tests replay a route through each hand level and check that it finishes the level. `tools/solve.tcl` finds the routes.

Expand Down
5 changes: 4 additions & 1 deletion levels/06-rooftops.tcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Rooftops: chimneys, gutters over the water, and a weathervane.
# Rooftops: chimneys, gutters over the water with a falling tile, and a
# weathervane in the wind.
#
# Copyright (C) 2026 Jeremy Collins
# SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -13,10 +14,12 @@ level Rooftops {
blocks {{0 196 90} {150 180 250} {310 160 472}}
lamps {{200 150} {430 130}}
water {{90 150} {250 310}}
tiles {{380 0 150}}
}
street Weathervane {
blocks {{0 196 472}}
ledges {{80 166 150} {170 136 240} {260 106 330}}
lamps {{295 76} {60 166}}
winds {{140 340 -0.9 200}}
}
}
6 changes: 4 additions & 2 deletions levels/07-the-canal.tcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# The canal: a lock with a boat, a towpath with a spring, and a footbridge of boards.
# The canal: a lock with a boat, a towpath with a spring, and a
# footbridge of boards with a drawbridge in the middle.
#
# Copyright (C) 2026 Jeremy Collins
# SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -19,7 +20,8 @@ level {The Canal} {
street Footbridge {
blocks {{0 196 100} {380 196 472}}
lamps {{240 146} {430 166}}
crumbles {{100 186 180} {200 176 280} {300 186 380}}
crumbles {{100 186 180} {300 186 380}}
bridges {{200 176 280 180}}
water {{100 380}}
}
}
6 changes: 4 additions & 2 deletions levels/08-market-square.tcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Market square: the awnings of the stalls, a fountain with a spring, and the clock.
# Market square: the awnings of the stalls, a fountain with a spring,
# and the clock with a lift.
#
# Copyright (C) 2026 Jeremy Collins
# SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -18,6 +19,7 @@ level {Market Square} {
street Clock {
blocks {{0 196 472}}
ledges {{100 150 170} {200 110 270} {300 70 370}}
lamps {{335 40} {135 120}}
lamps {{335 40} {135 120} {405 60}}
lifts {{380 190 430 100 240}}
}
}
4 changes: 3 additions & 1 deletion levels/09-old-wall.tcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Old wall: an arch with a board, the rampart over a moat, and the watchtower.
# Old wall: an arch with a board, the rampart over a moat in the wind,
# and the watchtower.
#
# Copyright (C) 2026 Jeremy Collins
# SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -13,6 +14,7 @@ level {Old Wall} {
blocks {{0 196 60} {60 146 200} {260 146 400} {400 196 472}}
lamps {{130 116} {330 116}}
water {{200 260}}
winds {{150 300 1.0 160}}
}
street Watchtower {
blocks {{0 196 472}}
Expand Down
4 changes: 3 additions & 1 deletion levels/10-lantern-hill.tcl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# Lantern hill: a path of steps, terraces over the water, and the crown of the hill.
# Lantern hill: a path of steps, terraces over the water under a
# falling tile, and the crown of the hill.
#
# Copyright (C) 2026 Jeremy Collins
# SPDX-License-Identifier: AGPL-3.0-or-later
Expand All @@ -15,6 +16,7 @@ level {Lantern Hill} {
boats {{90 186 150 60 100}}
crumbles {{200 166 260}}
water {{80 380}}
tiles {{320 0 160}}
}
street Crown {
blocks {{0 196 472}}
Expand Down
4 changes: 4 additions & 0 deletions levels/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ One file for each hand level, in the order of `files` in `load.tcl`. A file call
| `boats` | `{x0 y x1 dx frames}`: a floor that swings by dx in the given frames. |
| `crumbles` | `{x0 y x1}`: a board that breaks 40 frames after a step. |
| `water` | `{x0 x1}` |
| `winds` | `{x0 x1 force period}`: a gust for the first half of each period pushes the hero by force pixels a frame. |
| `tiles` | `{x y0 period}`: a shadow for 40 frames, then a tile falls from y0 at x. |
| `lifts` | `{x0 y0 x1 y1 period}`: a floor that goes from y0 to y1 and back. The period is at least 2 times the distance. |
| `bridges` | `{x0 y x1 period}`: a floor that is down for the first half of each period. |

A street is 472 by 232. A level has 1 to 3 streets, and the gate is at the right of the last one. `parseLevel` of `core/levels.tcl` checks each part. A new level gets a route from `tools/solve.tcl` in `tests/data/routes.txt`.
Loading
Loading