`-----------------------------
`PROJECT:  Morph
`CREATED:  24/11/2007 20:36:12
`AUTHOR :  Bongadoo 
`-----------------------------
 
`-------
`GLOBALS
`-------
 
`Camera
global cam_trail# = 25.0
global cam_dist#  = 50.0
 
`Stages
global stage      = 1
global sub_stage  = 1
 
`----------
`INITIALISE
`----------
 
if check display mode(1024,768,32) = 1
  set display mode 1024,768,32
else
  exit prompt "Cannot support 1024x768 32-bit","Error"
  end
endif
 
`if get maximum antialias level() >= 4
`  set antialias level 4
`endif
 
`-----
`SETUP
`-----
 
sync on
sync rate 60
color backdrop rgb(0,0,0)
 
`Keep same value so images remain constant
randomize 1 
 
autocam off
position camera 15.0,15.0,15.0
point camera 7.5,0.0,0.0
position camera 25.0,50.0,50.0
 
`-----------
`LOAD STAGES
`-----------
 
load_stage1()
load_stage2()
load_stage3()
load_stage4()
load_stage5()
 
`----
`MAIN
`----
 
do
 
  select stage
    case 1 : run_stage1() : endcase
    case 2 : run_stage2() : endcase
    case 3 : run_stage3() : endcase
    case 4 : run_stage4() : endcase
    case 5 : run_stage5() : endcase
    case 6 : run_stage6() : endcase
  endselect
 
  `Debug
  tx=10
  ty=10
  ty_step=15
 
  TEXT tx,ty,"MORPH" : inc ty,ty_step*2
 
  sync
 
loop
 
`---------
`FUNCTIONS
`---------
 
`Gets a free object number
function free_obj()
 
  do
    inc x
    if object exist(x) = 0 then exit
  loop
 
endfunction x
 
`Creates a new plain
function new_plain(x,y)
 
  n = free_obj()
  make object plain n,x,y
 
endfunction n
 
`Creates a new cube
function new_cube(size)
 
  n = free_obj()
  make object cube n,size
 
endfunction n
 
`Creates a new box
function new_box(x,y,z)
 
  n = free_obj()
  make object box n,x,y,z
 
endfunction n
 
`Creates a new sphere
function new_sphere(size,rows,cols)
 
  n = free_obj()
  make object sphere n,size,rows,cols
 
endfunction n
 
`Loads stage1
function load_stage1()
 
  `Globals
  dim s1_plain_g(6)  
  dim s1_plain(12)
  dim s1_count(1)
 
  `Create first plains
  ` This creates two plains and glues their edges to a cube
  ` This means the cube can be rotated to give the effect
  ` of the plains 'flipping' along
  for i = 1 to 6
    s1_plain_g(i) = new_cube(1)
    s1_plain(i) = new_plain(5,5)
    s1_plain(i+6) = new_plain(5,5)
    position object s1_plain(i),2.5,0.06,0
    position object s1_plain(i+6),2.5,0,0
    xrotate object s1_plain(i),-90
    xrotate object s1_plain(i+6),-90
    zrotate object s1_plain(i+6),180
    fix object pivot s1_plain(i)
    fix object pivot s1_plain(i+6)
    glue object to limb s1_plain(i),s1_plain_g(i),0
    glue object to limb s1_plain(i+6),s1_plain_g(i),0
    hide object s1_plain_g(i)
    hide object s1_plain(i)
    hide object s1_plain(i+6)
  next i
 
  s1_count(1) = 0
 
endfunction
 
`Flips first plains across the floor
function run_stage1() 
 
  `Fade in
  if s1_count(1) <= 100
    fade object s1_plain(1),s1_count(1)
    fade object s1_plain(1+6),s1_count(1)
    inc s1_count(1)
  endif
 
  `Flip
  if object angle z(s1_plain_g(1)) < 180
    show object s1_plain(1)
    show object s1_plain(1+6)
    zrotate object s1_plain_g(1),object angle z(s1_plain_g(1)) + 2
  endif
 
  `Reposition
  ` Flip around and continue, unless at the last part of the box layout 
  if object angle z(s1_plain_g(1)) >= 180
    if object position x(s1_plain_g(1)) <> ( 8 * -5 )
      zrotate object s1_plain_g(1),0
      position object s1_plain_g(1),object position x(s1_plain_g(1)) - 5,0,0
    else
      stage = 2
    endif
  endif
 
  `Box layout part 1
  if object position x(s1_plain_g(1)) = ( 6 * -5 )
    position object s1_plain_g(2),6*-5,0,0
    show object s1_plain(2)
    show object s1_plain(2+6)
  endif
 
  `Box layout part 2
  if object position x(s1_plain_g(1)) = ( 7 * -5 )
    position object s1_plain_g(3),7*-5,0,0
    show object s1_plain(3)
    show object s1_plain(3+6)
  endif
 
  `Box layout part 3
  if object position x(s1_plain_g(1)) = ( 8 * -5 ) and object position z(s1_plain_g(4)) = 0
    position object s1_plain_g(4),(8*-5)+2.5,0,2.5
    yrotate object s1_plain_g(4),90
    fix object pivot s1_plain_g(4)
    position object s1_plain_g(5),(8*-5)+2.5,0,-2.5
    yrotate object s1_plain_g(5),-90
    fix object pivot s1_plain_g(5)
    position object s1_plain_g(6),(8*-5),0,0
    show object s1_plain(4)
    show object s1_plain(5)
    show object s1_plain(6)
    show object s1_plain(4+6)
    show object s1_plain(5+6)
    show object s1_plain(6+6)
  endif
 
  `Unfold final parts
  if object angle x(s1_plain_g(4)) < 180 and object position x(s1_plain_g(4)) < 0
    xrotate object s1_plain_g(4),object angle x(s1_plain_g(4)) + 2
    xrotate object s1_plain_g(5),object angle x(s1_plain_g(5)) - 2
  endif
 
  position camera camera position x() - (5.0/90.0),cam_dist#,cam_dist#
 
endfunction
 
`Loads stage2
function load_stage2()
 
endfunction
 
`Fold back up into cube
function run_stage2()
 
  `First fold
  if object angle z(s1_plain_g(2)) < 90
    zrotate object s1_plain_g(2),object angle z(s1_plain_g(2)) + 2
  endif
 
  `Reglue
  if sub_stage = 1 and object angle z(s1_plain_g(2)) = 90
    sx = object position x(s1_plain_g(3))
    position object s1_plain_g(2),5,0,0
    position object s1_plain_g(3),0,0,0
    glue object to limb s1_plain_g(2),s1_plain_g(3),0
    position object s1_plain_g(3),sx,0,0
    inc sub_stage
  endif
 
  `Second fold
  if sub_stage = 2 and object angle z(s1_plain_g(3)) < 90
    zrotate object s1_plain_g(3),object angle z(s1_plain_g(3)) + 2
    xrotate object s1_plain_g(4),object angle x(s1_plain_g(4)) - 2
    xrotate object s1_plain_g(5),object angle x(s1_plain_g(5)) + 2
  endif
 
  `Reglue
  if sub_stage = 2 and object angle z(s1_plain_g(3)) = 90
    sx = object position x(s1_plain_g(6))
    position object s1_plain_g(3),5,0,0
    position object s1_plain_g(4),2.5,0,2.5
    position object s1_plain_g(5),2.5,0,-2.5
    position object s1_plain_g(6),0,0,0
    glue object to limb s1_plain_g(3),s1_plain_g(6),0
    glue object to limb s1_plain_g(4),s1_plain_g(6),0
    glue object to limb s1_plain_g(5),s1_plain_g(6),0
    position object s1_plain_g(6),sx,0,0
    inc sub_stage
  endif
 
  `Final fold
  if sub_stage = 3 and object angle z(s1_plain_g(6)) < 90
    zrotate object s1_plain_g(6),object angle z(s1_plain_g(6)) + 2
  endif
 
  `Next stage
  if object angle z(s1_plain_g(6)) = 90
    sub_stage = 1
    inc stage
  endif
 
  position camera camera position x() - (5.0/90.0),cam_dist#,cam_dist#
 
endfunction
 
`Loads stage3
function load_stage3()
 
  `Globals
  dim s3_cube(29)
  dim s3_cube_g(29)
 
  `Create cubes for body
  for i = 1 to 29
    s3_cube(i) = new_cube(5)
    s3_cube_g(i) = new_cube(1)
    position object s3_cube(i),2.5,2.5,0
    glue object to limb s3_cube(i),s3_cube_g(i),0
    hide object s3_cube(i)
    hide object s3_cube_g(i)
  next i
 
endfunction
 
`Cube to man
function run_stage3()
 
  `Hide plains and show first cube
  if sub_stage = 1
    position object s3_cube_g(1),object position x(s1_plain_g(1)) - 5,0,0
    show object s3_cube(1)
    for i = 1 to 12
      hide object s1_plain(i)
    next i
    inc sub_stage
  endif
 
  `Flip cube
  if sub_stage >= 2 and sub_stage <= 12 and object angle z(s3_cube_g(1)) < 90
    zrotate object s3_cube_g(1),object angle z(s3_cube_g(1)) + 2
  endif
 
  `Reposition
  if sub_stage >= 2 and sub_stage <= 12 and object angle z(s3_cube_g(1)) = 90
    zrotate object s3_cube_g(1),0
    position object s3_cube_g(1),object position x(s3_cube_g(1))-5,0,0
    inc sub_stage
  endif
 
  `First 7 cubes (spine)
  for i = 6 to 12
    if sub_stage = i and object angle z(s3_cube_g(1)) = 0
      position object s3_cube_g(i-4),object position x(s3_cube_g(1)),0,0
      show object s3_cube(i-4)
    endif
  next i
 
  `Shoulders (pre)
  if sub_stage = 8 and object angle z(s3_cube_g(1)) = 0
      position object s3_cube_g(9),object position x(s3_cube_g(1))+2.5,0,-2.5
      position object s3_cube_g(10),object position x(s3_cube_g(1))+2.5,0,2.5
      yrotate object s3_cube_g(9),-90
      yrotate object s3_cube_g(10),90
      fix object pivot s3_cube_g(9)
      fix object pivot s3_cube_g(10)
      show object s3_cube(9)
      show object s3_cube(10)
  endif
 
  `Flip cube (shoulders)
  if sub_stage >= 8 and sub_stage <= 9 and object angle x(s3_cube_g(10)) < 90
    xrotate object s3_cube_g(9),object angle x(s3_cube_g(9)) - 2
    xrotate object s3_cube_g(10),object angle x(s3_cube_g(10)) + 2
  endif
 
  `Reposition (shoulders)
  if sub_stage >= 8 and sub_stage <= 9 and object angle x(s3_cube_g(10)) = 90
    xrotate object s3_cube_g(9),0
    xrotate object s3_cube_g(10),0
    position object s3_cube_g(9),object position x(s3_cube_g(9)),0,object position z(s3_cube_g(9))-5
    position object s3_cube_g(10),object position x(s3_cube_g(10)),0,object position z(s3_cube_g(10))+5
  endif
 
  `Shoulders (new cubes)
  for i = 8 to 9
    if sub_stage = i+1 and object angle z(s3_cube_g(1)) = 0
      yrotate object s3_cube_g(i+3),-90
      yrotate object s3_cube_g(i+5),90
      position object s3_cube_g(i+3),object position x(s3_cube_g(9)),0,object position z(s3_cube_g(9))
      position object s3_cube_g(i+5),object position x(s3_cube_g(10)),0,object position z(s3_cube_g(10))
      show object s3_cube(i+3)
      show object s3_cube(i+5)
    endif
  next i
 
  `Arms (pre)
  if sub_stage = 10 and object angle z(s3_cube_g(1)) = 0
      position object s3_cube_g(9),object position x(s3_cube_g(9))-2.5,0,object position z(s3_cube_g(9))+2.5
      position object s3_cube_g(10),object position x(s3_cube_g(10))-2.5,0,object position z(s3_cube_g(10))-2.5
      yrotate object s3_cube_g(9),90
      yrotate object s3_cube_g(10),-90
      fix object pivot s3_cube_g(9)
      fix object pivot s3_cube_g(10)
  endif
 
  `Flip cube (arms)
  if sub_stage >= 10 and sub_stage <= 12 and object angle z(s3_cube_g(10)) < 90
    zrotate object s3_cube_g(9),object angle z(s3_cube_g(9)) + 2
    zrotate object s3_cube_g(10),object angle z(s3_cube_g(10)) + 2
  endif
 
  `Reposition (arms)
  if sub_stage >= 10 and sub_stage <= 12 and object angle z(s3_cube_g(10)) = 90
    zrotate object s3_cube_g(9),0
    zrotate object s3_cube_g(10),0
    position object s3_cube_g(9),object position x(s3_cube_g(9))-5,0,object position z(s3_cube_g(9))
    position object s3_cube_g(10),object position x(s3_cube_g(10))-5,0,object position z(s3_cube_g(10))
  endif
 
  `Arms (new cubes)
  for i = 10 to 11
    if sub_stage = i and object angle z(s3_cube_g(10)) = 0
      position object s3_cube_g(i+5),object position x(s3_cube_g(9)),0,object position z(s3_cube_g(9))
      position object s3_cube_g(i+7),object position x(s3_cube_g(10)),0,object position z(s3_cube_g(10))
      show object s3_cube(i+5)
      show object s3_cube(i+7)
    endif
  next i
 
  `Hips (pre)
  if sub_stage = 13
      position object s3_cube_g(19),object position x(s3_cube_g(1))+2.5,0,-2.5
      position object s3_cube_g(20),object position x(s3_cube_g(1))+2.5,0,2.5
      yrotate object s3_cube_g(19),-90
      yrotate object s3_cube_g(20),90
      fix object pivot s3_cube_g(19)
      fix object pivot s3_cube_g(20)
      show object s3_cube(19)
      show object s3_cube(20)
      inc sub_stage
  endif
 
  `Flip cube (hips)
  if sub_stage = 14 and object angle x(s3_cube_g(20)) < 90
    xrotate object s3_cube_g(19),object angle x(s3_cube_g(19)) - 2
    xrotate object s3_cube_g(20),object angle x(s3_cube_g(20)) + 2
  endif
 
  `Reposition (hips)
  if sub_stage = 14 and object angle x(s3_cube_g(20)) = 90
    xrotate object s3_cube_g(19),0
    xrotate object s3_cube_g(20),0
    position object s3_cube_g(19),object position x(s3_cube_g(19)),0,object position z(s3_cube_g(19))-5
    position object s3_cube_g(20),object position x(s3_cube_g(20)),0,object position z(s3_cube_g(20))+5
    inc sub_stage
  endif
 
  `Legs (pre)
  if sub_stage = 15 
      position object s3_cube_g(21),object position x(s3_cube_g(19))-2.5,0,object position z(s3_cube_g(19))+2.5
      position object s3_cube_g(22),object position x(s3_cube_g(20))-2.5,0,object position z(s3_cube_g(20))-2.5
      show object s3_cube(21)
      show object s3_cube(22)
      inc sub_stage
  endif
 
  `Flip cube (legs)
  if sub_stage >= 16 and sub_stage <= 19 and object angle z(s3_cube_g(22)) < 90
    zrotate object s3_cube_g(21),object angle z(s3_cube_g(21)) + 2
    zrotate object s3_cube_g(22),object angle z(s3_cube_g(22)) + 2
  endif
 
  `Reposition (legs)
  if sub_stage >= 16 and sub_stage <= 19 and object angle z(s3_cube_g(22)) = 90
    zrotate object s3_cube_g(21),0
    zrotate object s3_cube_g(22),0
    position object s3_cube_g(21),object position x(s3_cube_g(21))-5,0,object position z(s3_cube_g(21))
    position object s3_cube_g(22),object position x(s3_cube_g(22))-5,0,object position z(s3_cube_g(22))
    inc sub_stage
  endif
 
  `Legs (new cubes)
  for i = 16 to 19
    if sub_stage = i and object angle z(s3_cube_g(22)) = 0
      position object s3_cube_g(i+7),object position x(s3_cube_g(21)),0,object position z(s3_cube_g(21))
      position object s3_cube_g(i+10),object position x(s3_cube_g(22)),0,object position z(s3_cube_g(22))
      show object s3_cube(i+7)
      show object s3_cube(i+10)
    endif
  next i
 
  if sub_stage < 10
    position camera camera position x() - (5.0/45.0),cam_dist#,cam_dist#
  endif
 
  `Final
  if sub_stage = 20
    sub_stage = 1
    inc stage
  endif
 
endfunction
 
`Load stage4
function load_stage4()
 
  `Globals
  ` Vis boxes
  dim s4_spine(1)
  dim s4_shoulder_l(1)
  dim s4_shoulder_r(1)
  dim s4_arm_top_l(1)
  dim s4_arm_top_r(1)
  dim s4_arm_bot_l(1)
  dim s4_arm_bot_r(1)
  dim s4_leg_top_l(1)
  dim s4_leg_top_r(1)
  dim s4_leg_bot_l(1)
  dim s4_leg_bot_r(1)
  ` Joints
  dim s4_shoulder_l_j(1)
  dim s4_shoulder_r_j(1)
  dim s4_arm_top_l_j(1)
  dim s4_arm_top_r_j(1)
  dim s4_arm_bot_l_j(1)
  dim s4_arm_bot_r_j(1)
  dim s4_leg_top_l_j(1)
  dim s4_leg_top_r_j(1)
  dim s4_leg_bot_l_j(1)
  dim s4_leg_bot_r_j(1)
  dim s4_rotator(1)
  ` Fake cloud
  dim s4_cloud(1)
  dim s4_cloud_count(1)
 
  `Make left arm
  s4_arm_top_l(1) = new_box(10,5,5)
  s4_arm_bot_l(1) = new_box(10,5,5)
  s4_arm_bot_l_j(1) = new_cube(1)
  position object s4_arm_bot_l_j(1),-5,0,0
  glue object to limb s4_arm_bot_l_j(1),s4_arm_top_l(1),0
  position object s4_arm_top_l(1),5,0,0
  position object s4_arm_bot_l(1),-5,0,0
  glue object to limb s4_arm_bot_l(1),s4_arm_bot_l_j(1),0
 
  `Make left shoulder, connect to arm
  s4_shoulder_l(1) = new_cube(5)
  s4_arm_top_l_j(1) = new_cube(1)
  position object s4_arm_top_l_j(1),0,0,-2.5
  glue object to limb s4_arm_top_l_j(1),s4_shoulder_l(1),0
  position object s4_shoulder_l(1),0,0,2.5
  position object s4_arm_top_l(1),-2.5,0,-2.5
  glue object to limb s4_arm_top_l(1),s4_arm_top_l_j(1),0
 
  `Make right arm and shoulder
  s4_arm_top_r(1) = new_box(10,5,5)
  s4_arm_bot_r(1) = new_box(10,5,5)
  s4_arm_bot_r_j(1) = new_cube(1)
  position object s4_arm_bot_r_j(1),-5,0,0
  glue object to limb s4_arm_bot_r_j(1),s4_arm_top_r(1),0
  position object s4_arm_top_r(1),5,0,0
  position object s4_arm_bot_r(1),-5,0,0
  glue object to limb s4_arm_bot_r(1),s4_arm_bot_r_j(1),0
 
  `Make right shoulder, connect to arm
  s4_shoulder_r(1) = new_cube(5)
  s4_arm_top_r_j(1) = new_cube(1)
  position object s4_arm_top_r_j(1),0,0,2.5
  glue object to limb s4_arm_top_r_j(1),s4_shoulder_r(1),0
  position object s4_shoulder_r(1),0,0,-2.5
  position object s4_arm_top_r(1),-2.5,0,2.5
  glue object to limb s4_arm_top_r(1),s4_arm_top_r_j(1),0
 
  `Make spine
  s4_spine(1) = new_box(40,5,5)
  s4_shoulder_l_j(1) = new_cube(1)
  s4_shoulder_r_j(1) = new_cube(1)
  s4_leg_top_l_j(1) = new_cube(1)
  s4_leg_top_r_j(1) = new_cube(1)
  position object s4_shoulder_l_j(1),7.5,0,-2.5
  position object s4_shoulder_r_j(1),7.5,0,2.5
  position object s4_leg_top_l_j(1),-17.5,0,-2.5
  position object s4_leg_top_r_j(1),-17.5,0,2.5
  glue object to limb s4_shoulder_l_j(1),s4_spine(1),0
  glue object to limb s4_shoulder_r_j(1),s4_spine(1),0
  glue object to limb s4_leg_top_l_j(1),s4_spine(1),0
  glue object to limb s4_leg_top_r_j(1),s4_spine(1),0
 
  `Make left leg
  s4_leg_top_l(1) = new_box(12,5,5)
  s4_leg_bot_l(1) = new_box(13,5,5)
  s4_leg_bot_l_j(1) = new_cube(1)
  position object s4_leg_bot_l_j(1),-6,0,0
  glue object to limb s4_leg_bot_l_j(1),s4_leg_top_l(1),0
  position object s4_leg_top_l(1),6,0,0
  position object s4_leg_bot_l(1),-6.5,0,0
  glue object to limb s4_leg_bot_l(1),s4_leg_bot_l_j(1),0
 
  `Make right leg
  s4_leg_top_r(1) = new_box(12,5,5)
  s4_leg_bot_r(1) = new_box(13,5,5)
  s4_leg_bot_r_j(1) = new_cube(1)
  position object s4_leg_bot_r_j(1),-6,0,0
  glue object to limb s4_leg_bot_r_j(1),s4_leg_top_r(1),0
  position object s4_leg_top_r(1),6,0,0
  position object s4_leg_bot_r(1),-6.5,0,0
  glue object to limb s4_leg_bot_r(1),s4_leg_bot_r_j(1),0
 
  `Glue arms to spine
  position object s4_spine(1),-7.5,0,2.5
  position object s4_shoulder_l(1),0,0,-2.5
  glue object to limb s4_shoulder_l(1),s4_shoulder_l_j(1),0
  position object s4_spine(1),-7.5,0,-2.5
  position object s4_shoulder_r(1),0,0,2.5
  glue object to limb s4_shoulder_r(1),s4_shoulder_r_j(1),0
 
  `Glue legs to spine
  position object s4_spine(1),17.5,0,2.5
  position object s4_leg_top_l(1),-3.5,0,-2.5
  glue object to limb s4_leg_top_l(1),s4_leg_top_l_j(1),0
  position object s4_spine(1),17.5,0,-2.5
  position object s4_leg_top_r(1),-3.5,0,2.5
  glue object to limb s4_leg_top_r(1),s4_leg_top_r_j(1),0
 
  `Make rotator
  s4_rotator(1) = new_cube(1)
  position object s4_spine(1),30,2.5,0
  glue object to limb s4_spine(1),s4_rotator(1),0
 
  `Cloud
  s4_cloud(1) = new_plain(10,10)
  color object s4_cloud(1),rgb(0,0,0)
  fade object s4_cloud(1),25
  hide object s4_cloud(1)
 
  `Hide limbs
  hide object s4_spine(1)
  hide object s4_shoulder_l(1)
  hide object s4_shoulder_r(1)
  hide object s4_arm_top_l(1)
  hide object s4_arm_top_r(1)
  hide object s4_arm_bot_l(1)
  hide object s4_arm_bot_r(1)
  hide object s4_leg_top_l(1)
  hide object s4_leg_top_r(1)
  hide object s4_leg_bot_l(1)
  hide object s4_leg_bot_r(1)
 
  `Hide joints
  hide object s4_shoulder_l_j(1)
  hide object s4_shoulder_r_j(1)
  hide object s4_arm_top_l_j(1)
  hide object s4_arm_top_r_j(1)
  hide object s4_arm_bot_l_j(1)
  hide object s4_arm_bot_r_j(1)
  hide object s4_leg_top_l_j(1)
  hide object s4_leg_top_r_j(1)
  hide object s4_leg_bot_l_j(1)
  hide object s4_leg_bot_r_j(1)
  hide object s4_rotator(1)
 
endfunction
 
`Walking man
function run_stage4()
 
  `Hide old objects, display new body
  if sub_stage = 1
    for i = 1 to 29
      position object s4_rotator(1),object position x(s3_cube_g(2))-45,0,0
      hide object s3_cube(i)
    next i
    show object s4_spine(1)
    show object s4_shoulder_l(1)
    show object s4_shoulder_r(1)
    show object s4_arm_top_l(1)
    show object s4_arm_top_r(1)
    show object s4_arm_bot_l(1)
    show object s4_arm_bot_r(1)
    show object s4_leg_top_l(1)
    show object s4_leg_top_r(1)
    show object s4_leg_bot_l(1)
    show object s4_leg_bot_r(1)
    inc sub_stage
  endif
 
  `Stand up
  if sub_stage = 2 and object angle z(s4_rotator(1)) < 90
    zrotate object s4_rotator(1),object angle z(s4_rotator(1)) + 1
    position camera camera position x() - (5.0/45.0),camera position y() + 0.25,camera position z() + 0.25
  endif
 
  `Increase sub_stage
  if sub_stage = 2 and object angle z(s4_rotator(1)) = 90
    inc sub_stage
  endif
 
  `Walk 1
  if sub_stage = 3 and object angle z(s4_leg_top_r_j(1)) > -20
    zrotate object s4_leg_top_r_j(1),object angle z(s4_leg_top_r_j(1)) - 0.5
    zrotate object s4_leg_top_l_j(1),object angle z(s4_leg_top_l_j(1)) + 0.5
    zrotate object s4_leg_bot_l_j(1),object angle z(s4_leg_bot_l_j(1)) + 0.7
    zrotate object s4_arm_top_l_j(1),object angle z(s4_arm_top_l_j(1)) - 0.5
    zrotate object s4_arm_bot_l_j(1),object angle z(s4_arm_bot_l_j(1)) - 0.7
    zrotate object s4_arm_top_r_j(1),object angle z(s4_arm_top_r_j(1)) + 0.5
  endif
 
  `Walk next stage
  if sub_stage = 3 and object angle z(s4_leg_top_r_j(1)) <= -20
    inc sub_stage
  endif
 
  `Walk 2
  if sub_stage = 4 and object angle z(s4_leg_top_l_j(1)) > -20
    zrotate object s4_leg_top_r_j(1),object angle z(s4_leg_top_r_j(1)) + 0.5
    zrotate object s4_leg_bot_r_j(1),object angle z(s4_leg_bot_r_j(1)) + 0.35
    zrotate object s4_leg_top_l_j(1),object angle z(s4_leg_top_l_j(1)) - 0.5
    zrotate object s4_leg_bot_l_j(1),object angle z(s4_leg_bot_l_j(1)) - 0.35
    zrotate object s4_arm_top_l_j(1),object angle z(s4_arm_top_l_j(1)) + 0.5
    zrotate object s4_arm_bot_l_j(1),object angle z(s4_arm_bot_l_j(1)) + 0.35
    zrotate object s4_arm_top_r_j(1),object angle z(s4_arm_top_r_j(1)) - 0.5
    zrotate object s4_arm_bot_r_j(1),object angle z(s4_arm_bot_r_j(1)) - 0.35
    xrotate object s4_rotator(1),object angle x(s4_rotator(1)) + 0.1
  endif
 
  `Walk next stage
  if sub_stage = 4 and object angle z(s4_leg_top_l_j(1)) <= -20
    inc sub_stage
  endif
 
  `Walk 3 (walk 2 and 3 make loop)
  if sub_stage = 5 and object angle z(s4_leg_top_r_j(1)) > -20
    zrotate object s4_leg_top_l_j(1),object angle z(s4_leg_top_l_j(1)) + 0.5
    zrotate object s4_leg_bot_l_j(1),object angle z(s4_leg_bot_l_j(1)) + 0.35
    zrotate object s4_leg_top_r_j(1),object angle z(s4_leg_top_r_j(1)) - 0.5
    zrotate object s4_leg_bot_r_j(1),object angle z(s4_leg_bot_r_j(1)) - 0.35
    zrotate object s4_arm_top_l_j(1),object angle z(s4_arm_top_l_j(1)) - 0.5
    zrotate object s4_arm_bot_l_j(1),object angle z(s4_arm_bot_l_j(1)) - 0.35
    zrotate object s4_arm_top_r_j(1),object angle z(s4_arm_top_r_j(1)) + 0.5
    zrotate object s4_arm_bot_r_j(1),object angle z(s4_arm_bot_r_j(1)) + 0.35
    xrotate object s4_rotator(1),object angle x(s4_rotator(1)) - 0.1
  endif
 
  `Loop back to walk 2
  if sub_stage = 5 and object angle z(s4_leg_top_r_j(1)) <= -20
    sub_stage = 4
  endif
 
  `Camera
  if sub_stage >= 3 and camera position y() < 600
    position camera camera position x() - (5.0/45.0),camera position y() + 0.5,camera position z() + 0.5
  endif
 
  `Cloud 1
  if sub_stage >= 3 and camera position y() >= 600 and s4_cloud_count(1) = 0
    position object s4_cloud(1),camera position x()-1,camera position y()-1,camera position z()-1
    point object s4_cloud(1),camera position x(),camera position y(),camera position z()
    set object transparency s4_cloud(1),1
    set alpha mapping on s4_cloud(1),100
    show object s4_cloud(1)
    s4_cloud_count(1) = 1
  endif
 
  `Cloud 2 - fade in (more bad code)
  if s4_cloud_count(1) >= 1 and s4_cloud_count(1) <= 100
    position camera camera position x() - (5.0/45.0),camera position y() + 0.25,camera position z() + 0.25
    position object s4_cloud(1),camera position x()-1,camera position y()-1,camera position z()-1
    point object s4_cloud(1),camera position x(),camera position y(),camera position z()
    set alpha mapping on s4_cloud(1),s4_cloud_count(1)
    inc s4_cloud_count(1)
  endif
 
  if s4_cloud_count(1) = 101
    s4_cloud_count(1) = 0
    hide object s4_spine(1)
    hide object s4_shoulder_l(1)
    hide object s4_shoulder_r(1)
    hide object s4_arm_top_l(1)
    hide object s4_arm_top_r(1)
    hide object s4_arm_bot_l(1)
    hide object s4_arm_bot_r(1)
    hide object s4_leg_top_l(1)
    hide object s4_leg_top_r(1)
    hide object s4_leg_bot_l(1)
    hide object s4_leg_bot_r(1)
    sub_stage = 1
    inc stage
  endif
 
endfunction
 
`Load stage5
function load_stage5()
 
  `Globals
  dim s5_planet(1)
  dim s5_cloud(1)
  dim s5_stars(1)
 
  `Planet
  s5_planet(1) = new_sphere(98,20,20)
  s5_cloud(1) = new_sphere(100,20,20)
  color object s5_planet(1),rgb(0,0,0)
  fade object s5_planet(1),10
 
  `Stars
  s5_stars(1) = new_plain(500,500)
  create bitmap 1,500,500
  ink rgb(255,255,255),0
  for i=1 to 200
    dot rnd(500),rnd(500)
  next i  
  get image 2,0,0,500,500,1
  delete bitmap 1
  set current bitmap 0
  ink rgb(255,255,255),0
  `set object texture s5_stars(1),0,1
  texture object s5_stars(1),2
  hide object s5_stars(1)
 
  `Texture
  size = 300
  create bitmap 1,size,size
  ink rgb(141,141,141),0
  make_cloud(0,0)
  make_cloud(50,20)
  make_cloud(130,10)
  make_cloud(220,40)
  make_cloud(10,60)
  make_cloud(40,150)
  make_cloud(160,140)
  make_cloud(220,220)
  make_cloud(200,210)
  make_cloud(10,0)
  make_cloud(20,20)
  make_cloud(250,100)
  make_cloud(250,200)
  make_cloud(150,220)
  make_cloud(100,100)
  blur bitmap 1,3
  get image 1,0,0,300,300
  delete bitmap 1
  set current bitmap 0
  ink rgb(255,255,255),0
  texture object s5_cloud(1),1
  set object transparency s5_cloud(1),1
 
  `Hide
  hide object s5_planet(1)
  hide object s5_cloud(1)
 
endfunction
 
`Cloud function
function make_cloud(x,y)
 
  box 20+x,10+y,30+x,50+y
  box 10+x,20+y,40+x,30+y
  box 30+x,30+y,50+x,40+y
 
endfunction
 
`Zoom to planet
function run_stage5()
 
  if sub_stage = 1
    hide object s4_cloud(1)
    `Show planet and clouds
    show object s5_planet(1)
    show object s5_cloud(1)
    yrotate object s5_cloud(1),15
    xrotate object s5_cloud(1),5
    position camera 37,0,37
    point camera 0,0,0
    `Show start
    show object s5_stars(1)
    inc sub_stage
  endif
 
  if sub_stage = 2
    `Keep stars distance
    position object s5_stars(1),camera position x()-200,0,camera position z()-200
    point object s5_stars(1),camera position x(),camera position y(),camera position z()
    `Rotate clouds
    xrotate object s5_cloud(1),object angle x(s5_cloud(1))+0.001
    yrotate object s5_cloud(1),object angle y(s5_cloud(1))+0.1
    position camera camera position x()+0.1,0,camera position z()+0.05
  endif
 
  if sub_stage = 2 and camera position x() > 190 and s4_cloud_count(1) = 0
    s4_cloud_count(1) = 100
  endif
 
  if s4_cloud_count(1) <= 100 and s4_cloud_count(1) > 1
    fade object s5_cloud(1),s4_cloud_count(1)
    fade object s5_planet(1),s4_cloud_count(1)/10
    fade object s5_stars(1),s4_cloud_count(1)
    dec s4_cloud_count(1)
  endif
 
  if s4_cloud_count(1) = 1
    sub_stage = 1
    inc stage
  endif
 
endfunction
 
function run_stage6()
 
  flush video memory
  delete objects 1,1000
  delete image 1
  delete image 2
  position camera 15.0,15.0,15.0
  point camera 7.5,0.0,0.0
  position camera 25.0,50.0,50.0
 
  s1_count(1) = 0
  s4_cloud_count(1) = 0
 
  load_stage1()
  load_stage2()
  load_stage3()
  load_stage4()
  load_stage5()
 
  stage = 1
 
endfunction