# Timers and games

`every(seconds, action)` runs an action again and again and gives back a timer; `stop(timer)` ends
it. A game is a step function that `every` runs about 30 times a second.

```vi
ball_y = 10
speed = 0
loop = 0

step():
  speed = speed + 0.3
  ball_y = ball_y + speed
  if (ball_y > 90):
    ball_y = 90
    speed = 0 - speed * 0.7

drop():
  stop(loop)
  ball_y = 10
  speed = 0
  loop = every(0.03 seconds, step())

main court:
  color: slate[900]
  on_touch: drop()
  children:
    ball:
      place: 50, ball_y
      size: 10
      shape: circle
      color: orange[400]
    hint:
      place: 50, 96
      text: "Tap to drop the ball"
      text_style: 14, white
```

- `place: x, y` puts a container's middle at x across and y down, out of 100. Change x and y in
  the step function and it moves.
- `on_touch` reacts the moment a finger lands: better than `on_tap` for "tap to jump".
- `on_hit` notices when two containers start to overlap:

```vi fragment
main field:
  on_hit:
    ball, wall: bounce()
    ball, goal:
      score()
      play(@cheer.mp3)
```

- `flip: 180` turns a container over (a card flip) and `tilt: 20` leans it back, in degrees.
- Edit the code while a game runs and the old timers stop by themselves.

The **Comet Glide** template is a whole game built this way.
