The process of writing a video game can be an exciting and challenging proposition. Not only is it necessary to develop an idea but one must also program a computer to execute the commands. This article will describe the process of translating ideas into a working Atari program. Tic-Tac-Toe was chosen so that the process could be explained as simple as possible.
Tic-Tac-Snack is a simplified version of Tic-Tac-Toe. There is one minor change: the traditional X and 0 are replaced with an apple and chocolate chip cookie.
Each player types the number of the square he wishes the apple or cookie placed into. The player's number and symbol name (our apple or cookie) appear in the text window indicating whose turn it is. If a player chooses a box that is already occupied, the computer will ask him to choose again. Three things occur at the end of a game: the players' score is shown; a running total of games played is displayed; and the players are given the opportunity to begin a new game.
Beginning Your Program
The first step in writing any program is to organize your ideas. Few people enjoy the tedium of flow charting, but it is an integral part of program design. Some people are talented enough to program from "scratch," but I have found that time set aside for planning and organizing can easily save hours of work.
Whether you write an outline, a detailed flow chart, or a list of modules, organizing your program will help the flow of your program and will also simplify debugging it. Good organization also makes it much easier to change your program with a minimum of hassle.
Now, let's talk about Tic-Tac-Snack. I wanted to write a Tic-Tac-Toe game but wanted to use something a little less drab than the traditional X's and O's. To show off the Atari's graphics and colors, I decided to substitute apples and cookies. Everything else about Tic-Tac-Toe remains the same.
Here is a list of the modules needed to -- or sections to -- create Tic-Tac-Snack:
2) Title screen
3) Draw blank board
4) Draw individual apple or cookie
5) Have simple, one-key input from keyboard
6) Place correct figure in blank box
7) Check for correct input and keep score of results
8) Check after every input and see if game is over
9) Design end screen over and ask for re-play
10) Program appropriate sounds.
By listing the program objectives, the problems I would have to solve in order for Tic-Tac-Snack to work are clarified. By visualizing the end product, I could begin programing the individual modules. Remember, the solutions to each of these problems represent my programing approach. Yours may be entirely different, yet just as functional.
A Closer Look
Lines 1 thru 4 create the original screen which contain the title and the simple sound effect of munching. By checking the console keys the game can begin with a simple press of the start button.
After this is done, the program prints a short screen message and then initializes all the variables and reads in the machine-language subroutines that will be used to draw the board, apple and cookie.
While images could have been plotted and drawn to in the Graphics 7 mode, I felt that that process would be too slow. Instead, I used a public-domain utility to draw rectangles of different colors and another utility to flip the images using string data. These machine-language routines are placed in strings I1$ for the first image and I2$ for the second image. The routine for flipping the images is in E$ and the rectangle routine is in R$. (These routines are between lines 50 and 865.)
The rectangle routine uses a USR with the following conditions: (R, Y, X, width, height, color) R is the address of the string R$; Y and X are the starting screen coordinates; width and height are how many bytes of data you wish to draw; and color is one of the four colors in Graphics 7. The numbers 0, 85, 170, and 255 provide a solid color while any other number to 255 will create a stripe effect.
The routine to flip the images is similar. The condition is USR(E,X,Y,I) where E is the address of string E$, followed by the upper left-hand coordinates of the box of data to be flipped. This routine will flip a box of data 5 bytes wide (20 pixels) by 12 lines high. (This requires 60 bytes of data per image.) I is the address of the String I1$ and I2$ which are the images for the apple and the cookie. Use the same type of color data numbers that were used in the rectangle routine for solid colors or stripes.
Up to this point, we've created the title screen and have pinned down a couple of graphic routines. The next step is to open the keyboard for input and set the background color to black (poke 710,0) and turn off the cursor (poke 752,1) in lines 10 thru 45.
You may have noticed that Tic-Tac-Snack jumps through several of the routines. The reason is that the for-next loops execute faster at the beginning of a program. Starting the main loop at line 2200 will give more area to work with as the rest of the logic for this program is developed.
At line 2200 the main loop starts. From here, the program returns to line 900 and the rectangle routine draws all the squares. The colors of the borders and background are changed as well. Starting at line 954 the numbers of the boxes are plotted and drawn. Then a quick check is implemented to see if any boxes contain a previous input. If so, that box is filled with the correct symbol and the next box is checked. After each square has been checked the program returns to the main loop.
The current player is given an option of which square he wishes to fill. After his input, a check is made to see if that box is already occupied and whether the key pressed is between 1 and 9. Assuming that the square selected was unoccupied, the correct symbol is flipped to the screen with a calculation that jumps the program to the correct line between 1000 and 1109 (which draws the symbol on the screen). Next there is a check to see if a winning combination is present. If not, the square chosen is also placed in an array for future checking to determine which squares remain open for use. The player number is changed to the opponent and the main loop starts again.
When a correct combination is found, or when all the squares are occupied, a message is printed to the screen and a sound is executed. This is followed by a new screen which shows the total score between the two opponents. A choice is also given to start again, change players or quit.
As you can see, once the decisions were made on how to flip the apples and cookies, it became very easy to program the remaining logic. Again, the importance of flow charting beforehand cannot be over emphasized!
How you go about the individual steps of programming each line and which techniques you use will depend on your background and creativity. There are numerous ways of producing screen colors, but it will be your decision to choose one method that successfully fits in with the other elements of your program.
Finally, it's important to realize that you can only design what you are capable of programming. Once one programmer demonstrated the Space Invaders graphics technique, many other programmers experimented until they too could do the same; and some even improved on the original. Remember, your Atari will only do what you program it to do. Your Atari does not know its own limitations: the limitations are your own. By reading, examining, and experimenting, you can develop new and exiting combinations of programming techniques.
Now for that graphic adventure game. . .
Duane Tutaj is a contributing writer living in Addison, Illinois.
Listing: TICTAC.BAS Download