' This game is a re-write of an original game
' for the VIC20 computer by Peter Fokos
' (c) 1982 Tensor Technology
' This version of cloudburst (c) Paul Moore 2002
' X - the fire button
' D pad - left and right move
' D pad and X left and right fire

open window 640,512
setrgb 0,100,100,255

dim xa(50),xs(50),xd(50)
dim cal(20),clx(20),cly(20),cld(20)
dim drp(20),drpx(20),drpy(20),dry(20)

drop=1000:gameover=1:hi=0:hi$="HI-000000"

label begin
newlife=10000
x=320:count=5:seed=2:off=8:off1=8:w=10:t=10:d=.5
lives=3:sc=0:sc$="000000"

goto reset

sub explode (bgx,bgy,tp)
for k=0 to 6.38 step 0.628
    di=ran(20)+10
    setrgb 1,0,0,0
    line bgx,bgy to bgx+sin(k)*di,bgy+cos(k)*di
next k
if tp=1 then cal(s)=0
else drp(s)=0
     drpx(s)=0
     drpy(s)=0
fi
end sub

label reset
for a=0 to 49
    xa(a)=(ran(3.1415))+1.57
    xs(a)=ran(1)+1
    xd(a)=0
next a

if count>10 then count=5
   seed=seed+1
fi
cdd=0
for a=0 to count
if (a/2)=int(a/2) then 
   clx(a)=14
   cld(a)=int(ran((seed+1))+1)
   cly(a)=64+a*16
   else clx(a)=626
        cld(a)=-int(ran((seed+2))+1)
        cly(a)=64+a*16
fi
cal(a)=1
next a

repeat
off=off-d
off1=off1+d
if off<6 or off1<6 then d=-d
fi
t=t-.2
if t<-5 then t=11
fi
gosub clouds
gosub controls
if cdd>count then count=count+1:goto reset
fi
if boom=1 then goto death
fi
until (gameover=1)

drop=1000
col=255
cdir=-2
for a=6 to 15:cal(a)=0:next a
repeat
col=col+cdir
if col>255 or col<0 then 
cdir=-cdir
fi
setrgb 1,255,255,255
text 235,210,("C L O U D B U R S T")
text 320,230,("BY")
text 285,250,("PAUL MOORE")
setrgb 1,col,col,col
text 290,300,("GAME OVER")
text 241,320,("PRESS START BUTTON")
off=off-d
off1=off1+d
if off<6 or off1<6 then d=-d
fi
gosub clouds
until (peek("port1")=8)
gameover=0
drop=5.91
goto begin

label clouds
setdispbuf db
db = 1 - db
setdrawbuf db
clear window
setrgb 1,212,121,71
fill rectangle 0,476 to 640,512
setrgb 1,0,0,0
s$=str$(sc)
sc1=len(sc$)-len(s$)
text 50,500,left$(sc$,sc1)+s$
if sc>newlife then lives=lives+1:newlife=newlife+10000
fi
if sc>hi then hi=sc
fi
h$=str$(hi)
hi1=len(hi$)-len(h$)
text 280,500,left$(hi$,hi1)+h$
setrgb 1,80,80,80
fill triangle 484,495 to 490,488 to 496,495
rectangle 481,495 to 499,497
rectangle 489,487 to 491,489
setrgb 1,255,255,255
fill rectangle 485,498 to 495,500
setrgb 1,0,0,0
rectangle 484,497 to 496,501
text 500,500,str$(lives)

for a=0 to 15
if cal(a)=2 then explode(clx(a),cly(a),1)
fi
if drp(a)=3 then explode(drpx(a),drpy(a),2)
fi

if cal(a)=1 then
     clx(a)=clx(a)+cld(a)
     if clx(a)<14 or clx(a)>626 then cld(a)=-cld(a)
     fi
     setrgb 1,180,180,180
fill rectangle clx(a)-8,cly(a)-7 to clx(a)+8,cly(a)+7
fill rectangle clx(a)-6,cly(a)-off to clx(a),cly(a)+off1
fill rectangle clx(a)-10,cly(a)-off+2 to clx(a)-6,cly(a)+off1-2
fill rectangle clx(a)-14,cly(a)-off+4 to clx(a)-10,cly(a)+off1-4
fill rectangle clx(a)+6,cly(a)+off to clx(a),cly(a)-off1
fill rectangle clx(a)+10,cly(a)+off-2 to clx(a)+6,cly(a)-off1+2
fill rectangle clx(a)+14,cly(a)+off-4 to clx(a)+10,cly(a)-off1+4

n=int(ran(16))
   if ran(6)>drop and drp(n)=0 then 
      drp(n)=int(ran(2)+1)
      drpx(n)=clx(a)
      drpy(n)=cly(a)
      dry(n)=(ran(seed))+2
   fi
fi
   if drp(a)>0 then
      drpy(a)=drpy(a)+dry(a)
   if drpy(a)>466 and (drpx(a)<x+16 and drpx(a)>x-16) then boom=1:drp(a)=0
   fi
     if drpy(a)>=474 and drp(a)=1 then drp(a)=0:dry(a)=0
     fi
   if drpy(a)>466 and drp(a)=2 then 
      dry(a)=0
      w=t
      if drpx(a)>x then z=-1
         else z=1
      fi
         drpx(a)=drpx(a)+z
   fi
if drp(a)=1 then
   setrgb 1,0,0,255
   fill rectangle drpx(a)-1,drpy(a)-8 to drpx(a)+1,drpy(a)+6
   fill rectangle drpx(a)-4,drpy(a)-4 to drpx(a)+4,drpy(a)+4
   setrgb 1,255,255,255
   fill rectangle drpx(a)-4,drpy(a)-3 to drpx(a),drpy(a)
fi
  if drp(a)=2 then
   setrgb 1,100,0,0
   triangle drpx(a)-10,drpy(a) to drpx(a),drpy(a)-15 to drpx(a)+9,drpy(a)
   rectangle drpx(a)-w+5,drpy(a) to drpx(a)-w,drpy(a)+10
   rectangle drpx(a)+w-5,drpy(a) to drpx(a)+w,drpy(a)+10
   setrgb 1,255,255,255
   fill rectangle drpx(a)+z*4-2,drpy(a)-8 to drpx(a)+z*4+2,drpy(a)-2
 fi
fi
z=0
w=10
next a
return

label controls
k=peek("port1")
 if f=0 then
   if k=16512 then f=1:fdx=-16:fdy=0:fx=x-16:fy=466
      elsif k=16416 then f=1:fdx=16:fdy=0:fx=x+16:fy=466
      elsif k=16384 then f=1:fdx=0:fdy=-16:fx=x:fy=452
   fi
 fi
if and(k,128)<>0 and x>18 then x=x-4
fi
if and(k,32)<>0 and x<634 then x=x+4
fi
setrgb 1,140,140,140
fill triangle x-10,464 to x,456 to x+10,464
setrgb 1,80,80,80
fill rectangle x-16,464 to x+16,468
fill rectangle x-2,458 to x+2,454
setrgb 1,255,255,255
fill rectangle x-8,470 to x+8,474
setrgb 1,0,0,0
rectangle x-10,468 to x+10,476
rectangle x-5,470 to x+4,474

if f=1 then
   fx=fx+fdx:fy=fy+fdy
   if fy<56 or fx<0 or fx>640 then f=0
   fi
   setrgb 1,0,0,0
   fill rectangle fx-2,fy-2 to fx+2,fy+2
for s=0 to 15
         if cal(s)=1 and (fx>clx(s)-14 and fx<clx(s)+14) and (fy > cly(s)-6 and fy < cly(s)+6) then 
            cal(s)=2
            cdd=cdd+1
            sc=sc+10
            f=0            
         return
         fi
       if drp(s)>0 and (fx<drpx(s)+10 and fx>drpx(s)-10) and (fy > drpy(s)-10 and fy < drpy(s)+10) then 
            f=0
            if drp(s)=1 then sc=sc+40
            else sc=sc+30
            fi
        drp(s)=3
        return       
       fi
next s
fi
return

label death
repeat
gosub clouds
for i=0 to 49
  if xs(i)>0 then
     xd(i)=xd(i)+xs(i)
     xs(i)=xs(i)+xs(i)/5
   if xd(i)>250 then xs(i)=0
      yet=yet+1
      if yet>48 then boom=0
      fi 
   fi
      setrgb 1,xd(i),xd(i),xd(i)
      fill rectangle x+xd(i)*sin(xa(i)),470+xd(i)*cos(xa(i)) to x+5+xd(i)*sin(xa(i)),475+xd(i)*cos(xa(i))
  fi 
next i
until (boom=0)
yet=0
for a=0 to 15:drp(a)=0:drpx(a)=0:drpy(a)=0:next a
lives=lives-1
if lives=0 then gameover=1
fi
goto reset














