Monday, 4 February 2019

"Chopper" for Homeputerium BASIC 10-Liners Programming Contest 2019

This year for the Homeputerium Basic 10-Liner Contest I decided to try to create a simple version of Choplifter, which is a classic game that appeared on most of 8-bit computers (VIC, C64, Atari, Apple).  This is a pic of the Apple II version:
The game has a simple premise. Fly the chopper from left to right.  The landscape scrolls as you go.  Tanks and other threats appear to shoot you down. You must land to rescue the fleeing people. They will run to your chopper and climb in when you set down. Return to base for fuel and to offload.

Obviously despite the simple premise, it would still be too complex to have scrolling, running people,  homing attacks from attacking enemies and base interactions. But I thought, maybe I could at least have a chopper picking up people on a static screen, while avoiding random shots from two randomly moving tanks.

It worked. Some nice features presented themselves almost by chance.

The logic imposed by so few lines meant that I had to reuse the routine that prevents the helicopter from moving down below ground level by automatically reversing the chopper up one space if it goes too low. This is also a part of the random placement of soldiers routine. The occasional random motion upwards even if it is not near the ground gives the chopper a kind of buoyant feel, which I think adds something to the verisimilitude of its flight characteristics. This routine also gets used when you set down on top soldiers to pick them up. So setting down triggers new random placements of soldiers. I thought this was a bug, but I think it turned out to be a feature. It's kind of like in the original game when the soldiers come running when you touch down. It is mitigated somewhat by several factors. The tanks are continuously randomly "rolling over" many of the hapless soldiers who appear and the animation blanking routine of the chopper erases three spaces immediately below the chopper so you can only pick up one soldier at a time. The others get blown away by your powerful propeller. So be careful when and where to set down!

The shots moving in opposite directions can be challenging. Especially since they can screen wrap from the left and right side of the screen. You really have maintain global awareness of where the tanks are and plan your moves across the lines of fire very carefully. The speed of shots is pretty quick because the only check is whether a space is non blank (not black character 128). The line across the top stops all shots from going further and the single check jumps to a routine that determines if what was hit was the ceiling line, which simply triggers the next shot from the relevant tank, or the game over routine.

Random seed peek, initialization of main variables, poke lines top (blue block 175) and bottom (red block 191)
0 CLS:DIMK(255):M=RND(-(PEEK(9)*256+PEEK(10))):M=16384:T=416:P=T-32:R=T+16+RND(8):Q=R-29:H=0:V=128:L=10:K(65)=-1:G=32:GOTO9
1 K(83)=1:K(87)=-G:K(90)=G:K(74)=-1:K(76)=1:K(73)=-G:K(75)=G:CLS0:FORC=0TO31:POKEM+C,175:POKEM+C+480,191:NEXT:H=112:I=-33:J=-31

Beginning of Main Loop.  Print and move both tanks randomly.  Each tank has blank/black characters on it left and right sides of it, so it erases the left or right edges of itself as it moves in either direction.  Move shots and check if hit anything.  If so jump to hit routines at line 7 or 8.
2 ?@T,"€€‚€€";:?@T+G,"€„ˆ€";:T=T+2-RND(3):T=T-(T<416)+(T>441):?@P,"€";:P=P+I:ON-(PEEK(M+P)<>V)GOTO7:PRINT@P,"Ã";
3 ?@R,"€€Ž€";:?@R+G,"€„ˆ€";:R=R+2-RND(3):R=R-(R<416)+(R>441):?@Q,"€";:Q=Q+J:ON-(PEEK(M+Q)<>V)GOTO8:PRINT@Q,"Ã";

Blank helicopter's last location. Check for key input and then move by adding or subtracting appropriate amount from location based on key input and direction value stored in array for keys.
4 ?@H,"€€€€";:?@H+G,"€€€€";:H=H+K(PEEK(2)ANDPEEK(17023)):IFH>63ANDH<413THEN?@H,"‘˜‘˜";:?@H+G,"˜Ÿ˜€";:IFRND(L)>1THEN2

Randomly place new soldiers/and or check if too low or if soldier is immediately beneath chopper and jump to appropriate subroutines
5 IFH<64THENH=H+G:?@H,"‘˜‘˜";:?@H+G,"˜Ÿ˜€";:GOTO2
6 POKERND(28)+448+M,30:H=H-G:?@H,"‘˜‘˜";:?@H+G,"˜Ÿ˜€";:C=-(PEEK(H+M+65)<>30):?@H+64,"€€€€";:ONCGOTO2:SOUND183,1:SC=SC+1:GOTO2

Subroutines for shot hits.  Chopper?  Or ceiling?  If chopper (character<161) then jump to game over routine at line 9. Otherwise, must be ceiling so restart shot from tank's current location and go back to main loop.  
8 ON-(PEEK(M+Q)<161)GOTO9:Q=R-29:PRINT@Q,"Ã";:GOTO4

Game over routine.

Remarks with instructions
10 REM USE awsz OR ijkl
13 REM FOR TRS-80 MC-10

The game can be played in the MC-10 Javscript emulator hosted at my faculty website at Cape Breton University:

Just click on the "- Select Cassette -" menu and choose "CHOPPER". Then type RUN and hit the <ENTER> key. Use IJKL keys to move. Avoid being hit land your chopper on top of the up arrows (men) that appear at the bottom of the screen.  Landing when no men are around will make some appear.

No comments:

Post a Comment