ztk::game
Guide: Games: the loop and actions
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
| Subcommand | Description |
|---|---|
ztk::game loop | Starts the loop of the game at a fixed step, or changes its options. |
ztk::game stop | Stops the loop. |
ztk::game pause | Pauses the steps of the loop. |
ztk::game resume | Resumes the steps of a paused loop. |
ztk::game step | Runs a count of steps now, and then the draw script once. |
ztk::game time | Gives the count of steps of the game. |
ztk::game info | Gives the state of the loop as a dict. |
ztk::game random | Gives a number of the random generator of the game, or sets its seed. |
ztk::game action | Names an action and the keys and the zones of the screen that press it. |
ztk::game pressed | Gives 1 when the action was pressed since the step before this step. |
ztk::game held | Gives 1 while a key, the pointer, or a finger holds the action. |
ztk::game released | Gives 1 when the last holder of the action let go since the step before this step. |
ztk::game axis | Names an axis from -1 to 1, or gives its value in this step. |
ztk::game pointers | Gives the pointer and the fingers on the view as a list of dicts. |
ztk::game pad | Gives the controllers of the game, an empty list in this stage. |
ztk::game view | Fits the game into a toplevel with its zoom, or gives the options of the fit. |
ztk::game save | Writes a dict as the save of a name. |
ztk::game load | Gives 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