`**************************************
`* Title  : Clock Sapien
`* Author : latch
`* Date   : 11-01-2007
`* Version:
`**************************************
 
rem =============================================================
rem = set up display
rem =============================================================
autocam off
set display mode 800,600,32
sync on
sync rate 60
hide mouse
 
position camera 0,80,-200
point camera 0,40,0
 
dim man(1000)
 
box 1,1,10,10
get image 1,0,0,11,11
 
ground=make_floor(1,100000.0,100000.0,0.0,-100.0,0.0,1,200.0,200.0)
 
for n = 20 to 60
   man(n)=stick_man(n)
   loop object man(n)
   set object speed man(n),rnd(25)+25
   center text screen width()/2,20,"Initializing Object Data..."
   sync
next n
 
randomize timer()
 
 
      cls 0
      ink rgb(255,255,255),0
      text 0,0,"I'M LATE!!  I'M LATE!!"
      get image 3,0,0,140,17
 
      sprite 1,330,10,3
      set sprite 3,1,0
 
      set camera view 0,0,screen width(),screen height()
 
do
      create bitmap 1,192,128
      ink rgb(0,255,0),0
      box 0,0,127,127
      ink 0,0
      text 33,64,get time$()
      get image 2,0,0,128,128
      delete bitmap 1
 
      for obj = 20 to 60
 
         move object man(obj),rnd(10)
         yrotate object man(obj),wrapvalue(object angle y(man(obj))+rnd(20)-10)
         texture object man(obj),2
      next obj
 
      objx#=object position x(man(20))
      objy#=object position y(man(20))
      objz#=object position z(man(20))
      angy#=object angle y(man(20))
 
      set camera to follow objx#,objy#,objz#,angy#,150,50,30,1
 
 
      sync
loop
 
end
 
rem =============================================================
rem = FUNCTIONS
rem =============================================================
 
   function is_even(num)
      true = 1
      false = 0
      test#=num/2.0
      if test# > (num/2) then exitfunction false
   endfunction true
`----------------------------------------------------------------
   function avail_obj(obj)
      while object exist(obj)=1
         inc obj
      endwhile
   endfunction obj
`-----------------------------------------------------------------
 
function stick_man(obj)
   rem =============================================================
   rem = Create character
   rem =============================================================
 
   rem variables
   body=avail_obj(obj)
   joint=avail_obj(body+1)
   head=avail_obj(body+2)
   chimney=avail_obj(body+3)
   bone=body
 
         rem right leg
         r_hip=1:r_thigh=2:r_knee=3:r_shin=4
 
         rem left leg
         l_hip=5:l_thigh=6:l_knee=7:l_shin=8
 
         rem right arm
         r_shold=9:r_bi=10:r_elbow=11:r_arm=12
 
         rem left arm
         l_shold=13:l_bi=14:l_elbow=15:l_arm=16
 
         rem head
         kneck=17:head=18:chimney=19
 
   rem body parts
   make object cylinder body,50
   scale object body,25,70,25
   make mesh from object bone,body
   scale object body,100,100,100
   make object cube head,25
   make mesh from object head,head
   make object cylinder chimney,5
   scale object chimney,60,400,60
   make mesh from object chimney,chimney
 
   rem joints
   make object sphere joint,50
   scale object joint,36,36,36
   make mesh from object joint,joint
   scale object joint,100,100,100
 
   rem create limbs
   count = 0
   for lmb=1 to 16
      inc count
      if is_even(lmb)=1
         add limb body,lmb,bone
      else
         add limb body,lmb,joint
      endif
 
      rem link limbs
      if count > 1
         link limb body,lmb,lmb-1
      endif
 
      if count = 4 then count = 0
 
   next lmb
 
   rem neck head and smoke stack
   add limb body,kneck,bone
   add limb body,head,head
   link limb body,head,kneck
   add limb body,chimney,chimney
   link limb body,chimney,head
 
   rem initial position of limbs
         rem right leg
   offset limb body,r_hip,-12,-26,0
   offset limb body,r_thigh,0,-20,0
   offset limb body,r_knee,0,-20,0
   offset limb body,r_shin,0,-20,0
 
         rem left leg
   offset limb body,l_hip,12,-26,0
   offset limb body,l_thigh,0,-20,0
   offset limb body,l_knee,0,-20,0
   offset limb body,l_shin,0,-20,0
 
         rem right arm
   offset limb body,r_shold,-33,20,0
   offset limb body,r_bi,-2,-20,0
   offset limb body,r_elbow,0,-20,0
   rotate limb body,r_elbow,300,0,0
   offset limb body,r_arm,0,-20,0
 
         rem left arm
   offset limb body,l_shold,33,20,0
   offset limb body,l_bi,2,-20,0
   offset limb body,l_elbow,0,-20,0
   rotate limb body,l_elbow,300,0,0
   offset limb body,l_arm,0,-20,0
 
         rem head
   offset limb body,kneck,0,20,0
   offset limb body,head,0,20,0
   offset limb body,chimney,5,20,-8
 
   rem object animation
   set object keyframe body,0
   rotate limb body,r_hip,310,0,0
   rotate limb body,r_knee,60,0,0
   rotate limb body,r_shold,30,0,0
   rotate limb body,l_hip,20,0,0
   rotate limb body,l_knee,20,0,0
   rotate limb body,l_shold,310,0,0
   set object keyframe body,10
   rotate limb body,r_hip,0,0,0
   rotate limb body,r_knee,3,0,0
   rotate limb body,r_shold,330,0,0
   rotate limb body,l_hip,340,0,0
   rotate limb body,l_knee,60,0,0
   rotate limb body,l_shold,0,0,0
   set object keyframe body,20
   rotate limb body,r_hip,20,0,0
   rotate limb body,r_knee,30,0,0
   rotate limb body,r_shold,300,0,0
   rotate limb body,l_hip,310,0,0
   rotate limb body,l_knee,30,0,0
   rotate limb body,l_shold,20,0,0
   set object keyframe body,28
   rotate limb body,l_hip,0,0,0
   rotate limb body,l_knee,3,0,0
   rotate limb body,l_shold,359,0,0
   rotate limb body,r_hip,359,0,0
   rotate limb body,r_knee,10,0,0
   rotate limb body,r_shold,0,0,0
   set object keyframe body,38
 
   rem cleanup unneeded meshes and objects
   delete object chimney
   delete mesh chimney
   delete object head
   delete mesh head
   delete object joint
   delete mesh joint
   delete mesh bone
 
endfunction body
`-----------------------------------------------------------------------------
function make_floor(obj,width#,height#,posx#,posy#,posz#,texture,across#,down#)
 
   rem check for exisiting objects
   while object exist(obj)=1
      inc obj
   endwhile
 
   rem make the actual plain object and rotate it flat
   make object plain obj,width#,height#
   xrotate object obj,90
   fix object pivot obj
 
   rem texture and scale the texture to tile it or not
   texture object obj,texture
   scale object texture obj,across#,down#
 
   rem set the initial position of the floor
   position object obj,posx#,posy#,posz#
endfunction obj