REM ===========SETUP==========
`Setup sync(-rate) etc.
sync on : sync rate 60
hide mouse : autocam off
set display mode 800,600,32
 
`Number of balls in lamp
#constant C_num 5
 
`random global color of the light and balls
global color : color=rgb(rnd(255),rnd(255),rnd(255))
 
`background color will be grey
bgcolor=rgb(127,127,127)
 
 
 
REM ==========IMAGES==========
 
`make image for metal above and below the glas, black will be invisible
cls                        `clear to make sure its all black
ink rgb(120,120,120),0        `grey-metallic color
box 0,0,512,150            `  "     "     box at the top..
box 0,320,512,512          `...and bottom of the image
get image 1,0,0,512,512    `get the image
 
`make image for the stand, just the top will be visible so we'll keep everything below blsck
cls                        `erase old boxes from screen
box 0,0,512,200            `a box, just at the top
get image 2,0,0,512,512    `finally get the image
 
 
 
 
REM ==========OBJECTS=========
 
`glas
make object sphere 1,5,32,32     `make a sphere...
scale object 1,25,100,25         `...stretch it...
ghost object on 1,2              `...ghost it so it looks like glas, ghost mode 2 is perfect...
set alpha mapping on 1,25        `...and then make it 75% transparent
 
`metal
make object sphere 2,5.05,32,32  `nearly same size...
scale object 2,25,100,25         `...as the glas , just a little bit bigger
texture object 2,1               `texture it with image 1
set object transparency 2,1      `hide black parts, there the glas will be visible
 
`stand
make object sphere 3,5,32,32     `again, same size...
scale object 3,30,75,30          `but different scale
texture object 3,2               `texture with img 2
set object transparency 3,1      `and hide lower part
move object down 3,3             `its the stand/base isnt it? so it has be at the top, yeah...
 
`balls
for ball=11 to 10+C_num          `as 1 to 3 are already used the balls will be 10+1 to 10+number of balls
   new_ball(ball)                `creates a new ghosted ball at the bottom of the lamp (explained in the function itself)
   move object up ball,rnd(5)    `as they'll move with same speed they have to be "spawned" random
next ball                        `or they'll be on the same height all the time
 
 
 
REM =========LIGHTS===========
 
`light from inside the stand/base, colored with the random 'color' defined earlier
make light 1
set directional light 1,5,1000,5
color light 1,color
 
set normalization on `this will smooth lighting
 
REM ======CAMERA-SETUP========
position camera 25,5,25  `position it outside the lamp
color backdrop bgcolor   `color the backdrop with background-color (grey)
 
 
REM ======MAIN_LOOP====>>>>>>>
do
 
   gosub Camera
 
   `control lava-balls
   for ball=11 to 10+C_num
      `slowly move them up
      move object up ball,lavaspeed#/1000.0
 
      `if it is at the top it will "respawn" at the bottom lol *unrealistic*
      if object position y(ball) >= 1.5-object size(ball)/2.0
         `just delete...
         delete object ball
         `...and make a new one
         new_ball(ball)
      endif
   next ball
 
   `if speed of the balls is lower than 5...
   if lavaspeed#<5
      `... then slowly increase it
      inc lavaspeed#,0.01
   endif
 
   `print FPS
   set cursor 0,0 : print screen fps()
 
   `update screen
   sync
 
loop
REM <<<<<<=========
 
 
REM ==========SUBS===========
Camera:
 
   if spacekey()
      `move camera forward and backward with arrowkeys
      move camera upkey()-downkey()
      `rotate it with the mouse
      rotate camera camera angle x()+mousemovey(),camera angle y()+mousemovex(),0
 
   else
 
      `if space is not pressed:
 
      `rotate camera nearly 90° ...
      rotate camera camera angle x()-5,camera angle y()+87.5,0
      `... move it to that direction ...
      move camera 0.5
      `... and turn it back to face the lamp
      point camera 0,0,0
 
      `this way it will move around the lamp (i know its not very exact but it was easy to code :p )
   endif
 
return
 
 
REM ========FUNCTIONS===========
function new_ball(num)
   make object sphere num,(1+rnd(2))/5.0,32,32      `make random-sized new sphere, with 32 rows and columns so it'll be smooth
   ghost object on num,2                            `ghost it
   set alpha mapping on num,60+rnd(40)              `random transparency between 0% and 40%
   local x# : local y# : local z#                   `local vars for the position
   x#=(rnd(5)-rnd(5))/25.0                          `random x position between -0.2 and +0.2
   y#=-1.0+object size(num)/2.0                     `       y position at the bottom
   z#=(rnd(5)-rnd(5))/25.0                          `random z position between -0.2 and +0.2
   position object num,x#,y#,z#                     `position it now
   color object num,color                           `color it (with the global random 'color')
   disable object zdepth num                        `always draw in front, or it will be sometimes hidden by glas
endfunction