'              ###############################
'              #  Electric-ball-thingy-demo  #
'              #                             #
'              #      By: Bongotrummor       #
'              ###############################
numballs=6:dim balls(numballs,5):maxzaps=8
for thisball=1 to numballs
balls(thisball,0)=100+ran(440)
balls(thisball,1)=200+ran(300)
balls(thisball,2)=(-45+ran(90))*pi/180
balls(thisball,3)=20+ran(10)
next thisball

open window 640,512
repeat
 dim balls(numballs,5)
 setdispbuf d:d=1-d:setdrawbuf d
 gosub refresh

 for thisball=1 to numballs
  balls(thisball,4)=balls(thisball,4)+0.1
  balls(thisball,0)=balls(thisball,0)+((sin(balls(thisball,2)))*balls(thisball,3)*balls(thisball,4))
  balls(thisball,1)=balls(thisball,1)-(balls(thisball,3)*cos(balls(thisball,2))-(9.82*balls(thisball,4)^2)/2)
  setrgb 1,0,50,150
  fill circle balls(thisball,0),balls(thisball,1),16

  for ballcrash=1 to numballs
   if (balls(thisball,0)+8)>balls(ballcrash,0) and (balls(thisball,0)-8)<balls(ballcrash,0) and (balls(thisball,1)-8)<balls(ballcrash,1) and (balls(thisball,1)+8)>balls(ballcrash,1) and ballcrash<>thisball then
    gosub crash
   fi
  next ballcrash

  if balls(thisball,1)>464 then
   balls(thisball,1)=464
   gosub crash
   balls(thisball,2)=balls(thisball,2)+90
   line balls(thisball,0)-100+ran(200),0 to balls(thisball,0)-100+ran(200),150
   line to balls(thisball,0)-100+ran(200),300
   line to balls(thisball,0)-100+ran(200),450
   line to balls(thisball,0),464
  fi

  if balls(thisball,0)>624 then
    balls(thisball,0)=624
    gosub crash
  fi
  if balls(thisball,0)<16 then
   balls(thisball,0)=16
   gosub crash
  fi
  if balls(thisball,3)<2 then
   gosub crash
   balls(thisball,3)=20+ran(10)
   balls(thisball,2)=(-45+ran(90))*pi/180
  fi

  setrgb 1,0,200,255
  for zaps=1 to int(maxzaps)
   zapangle=ran(2*pi)
   line balls(thisball,0),balls(thisball,1) to balls(thisball,0)+sin(zapangle)*32,balls(thisball,1)-cos(zapangle)*32
   zapangle=ran(2*pi)
   line to balls(thisball,0)+sin(zapangle)*16,balls(thisball,1)-cos(zapangle)*16
  next zaps
 next thisball

 if (and(peek("port1"),16)>0) then
  numballs=numballs+1
 fi

 if (and(peek("port1"),64)>0) and numballs>1 then
  numballs=numballs-1
 fi

 text 320,100,"Number of balls:"+str$(numballs),"cb"
 clear fill rectangle 0,480 to 640,512
 text textx,500,"Wohoo!!! I've completed my first demo ever! And believe it or not, I'm actually quite happy with it. It looks so much better now than it did a few days ago. I don't really know what to write in this scroll, but from what I've seen, a scrolling text is something you must have...             Maybe I should have some kind of credits here...      OK here goes: Zorlius (for helping me understand the array stuff), Shockwave, Xalthorn, Rafryer, Jomorrow and everybody else at the ps2-yabasic forum (for helping me out with my game and for making cool demos), maybe I should thank my parents to (for buying me this PS2).               I don't know who else to thank, so I guess this text will end here. But it will return in a few secs, from the beginning, cool huh?           Men innan det roliga tar slut vill jag bara halsa alla svenskar har, fast det finns nog inga...", "rb"
 text textx-3000,50+sin(textx*3)*20, "Muahaha!!! I am the evil scroller! I'm here to annoy you and make thing generally irritating.  I will never let you read the real scroller down there, I will disturb you, I want to disturb you. Don't read me, It's bad for you. *evil laughter* Ha, you will never get rid of me. And together with my friends, the other evil scrollers, I will soon be able to take over the world!! Just code more demos, loaders, screensavers, or whatever uses a scrolling text, and we will take over the world!! Muahaha!!","rb"
 textx=textx-2
 if textx<0 textx=9600
until (and(peek("port1"),16384)>0)
end

label crash
 balls(thisball,2)=0-balls(thisball,2)
 balls(thisball,4)=0
 balls(thisball,3)=balls(thisball,3)-4
 setrgb 1,0,50,100
 fill circle balls(thisball,0),balls(thisball,1),64
 setrgb 1,0,200,255
 fill circle balls(thisball,0),balls(thisball,1),24
return

label refresh
 setrgb 1,0,0,50
 setrgb 2,0,0,50
 setrgb 3,0,0,0
 gtriangle 0,0 to 640,0 to 640,512
 setrgb 1,0,0,0
 gtriangle 0,512 to 0,0 to 640,512
return



