Programming Course for Beginners - ZedLX

The Easiest Online Computer Programming Course, for Free

Time and Animation [5/9]

Here is a program that moves a ball left and right according to the presses of the arrow keys.

The speed of the ball is the same on any computer running this program, and equals 300 pixels per second.

Run the program and then examine it.

The ball can move outside the screen. Prevent this by adding the following two statements before the disc statement: x = x.atleast(50); x = x.atmost(960-50);

After that, add a new variable y of type num with an initial value of 360 at the beginning of the source code. Then, add a functionality that enables the ball to also move in the up and down direction when the appropriate arrow keys are pressed.

Loading...