Atari Basic
Programming
Simple game tutorial
This page explains how to create a simple game using Atari Basic 800/XL/XE. For easier reference I have created a listing of the code first following how the program works.
10 GRAPHICS 3
20 X=1:Y=1:C=1
25 COLOR C: PLOT X, Y
26 COLOR 3:PLOT 15,8:DRAWTO 25,8:DRAWTO 25,15:DRAWTO 15,15:DRAWTO 15,8
27 COLOR 0:PLOT 15,11:DRAWTO 15,13
28 COLOR 2:PLOT 20,11
30 J=PEEK(632) 40 COLOR C:PLOT X,Y
50 X1=X:Y1=Y
60 IF J=7 THEN X=X+1:IF X>39 THEN X=39
70 IF J=11 THEN X=X-1:IF X<0 THEN X=0
80 IF J=14 THEN Y=Y-1:IF Y<0 THEN Y=0
90 IF J=13 THEN Y=Y+1:IF Y>19 THEN Y=19
100 IF PEEK(632)=15 THEN COLOR 0:PLOT X1,Y1
200 IF PEEK(632)<>15 THEN COLOR 0:PLOT X1,Y1
210 LOCATE X,Y,COL:IF COL=3 THEN X=X1:Y=Y1 220 IF COL=2 THEN PRINT CHR$(253);”{clear}{inverse}NICE JOB! “:END 300 GOTO 30
Add Your Heading Text Here
10 GRAPHICS 3
This line creates a Graphics mode with a resolution of 40 X 20 including a text window. Graphics modes range from 0-14 (ensuring you have the GTIA chip upgrade).
20 X=1:Y=1:C=1
When plotting a graphics pixel on a screen to keep track of the positioning it is common to create variables fixed to them. The X represents the horizontal starting position and the Y represents the vertical starting position.
The C variable represents the color for the pixel. In this example C=1 is a placeholder for the color “orange” to be explained in the next section.
25 COLOR C: PLOT X,Y
The COLOR C is read as “COLOR 1” since the variable of C was assigned a value of 1.
The PLOT X,Y is read as PLOT 1,1 since the variable of X was assigned a value of 1 and the variable of Y was assigned a value of 1.
26 COLOR 3:PLOT 15,8:DRAWTO 25,8:DRAWTO 25,15: DRAWTO 15,15:DRAWTO 15,8
The next line is used to draw a blue, partial rectangle which will be used to test for a collision. The easiest way to understand this is to look at the following pictures below.
The first picture shows a graph I drew that is 40 pixels across by 20 pixels down (sorry for the bad image).
27 COLOR 0:PLOT 15,11:DRAWTO 15,13
The next line draws over top of the current image at location 15,11 and draws down to 15,13. The COLOR 0 will draw the pixel in the background color. When a pixel is drawn in the “background color” it will erase any pixels in that location.
So this will draw the opening where our player can enter the small rectangle area.
28 COLOR 2:PLOT 20,11
This line will create a green pixel at location 20,11. This is denoted by the “green” block you see below in the center of the rectangle.
PLOT Command
DRAWTO command
Examine the image here and you will see how the rectangle appears with the background colored in. Hopefully this gives you a better understanding of how PLOT and DRAWTO work.
The easiest way to comprehend this is know that a pixel is “plotted” with PLOT and then the area is “drawn to” with DRAWTO. Think of it as starting at one position and drawing a line to the next position
Notice the orange dot in the image. This is where your player position begins at PLOT 1,1 or PLOT X,Y.
Joystick Control
30 J=PEEK(632)
The line above initializes the Atari joystick so that a player can be moved around on the graphics screen. You can also use J=STICK(0) to do the same thing. However using J=PEEK(632) helps to save memory. Saving memory is important since Atari Basic can only hold so much code in memory before you get an error message telling you that the memory is full.
Below is a picture of a typical joystick. These were also originally used on the Atari 2600 system back in the days.
40 COLOR C:PLOT X,Y
This next line will plot our starting joystick position at PLOT 1,1 (the orange pixel in the upper left hand corner).
50 X1=X:Y1=Y
This line will save our X and Y position which will be used to detect a collision later in the demo. It is always important to save the X and Y variable positions before you write the code to move the player (which follows below).
Moving the Player
In the next example, you will learn how the joystick can be used to move the orange pixel around on the screen.
Below I show the code to move the player, it is first important to understand how the joystick works. Take a look at the diagram below.
Joystick Registers
The joystick will return a number based on the direction of where the player moved to. If the player moved up it will return a 14. Down will be 13. If the player moved right it will return a 11. Right will return a 7. The diagonal positions can also be seen in the image below. Finally the value of 15 means that the joystick is in the "idle" position and has not been moved yet.