Use a variable like s
(with
fd s
) to vary the speed of the car.
In the program above, it starts at
s = 0
, but holding the up-arrow changes
it like this:
|
s = 0.0 ⇒ s = 0.1 s = 0.1 ⇒ s = 0.2 s = 0.2 ⇒ s = 0.3 ... s = 2.9 ⇒ s = 3.0 s = 3.0 ⇒ s = 3.0 |
Use else
to do something when an if
does not happen. When you let go of the up-arrow,
the else
runs s = max(s - 0.2, 0)
,
which makes s
go gradually down to zero to slow
down the car.