beetlebug

One script on desktop, web, and phones

Write one Tk script and run it in a desktop window, in a web page, and as an app on Android and iOS. The three games of Learn with games are the proof: each game is one Tcl file with no change for each platform.

Skate Pond on a desktop: a purple pond with thin ice, snowflakes, and the card of the level
Skate Pond in a desktop window.
Skate Pond on an Android phone
The same script as an Android app.

How it works

A small host runs the game. On the site the host is the web page. On a desktop or a phone the host is toyhost.tcl. The game and the host share one proc and one array, so the game has no code for each platform.

The main script of the app sources the game, then the host (the code):

set here [file dirname [info script]]
source [file join $here .. skatepond.tcl]
source [file join $here toyhost.tcl]

ztk bundle makes one app file from the scripts:

ztk docs/toys/native/skatepond.tcl
ztk bundle -o SkatePond.apk --target aarch64-linux-android \
    docs/toys/native/skatepond.tcl docs/toys/skatepond.tcl docs/toys/native/toyhost.tcl

On a phone, tk touchscreen gives 1, a tap is a click, and tk insets . gives the parts of the screen under the bars. wm attributes . -zoom Z draws the whole window larger, so the game fills the screen.

Real today

The games run on the Toys page of this site, and ztk bundle makes the apps for Android and iOS.