/***************
 * NAME:        bounce.ray
 * VERSION:     1.0 08.10.95
 * DESCRIPTION: Tutorial: bouncing ball
 * AUTHOR:      Andreas Heumann
 * BUGS:        none
 * TO DO:       nothing
 * HISTORY:
 *    DATE     NAME  COMMENT
 *    08.10.95 ah    initial release
 ***************/

signal on error

options results

IF ~show('P','RAYSTORM') THEN DO
  address COMMAND 'run >NIL: <NIL: /RayStorm'
  address COMMAND WaitForPort RAYSTORM
END  

address RAYSTORM

frames = 17
g = .2

'BRUSHPATH /brushes'
'TEXTUREPATH /textures'

'SETSCREEN 160 128'
'SETCAMERA <0,10,40> <0,5,0> <0,1,0> 25 20'
'POINTLIGHT <5,20,20>'
'SETWORLD [10,30,200] [10,10,10]'

'NEWACTOR groundactor'
'ALIGNMENT 0 ' frames+2 ' <0,0,360>'

'NEWSURFACE groundtop'
'DIFFUSE [255,255,255]'
'SPECULAR [0,0,0]'
'REFLECT [50,50,50]'
'IMTEXTURE checker.itx <0,-1,0> <0,0,0> <1.5,1.5,1.5> ACTOR groundactor'

'NEWSURFACE groundbottom'
'DIFFUSE [255,0,0]'
'SPECULAR [0,0,0]'
'REFLECT [50,50,50]'
'IMTEXTURE checker.itx <0,-1,0> <0,0,0> <1.5,1.5,1.5> ACTOR groundactor'

'TRIANGLE groundtop <-2,0,-2> <2,0,-2> <2,0,2> ACTOR groundactor'
'TRIANGLE groundtop <-2,0,-2> <-2,0,2> <2,0,2> ACTOR groundactor'
'TRIANGLE groundbottom <-2,-.01,-2> <2,-.01,-2> <2,-.01,2> ACTOR groundactor'
'TRIANGLE groundbottom <-2,-.01,-2> <-2,-.01,2> <2,-.01,2> ACTOR groundactor'

speed = -g
pos = 10
'NEWACTOR ballactor <0,'pos',0>'
do i=0 to frames
  'POSITION 'i i+1' <0,'pos',0>'
  pos = pos+speed
  if pos<=1 & speed<0 then
    speed = -speed
  else
    speed = speed-g
end
'ALIGNMENT 0 ' frames+2 ' <0,360,0>'

'NEWSURFACE ball'
'BRUSH earth.iff COLOR WRAPXY <0,10,0> <0,0,0> <.1,.1,.1> ACTOR ballactor'

'SPHERE ball <0,10,0> 1 ACTOR ballactor'

'ANTIALIAS 1'
'DISTRIB 2'

do i=12 to frames
  'STARTRENDER QUICK FROM 'i' TO 'i+1
  'SAVEPIC bounce' || RIGHT(i+1,4,0) || '.iff'
end

'CLEANUP'

exit 0

error:
say "Error" rc "in line" sigl ":"
GETERRORSTR rc
say result
exit 0
