TrainsCoding

Samples

The sample projects

Four small projects ship with the app. Each one shows a different idea. Open them from the Samples row on the home screen; you always get a fresh copy to play with.

Bouncy ball

Shows: gravity, walls, fixed obstacles and bump events. Stage: Meadow, walls on, gravity on at start.

A light beach ball falls onto the meadow. Every time it lands on the bottom wall it is kicked back up and changes colour. Two fixed bricks stand in its way, and tapping the ball gives it an extra-big kick.

Ball · light, physics · (8, 12)
Brick · fixed · (4, 5), (12, 5)

Ball

When ▶ pressed
Say“Boing!” · 1 s
Kickright · 3
When bumpingbottom wall
Kickup · 6
Colournext
When tapped
Kickup · 9

Things to notice

Banana chase

Shows: gamepad input, variables and a score, if, win and lose, chasing with point toward. Stage: Grid, walls on, no gravity.

Steer the cat with the arrow keys or the d-pad. Each banana you catch jumps to a random tile and adds a point. Five points wins, but the monkey slowly chases the cat, and if it catches you the game is over.

Cat · ghost · (3, 3)
Banana · ghost · (12, 12)
Monkey · ghost · (13, 3)

Cat: four steering trains (one per arrow), a score keeper and a banana catcher

When button← (and → ↑ ↓)
Moveleft · 1 · fast
When ▶ pressed
SetA = 0
Show variableA · on
When bumpingBanana
ChangeA + 1
Say“Yum!” · 1 s
IfA ≥ 5
then
Win

Banana

When bumpingCat
Go torandom

Monkey

When ▶ pressed
Wait2 s
Forever
forever
Pointtoward Cat
Moveforward · 1 · slow
When bumpingCat
Lose
The monkey's trains in the editor
The monkey’s trains in the editor. The forever loop’s siding runs under an orange canopy.
The monkey's trains during a run
During the run, the forever wagon and the Move wagon on its siding are lit up.

Things to notice

Pen spiral

Shows: loops, a variable that grows, using a variable as a parameter, and the pen. Stage: Space, walls on, no gravity.

The owl draws a blue spiral. On each of 36 passes it adds 0.1 to A, walks A tiles and turns 30° left. The steps get longer, so the path spirals outwards.

Owl · ghost · (8, 8) · 75 %

Owl

When ▶ pressed
Clear pen
SetA = 0
Pen downblue
Repeat36
×36
ChangeA + 0.1
Moveforward · A · fast
Turnleft · 30°
Pen up
Say“Ta-da!” · 2 s
When tapped
Clear pen
Colournext
The owl drawing a blue spiral on the space background
The spiral after a few seconds.
The Pen spiral code during the run
The code during the run, with the mini stage drawing the same spiral.

Things to notice

Ping-pong

Shows: messages between characters, counting, and if/else. Stage: Dusk, walls on, no gravity.

The pig says “Ping!” and sends a red message. The bear spins round, says “Pong!” and sends a blue message back. The pig counts the rallies, and after five it says “I win!” and the run ends with a win.

Pig · fixed · (4, 8)
Bear · fixed · (12, 8) · 180°

Pig

When ▶ pressed
SetA = 0
Show variableA
Say“Ping!” · 1 s
Sendred
When messageblue
ChangeA + 1
IfA ≥ 5
then
Say“I win!” · 2 s
Win
else
Say“Ping!” · 1 s
Sendred

Bear

When messagered
Turnleft · 360°
Say“Pong!” · 1 s
Sendblue

Things to notice