1 Fundamentals Of Atari Graphics

Using The COLOR And
LOCATE Instructions To
Program Pong-Type Games

Michael A. Greenspan

Here's the skeleton of a Pong-type game that demonstrates simple Atari playfield graphics. When you grasp the principles, it will be easy to flesh out the program yourself.

New Atari owners may be confused (as I was) about the COLOR and SETCOLOR instructions. These two commands, and the LOCATE instruction, form the basis of the following Pong-type game.

In GRAPHICS 3, there are four color registers labeled 0, 1, 2, and 3, which are accessed by the instruction COLOR X, where X is the number of the register desired. (COLOR 4 is the same as COLOR 0; COLOR 5 is the same as COLOR 1, etc.) While COLOR determines the register used, SETCOLOR enables you to determine which of the 128 colors are used by your chosen register to draw points on the screen. Thus, since the SETCOLOR instructions are identical, the following commands will each put a dark gold point on the screen at location 1,1:

10 GR.3: COLOR 1: SETCOLOR 0, 1, 2: PLOT 1,1
10 GR.3: COLOR 2: SETCOLOR 0, 1, 2: PLOT 1,1

*The SETCOLOR command instructs the computer to set the color of the points on the screen (that's the function of the 0) to color 1 (that's gold) brightness 2. A two for the first number will change the text window to that color. A four will change the background.

Each color register has a different default color that determines the color of the points plotted in that register if no SETCOLOR 0, X,X instruction is given. Therefore, plotting points in different color registers will produce different colors in the absence of SETCOLOR instructions, and identical colors if identical SETCOLOR instructions are used.

In the program below, a ball moves from left to right and a joystick maneuvers a paddle on the far right to intercept the ball. The paddle is plotted in color register 1, and the ball in color register 2. In order to move the ball, it is replotted in color register 4, whose default color is the same as the background color (and thus is invisible), and then replotted on the adjacent square in color register 2.

The LOCATE instruction determines if there is a hit. X and Y are the X and Y coordinates of the ball. LOCATE X + 1, Y, X tells the computer to LOCATE the point to the right of the ball and to store the color register of that point in Z. Since the paddle is plotted in color register 1, Z = 1 means that the ball hit the paddle.

Once you understand the use of COLOR and LOCATE to move the ball and effect a hit, it is a relatively simple matter to add boundaries, two or more paddles, sound, etc. (Of course, the same result can be accomplished by player/missile graphics, but that's an advanced technique tackled later in this book.)

In the program below, A and B are the X and Y coordinates of the paddle. X and Y are the X and Y coordinates of the ball. C relates to random changes in the color of the paddle. S relates to the speed with which the ball moves.

Download P021L1.BAS (Saved BASIC)
Download / View P021L1.LST (Listed BASIC)

Return to Table of Contents | Previous Section | Next Section