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!
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!
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))
X
,
Y
, R
), whether a missile is in flight
(B
), and the missile's position (BX
,
BY
) and speed/trajectory (BXM
, BYM
),
and the pre-calculated cosine and sine values (CS
,
SN
)
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
B
)
30 FOR I=0 TO 35:CS(I)=COS(I*10):SN(I)=SIN(I*10):NEXT I
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
OA
- current player's position around the planet (angle)
XM
and YM
- cosine and negative-sine of that
angle, times 3
R
- radius of the player's planet, plus 2
X
and Y
- on-screen position of the
player's position around the planet
Q
)
S
)
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
X-XM
,Y-YM
; stored in C
)
S=0
), and their missile
is not in flight (B(I)=0
)...
XM
and YM
were set to cosine/negative-size times three)
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
BX
and BY
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
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
CR
)
OA
)
XM
, YM
)
R
)
X
, Y
)
XM
and YM
by three, so they can
be used for both looking below the gun to see if the surface is still
intact, and to set the initial speed of a missile (both on line 105)
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
BXM
) and vertical
(BYM
) speed and direction (positive/negative) based
on how far away the planet is, scaled by the planet's radius
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
CIRCLE
can't
draw a point, it seems)
Z
)...
DOS.SYS
, DUP.SYS
)
TBASIC.AR0
)
AUTORUN.BAS
;
except for the filename , same as PLANETS.TBS
stand-alone file, above)
Bill Kendrick, 2014,
nbs@sonic.net,
New Breed Software
Other games I wrote for NOMAM 2014