10 rem ***************************************************** 20 rem * 30 rem * space war 40 rem * for one or two players on a graphics terminal 50 rem * jobst brandt 60 rem * hewlett-packard 61 rem * (01 apr 82) 65 rem * 66 rem * converted for c64 from the trs-80 mc-10 version 68 rem * by troy morrison 69 rem * (29 mar 2015 80 rem * 90 rem ***************************************************** 100 dim c(46),oa(21,3),s(16,2),e(8,2) 120 rem star locs and size: xmax=720, ymax=360, smax=0, smin=0 130 data 0,0,0,0,10,0,-2,0,0,2,-1,0,3,2,-8,0,-2,-2,-4,0,-4 140 data -2,4,-2,4,0,2,-2,8,0,-3,2,1,0,0,2 145 data -2,6,-2,-6,-6,-2,6,-2,2,-6,2,6,6,2,-6,2 150 fori=1to4:readq(i):next:fori=1to16:forj=1to2:reads(i,j):nextj,i 155 fori=1to8:forj=1to2:reade(i,j):nextj,i 160 gosub 2740:g = r1 170 rem - q contains xlim,ylim(screen),distance,maxsize(stars) 220 m = int (2 * rnd(0) + 1):o = 0 230 n1$ = "9":p$ = "2" 250 gosub 2370 270 print chr$(147); 280 f1 = 0:f2 = 0:f3 = 0:v1$(1) = "20":v1$(2) = "20" 290 print "(";p$;") one or two players? "; 300 input "";a$:p1$ = a$ 310 gosub 2000: on r1 goto 290,290,290,270,290,2980 320 if a$ = "" then a$ = p$ 330 q = val (a$) 340 if q < > 1 and q < > 2 then 290 350 np = q 360 p$ = str$ (np) 370 if np = 2 then 400 380 n$(1) = "player":n$(2) = "enemy" 390 goto 470 400 n$(1) = "spock":n$(2) = "darth": for j = 1 to 2 410 print "("n$(j)") name of captain #";j;" "; 420 input "";a$ 430 p1$ = a$: gosub 2000: on r1 goto 280,440,280,270,280,2980 440 if a$ = "" then 460 450 p1$ = a$: gosub 2610:n$(j) = r1$ 460 next j 470 print "(";n1$;") how many stars? (0 to 18): "; 480 input "";a$ 490 p1$ = a$: gosub 2000: on r1 goto 280,470,470,470,280,2980 500 if a$ = "" then a$ = n1$ 510 n = val (a$) 530 if abs (n) < 0 or abs (n) > 18 then 470 540 n1$ = str$ (n) 550 rem o=black hole 560 o = 0: if n <= 0 then o = 1 570 n = abs (n) 580 q(4) = int (10 - n / 6) 590 q(3) = int (q(2) / 3) - n 600 print chr$(147); 610 rem -------------------- make stars --------------------- 620 n = n + o 630 for i = 1 to n 640 r = 0 650 r = r + 1 660 if r > 20 then i = n + 1: goto 760 670 oa(i,3) = q(4) 680 rem -- j: 1 = xpos, 2 = ypos, 3 = mass/size -- 690 for j = 3 to 1 step - 1 700 oa(i,j) = int ((q(j) - 2 * oa(i,3)) * rnd(0) + oa(i,3)) 710 next j:if i = 1 then 760 720 for j = 1 to i - 1 730 t = (oa(i,3) + oa(j,3) + 10) ^ 2 740 if (oa(i,1) - oa(j,1)) ^ 2 + (oa(i,2) - oa(j,2)) ^ 2 < t then j = i 750 next j:if j > i then 650 760 next i:if r > 20 then print"still thinking...":goto630 770 rem ----------------- place space ships ----------------- 780 rem -- space ship size = 5 -- 790 oa(n + 1,3) = 5:oa(n + 2,3) = 5 800 for j = 1 to 2 810 t = 4 * len (n$(j)): if t < 10 then t = 10 820 if j = 1 then i = .28 * q(1):q = 0: goto 840 830 t = - t:i = - .28 * q(1):q = q(1) 840 r = 0 850 r = r + 1 860 if r > 20 then j = 3: goto 940 870 x = int (i * rnd(0)) + q + t 880 y = int ((q(2) - 30) * rnd(0) + 20) 890 for k = 1 to n 900 if (x - oa(k,1)) ^ 2 + (y - oa(k,2)) ^ 2 < (oa(k,3) * 2) ^ 2 then k = n + 1 910 next k:if k > n + 1 then 850 920 oa(n + j,1) = x 930 oa(n + j,2) = y 940 next j: if j = 4 then 630 950 a1$(1) = "0":a1$(2) = "180" 960 if np > 1 then a$ = n$(1):n$(1) = n$(2):n$(2) = a$ 970 rem -------------------- plot stars --------------------- 980 gosub 4030 990 z1 = 3.14159 * (1 / 180) 1000 for i = 0 to 45 1010 c(i + 1) = cos (i * 10 * z1) 1020 next i 1030 for i = 1 to n - o 1040 for j = 1 to 37 1050 x = int (oa(i,1) + oa(i,3) * c(j) + .5) 1060 y = int (oa(i,2) - oa(i,3) * c(j + 9) + .5) 1070 if j = 1 then x1%=x:y1%=y:gosub 4100 1080 x2%=x:y2%=y:gosub5000 1090 next j 1110 next i 1130 rem ------------------ plot space ships ----------------- 1140 for i = 1 to 2 1150 p1 = oa(n + i,1):p2 = oa(n + i,2):p3$ = n$(i):p4 = i: gosub 2120 1160 next i 1170 if a$(1,1) = "i" then 1450 1180 goto 1210 1190 rem --------------------- play game --------------------- 1200 m = m - int (m / 2) * 2 + 1 1210 if np = 1 then m = 1 1220 poke 53280,0 1240 get a$:if a$ = "" then 1240 1242 gosub 4050:poke 53280,14 1245 print "(" + a1$(m) + ") ";n$(m);"'s, launch angle: "; 1250 b = 20:f1 = 1 1260 input "";a$ 1270 if a$ = "" then a$ = a1$(m) 1280 p1$ = a$: gosub 2000: on r1 goto 1245,980,1245,270,1245,2980 1290 a = val (a$) 1300 a = - sgn (a) * ( abs (a) - int ( abs (a) / 360) * 360) 1310 a1$(m) = str$ ( - a) 1320 if n = 0 then 1450 1330 rem locate 23,26 1340 print "(";v1$(m);") ";n$(m);"'s initial velocity: "; 1350 input "";a$ 1360 if a$ = "" then a$ = v1$(m) 1370 p1$ = a$: gosub 2000: on r1 goto 1245,980,1330,270,1245,2980 1380 b = val (a$) 1390 if b > = 0 and b < = 20 then 1420 1400 print "velocity must be from 0 to 20" 1410 goto 1330 1420 v1$(m) = str$ (b) 1450 u1 = 0:u2 = 0:v1 = 0:v2 = 0:f3 = 0 1460 x=.35 * b * cos (a * z1) 1470 y=.35 * b * sin (a * z1) 1480 u=x + oa(n + m,1) + 8 * cos (a * z1) 1490 v=y + oa(n + m,2) + 8 * sin (a * z1) 1500 p1 = u:p2 = v: gosub 2230 1510 if f2 then 1570 1520 rem ----------------- draw rocket path ------------------ 1525 gosub 4000 1530 u1=int(u+.5):v1=int(v+.5) 1540 if u1<>u2 or v1<>v2 then p1=u1:p2=v1:gosub 2290 1550 u2 = u1:v2 = v1 1560 rem -- e = xforce, f = yforce -- 1570 e = 0:f = 0 1580 for j = 1 to n 1590 r5=oa(j,1)-u 1600 r6=oa(j,2)-v 1610 r4=r5^2+r6^2 1620 r3=sqr(r4) 1630 r2=r5/r3 1640 r1=r6/r3 1650 g=.017*(oa(j,3)^3)/r4 1660 e=e+g*r2 1670 f=f+g*r1 1680 next j 1690 x=x+e 1700 y=y+f 1710 u=u+x 1720 v=v+y 1730 rem ------------------ find collisions ------------------ 1740 if f2 then 1790 1750 rj=0:forj=1ton+2 1755 ifj=n+1then1780 1760 ifoandj=nthen1780 1770 if(u-oa(j,1))^2+(v-oa(j,2))^2q(1)*2orv<-q(2)orv>q(2)*2then1200 1800 f2=(u<0oru>q(1)orv<0orv>q(2)) 1810 rem -- f2=f3 (no change............) -- 1820 rem -- f2=1 (just went off screen.) -- 1830 rem -- f3=1 (just came onto screen) -- 1840 if f2 = f3 then 1510 1850 if f3 then p1 = u:p2 = v: gosub 2230 1860 f3 = f2 1870 goto 1510 1880 rem ------------------ make explosions ------------------ 1890 p1 = u + 2:p2 = v + 2: gosub 2230 1900 for i = 1 to 8:p1 = e(i,1):p2 = e(i,2): gosub 2250: next 1910 if j < = n then 1200 1920 rem locate 23,16 1925 poke 53280,0 1926 get a$:if a$="" then 1926 1927 gosub 4050:poke 53280,14 1930 print n$(m);" destroyed ";n$(j - n);"'s ship!" 1940 print " (y) again? : "; 1950 input "";a$ 1970 if mid$ (a$,1,2) = "//" then 2980 1980 a$=left$(a$,1):if a$="d" or a$="i" or a$="d" or a$="i" then 980 1985 if a$="n" or a$="e" or a$="n" or a$="e" then 2980 1990 goto 270 2000 rem ******************* input ******************* fnc *** 2010 p1$ = left$ (p1$,1) 2060 if p1$ = "" then r1 = 0: return 2061 p = 7 2062 p = p - 1: if p = 0 then 2100 2063 if mid$ ("bdhs/e",p,1) = p1$ then 2080 2064 goto 2062 2080 if mid$ (a$,1,2) = "//" then p = 6 2090 if p = 3 then gosub 2370 2100 r1 = p: return 2120 rem **************** make ships ***************** fns *** 2140 s = (p4 - 1) * 2 - 1 2150 gosub 2230 2160 for k = 1 to 16:p1 = s(k,1) * s:p2 = s(k,2): gosub 2250: next 2210 return 2230 rem ***************** g cursor ****************** fng$ ** 2240 cx = p1:cy = p2: return 2250 rem ***************** draw line ************************* 2260 ifcx<0orcx>q(1)orcy<0orcy>q(2)then2270 2261 ifcx+p1<0orcx+p1>q(1)orcy+p2<0orcy+p2>q(2)then2270 2265 x1%=cx:y1%=cy:x2%=cx+p1:y2%=cy+p2:gosub5000 2270 cx = cx + p1:cy = cy + p2 2280 return 2290 ifcx<0orcx>q(1)orcy<0orcy>q(2)orp1<0orp1>q(1)orp2<0orp2>q(2)then2300 2295 x1%=cx:y1%=cy:x2%=p1:y2%=p2:gosub5000 2300 cx = p1:cy = p2: return 2370 rem ******************* help ******************** fnh *** 2410 gosub4050:print chr$(147); 2420 print "space war ";d$: rem locate 7,1 2430 print tab( 6);" commands:": print 2440 print tab( 6);" h = help" 2450 print tab( 6);" s = start" 2460 print tab( 6);" d = display" 2470 print tab( 6);" i = instant replay after hit" 2480 print tab( 6);" / or b = back" 2490 print tab( 6);"// or e = exit": rem locate 17,17 2500 print "negative number of stars gives":print "a black hole" 2510 print "(y) are you ready to play? (y/n): "; 2520 input "";a$ 2530 a$=left$(a$,2):ifa$>""thena=asc(a$):a$=chr$(a-32*(a>96anda<123))+mid$(a$,2) 2540 if a$="n" or a$="e" or a$="//" then 2580 2550 if a$="h" then 2410 2560 return 2580 print chr$(147); 2590 end 2610 rem ************** function downshift *********** fns$ ** 2640 m = 0: if p1$ = "" then return 2650 for i = 1 to len (p1$) 2660 k = asc ( mid$ (p1$,i,1)) 2670 if k = 32 then m = 0 2680 if k < 65 or k > 91 then 2710 2690 if m then p1$ = mid$ (p1$,1,i - 1) + chr$ (k + 32) + mid$ (p1$,i + 1) 2700 m = 1 2710 next i 2720 r1$ = p1$: return 2740 rem *********** poll terminal capability ******** fni *** 2750 r1=1:q(1)=320:q(2)=200 2760 return 2970 rem ******************** exit *************************** 2980 if g then gosub 4050 2990 print chr$(147); 3000 end 4000 rem ************************* c64 routines ***************************** 4010 rem -- set graphics mode 4020 gb=2:poke 56576,gb:rem select vic-ii bank 1 4021 sb=7:mb=1:poke 53272,sb*16+mb*8:rem select screen block 7, bitmap block 1 4022 gm=49152-gb*16384:sm=gm+sb*1024:mm=gm+mb*8192:rem set addresses 4023 poke 53265,peek(53265)or 32 4024 fori=0to7:tp(i)=2^i:next 4025 return 4028 rem -- clear graphics screen 4030 gosub 4000:oe=16:ze=0 4032 for i=sm to sm+1000:poke i,oe:next:rem set colors 4035 for i=mm to mm+8191:poke i,ze:next:rem clear bitmap 4038 sv=7:ei=8:tt=320 4040 return 4050 rem -- set text mode 4051 poke 56576,151:rem select bank 0 4052 poke 53272,23:rem select screen block and bitmap block 4060 poke 53265,peek(53265) and 223:rem turn off bitmap mode 4070 return 4100 rem -- plot a point 4105 ifx%<0orx%>320ory%<0ory%>200thenreturn 4110 row=int(y%/ei):char=int(x%/ei) 4120 line=y% and sv:bit=sv-(x% and sv) 4130 byte=mm+row*tt+char*ei+line 4140 poke byte,peek(byte)or tp(bit) 4150 return 5000 rem -- draw a line 5010 rem inputs in x1%, y1%, x2%, y2%; destroys x1,y1 5020 dx%=abs(x2%-x1%):sx%=-1:if x1%=dy% then er=dx% 5050 er=int(er/2) 5060 x%=x1%:y%=y1%:gosub 4100 5070 if x1%=x2% and y1%=y2% then return 5080 e2=er 5090 if e2>-dx% then er=er-dy%:x1%=x1%+sx% 5100 if e2