-
Notifications
You must be signed in to change notification settings - Fork 0
/
spacewar_bas.txt
177 lines (177 loc) · 7.55 KB
/
spacewar_bas.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
1 rem ************************************************************
2 rem ** spacewar by jobst brandt (1/4/82) **
3 rem ** commodore 128 port by marek karcz (3/31/2015) **
4 rem ** based heavily on bbc micro port by /u/to3m (3/23/2015) **
5 rem ** for basic week challenge by chris osborn on reddit **
6 rem ** note: requires dual monitor 80/40 column **
7 rem ************************************************************
9 rem
30 pi=3.14159265358979:d$="3/31/15":dim oa(21,3),q(4),v1$(2),n$(2),a1$(2)
40 data 10,0,-2,0,0,2,-1,0,3,2,-8,0,-2,-2,-4,0,-4,-2,4,-2,4,0,2,-2,8,0,-3,2,1,0,0,2
50 data -2,6,-2,-6,-6,-2,6,-2,2,-6,2,6,6,2,-6,2
55 graphic clr
60 gosub 1440:gosub 1400:g=r1:m=int(2*rnd(0)+1):o=0:n1$="9":p$="2":gosub 1230
65 gosub 1540
70 graphic 5:gosub 1440:scnclr
80 f1=0:f2=0:f3=0:v1$(1)="20":v1$(2)="20"
90 a$=p$:co=21:ro=1:gosub 1550:print "(";p$;") one or two players? ";:input a$:p1$=a$:gosub 1070:if r1<>0 then on r1 goto 90,90,90,70,90,1430
100 if a$="" then a$=p$
110 q=val(a$):if q<>1 and q<>2 then 90
120 np=q:p$=str$(np):if np=2 then 140
130 n$(1)="player":n$(2)="enemy":goto180
140 n$(1)="Spock":n$(2)="Darth":for j=1 to 2:a$=n$(j):co=21:ro=1:gosub 1550:print "(";n$(j);") name of captain #";j;" ":input a$:p1$=a$:gosub 1070
145 if r1<>0 then on r1 goto 80,150,80,70,80,1430
150 if a$="" then 170
160 p1$=a$:gosub 1330:n$(j)=r1$
170 next j
180 a$=n1$:co=21:ro=1:gosub 1550:print "(";n1$;") how many stars? (0 to 18): ";:input a$:p1$=a$:gosub 1070:if r1<>0 then on r1 goto 80,180,180,180,80,1430
190 if a$="" then a$=n1$
200 n=val(a$):if abs(n)<0 or abs(n)>18 then 180
210 n1$=str$(n)
220 rem
230 o=0:if n<0 then o=1
240 n=abs(n):q(4)=int(10-n/6):q(3)=int(q(2)/3)-n
250 scnclr
260 rem *** make stars ***
270 n=n+o
280 ri=0:for i=1 to n
290 r=0
300 r=r+1:rj=0
310 if r>20 then ri=1:i=n+1:goto 410
320 oa(i,3)=q(4)
330 rem *** j: 1 = xpos, 2 = ypos, 3 = mass/size ***
340 for j=3 to 1 step -1
350 oa(i,j)=int((q(j)-2*oa(i,3))*rnd(0)+oa(i,3))
360 next j
370 for j=1 to i-1:if j>i-1 then 400
380 t=(oa(i,3)+oa(j,3)+10)^2
390 if (oa(i,1)-oa(j,1))^2+(oa(i,2)-oa(j,2))^2<t then j=i:rj=1
400 next j:if rj then 300
410 next i:if ri then 280
420 rem
430 rem *** place space ships ***
440 oa(n+1,3)=10:oa(n+2,3)=10:for j=1 to 2:t=4*len(n$(j)):if t<10 then t=10
450 if j=1 then i=0.28*q(1):q=0:goto 470
460 t=-t:i=-0.28*q(1):q=q(1)
470 r=0
480 r=r+1:rk=0:if r>20 then j=3:rj=1:goto 520
490 x=int(i*rnd(0))+q+t:y=int((q(2)-30)*rnd(0)+20):for k=1 to n:if (x-oa(k,1))^2+(y-oa(k,2))^2<(oa(k,3)*2)^2 then k=n+1:rk=1
500 next k:if rk then 480
510 oa(n+j,1)=x:oa(n+j,2)=y
520 next j:if rj then 280
530 a1$(1)="0":a1$(2)="180":if np>1 then a$=n$(1):n$(1)=n$(2):n$(2)=a$
540 rem *** draw stars ***
550 graphic 5:gosub 1440
560 z1=pi/180
570 for i=1 to n-o:for j=0 to 36:x=int(oa(i,1)+oa(i,3)*cos(j*10*z1)+0.5):y=int(oa(i,2)-oa(i,3)*sin(j*10*z1)+0.5)
574 xx=x:yy=y
575 if j=0 then gosub 1480: else gosub 1490
580 next j,i
590 rem *** draw space ships ***
600 for i=1 to 2:p1=oa(n+i,1):p2=oa(n+i,2):p3$=n$(i):p4=i:gosub 1160:next i
610 if mid$(a$,1,1)="i" then 760
620 goto 650
630 rem *** play game ***
640 m=m-int(m/2)*2+1
650 if np=1 then m=1
660 a$=a1$(m):gosub 1520:co=23:ro=23:gosub 1550:print "(";a1$(m);") ";n$(m);"'s, launch angle: ";:b=20:f1=1:input a$:if a$="" then a$=a1$(m)
670 p1$=a$:gosub 1070:if r1<>0 then on r1 goto 660,550,660,70,660,1430
680 a=val(a$):a=-sgn(a)*(abs(a)-int(abs(a)/360)*360):a1$(m)=str$(-a)
690 if n=0 then 760
700 a$=v1$(m):gosub 1520:co=23:ro=23:gosub 1550:print "(";v1$(m);") ";n$(m);"'s initial velocity (0-20): ";:input a$
710 if a$="" then a$=v1$(m)
720 p1$=a$:gosub 1070:if r1<>0 then on r1 goto 660,550,700,70,660,1430
730 b=val(a$)
740 if b<0 or b>20 then 700
750 v1$(m)=str$(b)
760 u1=0:u2=0:v1=0:v2=0:f3=0:x=0.35*b*cos(a*z1):y=0.35*b*sin(a*z1):u=x+oa(n+m,1)+8*cos(a*z1):v=y+oa(n+m,2)+8*sin(a*z1):p1=u:p2=v:gosub 1180
770 if f2 then 820
780 rem *** draw rocket path ***
790 u1=int(u+0.5):v1=int(v+0.5):if u1<>u2 or v1<>v2 then p1=u1:p2=v1:gosub 1220
800 u2=u1:v2=v1
810 rem
820 e=0:f=0
830 for j=1 to n:r5=oa(j,1)-u:r6=oa(j,2)-v:r4=r5^2+r6^2:r3=sqr(r4):r2=r5/r3:r1=r6/r3:g=0.017*(oa(j,3)^3)/r4:e=e+g*r2:f=f+g*r1:next j
840 x=x+e:y=y+f:u=u+x:v=v+y
850 rem *** detect collisions ***
860 if f2 then 920
870 sj=0:for j=1 to n+2
880 if j=n+1 then 910
890 if o and j=n then 910
900 if (u-oa(j,1))^2+(v-oa(j,2))^2<oa(j,3)^2 then f1=j:j=n+3:sj=1
910 next j:if sj then j=f1:goto 980
920 if u<-q(1) or u>q(1)*2 or v<-q(2) or v>q(2)*2 then 640
930 f2=(u<0 or u>q(1) or v<0 or v>q(2))
940 if f2=f3 then 770
950 if f3 then p1=u:p2=v:gosub 1180
960 f3=f2
970 goto 770
980 rem
990 p1=u+2:p2=v+2:gosub 1180
1000 restore 50:n9=8:sx=1:sy=1:gosub 1510:rem *** explosions ***
1010 if j<=n then 640
1020 a$="y":co=23:ro=16:gosub 1550:print n$(m);" destroyed ";n$(j-n);"'s ship! (y) again? : ";:input a$
1030 if left$(a$,2)="//" then 1430
1040 a$=left$(a$,1):if a$="d" or a$="i" then 550
1050 if a$="n" or a$="e" then 1430
1060 goto 70
1070 p1$=left$(p1$,1)
1080 if p1$="" then r1=0:return
1090 p=7
1100 p=p-1:if p=0 then 1150
1110 if mid$("bdhs/e",p,1)=p1$ then 1130
1120 goto 1100
1130 if mid$(a$,1,2)="//" then p=6
1140 if p=3 then gosub 1230
1150 r1=p:return
1160 rem
1170 s=(p4-1)*2-1:gosub 1180:restore 40:n9=16:sx=2*s:sy=2:gosub 1510:return
1180 rem
1190 cx=p1:cy=p2:return
1200 rem
1210 x0=cx:y0=cy:x1=cx+p1:y1=cy+p2:gosub 1500:cx=cx+p1:cy=cy+p2:return
1220 x0=cx:y0=cy:x1=p1:y1=p2:gosub 1500:cx=p1:cy=p2:return
1230 rem
1240 graphic 5:gosub 1440:scnclr
1250 print "space war ";d$:print spc(31);"commands":print:print spc(32);"h = help":print spc(32);"s = start"
1252 print spc(32);"d = display":print spc(32);"i = instant replay after hit":print spc(27);"/ or b = back"
1255 print spc(26);"// or e = exit";
1260 co=17:ro=17:gosub 1550:print "negative number of stars gives a black hole"
1270 a$="y":co=19:ro=22:gosub 1550:print "(y) are you ready to play? (y/n): ";:input a$
1280 a$=left$(a$,2):if a$>"" then a=asc(a$):a$=chr$(a-32*(a>96 and a<123))+mid$(a$,2)
1290 if a$="n" or a$="e" or a$="//" then 1320
1300 if a$="h" then 1240
1310 return
1320 scnclr:graphic clr:graphic 5:end
1330 rem
1340 m=0:if p1$="" then return
1350 for i=1 to len(p1$):k=asc(mid$(p1$,i,1)):if k=32 then m=0
1360 if k<65 or k>91 then 1390
1370 if m then p1$=mid$(p1$,1,i-1)+chr$(k+32)+mid$(p1$,i+1)
1380 m=1
1390 next i:r1$=p1$:return
1400 rem
1410 r1=1:q(1)=800:q(2)=450:return
1411 rem r1=1:q(1)=639:q(2)=350:return
1412 rem r1=1:q(1)=750:q(2)=400:return
1420 rem
1430 graphic clr:graphic 5:end
1440 rem
1450 trap 1530
1460 def fnx(x)=x*2
1470 def fny(y)=y*2
1475 return
1480 graphic 1:gosub 1460:scale 1,1600,1023:locate fnx(xx),fny(yy):graphic 5:gosub 1460:return
1490 graphic 1:gosub 1460:scale 1,1600,1023:draw 1,+0,+0 to fnx(xx),fny(yy):graphic 5:gosub 1460:return
1500 xx=x0:yy=y0:gosub 1480:xx=x1:yy=y1:gosub 1490:return
1510 for li=1 to n9:read p1:read p2:p1=p1*sx:p2=p2*sy:gosub 1200:next:return
1520 co=0:ro=23:gosub 1550:print " ";:return
1530 graphic clr:graphic 5:print:print err$(er);" in ";el:end
1540 graphic 1,1:color 4,1:color 0,1:color 1,6:color 5,6:graphic 5:gosub 1440:print chr$(14):return
1550 rem gotoxy co,ro
1560 print chr$(19);
1570 if co<=0 then 1590
1580 print spc(co);
1590 if ro<=0 then 1610
1600 for xr=1 to ro:print chr$(17);:next xr
1610 return