beetlebug▾
/

ztk::game

Runs the loop of a 2D game, reads its input as actions, and keeps its random numbers, its fit, and its saves.

ztk::game SUBCOMMAND ?ARG ...?

Description

The ensemble of the game APIs of ztk. This is stage 1 of the design: the loop, the actions, the random numbers, the fit of the view, and the saves. The sprite layer, controllers, sound, physics, and record and replay come in later stages. Games: the loop and actions has a guide.

A script calls the ensemble by its full name, or makes a short name with interp alias {} game {} ztk::game. Each string of a script is data: a name of an action or of a save is a key of a table, and no text of a save goes to eval.

Subcommands

SubcommandDescription
ztk::game loopStarts the loop of the game at a fixed step, or changes its options.
ztk::game stopStops the loop.
ztk::game pausePauses the steps of the loop.
ztk::game resumeResumes the steps of a paused loop.
ztk::game stepRuns a count of steps now, and then the draw script once.
ztk::game timeGives the count of steps of the game.
ztk::game infoGives the state of the loop as a dict.
ztk::game randomGives a number of the random generator of the game, or sets its seed.
ztk::game actionNames an action and the keys and the zones of the screen that press it.
ztk::game pressedGives 1 when the action was pressed since the step before this step.
ztk::game heldGives 1 while a key, the pointer, or a finger holds the action.
ztk::game releasedGives 1 when the last holder of the action let go since the step before this step.
ztk::game axisNames an axis from -1 to 1, or gives its value in this step.
ztk::game pointersGives the pointer and the fingers on the view as a list of dicts.
ztk::game padGives the controllers of the game, an empty list in this stage.
ztk::game viewFits the game into a toplevel with its zoom, or gives the options of the fit.
ztk::game saveWrites a dict as the save of a name.
ztk::game loadGives the save of a name over a dict of defaults.

Examples

% ztk::game time
0

Errors

% ztk::game
wrong # args: should be "ztk::game subcommand ?arg ...?"
-errorcode TCL WRONGARGS

% ztk::game bogus
unknown or ambiguous subcommand "bogus": must be action, axis, held, info, load, loop, pad, pause, pointers, pressed, random, released, resume, save, step, stop, time, or view
-errorcode TCL LOOKUP SUBCOMMAND bogus

Facts

Capability
None.
Tcl release
Tcl 9.1 and 8.6.
Since
ztk 1.0.0-beta.7

See also