'
'       Thunderstruck coded by Shockwave (c) 2001
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
'
btc=255
sss=1
obx=320
oby=256
p=0
p2=1
'        12345678901234567890
    s2$="                     "
s2$=s2$+"USE L1 AND R1 TO ZOOM"
s2$=s2$+" NICE  LIGHTNING EH? "
s2$=s2$+"SHAME THERE'S NO SFX!"
s2$=s2$+" CHECK THE FORUMS AT "
s2$=s2$+"  WWW.YABASIC.CO.UK  "
s2$=s2$+" GREETINGS TO ALL MY "
s2$=s2$+"FRIENDS AND 2 MY GIRL"
s2$=s2$+"       VICKI!!       "

s$="                                                                 "
s$=s$+"THE THUNDERSTRUCK DEMO WAS PROGRAMMED BY SHOCKWAVE"
s$=s$+" IN SEPTEMBER 2001... I HOPE THAT YOU LIKE IT.. "
s$=s$+"THE DEMO IS BOG STANDARD STUFF I SUPPOSE BUT THE "
s$=s$+"BACKGROUND IS... ORIGINAL!!  I WANTED TO SEE IF I "
s$=s$+"COULD MAKE POLYGONAL LIGHTNING AND MAKE IT LOOK "
s$=s$+"LIKE COMIC BOOK STYLE LIGHTNING, I THINK I'VE GOT "
s$=s$+"IT RIGHT!!!     ANYWAY, NO TIME FOR ANY MORE TEXT "
s$=s$+"JUST NOW SO I'M OFF.. GREETS TO THOSE WHO KNOW "
s$=s$+"ME AND THOSE PEOPLE WHO USE THE YABASIC FORUMS...."

open window 640,512
gosub message
rain=55

dim rnx(rain)
dim rny(rain)
dim rns(rain)

for a=1 to rain
  rnx(a)=1+ran(640)
  rny(a)=-10+ran(522)
  rns(a)=40+ran(10)
next a
gosub precalculate
b=0

label loop
   setdrawbuf dw
   dw=1-dw
   setdispbuf dw
   gosub cw
   if sss>=1 gosub drawprecalcobj
   gosub wet
   gosub frm
   if sss<1 gosub drawprecalcobj

c=peek("port1")
if (and(c,2048)<>0) sss=sss+.1
if (and(c,1024)<>0) sss=sss-.1
if sss<.4 sss=.4
if sss>10 sss=10
cca=cca-(sss*40)

goto loop

label frm
setrgb 1,55,100,160+bcl/2
fill rectangle 0,0 to 640,30
fill rectangle 0,482 to 640,512
fill rectangle 0,30 to 31,482
fill rectangle 610,30 to 640,482

setrgb 1,55,150,155+blc/2
fill rectangle 30,30 to 40,482
setrgb 1,25,70,75+blc/2
fill rectangle 610,30 to 600,482
setrgb 1,35,125,125+blc/2
fill rectangle 40,472 to 600,482
fill triangle 30,482 to 40,472 to 40,482
fill triangle 600,482 to 600,472 to 610,482
setrgb 1,35,85,70+blc/2
fill rectangle 40,30 to 600,40
fill triangle 30,30 to 40,30 to 40,40
fill triangle 600,30 to 600,40 to 610,30

setrgb 1,0,0,0
text 100,21,"SHOCKWAVE PRESENTS THE THUNDERSTRUCK DEMO!"
setrgb 1,255-bcl,255-bcl,255
text 102,19,"SHOCKWAVE PRESENTS THE THUNDERSTRUCK DEMO!"

setrgb 1,0,0,0
text scx,503,mid$(s$,p,67)
setrgb 1,255-bcl,255-bcl,255
text scx+2,501,mid$(s$,p,67)

scx=scx-2
if scx<-10 then
scx=scx+10
p=p+1
if p>len(s$) p=0
end if
btc=btc-2
if btc<20 then
btc=255
p2=p2+21
if p2>len(s2$) p2=1
fi

setrgb 1,btc,btc,btc+bcl
text 215,250,mid$(s2$,p2,21)

return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'Draw the rain
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label wet
setrgb 1,0,0,255
setrgb 2,155,155,255
setrgb 3,155,155,255
for a=1 to rain

 gtriangle rnx(a),rny(a) to rnx(a)-1,rny(a)+rns(a) to rnx(a)+1,rny(a)+rns(a)

 rny(a)=rny(a)+rns(a)
 if rny(a)>512 then
rnx(a)=1+ran(640)
rny(a)=rny(a)-512
fi
next a
return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%#
'Lightning Background!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label cw
if bcl>0 bcl=bcl-30
fu=fu+.1
setrgb 1,50+10*sin(fu/3),0,30+bcl
setrgb 2,20,20+10*sin(fu/7),40+bcl
setrgb 3,20+10*sin(fu/5),30,50+bcl
gtriangle 0,0 to 640,512 to 0,512
gtriangle 0,0 to 640,512 to 640,0
c=ran(1000)
if c<25 then
bcl=250
lcl=255
start=ran(640)
end if
if lcl>0 then
 s=start-30+ran(60)
 s2=s
lcl=lcl-30
if lcl<0 lcl=0
for y=0 to 482 step 40
setrgb 1,lcl/2,lcl/2,155
fill triangle s,y to s2-25,y+40 to s2+25,y+40
fill triangle s+25,y to s-25,y to s2,y+40
setrgb 1,lcl,lcl,255
fill triangle s,y to s2-5,y+40 to s2+5,y+40
fill triangle s+5,y to s-5,y to s2,y+40
 s=s2
 s2=s2-50+ran(100)
  next y
end if
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'     Draw the umbrella from out software memory bank!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label drawprecalcobj

for a=1 to polys
setrgb 1,cca+rstore(b/3),cca+gstore(b/3),cca+bstore(b/3)+bcl
   fill triangle obx+xstore(b)/sss,oby+ystore(b)/sss to obx+xstore(b+1)/sss,oby+ystore(b+1)/sss to obx+xstore(b+2)/sss,oby+ystore(b+2)/sss

b=b+3 
cca=cca+10
next a
'sss=sss+.1
if b>=(polys*3)*175 b=0
cca=-100
return


label message
yi=-185
for a=0 to 100 
setrgb 1,a/2,a/2,a
text 113,125+yi,"          THE THUNDERSTRUCK DEMO"
text 113,145+yi,"   CODED BY SHOCKWAVE  IN SEPTEMBER 2001"
text 113,165+yi,"  AN UNUSUAL  3D OBJECT WITH AN EVEN MORE"
text 113,185+yi,"       UNUSUAL  BACKGROUND EFFECT!!"
text 113,205+yi,"         I HOPE THAT YOU LIKE IT!"
text 113,255+yi,"        GREETINGS TO THESE PEOPLE:"
text 113,275+yi," ADAM LAY,  MARC GALE, CHRISTOPHER RANKINE"
text 113,295+yi,"FRYER, MIKAEL LAGRE, GAZ, IAN, STATICGERBIL"
text 113,315+yi," AND ALL FORUM USERS AT WWW.YABASIC.CO.UK"
text 113,335+yi,"     CONTACT ME VIA THE FORUMS THERE!"
text 113,375+yi,"         HOPE YOU ENJOY THE DEMO!"
yi=yi+2

next a


setrgb 1,255,255,255
text 113,125+yi,"          THE THUNDERSTRUCK DEMO"
text 113,145+yi,"   CODED BY SHOCKWAVE  IN SEPTEMBER 2001"
text 113,165+yi,"  AN UNUSUAL  3D OBJECT WITH AN EVEN MORE"
text 113,185+yi,"       UNUSUAL  BACKGROUND EFFECT!!"
text 113,205+yi,"         I HOPE THAT YOU LIKE IT!"
text 113,255+yi,"        GREETINGS TO THESE PEOPLE:"
text 113,275+yi," ADAM LAY,  MARC GALE, CHRISTOPHER RANKINE"
text 113,295+yi,"FRYER, MIKAEL LAGRE, GAZ, IAN, STATICGERBIL"
text 113,315+yi," AND ALL FORUM USERS AT WWW.YABASIC.CO.UK"
text 113,335+yi,"     CONTACT ME VIA THE FORUMS THERE!"

text 113,375+yi,"         HOPE YOU ENJOY THE DEMO!"

text 123,455+yi," TRY PRESSING L1 AND R1 DURING THE DEMO"
text 123,475+yi,"IT GIVES A BETTER VIEW OF THE BACKGROUND"

return


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'The rest of the listing is the precalculation routine!!!!
'This code will work out the screen co-ordinates for the
'32 polygon diamond!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label precalculate
'## Number of faces in object:

polys=23

dim xstore((polys*3)*179)
dim ystore((polys*3)*179)
dim rstore(polys*179)
dim gstore(polys*179)
dim bstore(polys*179)

'## X and Y screen offset positions to centre object:
xff=0
yff=0

' ## X+Y rotation values!

rotx=0.03601
roty=0.03601
rtx=0
rty=0

' ## How big do you want it???
size=12

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'      Permanent and temporary storage definition!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'## Define arrays to store data:

dim x(polys*3)
dim y(polys*3)
dim z(polys*3)
dim c(polys*3)

'## Define arrays to hold transformed data:

dim tx(polys*3)
dim ty(polys*3)
dim tz(polys*3)
dim tc(polys*3)

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Read in the object data and place into storage arrays:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b=1
for a=1 to polys

   read x(b),y(b),z(b),x(b+1),y(b+1),z(b+1),x(b+2),y(b+2),z(b+2),c(b),c(b+1),c(b+2)
   b=b+3

next a

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                      Make movement!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

dw=0
for frames=1 to 175

'   setdrawbuf dw
'   clear window
     gosub transform
     gosub rotate
     gosub sort
     gosub draw
'   setdispbuf dw
'dw= 1-dw


next frames

return
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                 End of precalculation                   
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'  Sort Faces, colours and z co-ords according to depth!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label sort

for lame=1 to polys-1
b=1
for a=1 to polys-1

  dck1=tz(b)+tz(b+1)+tz(b+2)
  dck2=tz(b+3)+tz(b+4)+tz(b+5)
  if dck2>dck1 gosub swap
  b=b+3
next a
next lame

return

label swap

  for in=0 to 2
    tmpx=tx(b+in)
    tmpy=ty(b+in)
    tmpz=tz(b+in)
    tmpc=tc(b+in)
      tx(b+in)=tx(b+in+3)
      ty(b+in)=ty(b+in+3)
      tz(b+in)=tz(b+in+3)
      tc(b+in)=tc(b+in+3)
        tx(b+in+3)=tmpx
        ty(b+in+3)=tmpy
        tz(b+in+3)=tmpz
        tc(b+in+3)=tmpc
  next in

return


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'           Rotate Object and apply perspective:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label rotate
'## New angles:

rtx=rtx+rotx
rty=rty+roty
'## For tidyness
crx=cos(rtx)
srx=sin(rtx)
cry=cos(rty)
sry=sin(rty)
'## spin `em!!
b=1
for p=1 to polys
for inner=1 to 3

 nwy= crx*ty(b) + srx*tz(b)
 nwz= crx*tz(b) - srx*ty(b)

 nwx= cry*tx(b) + sry*nwz
 nwz= cry*nwz - sry*tx(b)

'##  Perspective+offset
 nwz=nwz+700
 tx(b)=xff+nwx*1300 /nwz
 ty(b)=yff+nwy*1300 /nwz
 tz(b)=nwz

 b=b+1
next inner
next p

return


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'  Pull Object into temporary storage for manipulation!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label transform
b=1

for a=1 to polys
for inner=1 to 3
 tx(b)=x(b)*size
 ty(b)=y(b)*size
 tz(b)=z(b)*size
 tc(b)=c(b)
 b=b+1
next inner
next a
 
return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Draw the object held in the temporary array!!!!!!!!!!!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label draw
b=1

for a=1 to polys
xstore(mp)=tx(b)
xstore(mp+1)=tx(b+1)
xstore(mp+2)=tx(b+2)

ystore(mp)=ty(b)
ystore(mp+1)=ty(b+1)
ystore(mp+2)=ty(b+2)
rstore(cp)=tc(b)+(size*4) -100
gstore(cp)=tc(b+1)+(size*4) -100
bstore(cp)=tc(b+2)+(size*4) -100

' setrgb 1, tc(b),tc(b+1),tc(b+2)
'fill triangle tx(b),ty(b) to tx(b+1),ty(b+1) to tx(b+2),ty(b+2)
 b=b+3
cp=cp+1
mp=mp+3
next a

return

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' 3D Object Description As Numerical Data...
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label object
' data structure: x,y,z,x,y,z,x,y,z,r,g,b
' (umbrella object, 23 polygons)

data 0,10,5,0,0,10,-7,7,5,155,0,155
data -7,7,5,-10,0,5,0,0,10,155,155,0
data 0,10,5,0,0,10,7,7,5,155,155,0
data 7,7,5,10,0,5,0,0,10,155,0,155
data 0,-10,5,0,0,10,-7,-7,5,155,155,0
data -7,-7,5,-10,0,5,0,0,10,155,0,155
data 0,-10,5,0,0,10,7,-7,5,155,0,155
data 7,-7,5,10,0,5,0,0,10,155,155,0
data 0.1,0,10,-0.1,0,10,0,0,11,255,255,255
data 0,0,10,.1,0,-8,-.1,0,-8,255,255,255
data 0,0,10,0,.1,-8,0,-.1,-8,255,255,255
data 0,10,5,0,0,4,0,0,4.1,255,255,155
data -7,7,5,0,0,4,0,0,4.1,255,255,155
data -10,0,5,0,0,4,0,0,4.1,255,255,155
data 7,7,5,0,0,4,0,0,4.1,255,255,155
data 0,-10,5,0,0,4,0,0,4.1,255,255,155
data -7,-7,5,0,0,4,0,0,4.1,255,255,155
data 10,0,5,0,0,4,0,0,4.1,255,255,155
data 7,-7,5,0,0,4,0,0,4.1,255,255,155
data -.3,0,-8,.3,0,-8,0,0,-10,155,100,0
data 0,0,-8,.3,0,-10,-.3,0,-10,155,100,0
data 0,-.3,-8,0,.3,-8,0,0,-10,155,100,0
data 0,0,-8,0,.3,-10,0,-.3,-10,155,100,0


'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'                    End of routine!!!
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%







