include "window.inc"
Window "Night Waterfall",800,600,1
include "Fernsprite.inc"
CreateFern
ColorKey 0,0,0


Type pType
     single lifespan
     single x
     single y
     single xv
     single yv
End Type

Dim Particle(10000) as pType
sys pic,xstart, ystart, i, mx=10000
'pic = LoadBmp("bmp/night",0)

Sub ParticleInit()
int Xstart = Width  \ 10
int Ystart = Height \ 10
int i
For i = 0 To mx
    Particle(i).lifespan = Rand 1,500
    Particle(i).x  = Xstart
    Particle(i).y  = Ystart
    Particle(i).yv = Rand(1,4)
    Particle(i).xv = Rand(1,8) 
Next
End Sub

Sub drop(sys x,y,ra,rb,r,g,b)       
int iBrush,iPen,c
c=b*0x10000+g*0x100+r
iBrush = CreateSolidBrush c
iPen=CreatePen -1,-1,c
SelectObject bHdc, iBrush
SelectObject bHdc, iPen
Ellipse bHdc,x,y,x+ra,y+rb
DeleteObject iBrush
DeleteObject iPen
End Sub

single pp=0.3
sys i,j,px,py,spla


ParticleInit()
While EscKey()=0
'ClsColor (200,200,200)
'SetBmp (pic,0,0,800,600,0) 

'SKY

int y
for y=0 to 549
  line 0,y,799,y,0xffffffff,10,10,y*pp
next

For i=0 To mx
px=particle[i].x
py=particle[i].y
if py>550 then spla=1
int x=Particle(i).x
int y=Particle(i).y
RoundBox Particle(i).x, Particle(i).y,12,10,10,10, 0,Rand(32,64),Rand(200,255)
Particle(i).x  = Particle(i).x + Particle(i).xv
Particle(i).y  = Particle(i).y + Particle(i).yv
Particle(i).yv = Particle(i).yv + 0.96
iF Particle(i).y >= Height  
   Particle(i).yv = -(Particle(i).yv * 0.46)
   Particle(i).y  =  Height
End iF
Particle(i).LifeSpan = Particle(i).LifeSpan -1
iF Particle(i).LifeSpan <=0 
   Particle(i).LifeSpan = Rand(1,500)
   Particle(i).x = Xstart
   Particle(i).y = Ystart
   Particle(i).yv = Rand(1,4)
   Particle(i).xv = Rand(1,8) 
End iF
Next

FernCopy -100,150,300,470,420,470
FernCopy 0,150,300,470,420,470
FernCopy 120,250,300,470,420,470

'WATER

spla=1
if spla then
  for j=0 to 80 step 5
    py=545
    px=j*10+rand(0,20)
    drop px,py,47,14,0,32,220
  next
end if

for y=550 to 799
  line 0,y,799,y,0xffffffff,0,32,220
next

FlipBuffer
WaitFPS 14
Wend
DeleteFern
WinEnd
WinEnd