sync on
autocam off
sync rate 60
color backdrop rgb(10,20,40)
color ambient light rgb(200,200,255)
set ambient light 4
 
`make_specularmap()
`make_snowmap()
`make_shader_snow()
make_textures()
 
rotate light 0,140,0,-40
color light 0,rgb(100,100,128)
 
load effect "snowshader.fx",1,1
set effect constant integer 1,"SpecularPower",15
 
 
LightDir = 1
null = Make Vector4(LightDir)
SET VECTOR4 LightDir, light direction x(0), light direction y(0), light direction z(0), 0
set effect constant vector 1,"LightDir",LightDir
 
`Making our textures.&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
create bitmap 1,64,64
set current bitmap 1
ink rgb(5,5,5),0
CircleFill(32, 32, 30, rgb(5,5,5))
get image 1,0,0,64,64
ink 0,0
cls
ink rgb(128,0,0),0
box 0,0,50,64
box 0,0,64,5
box 0,20,64,25
box 0,40,64,45
box 0,60,64,64
get image 2,0,0,64,64
set current bitmap 0
delete bitmap 1
 
`&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
 
`********WORLD***********
make object plain 3,200,200
scale object texture 3,8,8
rotate object 3,-90,0,0
set object effect 3,1
 
`*******SNOWMAN************
make object sphere 2,4
set object effect 2,1
position object 2,0,1,20
 
 
` HEAD - Limb 1.
make object sphere 4,3
make mesh from object 1,4
delete object 4
add limb 2,1,1
link limb 2,0,1
offset limb 2,1,0,3,0
set limb effect 2,1,1
delete mesh 1
 
`COAL MOUTH - Limb 2.
make object sphere 11,0.4,4,4
make mesh from object 11,11
delete object 11
add limb 2,2,11
delete mesh 11
link limb 2,1,2
offset limb 2,2,0.2,-0.35,1.4
color limb 2,2,rgb(5,5,5)
 
`CARROT NOSE - Limb 3.
make object cone 7,1
scale object 7,50,130,50
make mesh from object 7,7
delete object 7
add limb 2,3,7
link limb 2,1,3
delete mesh 7
offset limb 2,3,0,0.15,1.8
rotate limb 2,3,95,0,0
color limb 2,3,rgb(255,175,0)
 
`RIGHT EYE - Limb 4.
make object sphere 9,0.45,4,4
make mesh from object 9,9
add limb 2,4,9
link limb 2,1,4
offset limb 2,4,-0.65,0.45,1.2
color limb 2,4,rgb(5,5,5)
delete object 9
delete mesh 9
 
`LEFT EYE - Limb 5.
make object sphere 10,0.45,4,4
make mesh from object 10,10
add limb 2,5,10
link limb 2,1,5
offset limb 2,5,0.65,0.45,1.2
color limb 2,5,rgb(5,5,5)
delete object 10
delete mesh 10
 
` HAT BRIM - Limb 6.
make object plain 5,4,4
set object cull 5,0
rotate object 5,-90,0,0
make mesh from object 5,5
add limb 2,6,5
link limb 2,1,6
offset limb 2,6,0,0.94,0
texture limb 2,6,1
delete object 5
delete mesh 5
 
`HAT PILLAR - Limb 7.
make object cylinder 6,2.25
make mesh from object 6,6
add limb 2,7,6
link limb 2,6,7
offset limb 2,7,0,0.8,0
color limb 2,7,rgb(5,5,5)
delete object 6
delete mesh 6
 
`HAT TOP - Limb 8.
make object plain 8,2.35,2.35
rotate object 8,-90,0,15
make mesh from object 8,8
add limb 2,8,8
link limb 2,7,8
texture limb 2,8,1
offset limb 2,8,0,1.29,0
delete object 8
delete mesh 8
 
`SCARF - Limb 9
make object cylinder 12,2.4
scale object 12,100,25,100
color object 12,rgb(128,0,0)
rotate object 12,0,0,5
make mesh from object 12,12
add limb 2,9,12
link limb 2,0,9
offset limb 2,9,0,1.75,0
color limb 2,9,rgb(128,0,0)
delete object 12
delete mesh 12
 
 
`SCARF TASSLES
make object plain 13,2,1
rotate object 13,0,40,90
texture object 13,2
set object transparency 13,1
scale object texture 13,1,4
make mesh from object 13,13
add limb 2,10,13
link limb 2,9,10
offset limb 2,10,0,-0.6,1.7
texture limb 2,10,2
delete object 13
delete mesh 13
 
 
`&&&&&&&&& MAKE THE SNOWMAN TRANSPARENT
set object transparency 2,4
set object cull 2,0
 
 
position object 2,40,1,0
 
PERFORM CHECKLIST FOR EFFECT VALUES 1
 
`set ambient light 4
`color light 0,rgb(255,255,255)
 
position camera 0,0,3.25,40
rotate camera 0,0,180,0
 
 
 
 
make_logcabin()
 
 
 
 
 
 
 
 
 
do
 
 
 
control camera using arrowkeys 0,1,1
 
`rotate limb 2,1,0,sin(timer()/10)*10,0
rotate limb 2,1,-abs(sin(timer()/6)*10)+10,0,0
 
`position object 2,object position x(2),abs(sin(timer()/6)*3)+1,object position z(2)
 
if ticker < 5
   ticker = ticker + 1
else
   color light 2,rgb(255,rnd(40)+150,50)
   ticker = 0
   for i = 0 to 15
      xpos# = (rnd(200)/100.0)-1.0
      ypos# = (rnd(200)/100.0)-1.0
      zpos# = (rnd(200)/100.0)-1.0
      position object 960+i,xpos#,2.0+ypos#,17.5+zpos#
   next i
 
   for i = 0 to 60
      emissiverand = rnd(255)
      set object emissive 980+i,rgb(emissiverand,emissiverand,emissiverand)
      scalerand = 100+(rnd(80)-25)
      scale object 980+i,scalerand,scalerand,scalerand
next i
 
 
endif
 
for i = 0 to 15
   emissiverand = rnd(255)
   set object emissive 960+i,rgb(emissiverand,emissiverand,emissiverand)
   scalerand = 100+(rnd(80)-25)
   scale object 960+i,scalerand,scalerand,scalerand
next i
 
for i = 0 to 60
   point object 980+i,camera position x(),camera position y(),camera position z()
next i
 
sync
 
loop
 
 
 
 
 
 
 
function CircleFill(x, y, radius, colour)
   ink colour, 0
   circle x, y, radius
   FloodFill(x, y, colour)
endfunction
 
function EllipseFill(x, y, radiusX, radiusY, colour)
   ink colour, 0
   ellipse x, y, radiusX, radiusY
   FloodFill(x, y, colour)
endfunction
 
function FloodFill(x, y, fillColour as dword)
   backgroundColour = point(x, y) : rem this should work in all bpp display modes
   if backgroundColour = fillColour then exitfunction
   ink fillColour, 0              : rem setup the fill colour as foreground, and background as black (this is not used)
   lock pixels
 
   __FloodFill(x, y, backgroundColour)
 
   unlock pixels
endfunction
 
function __FloodFill(x, y, backgroundColour as dword)
   BitmapWidth  = bitmap width()
 
   rem do current row as far as possible
   x1 = x - 1
   while (x1 >= 0) and (point(x1, y) = backgroundColour)
      dec x1
   endwhile
   rem from current point find righthand extent
   x2 = x + 1
   while (x2 < BitmapWidth) and (point(x2, y) = backgroundColour)
      inc x2
   endwhile
   inc x1
   if x2 - x1 > 0
      line x1, y, x2, y : rem draw a line between the extents
 
      for z = 1 to 2
         if z = 1
            y2 = y - 1 : rem process line of pixels above working along all breaks in the line
         else
            y2 = y + 1 : rem process line of pixels below working along all breaks in the line
         endif
 
         if (y > 0 and z = 1) or (y < bitmap height() - 1 and z = 2)
            x4 = x1
            while x4 > 0 and point(x4, y2) = backgroundColour
               dec x4
            endwhile
            x5 = x2 - 1
            while x5 < BitmapWidth - 1 and point(x5, y2) = backgroundColour
               inc x5
            endwhile
            newExtent = 1
            for x3 = x4 to x5 - 1
               if point(x3, y2) = backgroundColour
                  if newExtent = 1
                     newExtent = 0
                     xstart = x3
                  endif
               else
                  if newExtent = 0
                     __FloodFill(xstart, y2, backgroundColour)
                     newExtent = 1
                  endif
               endif
            next
            if newExtent = 0 then __FloodFill(xstart, y2, backgroundColour)
         endif
      next
   endif
endfunction
 
 
 
 
 
function make_shader_snow()
 
string1$ = "float4x4 matWorldViewProj : WorldViewProjection; float4x4 matWorld   : World; float3 vecEye : cameraposition;"
string2$ = "float4 LightDir : Direction < string Object = "+CHR$(34)+"DirectionalLight"+CHR$(34)+"; string Space = "+CHR$(34)+"World"+CHR$(34)+"; > = {-1.0f, 1.0f, -1.0f, 0.0f};"
string3$ = "int SpecularPower = 15;"
string4$ = "texture diffuseTexture : Diffuse < string name = "+CHR$(34)+"snow_texture.bmp"+CHR$(34)+"; >;"
string5$ = "texture specularTexture : Specular < string name = "+CHR$(34)+"snow_specular.bmp"+CHR$(34)+"; >;"
string6$ = "struct VS_OUTPUT { float4 Pos : POSITION; float2 Tex : TEXCOORD0; float3 Norm : TEXCOORD1; float3 View : TEXCOORD2; float3 Light : TEXCOORD3; };"
string7$ = "VS_OUTPUT VS(float4 Pos : POSITION, float3 Normal : NORMAL, float2 Tex : TEXCOORD) { VS_OUTPUT Out = (VS_OUTPUT)0; Out.Pos = mul(Pos, matWorldViewProj);  Out.Light = LightDir; float3 PosWorld = normalize(mul(Pos, matWorld)); Out.View = vecEye - PosWorld; Out.Norm = mul(Normal, matWorld); Out.Tex = Tex.xy; return Out; }"
string8$ = "sampler SpecularMapSampler = sampler_state { texture = <specularTexture>; AddressU  = CLAMP; AddressV  = CLAMP; AddressW  = CLAMP; MIPFILTER = LINEAR; MINFILTER = LINEAR; MAGFILTER = LINEAR; };"
string9$ = "sampler DiffuseMapSampler = sampler_state {texture = <diffuseTexture>; AddressU  = CLAMP; AddressV  = CLAMP; AddressW  = CLAMP; MIPFILTER = LINEAR; MINFILTER = LINEAR; MAGFILTER = LINEAR;};"
string10$ = "float4 PS(float2 Tex: TEXCOORD0, float3 Norm : TEXCOORD1, float3 View : TEXCOORD2, float3 Light: TEXCOORD3) : COLOR"
string11$ = "{ float4 psOut; float3 SpecLevel = tex2D(SpecularMapSampler, Tex).xyz; float4 diffuse = tex2D(DiffuseMapSampler, Tex); float4 ambient = {0.2, 0.25, 0.25, 1.0}; float3 Normal = normalize(Norm); float3 LightDir = -normalize(Light);"
string12$ = "float3 ViewDir = normalize(View); float4 diff = saturate(dot(Normal, LightDir)); float3 H = normalize(LightDir + ViewDir); float4 Specular = pow(saturate(dot(Normal, H)), SpecularPower); psOut.rgb = ambient + (diffuse * diff + Specular * SpecLevel); psOut.a = 1.0f; return(psOut);}"
string13$ = "technique textured { pass p0 { VertexShader = compile vs_1_1 VS(); PixelShader  = compile ps_2_0 PS(); } }"
 
 
 
if file exist("snowshader.fx") = 1
   delete file "snowshader.fx"
endif
   open to write 1,"snowshader.fx"
 
   write string 1,string1$: write string 1,string2$: write string 1,string3$: write string 1,string4$: write string 1,string5$
   write string 1,string6$: write string 1,string7$: write string 1,string8$: write string 1,string9$: write string 1,string10$
   write string 1,string11$: write string 1,string12$: write string 1,string13$
   close file 1
 
endfunction
 
 
function make_specularmap()
 
create bitmap 1,1024,1024
set current bitmap 1
ink rgb(255,255,255),0
for i = 0 to 4000
   dot rnd(1023),rnd(1023)
next i
 
get image 10,0,0,1024,1024
save image "snow_specular.bmp",10
 
set current bitmap 0
delete bitmap 1
delete image 10
endfunction
 
 
 
function make_snowmap()
 
create bitmap 1,1024,1024
set current bitmap 1
ink rgb(220-40,230-40,255-40),0
box 0,0,1024,1024
ink rgb(255-20,255-20,255-20),0
for i = 0 to 2000
   dot rnd(1023),rnd(1023)
next i
 
ink rgb(0,0,255-20),0
for i = 0 to 1000
   dot rnd(1023),rnd(1023)
next i
 
blur bitmap 1,4
 
get image 10,0,0,1024,1024
save image "snow_texture.bmp",10
set current bitmap 0
delete image 10,
delete bitmap 1
 
endfunction
 
 
 
 
function make_logcabin()
 
`biglog = free_object()
`make object cylinder biglog,4
`scale object biglog,100,1000,100
`rotate object biglog,90,0,0
 
for i = 0 to 3
   make object cylinder 900+i,4
   scale object 900+i,75,1000,75
   rotate object 900+i,90,0,0
   position object 900+i,-10,(i*3)+1,0
   `color object 900+i,rgb(128,64,0)
   set object effect 900+i,1
next i
 
for i = 0 to 2
   make object cylinder 910+i,4
   scale object 910+i,75,400,75
   rotate object 910+i,90,0,0
   position object 910+i,10,(i*3)+1,-12
   `color object 910+i,rgb(128,64,0)
   set object effect 910+i,1
next i
 
for i = 0 to 2
   make object cylinder 915+i,4
   scale object 915+i,75,400,75
   rotate object 915+i,90,0,0
   position object 915+i,10,(i*3)+1,12
   set object effect 915+i,1
   `color object 915+i,rgb(128,64,0)
next i
 
make object cylinder 919,4
scale object 919,75,1000,75
rotate object 919,90,0,0
position object 919,10,(3*3)+1,0
set object effect 919,1
 
 
 
make object box 920,20,0.5,40
position object 920,0,0,0
color object 920,rgb(128,64,0)
 
 
for i = 0 to 3
   make object cylinder 921+i,4
   scale object 921+i,75,500,75
   rotate object 921+i,90,90,0
   position object 921+i,0,(i*3)+1,-20
   set object effect 921+i,1
 
next i
 
for i = 0 to 3
   make object cylinder 925+i,4
   scale object 925+i,75,500,75
   rotate object 925+i,90,90,0
   position object 925+i,0,(i*3)+1,20
   set object effect 925+i,1
 
next i
 
make object box 929,20,0.5,48
position object 929,7.5,15,0
rotate object 929,0,0,-40
set object effect 929,1
 
make object box 930,20,0.5,48
position object 930,-7.5,15,0
rotate object 930,0,0,40
set object effect 930,1
 
 
make object cylinder 932,4
scale object 932,75,300,75
position object 932,10,5.25,20
set object effect 932,1
 
 
make object cylinder 933,4
scale object 933,75,300,75
position object 933,-10,5.25,20
set object effect 933,1
 
 
make object cylinder 934,4
scale object 934,75,300,75
position object 934,10,5.25,-20
set object effect 934,1
 
 
make object cylinder 935,4
scale object 935,75,300,75
position object 935,-10,5.25,-20
set object effect 935,1
 
 
`Gable Ends
make object triangle 936,11,11,20,-11,11,20,0,21,20
color object 936,rgb(128,64,0)
make object triangle 937,11,11,-20,-11,11,-20,0,21,-20
 
`Inner Walls
make object plain 938,20,40
rotate object 938,90,0,90
position object 938,-8.5,2,0
color object 938,rgb(128,64,0)
 
make object plain 939,20,15
rotate object 939,90,0,90
position object 939,8.5,2,-11.5
color object 939,rgb(128,64,0)
 
make object plain 940,20,15
rotate object 940,90,0,90
position object 940,8.5,2,11.5
color object 940,rgb(128,64,0)
 
make object plain 941,4,15
rotate object 941,90,0,90
position object 941,8.5,10,0
color object 941,rgb(128,64,0)
 
make object plain 942,20,17
rotate object 942,0,0,90
position object 942,0,2,-18.5
color object 942,rgb(128,64,0)
 
make object plain 943,20,17
rotate object 943,0,0,90
position object 943,0,2,18.5
color object 943,rgb(128,64,0)
 
`Doorframe
make object box 944,3.25,8,1
position object 944,10,4,4
 
make object box 945,3.25,8,1
position object 945,10,4,-4
 
make object box 946,4,1,10
position object 946,10,8.5,0
 
make object box 947,4,1,10
position object 947,10,0,0
 
`Fireplace
make object box 948,8,1,6
position object 948,0,0.25,18
 
make object box 949,1,3,4
position object 949,-2,2,18
 
make object box 950,1,3,4
position object 950,2,2,18
 
make object box 951,4,3,0.25
position object 951,0,2,18.5
 
make object box 952,5,1,4
position object 952,0,4,18
 
make object box 953,3.5,20,3
position object 953,0,14.5,18
`set object emissive 953,rgb(128,0,0)
 
make object box 954,4.5,2,4
position object 954,0,24,18
 
make object cylinder 955,2
position object 955,0,25,18
 
`Light?
make light 1
position light 1,0,2,17.5
color light 1,rgb(128,10,0)
set light range 1,40
 
make light 2
position light 2,0,8,0
color light 2,rgb(255,220,50)
set light range 2,30
 
`Presents!
make object cube 956,2
position object 956,5,1,13
rotate object 956,0,20,0
texture object 956,100
set object emissive 956,rgb(10,10,10)
 
make object cube 957,1.5
position object 957,6,0.75,11
rotate object 957,0,-15,0
texture object 957,101
set object emissive 957,rgb(10,10,10)
 
make object box 958,1.5,4,1.5
position object 958,6,2.25,17
rotate object 958,20,0,0
texture object 958,101
set object emissive 957,rgb(10,10,10)
 
`flickers
 
for i = 0 to 15
   make object plain 960+i,0.5,0.5
   xpos# = (rnd(200)/100.0)-1.0
   ypos# = (rnd(200)/100.0)-1.0
   zpos# = (rnd(200)/100.0)-1.0
   position object 960+i,xpos#,2.0+ypos#,17.5+zpos#
   texture object 960+i,200
   ghost object on 960+i
   set object emissive 960+i,rgb(255,255,255)
   rotate object 960+i,0,0,rnd(180)
next i
 
`stars
 
for i = 0 to 60
   make object plain 980+i,5,5
   xpos# = rnd(200)-100.0
   ypos# = rnd(200)-50.0
   zpos# = rnd(200)-100.0
   position object 980+i,xpos#,100+ypos#,zpos#
   texture object 980+i,201
   ghost object on 980+i
   set object emissive 980+i,rgb(255,255,255)
next i
 
endfunction
 
 
 
 
 
Function make_textures()
 
create bitmap 1,64,64
set current bitmap 1
ink rgb(128,0,0),0
box 0,0,64,64
ink rgb(128,128,0),0
box 28,0,36,64
box 0,28,64,36
get image 100,0,0,64,64
 
box 0,0,64,64
ink rgb(0,0,255),0
box 28,0,36,64
box 0,28,64,36
get image 101,0,0,64,64
 
 
ink 0,0
box 0,0,64,64
ink rgb(255,80,0),0
box 26,26,38,38
ink rgb(255,140,0),0
box 28,14,37,50
box 14,28,50,37
ink rgb(255,180,0),0
box 30,10,35,54
box 10,30,54,35
ink rgb(255,255,0),0
box 31,4,34,60
box 4,31,60,34
blur bitmap 1,5
get image 200,0,0,64,64,1
 
ink 0,0
box 0,0,64,64
ink rgb(80,80,80),0
box 26,26,38,38
ink rgb(140,140,140),0
box 28,14,37,50
box 14,28,50,37
ink rgb(200,200,200),0
box 30,10,35,54
box 10,30,54,35
ink rgb(255,255,255),0
box 31,4,34,60
box 4,31,60,34
blur bitmap 1,5
get image 201,0,0,64,64,1
 
 
set current bitmap 0
delete bitmap 1
 
endfunction
 
 
 
 
 
 
 
 
 
 
 
 
Function free_image()
   i=100
   Do
      If Image Exist(i)=0 then Exit
      inc i
   Loop
Endfunction i
 
Function free_object()
   i=100
   Do
      If Object Exist(i)=0 then Exit
      inc i
   Loop
Endfunction i
 
 
Function Get_Ground_Height_Not_Player(TerrainID,x#,z#)
 
   local_grounddistance# = intersect object (TerrainID,x#,500,z#,x#,-500,z#)
   local_height# = 500 - local_grounddistance#
 
EndFunction local_height#