rem prepare environment
 
sync on : sync rate 0 : color backdrop 0
 
randomize timer() : draw to front : fog on
 
fog distance 140 : fog color rgb(0, 0, 0)
 
 
 
rem variables
 
camera_angle_x# = 25
 
camera_angle_y# = 135
 
camera_height# = 25
 
camera_mode = 0
 
camera_zoom# = -40
 
cam_x# = 0 : cam_z# = 0 : cam_y# = 25
 
wave# = 0 : time# = 0
 
sun_dist = 130 : day = 0
 
clouds = 14 : first_cloud = 0
 
 
 
rem make sun/moon
 
make object sphere 1, 10
 
color object 1, rgb(255, 255, 0)
 
set object light 1, 0
 
set spot light 0, 10, 300
 
color light 0, rgb(255, 255, 0)
 
 
 
rem make island
 
make matrix 1, 100, 100, 18, 18
 
texture_matrix(1, 128, 64, 64)
 
position matrix 1, -50, 4, -50
 
rand_island()
 
add_bushes(3, 15)
 
add_trees(5)
 
 
 
rem setup water
 
make matrix 2, 240, 240, 100, 100
 
texture_matrix(2, 0, 128, 255)
 
position matrix 2, -120, 4.5, -120
 
 
 
rem other effects
 
first_cloud = free_number()
 
add_clouds(4, clouds)
 
 
 
rem setup camera
 
position camera 0, camera_height#, 0
 
 
 
do
 
 
 
 if camera_mode = 0 then text 10, 10, "Middle Camera"
 
 if camera_mode = 1 then text 10, 10, "Surround Camera"
 
 
 
 rem handle controls
 
 if upkey() = 1 then camera_angle_x# = wrapvalue(camera_angle_x# + 0.6)
 
 if downkey() = 1 then camera_angle_x# = wrapvalue(camera_angle_x# - 0.6)
 
 if leftkey() = 1 then camera_angle_y# = wrapvalue(camera_angle_y# + 0.6)
 
 if rightkey() = 1 then camera_angle_y# = wrapvalue(camera_angle_y# - 0.6)
 
 if camera_mode = 0
 
  if keystate(78) = 1 then camera_height# = camera_height# + 0.2
 
  if keystate(74) = 1 then camera_height# = camera_height# - 0.2
 
 endif
 
 if camera_mode = 1
 
  if keystate(78) = 1 then camera_zoom# = camera_zoom# + 0.5
 
  if keystate(74) = 1 then camera_zoom# = camera_zoom# - 0.5
 
 endif
 
 if keystate(50) = 1 then camera_mode = 0
 
 if keystate(31) = 1 then camera_mode = 1
 
 
 
 rem update time (sun/moon)
 
 if time# < 48 then time# = time# + 0.02
 
 if time# >= 48
 
  time# = 0
 
  day = wrapvalue(day + 10)
 
 endif
 
 if time# < 25
 
  color object 1, rgb(255, 255, 0)
 
  color light 0, rgb(180, 180, 180)
 
  red = 255 : green = 255 : blue = 255
 
  if time# < 13
 
   r# = time# * (red/12)
 
   g# = time# * (red/12)
 
   b# = time# * (red/12)
 
   fog color rgb(r#, g#, b#)
 
   color backdrop rgb(r#, g#, b#)
 
  endif
 
  if time# >= 12
 
   r# = 255 - ((time# - 12) * (red/12))
 
   g# = 255 - ((time# - 12) * (green/12))
 
   b# = 255 - ((time# - 12) * (blue/12))
 
   fog color rgb(r#, g#, b#)
 
   color backdrop rgb(r#, g#, b#)
 
  endif
 
  position object 1, 0, 2, 0
 
  rotate object 1, (8.5 * time#) + 160, day, 0
 
  move object 1, sun_dist
 
  position light 0, object position x(1), object position y(1), object position z(1)
 
  point light 0, 0, 0, 0
 
 endif
 
 if time# >= 24
 
  color object 1, rgb(100, 100, 250)
 
  color light 0, rgb(100, 100, 250)
 
  fog color rgb(0, 0, 0)
 
  color backdrop rgb(0, 0, 0)
 
  position object 1, 0, 2, 0
 
  rotate object 1, (8.5 * (time# - 24)) + 160, day, 0
 
  move object 1, sun_dist
 
  position light 0, object position x(1), object position y(1), object position z(1)
 
  point light 0, 0, 0, 0
 
 endif
 
 
 
 rem move clouds
 
 for cloud = 1 to clouds
 
  obj = ((cloud - 1) + first_cloud)
 
  z# = object position z(obj)
 
  x# = object position x(obj)
 
  y# = object position y(obj)
 
  if x# < -140 then x# = 140
 
  x# = x# - 0.1
 
  position object obj, x#, y#, z#
 
 next cloud
 
 
 
 rem move water
 
 wave# = wrapvalue(wave# + 1)
 
 for x = 0 to 100
 
  for z = 0 to 100
 
   f = 1.8 : fvx = 20 : fvz = 20
 
   h# = f * (cos((fvx * x) + wave#) + cos((fvz * z) + wave#))
 
   set matrix height 2, x, z, h#
 
  next y
 
 next x
 
 update matrix 2
 
 
 
 rem move camera
 
 if camera_mode = 0
 
  if camera_height# < 12 then camera_height# = 12
 
  if camera_height# > 42 then camera_height# = 42
 
  position camera cam_x#, camera_height#, cam_z#
 
  rotate camera camera_angle_x#, camera_angle_y#, 0
 
 endif
 
 if camera_mode = 1
 
  if camera_zoom# > 0 then camera_zoom# = 0
 
  if camera_zoom# < -120 then camera_zoom# = -120
 
  if camera_angle_x# < 1 then camera_angle_x# = 1
 
  if camera_angle_x# > 90 then camera_angle_x# = 90
 
  position camera cam_x#, cam_y#, cam_z#
 
  rotate camera camera_angle_x#, camera_angle_y#, 0
 
  move camera camera_zoom#
 
 endif
 
 
 
 rem refresh screen
 
 sync
 
 
 
loop
 
 
 
`////////////////////first level functions//////////////////////////
 
 
 
function rand_island()
 
 for x = 0 to 18
 
  for z = 0 to 18
 
   value = 4 + rnd(2)
 
   if x = 0 or x = 18 or z = 0 or z = 18 then value = 0
 
   set matrix height 1, x, z, value
 
  next z
 
 next x
 
 update matrix 1
 
endfunction
 
 
 
function add_bushes(number, n_bushes)
 
 randomize timer()
 
 for bush = 1 to n_bushes
 
  a = free_number() : b = free_number() + 1
 
  c = free_number() + 2 : d = free_number() + 3
 
  make object plain a, 2, 6
 
  make object plain b, 2, 6
 
  make object plain c, 2, 6
 
  make object plain d, 2, 4
 
  r = 100 : g = 255 : bl = 100
 
  color object a, rgb(r, g, bl)
 
  color object b, rgb(r, g, bl)
 
  color object c, rgb(r, g, bl)
 
  color object d, rgb(r, g, bl)
 
  x = (5 + rnd(90)) - 50 : z = (5 + rnd(90)) - 50
 
  xa# = 30 : dist# = 1.5 : h = 11
 
  position object a, x, h, z
 
  xrotate object a, xa#
 
  yrotate object a, 120
 
  move object a, dist#
 
  position object b, x, h, z
 
  xrotate object b, xa#
 
  yrotate object b, 240
 
  move object b, dist#
 
  position object c, x, h, z
 
  xrotate object c, xa#
 
  move object c, dist#
 
  position object d, x, h, z
 
  yrotate object d, rnd(360)
 
  xrotate object d, rnd(8)
 
  move object d, -0.2
 
 next bush
 
endfunction
 
 
 
function add_trees(n_trees)
 
 randomize timer()
 
 for tree = 1 to n_trees
 
  a = free_number() : b = free_number() + 1
 
  c = free_number() + 2 : d = free_number() + 3
 
  e = free_number() + 4 : f = free_number() + 5
 
  make object box a, 3, 8, 3
 
  make object plain b, 9, 2
 
  make object plain c, 9, 2
 
  make object plain d, 9, 2
 
  make object plain e, 7, 2
 
  make object plain f, 7, 2
 
  r = 100 : g = 255 : bl = 100
 
  color object a, rgb(128, 64, 64)
 
  color object b, rgb(r, g, bl)
 
  color object c, rgb(r, g, bl)
 
  color object d, rgb(r, g, bl)
 
  color object e, rgb(r, g, bl)
 
  color object f, rgb(r, g, bl)
 
  x = (5 + rnd(90)) - 50 : z = (5 + rnd(90)) - 50
 
  position object a, x, 12, z
 
  position object b, x, 16.1, z
 
  rotate object b, 90, 120, 0
 
  position object c, x, 16.1, z
 
  rotate object c, 90, 240, 0
 
  position object d, x, 16.1, z
 
  xrotate object d, 90
 
  position object e, x, 15, z
 
  rotate object e, 90, rnd(180), 0
 
  position object f, x, 15, z
 
  rotate object f, 90, 180 + rnd(180), 0
 
 next tree
 
endfunction
 
 
 
function add_clouds(number, n_clouds)
 
 create bitmap 1, 20, 20
 
 cls rgb(0, 0, 0)
 
 for d = 1 to 50
 
  v = rnd(15)
 
  dot rnd(20), rnd(20), rgb(240 + v, 240 + v, 240 + v)
 
 next d
 
 get image number, 0, 0, 20, 20
 
 delete bitmap 1
 
 set current bitmap 0
 
 for cloud = 1 to n_clouds
 
  a = free_number()
 
  make object plain a, 16, 16
 
  texture object a, number
 
  ghost object on a, 0
 
  x = rnd(240) - 120 : z = rnd(240) - 120
 
  position object a, x, 32 + (rnd(8) - 4), z
 
  xrotate object a, 90
 
 next cloud
 
endfunction
 
 
 
function free_number()
 
 retval = 1
 
 while object exist(retval) = 1
 
  retval = retval + 1
 
 endwhile
 
endfunction retval
 
 
 
function texture_matrix(number, r, g, b)
 
 if r = 255 then r = r - 4
 
 if g = 255 then g = g - 4
 
 if b = 255 then b = b - 4
 
 create bitmap 1, 60, 60
 
 for x = 0 to 60
 
  for y = 0 to 60
 
   v = rnd(8)
 
   dot x, y, rgb((r - 4) + v, (g - 4) + v, (b - 4) + v)
 
  next y
 
 next x
 
 get image number, 1, 1, 20, 20
 
 prepare matrix texture number, number, 3, 3
 
 fill matrix number, 0, 5
 
 delete bitmap 1
 
 set current bitmap 0
 
endfunction