Learn to Program with ZedLX

Free Online Programming Course for Beginners

The type vector2D [9/11]

This program allows a user to move a ball with a keyboard. The movement is accomplished by using vector calculations.
[Run the program]

The vector velocity represents the balls's speed and direction. The velocity is modified by pressing the arrow keys.

The point position represents the balls's current position.

The program is very similar to the program on the previous page, except that the code for keyboard key presses has been inserted into the main loop.

Exercise:

In the source code, uncomment the line for printing the point position on the display.

Loading...