How to Invent a Game, Part 2

See all articles from SYNC v2 n2

In Part 1, we covered the conception and initial game design of Flattop Lander, and we examined the Machine Code subroutine that will produce an instant display.

To finish up the display, let’s put the carrier characters into the storage line (2 REM) using the MC-input routine:

100 FOR X=16486 TO 16493
110 INPUT Y
120 POKE X,Y
130 PRINT PEEK(X),
140 NEXT X

GO TO 100 and enter these 8 character codes: 134,128,128,128,128,128,128, and 135. At this point, the display is complete with aircraft carrier and ocean surface, so, if you have entered lines 1, 2, and 40, and lines 90-180, you can GOTO 40 to check it.

The variable “C”(Change in direction) was initialized at “9” in line 40 and is added to “P”(Position/address of display in RAM) to put the aircraft in its initial position in the upper left corner of the display “block.” Now, we need an input routine to enable the player to move the aircraft in any forward direction.

In Part 1, the “3D” input matrix was explained, so that 7 means “straight ahead—no turn,” etc. See Figure 1.

Figure 1.

  1 | 2 | 3     = "UP"
 ---+---+---
  4 | 5 | 6
 ---+---+---
  7 | 8 | 9     = "DOWN"

"LEFT"   "RIGHT"

Since the display is 32 spaces wide, dropping one row means having to add 33 to the last aircraft position/address(“C”), while rising one row means “C” must be decremented by 33. Taking that “vertical” (and “L” for horizontal) movement into account, we have the finished input routine shown in Figure 2.

Figure 2.

250 INPUT M                         :Enter 0-9.
260 IF M=0 THEN GOTO 30 :"Reset" for a new approach.
270 IF M>6 THEN LET C=C+33 :Drop down 1 row.
280 IF M<4 THEN LET C=C-33 :Rise up 1 row.
290 IF M=3 OR M=6 OR M=9 THEN LET L=L+1
:To move right to get on approach
line.
300 IF M=1 OR M=4 OR M=7 THEN LET L=L-1
:To move left.
310 LET C=C+1 :This aircraft flies forward only.
320 LET D=D-50 :Distance decrementer.
330 LET H=400-((C-9)/33)*100 :Height decrementer.
340 GOTO 80 :For the game's ""loop."

So far, the game is not particularly challenging…input a move and the aircraft moves. Big deal. What all games need is an element of chance, so let us add some computer-generated “Lady Luck” to simulate wind or ship movements. See Figure 3.

Figure 3.

30 RANDOMISE
70 LET L=0 :Initialize "L" (approach line).
80 LET L=L+RND(3)-2 :"L" plus -1, 0, or +1.

Next we need some test lines for display output to simulate the deck flagman or instruments. See Figure 4.

Figure 4.

190 PRINT H,D                       :Show height and distance to
catchcable.
200 IF L<0 THEN PRINT ">" :"Move right to get on approach
line."
210 IF L>0 THEN PRINT "<" :"Move left."
220 IF L=0 THEN PRINT "X" :"On line."

Okay, now we have a loop that accomplishes both input and display. Lines 250-340 recalculate the variables, and lines 70-220 produce the display from those variables. But, it is still not a true game without a scoring mechanism or at least a win/lose test. By limiting the display area in the design stage, we have enough RAM left to include both. See Figure 5.

Figure 5.

 20 LET S=0                         :Initialize Score.
230 IF D=0 AND H=0 AND L=0 THEN GOTO 500
:Test for safe landing to exit
loop.
240 IF C>161 THEN GOTO 400 :Test for a crash.
400 PRINT "*CRASH*"
410 POKE P+C,59 :Show explosion CHR$(59).
420 LET S=0 :Take away player's points for
crashing.
430 GOTO 510 :Skip over "win."
500 LET S=S+1 :Increment score.
510 PRINT "SCORE=";S
520 INPUT X :Enter any number to continue or
530 IF X=0 THEN STOP :"0" to STOP.
540 GOTO 30 :"Reset" to initial aircraft
position.

After winning another point or losing everything, a player needs to be asked if he wants to continue, hence, lines 520-540. They are terse because, at this point, the program is very close to filling up the 1024 bytes in 1K RAM. To make this “endgame” routine even shorter, line 530 can be omitted, but the player must then enter an unused variable name to make the program stop (on error code 2).

After hours of thinking and planning and typing-in statements, the program is finally complete…or is it? If run as is, it will stop on error code 2/190 even before asking for the first move. By checking line 190 (PRINT H,D), it is apparent that we have not named either variable, yet. So:

50 LET H=400
60 LET D=1000

Line 50 shows the height above deck, and 60, the distance to the catchcable on deck.

Now the program will run as planned and within 1K of RAM.

Inventing a computer game is a reciprocal, creative process—while you are developing the game from first idea to finished program, the game is developing you.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.