Planets

A 10-line TurboBASIC XL program for the Atari 8-bit computer
Written for 2014 NOMAM programming competition

Bill Kendrick, February 16, 2014

An entry for the NOMAM 2014 10-line TurboBASIC XL game competition.


Objective

When the game begins, two randomly-sized planets appear at random spots on the left and right halves of the screen. Each player uses a joystick to control a gun on the planet; push left and right to rotate around the surface. Pressing fire launches a missile (each player may have only one missile in flight at a time. Good old fashioned arbitary limits!)

When a missile strikes, a circular chunk of planet is removed. If a missile hits near the center of a planet, that planet explodes, the player on the other planet wins, and the game ends. (A new game starts automatically.) Yes, you can fire upon your own planet. You might do this accidentally while trying a slingshot maneuvor, or if your planet is quite large, and pulls your missile back towards you before hitting your opponent's!

Your gun cannot remain over a hole on the surface. In fact, if there's no ground on either side of your gun, either, you won't be able to move much at all!


Development

I wanted to create a game that used rotation, with the goal of pre-calculating sine and cosine for for enhanced speed. My older son had been playing a ton of "Angry Birds: Space" on our Roku, and decided to make a artillery game where the players are on the surface of planets, firing at each other. Both planets' gravity affect the missiles' trajectories.

This game was fairly hard to squeeze down to 10 lines; it hovered at 11 lines for quite a while, until I started having subroutines do work, and determined that "END." in TurboBASIC XL is short for "ENDIF", allowing me to squeeze in a few more precious characters on some lines. You'll notice line 30 is short, but there's nowhere else to put it; it's a one-time set-up routine!


Line-by-line Breakdown of the Source Code

Set-up

10 DEG :GRAPHICS 23:DIM X(2),Y(2),R(2),A(2),B(2),BX(2),BY(2),BXM(2),BYM(2),CS(36),SN(36):FOR I=0 TO 1:X(I)=ABS(160*I-30-RAND(20))
20 Y(I)=28+RAND(40):R(I)=15+RAND(10):COLOR I+1:CIRCLE X(I),Y(I),R(I):PAINT X(I),Y(I):B(I)=0:A(I)=I*18:NEXT I
30 FOR I=0 TO 35:CS(I)=COS(I*10):SN(I)=SIN(I*10):NEXT I

Main loop

100 TRAP 100:FOR I=0 TO 1:CR=0:GOSUB 1000:Q=OA:S=STICK(I)*STRIG(I):IF S=11:A(I)=(A(I)+1) MOD 36:ENDIF :IF S=7 THEN A(I)=(A(I)+35) MOD 36
105 CR=I+1:GOSUB 1000:LOCATE X-XM,Y-YM,C:IF C=0:A(I)=Q:ENDIF :IF S+B(I)=0 THEN B(I)=100:BX(I)=X:BY(I)=Y:BXM(I)=XM:BYM(I)=YM
110 IF B(I):B(I)=B(I)-1:COLOR 0:PLOT BX(I),BY(I):BX(I)=BX(I)+BXM(I):BY(I)=BY(I)+BYM(I):BX=BX(I):BY=BY(I):LOCATE BX,BY,C:IF C
120 B(I)=0:FOR J=0 TO 5:CIRCLE BX,BY,J:NEXT J:GOSUB 4000:ENDIF :IF B(I):COLOR I+1:PLOT BX,BY:GOSUB 3000:ENDIF :ENDIF :NEXT I:GOTO 100

Subroutines

Draw the player's gun on the surface of the planet

1000 COLOR CR:OA=A(I):XM=CS(OA):YM=-SN(OA):R=R(I)+2:X=X(I)+XM*R:Y=Y(I)+YM*R:PLOT X,Y:XM=XM*3:YM=YM*3:RETURN

Affect a missile's speed and trajectory based on the positions and sizes of the planets

3000 FOR J=0 TO 1:BXM(I)=BXM(I)-(BX(I)-X(J))/(500-R(J)):BYM(I)=BYM(I)-(BY(I)-Y(J))/(500-R(J)):NEXT J:RETURN

Erase missile after collision, and check for hitting center of planet (and do game-over, if so)

4000 PLOT BX,BY:FOR J=0 TO 1:IF ABS(BX-X(J))+ABS(BY-Y(J))<=5:FOR Z=0 TO 255:POKE 708+J,255-Z:SOUND 0,Z,4,Z/16:NEXT Z:RUN :ENDIF :NEXT J:RETURN

Download


Bill Kendrick, 2014, nbs@sonic.net, New Breed Software
Other games I wrote for NOMAM 2014