open window 640,512
dim x(50),y(50),c(50),dx(50),dy(50),rot(50),tim(50)
dim stx(30),sty(30),sts(30)
dim rx(121),ry(121)
dim bt(50),bx(50),by(50),ch(50)
dim pbx(4),pby(4),pbs(4)
dim ex(8),ey(8),edx(8),edy(8)
dim dtx(8),dty(8),dtdx(8),dtdy(8),off(8)
dim hi$(6),hsc(6),stg(6),lv(6)
dim nx(3),hi(3),np(3)
sc$="000000"
stage=1
level=2
 
read a$
for a=1 to 5
hsc(a)=(6-a)*250
s$=str$(hsc(a))
sc1=len(sc$)-len(s$)
hi$(a)=left$(sc$,sc1)+s$+("  ")+a$+("   ")+str$(stage)+(".")+str$(level-1)
next a
data "LGM"

for a=0 to 29
    stx(a)=int(ran(440))+100
    sty(a)=int(ran(450))
    sts(a)=int(ran(8))+1
next a

d=0
for l=0 to 6.283 step 3.1415/60
rx(d)=sin(l)*2:ry(d)=cos(l)*2
d=d+1
next l

gosub intro
goto titlescreen
label begin
clear window
gosub setup
up=5
label main
repeat
setdrawbuf db
db=1-db
setdispbuf db
up=up+1
if up>6 then up=0
setrgb 1,0,0,0
setrgb 2,0,0,0
setrgb 3,0,0,255
gtriangle 0,0 to 640,0 to 0,512
setrgb 2,0,0,255
gtriangle 640,0 to 0,512 to 640,512
fi
setrgb 1,0,0,0
fill box 90,0,550,430

for s=0 to 29
    sty(s)=sty(s)+sts(s)
    if sty(s)>420 sty(s)=0
    sts_s=sts(s)*32
    setrgb 1,sts_s,sts_s,sts_s
    box stx(s),sty(s),stx(s)+1,sty(s)+1
next s

if dead=0 then
j=peek("port1")
if and(j,32)<>0 and xp<525 xp=xp+5
if and(j,128)<>0 and xp>115 xp=xp-5
if and(j,64)<>0 and yp<405 yp=yp+5
if and(j,16)<>0 and yp>240 yp=yp-5
if and(j,8192)<>0 and pro=0 and shds>0 then shds=shds-1:pro=200:sld=1
fi
if and (j,16384)<>0 and fd=0 then 
for h=1 to 2
if pbs(h)=0 then
   pbx(h)=xp
   pby(h)=yp-31
   pbs(h)=1
   fd=7
   h=3
fi
next h
fi

setrgb 1,0,200,200
triangle xp-6,yp to xp,yp-16 to xp+6,yp
triangle xp-12,yp to xp-8,yp-10 to xp-6,yp+16
triangle xp+6,yp+16 to xp+8,yp-10 to xp+12,yp
box xp-6,yp,xp+6,yp+8
setrgb 1,255,100+ran(155),0
fill triangle xp-3,yp+10 to xp,yp+20+ran(5) to xp+3,yp+10
fi

if pro>0 then
   pro=pro-1
     if pro=20 sld=-sld
   for shld=15 to 120 step 15
   setrgb 1,ran(255),ran(255),255
   line xp+rx(shld-15)*ss,yp+ry(shld-15)*ss to xp+rx(shld)*ss,yp+ry(shld)*ss 
   line to xp,yp-20
   next shld
   ss=ss+sld
     if ss>12 ss=12
     if ss=0 pro=0
fi

for a=0 to 49
b_t=bt(a):c_a=c(a)
if b_t>0 then
if b_t=1 then
   by(a)=by(a)+14
   if by(a)>410 bt(a)=0
      setrgb 1,255,60,60
      box bx(a),by(a),bx(a)+1,by(a)+14
fi
if b_t=2 then
   by(a)=by(a)+6
   if by(a)>410 bt(a)=0
      setrgb 1,255,255,255
      line bx(a)-4,by(a)-4 to bx(a)+4,by(a)+4
      line bx(a)+4,by(a)-4 to bx(a)-4,by(a)+4 
fi
if b_t=3 and c_a=8 then
   by(a)=by(a)+16
   if by(a)>410 bt(a)=0
      setrgb 1,255,255,0
      line x(a),y(a)+16 to bx(a),by(a)
fi
if b_t=4 then
   by(a)=by(a)+5
   if by(a)>410 bt(a)=0
   if bx(a)<xp bx(a)=bx(a)+(int(ran(3))+3)
   if bx(a)>xp bx(a)=bx(a)-(int(ran(3))+3)
      b_x=bx(a):b_y=by(a)
     setrgb 1,255,255,255
     fill box b_x-2,b_y-4,b_x+2,b_y+4
     fill triangle b_x-2,b_y+4 to b_x,b_y+8 to b_x+2,b_y+4
     fill triangle b_x-2,b_y-8 to b_x,b_y-4 to b_x+2,b_y-8
fi
fi
if (c_a<level+1 or c_a>9) then
x(a)=x(a)+dx(a)
y(a)=y(a)+dy(a)
fi
x_a=x(a):y_a=y(a)
for v=1 to 2
if (c_a>9 or (c_a>0 and c_a<level+1)) and (pbx(v)+7>x_a-10 and pbx(v)-8<x_a+10) and (pby(v)+15>y_a-10 and pby(v)<y_a+10) then 
pbs(v)=0
if c_a<>11 then
   ald=ald+1
   sc=sc+c_a*25
   c(a)=0
else ch(a)=ch(a)-84
if ch(a)<=0 c(a)=0
fi
for e=0 to 7
ex(e)=pbx(v)
ey(e)=pby(v)
edx(e)=-10+ran(20)
edy(e)=-10+ran(20)
next e
pbx(v)=600:ag=10
fi
next v

if c_a=3 and (x_a>535 or x_a<105) then y(a)=y(a)+16:dx(a)=-dx(a)
fi
if c_a=4 or c_a=8 then 
   rot(a)=rot(a)+1
   if rot(a)>120 rot(a)=0
    dx(a)=rx(rot(a)):dy(a)=ry(rot(a))
   if b_t=3 then dx(a)=0:dy(a)=0
   fi
fi
if level>4 and c_a=5 and tim(a)>0 then tim(a)=tim(a)-1
   if tim(a)=0 then
   dx(a)=0:dy(a)=16
   fi
fi
if (c_a=6 or c_a=7) dx(a)=(int(ran(3))-1)*4
if c_a=9 and (x_a>510 or x_a<130) dx(a)=-dx(a)
if c_a=10 and (y_a>120 or y_a<0) dy(a)=-dy(a)
if x_a<100 x(a)=540
if x_a>540 x(a)=100
if c_a=5 and y_a>395 then 
   tim(a)=int(ran(100))+10
   y(a)=20
   x(a)=108
   dx(a)=12
   dy(a)=0
fi
if y_a>415 y(a)=-20
if c_a=11 and y_a>130 y(a)=130

rem alien drawing routine
if (c_a>0 and c_a<=level) or c_a>9 then
x_a=x(a):y_a=y(a)
if pro=0 and dead=0 then
if (x_a-8<xp+10 and x_a+8>xp-10) and (y_a-8<yp+10 and y_a+8>yp-10) then dead=1
fi
b_x=bx(a):b_y=by(a)
if b_t>0 and (b_x-1<xp+10 and b_x+1>xp-10) and (b_y+10>yp-16 and b_y<yp+10) then dead=1
fi
fi
if c_a=1 then
   setrgb 1,128,128,128
   fill box x_a-ran(10),y_a-ran(10),x_a+ran(10),y_a+ran(10)
fi
if c_a=2 then
   setrgb 1,64,64,64
   fill box x_a-4,y_a-4,x_a+4,y_a+4
fi
if c_a=3 then
   setrgb 1,200,0,200
   fill box x_a-6,y_a-6,x_a+6,y_a+6
   setrgb 1,255,255,0
   fill box x_a-4,y_a-4,x_a+3,y_a
   setrgb 1,128,128,128
if tick>1 then fill box x_a-8,y_a+6,x_a-4,y_a+10
   fill box x_a+4,y_a+6,x_a+8,y_a+10
fi
if tick<2 then fill box x_a-6,y_a+6,x_a-2,y_a+10
   fill box x_a+2,y_a+6,x_a+6,y_a+10
fi
if ran(1)>.986 and b_t=0 then bt(a)=1:bx(a)=x_a:by(a)=y_a+10
fi
fi
if c_a=4 then
   setrgb 1,0,255,0
   fill triangle x_a-3,y_a to x_a,y_a+5 to x_a+3,y_a 
   if tick>1 then 
   triangle x_a-8,y_a to x_a-4,y_a-3 to x_a-3,y_a
   triangle x_a+8,y_a to x_a+4,y_a-3 to x_a+3,y_a
fi
   if tick<2 then 
   triangle x_a-4,y_a-3 to x_a-8,y_a+3 to x_a-4,y_a+5 
   triangle x_a+4,y_a-3 to x_a+8,y_a+3 to x_a+4,y_a+5
fi
if ran(1)>.986 and b_t=0 then bt(a)=1:bx(a)=x_a:by(a)=y_a+4
fi
fi
if c_a=5 then
if tick>1 then
   setrgb 1,255,255,0
   fill box x_a-6,y_a-4,x_a+6,y_a+4
   setrgb 1,0,0,255
   fill box x_a-4,y_a-3,x_a+4,y_a+3
fi
if tick<2 then
   setrgb 1,0,0,255
   fill box x_a-4,y_a-6,x_a+4,y_a+6
   setrgb 1,255,255,0
   fill box x_a-2,y_a-3,x_a+2,y_a+3
fi
fi
if c_a=6 then
   setrgb 1,255,255,255
   fill box x_a-2,y_a-2,x_a+2,y_a+2 
   if tick>1 then 
      setrgb 1,200,0,200
      fill box x_a-8,y_a-6,x_a-6,y_a+6
      fill box x_a+6,y_a-6,x_a+8,y_a+6
   fi
   if tick<2 then 
      setrgb 1,200,0,200
      fill box x_a-6,y_a-6,x_a+6,y_a-8
      fill box x_a-6,y_a+6,x_a+6,y_a+8
   fi
if ran(1)>.984 and b_t=0 then bt(a)=1:bx(a)=x_a:by(a)=y_a+4
fi
fi
if c_a=7 then
   setrgb 1,0,255,255
if tick>1 then
   fill triangle x_a-8,y_a-4 to x_a,y_a+8 to x_a+8,y_a-4
fi
if tick<2 then  
   fill triangle x_a-8,y_a+4 to x_a,y_a-8 to x_a+8,y_a+4
fi
    if b_t=0 then bt(a)=2:bx(a)=x_a:by(a)=y_a+8
    fi
fi
if c_a=8 then
   setrgb 1,255,255,255
   triangle x_a-6,y_a-2 to x_a,y_a+16 to x_a+6,y_a-2
   setrgb 1,255,0,0
   if tick>1 fill box x_a-6,y_a,x_a+6,y_a+2 
   if tick<2 fill box x_a-2,y_a+8,x_a+2,y_a+6
if ran(1)>.987 and b_t=0 then bt(a)=3:bx(a)=x_a:by(a)=y_a+16
fi
fi
if c_a=9 then
   setrgb 1,ran(255),ran(255),ran(255)
   fill box x_a-10,y_a-5,x_a+10,y_a+5
   setrgb 1,0,255,0
   box x_a-20,y_a-10,x_a+20,y_a+10
   triangle x_a-30,y_a to x_a-20,y_a-15 to x_a-20,y_a+15
   triangle x_a+30,y_a to x_a+20,y_a-15 to x_a+20,y_a+15
if ran(1)>.985 and b_t=0 then bt(a)=4:bx(a)=x_a:by(a)=y_a+11
fi
fi
if c_a=10 then
   setrgb 1,ran(255),ran(255),ran(255)
   fill box x_a-4,y_a-2,x_a+4,y_a+2
   setrgb 1,0,0,255
   fill triangle x_a-8,y_a+2 to x_a,y_a+8 to x_a+8,y_a+2
if ran(1)>.96 and b_t=0 then bt(a)=int(ran(2))+1:bx(a)=x_a:by(a)=y_a+3
fi
   if ran(1)>.988 then
      sh=int(ran(37))+10
        if c(sh)=0 then 
           c(sh)=11
           x(sh)=x_a
           y(sh)=y_a+8
           dx(sh)=0
           dy(sh)=2
           ch(sh)=250
        fi
   fi
fi
if c_a=11 then
   c_h=ch(a)
   setrgb 1,c_h,c_h,c_h
   fill box x_a-8,y_a-2,x_a+8,y_a+2
fi
fi
next a

if dead=1 gosub death
if dead=2 gosub bang

'if up>3 then
'   s$=str$(sc)
'   sc1=len(sc$)-len(s$)
'   s1$=left$(sc$,sc1)+s$+("  L:")+str$(lives)+("  S:")+str$(shds)+("  LV:")+str$(stage)+(".")+str$(level-1)
'fi

for h=1 to 2
  if pbs(h)=1 then
     p_bx=pbx(h):p_by=pby(h)
     setrgb 1,0,255,255
     box p_bx-8,p_by,p_bx-7,p_by+15
     box p_bx+8,p_by,p_bx+7,p_by+15
     pby(h)=pby(h)-16
     if pby(h)<=0 pbs(h)=0
  fi
next h

fd=fd-1
if fd<0 fd=0

if ag>0 then
    for e=0 to 7
    ex(e)=ex(e)+edx(e):ey(e)=ey(e)+edy(e)
    col=100+ran(128)
    e_x=ex(e):e_y=ey(e)
    setrgb 1,col,col-ran(64),0
    fill box e_x-ran(3),e_y-ran(3),e_x+ran(3),e_y+ran(3) 
    next e
fi
ag=ag-1
if ag<0 ag=0

if (ald>6 and level<9) or (ald>8 and level=9) then ald=0
level=level+1
if level=9 and ms=0 then
     for a=0 to 7
         c(a)=10
         x(a)=x(48)+(int(ran(9)+2)*16)
         y(a)=y(48)+(int(ran(8)+1)*8)
label sel
         dx(a)=(int(ran(3))-1)*4
      if dx(a)=0 goto sel
         dy(a)=2
         next a
         ms=1
fi
if level>9 then level=2:stage=stage+1:gosub setup
fi
fi
   tick=tick+1
   if tick>3 tick=0
until (j=8 or dead=3) 
if dead=3 then 
for hs= 1 to 5
  if sc>hsc(hs) then pos=hs:hs=6
  fi
next hs
  if pos=0 then goto titlescreen
    else gosub hiscore
    goto begin
  fi
fi
repeat
j=peek("port1")
setdrawbuf db
setdispbuf db
s$=str$(sc)
sc1=len(sc$)-len(s$)
s1$=("SC:")+left$(sc$,sc1)+s$+("  L:")+str$(lives)+("  S:")+str$(shds)+("  LV:")+str$(stage)+(".")+str$(level-1)
setrgb 1,255,255,255
text 165,470,s1$
text 290,200,("PAUSED")
until (j=16384)
goto main

label setup
o=0:sp=0:sp1=0:sp2=0:sp3=0:sp4=0:sp5=0:ms=0

for a=0 to 49
bt(a)=0
o=o+1
if o>8 then o=1
fi 
c(a)=int(o)
c_a=c(a)

if c_a=1 or c_a=2 then
   sp=sp+1
   if sp=13 then 
      c(a)=9
      x(a)=320
      y(a)=50
label select
      dx(a)=(int(ran(3))-1)*6
      if dx(a)=0 goto select
      dy(a)=0
      goto skip
   fi 
   x(a)=int(ran(440))+100
   y(a)=-int(ran(300)+100)
   dy(a)=8+int(ran(4)):dx(a)=0
   if ran(1)>.5 then dx(a)=(int(ran(3))-1)*8
   fi
label skip
fi
if c_a=3 then
   sp1=sp1+1
   x(a)=100+48*sp1
   y(a)=50
   dx(a)=4
   dy(a)=0
fi
if c_a=4 or c_a=8 then
   sp2=sp2+1
   x(a)=100+32*sp2
   y(a)=100+int(ran(5))*16
   rot(a)=int(ran(120))
   dx(a)=rx(rot)
   dy(a)=ry(rot)
fi
if c_a=5 then
   sp3=sp3+1
   x(a)=sp3*64+100
   y(a)=20
   dx(a)=12
   dy(a)=0
   tim(a)=int(ran(100))+10
fi
if c_a=6 then
   sp4=sp4+1
   x(a)=sp4*64+100
   y(a)=-int(ran(7)+1)*8
   dy(a)=3
   dx(a)=(int(ran(3))-1)*4
fi
if c_a=7 then
   sp5=sp5+1
   x(a)=sp5*64+100
   y(a)=-int(ran(7)+1)*16
   dy(a)=4
   dx(a)=(int(ran(3))-1)*4
fi
next a
return

label death
lives=lives-1
if lives<0 then lives=0
fi
for v=0 to 7
    dtx(v)=xp:dty(v)=yp
    dtdx(v)=rx(ran(int(120)))
    dtdy(v)=ry(ran(int(120)))
    off(v)=int(ran(120))
    clr=255
next v
dead=2
return

label bang
for v=0 to 7
    off(v)=off(v)+1
    clr=clr-.5
    if clr<0 then clr=0:dead=0
    pro=100:sld=1
    if lives=0 dead=3
    v=8
    fi
if off(v)>120 off(v)=0
   dtx(v)=dtx(v)+dtdx(v):dty(v)=dty(v)+dtdy(v)
   setrgb 1,0,clr,clr
   line dtx(v),dty(v) to dtx(v)+rx(off(v))*8,dty(v)+ry(off(v))*8
next v
return

label intro
b$="CALL US LEGION - FOR WE ARE MANY...."
j=120:i=70:c=64:n=0
restore txt
read a$
for u=1 to len(a$) step 2
j=j+10
if j>530 then i=i+20:j=120
fi
for q=0 to 1
    setrgb 1,255,255,255
    fill box j+2,i,j+10,i+2
    pause .04
    setrgb 1,0,0,0
    fill box j+2,i,j+10,i+2
    pause .03
next q
setrgb 1,255,255,255
mess=32+val(mid$(a$,u,2))
text j,i,chr$(mess)
next u
repeat
n=n+.1
setrgb 1,255-c,255-c,255-c
c=c+.5:if c>192 c=64
text 150,420,b$
until (n>250 or peek("port1")=16384)
for q=0 to 320 step .2
setrgb 1,0,0,0
box q,q/1.25,640-q,512-q/1.25
setrgb 1,255-c,255-c,255-c
c=c+.5:if c>192 c=64
text 150,420,b$
next q

label titlescreen
dead=0
pro=0
sc=0
shds=10
stage=1
level=2
lives=3
xp=320
yp=350
fd=1
for l=0 to 1
setdrawbuf l
clear window
next l
setdispbuf 1
label logo
restore title
for y=0 to 6
read a
for x=0 to 23
t=2^int(23-x)
if t>a then goto skip1
fi
setrgb 1,255-y,255-y*35,0
fill box 72+x*20,36+y*10,108+x*20,52+y*12 
a=a-t
label skip1
next x
next y
if called=1 then called=0
return
fi
cd=1:c=64
label loop
c=c+cd:if c>128 or c<32 cd=-cd
setrgb 1,100+c,32+c,0
text 200,160,("HEROES AGAINST THE LEGION")
text 258,190,("SCORE  NAME  LEVEL")
for a=1 to 5
text 225,200+a*24,str$(a)+(". ")+hi$(a)
next a
text 150,370,("DPAD - LEFT/RIGHT  X - FIRE/CONTINUE")
text 190,390,("O - SHIELD    Start - PAUSE/STATS")
setrgb 1,255,255,255
text 150,420,b$
if (peek("port1")<>16384) goto loop
goto begin

label txt
data "3048658383737871008472827985717200847269007985846982008273770783006583846982797368003073787069838469680083696784798283008979850082696773698669006500838482657871697689003067796869680084826578837773838373797812007982737173780085787578798778141414140000003052726900658384698279736800838479827700716984830077798269007378846978836912008379003084726900776983836571690082697765737883008578826965681414141400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003044658469821200897985008369840084726900677977808584698200737884790077798473797800003068696779687378710084726900838482657871690084698884141414667979797977777777010100003065780069568076798373797800827967758300897985820083727380007573767673787100847269003076737172848300130068658275786983830073830066827369701400527265787570857676891200003084726900697769827169786789008079876982007573677583007378141414141414000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003052726900686967796873787100777978738479820080798769828300858012006676737875737871003084726900838465846977697884141414"

label title
data 9331913,8951085,8946989,9352491,8951083,8951083,15623369

label hiscore
xp=318:yp=250:x1=3.12:tk=32:chr=0
for l=1 to 2
setdispbuf db
db=1-db
setdrawbuf db
clear window
called=1
gosub logo
next l

for a=0 to 2
nx(a)=275+(a*30)
next a

label selector
dir=0
j=peek("port1")
j$=inkey$(0)
if j$="la_left" then dir=-.0806:chr=chr-1
fi
if j$="la_right" then dir=.0806:chr=chr+1
fi
if chr<0 chr=25
if chr>25 chr=0
if j=128 sel=sel-1
if j=32 sel=sel+1
if j=16384 then hi(sel)=65+chr:np(sel)=sel:sel=sel+1
fi
if j=8192 goto ending
if sel>2 sel=0
if sel<0 sel=2

for b=0 to 2
x1=x1+dir
gosub wordial
next b
goto selector

label wordial
setdrawbuf db
db=1-db
setdispbuf db
setrgb 1,0,0,0
fill box 210,140,422,310
setrgb 1,0,200,200
triangle xp-6,yp to xp,yp-16 to xp+6,yp
triangle xp-12,yp to xp-8,yp-10 to xp-6,yp+16
triangle xp+6,yp+16 to xp+8,yp-10 to xp+12,yp
box xp-6,yp,xp+6,yp+8
setrgb 1,255,100+ran(155),0
fill triangle xp-3,yp+10 to xp,yp+20+ran(5) to xp+3,yp+10
x=x1
for a=65 to 90
setrgb 1,255,255,255
text 310+sin(x)*100,256+cos(x)*50,chr$(a)
x=x-.242
next a
setrgb 1,150,150,150
text 165,380,("LEFT ANALOG STICK - PICK LETTER")
text 170,400,("DPAD - CHANGE BOX   X - Select")
text 285,420,("O - END")
setrgb 1,255,255,255
for q=0 to 2:box nx(q)-3,150-3,nx(q)+23,173:next q
setrgb 1,280-tk,250-tk,0
box nx(sel),150,nx(sel)+20,170
tk=tk+5:if tk>255 tk=0
for a=0 to 2
setrgb 1,255,255,255
text nx(np(a))+5,165,chr$(hi(a))
next a
return

label ending
for a=5 to pos step -1 
hi$(a+1)=hi$(a):hsc(a+1)=hsc(a)
next a
hsc(pos)=sc
s$=str$(sc)
sc1=len(sc$)-len(s$)
hi$(pos)=left$(sc$,sc1)+s$+("  ")+chr$(hi(0))+chr$(hi(1))+chr$(hi(2))+("   ")+str$(stage)+(".")+str$(level-1)
pos=0
goto titlescreen



