TrainsCoding

Stage & characters

The stage and its characters

The stage is where programs come to life: a square pixel world with characters, physics and a pen. This page explains how the world is measured, how characters are placed and configured, and how players interact during a run.

The world

The stage is always square and always shows the whole world. The world is 16 × 16 tiles of 16 pixels each (256 × 256 pixels), drawn with hard, unsmoothed pixels at whatever size fits the screen.

(8, 8) (1, 1) 0815 0815 x y 0°90°180°270° counter-clockwise

By default there are walls just outside the four edges, so characters bounce off the sides and When bumping a wall trains can fire. Walls can be switched off in Settings, and then characters can leave the stage.

Characters and placements

A character is a type: its name, costume, colour, hearts, weight, body and trains. A character can stand on the stage several times. Each copy is a placement with its own position, angle and size. All placements of a character run the same trains, but each one runs them for itself. With three bricks placed, a When ▶ is pressed train runs three times, once per brick.

During a run, clones made by the Clone wagon behave like extra placements that exist only until the run stops.

Adding characters

Tap the brass + at the bottom of the dock and pick a costume. The new character:

Arranging the stage

While the program is stopped, the stage is in design mode. The selected character is marked with pixel corner brackets.

To…iPadMacSnaps to
Select a characterTap itClick it–
Move itDragDraghalf tiles
Resize itPinchTrackpad pinch, or scroll wheel over it5 %, 25–300 %
Turn itTwo-finger rotateTrackpad rotate, or ⌥-drag around it15°

Pinching and rotating work anywhere on the stage when the selected character has only one placement. Dragging, pinching and rotating the same character at once count as one change for undo.

The character inspector

Tap the selected character’s chip in the dock (or choose Edit character from its menu) to open the inspector. Everything here is disabled while a program runs.

The character inspector over the stage
The inspector: name, costume grid, colour, hearts, weight, body and placements.
SectionWhat it sets
NameUp to 20 characters. The name is shown in target pickers (“When bumping Banana”).
CostumeThe character’s picture (see Costumes).
ColourOne of 8 colour variants of the costume (palette swaps).
Hearts0–10 hearts at the start of each run. The default is 3. The Hearts wagon changes them, and reaching 0 fires When hearts run out.
WeightLight, Normal or Heavy. Light characters fly twice as far when kicked; heavy ones push others around. See Physics.
BodyPhysics: moves, falls with gravity and collides. Fixed: a solid obstacle that never moves by itself. Ghost: floats through other characters but still notices touches.
On stageThe list of placements with their tile positions. Add to stage places another copy on a free tile. The trash removes one; a character always keeps at least one.
Delete characterAfter a confirmation. Not possible for the last character in a project. Trains that pointed at the deleted character (for example When bumping Cat) are repaired by falling back to their default target.

Costumes

There are 22 costumes: round, friendly 32 × 32 pixel creatures and objects, all painted with the same 32-colour palette.

Owl
Cat
Pig
Monkey
Bear
Frog
Cow
Sheep
Hamster
Dog
Parrot
Mouse
Penguin
Dragon
Robot
Ghost
Ball
Banana
Star
Brick
Rocket
Car

Each costume comes in 8 colour variants, made by swapping palette colours at run time. Variant 1 is the original. The Colour wagon switches variants during a run:

1
2
3
4
5
6
7
8

Settings

The gear in the toolbar opens Settings. The stage settings belong to the project and cannot be changed while it runs. The sound and layout settings belong to the device.

The settings popover
Settings: background, walls, gravity at start, music and sound effects.

Backgrounds

Meadow
Space
Desert
Castle
Grid
Dusk

The Grid background shows tile lines, with heavier lines every 4 tiles. It is the best choice for lessons about coordinates.

All settings

SettingScopeEffect
BackgroundprojectOne of the six themes above. New projects use Meadow.
WallsprojectOn by default. Solid edges that characters bounce off, and that the bump and touching wall options detect.
Gravity at startprojectOff by default. Whether gravity is on when ▶ is pressed. The Gravity wagon can change it during the run.
MusicdeviceOn or off. The START theme plays on the home screen, the CODING tracks while you edit and the GAME tracks during a run. A WIN or FAIL jingle plays once when a run ends.
Sound effectsdeviceThe chiptune clacks, bumps and jingles.
Side by side on wide screensdevice, iPad onlyUse the Mac layout (stage and code side by side) instead of swap mode.

Controls during a run

Touch and mouse

The gamepad

When any train uses When a button is pressed, or any condition checks Button held, an 8-bit gamepad appears beside the stage during the run: a d-pad (← → ↑ ↓) and two buttons, red A and orange B. Buttons report both press and release, so programs can tell when a button is held down.

Banana chase running with the gamepad visible
Banana chase running: the d-pad on the left, A and B on the right, and the score tile “A 0” in the corner.

Keyboard (Mac)

KeyActs as
← → ↑ ↓The d-pad
SpaceButton A
Return / EnterButton B
Q / ETilt left / tilt right
⌘R · ⌘.Run · Stop
⌘Z · ⇧⌘ZUndo · Redo

Keys only drive the game while a program runs. Typing into a text field and shortcuts with ⌘, ⌃ or ⌥ pass through normally.

Tilt (iPad)

Tilting the iPad more than 20° to the left or right fires When tilted trains for that side. It must come back within 15° of level before the same side can fire again. Tilt is measured relative to how the screen is currently oriented, so it works the same in any landscape or portrait position.

What the stage shows