@WMG, thanks
@Callum, this code should work. When using functions make sure they are at the bottom of your program or in a separate include file.
Sync On
Sync Rate 60
Global MatX
Global MatZ
Global IsWater
Global WaterObject
Global WaterRise#
Global WaterSpeed#
Global WaterHeight#
Global WaterXScroll#
Global WaterZScroll#
Global AddedHeight#
Global WaterDownFlag
Global WaterUpFlag
load_matrix(1,"C:My Documentsanimmediamaptrixmapmaptrixmap.mtrix")
position matrix 1,0,0,0
make camera 1
position camera 1,0,300,200
do
maptrix_water()
control camera using arrowkeys 1,5,2
loop
Function MapTrix_Water()
If IsWater = 1
If WaterUpFlag = 1 then Inc AddedHeight#,WaterSpeed#
If WaterDownFlag = 1 then Dec AddedHeight#,WaterSpeed#
If AddedHeight#>WaterRise# and WaterUpFlag = 1
WaterDownFlag = 1
WaterUpFlag = 0
Endif
If WaterDownFlag = 1 and AddedHeight#<-WaterRise#
WaterDownFlag = 0
WaterUpFlag = 1
Endif
Position Object WaterObject,MatX/2,WaterHeight#+AddedHeight#,MatZ/2
Scroll Object Texture WaterObject,WaterXScroll#,WaterZScroll#
Endif
EndFunction
Function Smooth_Matrix(MatNum,TileX,TileZ,Times)
For Multiple=1 to Times
For X=1 to TileX-1
For Z=1 to TileZ-1
A=Get Matrix Height(MatNum,X-1,Z+1)
B=Get Matrix Height(MatNum,X,Z+1)
C=Get Matrix Height(MatNum,X+1,Z+1)
D=Get Matrix Height(MatNum,X+1,Z)
E=Get Matrix Height(MatNum,X+1,Z-1)
F=Get Matrix Height(MatNum,X,Z-1)
G=Get Matrix Height(MatNum,X-1,Z-1)
H=Get Matrix Height(MatNum,X-1,Z)
Total=A+B+C+D+E+G+G+H
Av#=Total/8
Set Matrix Height MatNum,X,Z,Av#
Next Z
Next X
Next Multiple
For X=0 to Tilex
Set Matrix Height MatNum,X,0,Get Matrix Height(MatNum,X,1)
Next X
For X=0 to TileX
Set Matrix Height MatNum,X,TileZ,Get Matrix Height(Matnum,X,TileZ-1)
Next X
For Z=0 to TileZ
Set Matrix Height MatNum,0,Z,Get Matrix Height(MatNum,1,Z)
Next Z
For Z=0 to TileZ
Set Matrix Height MatNum,TileX,Z,Get Matrix Height(MatNum,TileX-1,Z)
Next Z
Update Matrix MatNum
EndFunction
Function Load_Matrix(MatNum,LoadFile$)
WaterUpFlag = 1
If LoadFile$ > ""
If Right$(LoadFile$,6) = ".mtrix"
If Matrix Exist(MatNum) then Delete Matrix MatNum
Open to Read 1,LoadFile$
Read String 1,Image$
Read String 1,WaterImage$
Read String 1,MatX$
Read String 1,MatZ$
Read String 1,MatTileX$
Read String 1,MatTileZ$
MatX = Val(MatX$)
MatZ = Val(MatZ$)
MatTileX = Val(MatTileX$)
MatTileZ = Val(MatTileZ$)
Make Matrix MatNum,MatX,MatZ,MatTileX,MatTileZ
For t=Len(LoadFile$) to 0 Step -1
If Mid$(LoadFile$,t) = "" or Mid$(LoadFile$,t) = "/"
Dirname$ = Left$(LoadFile$,t)
t=0
Endif
Next t
If Dirname$>""
Set Dir Dirname$
Endif
MatrixImage = Free_Image()
If Image$>""
MatrixImage = Free_Image()
Load Image Image$,MatrixImage,1
Endif
If WaterImage$>""
WaterImNum = Free_Image()
Load Image WaterImage$,WaterImNum
Endif
Read String 1,Across$
Read String 1,Down$
A = Val(Across$)
D = Val(Down$)
If Image$>""
Prepare Matrix Texture MatNum,MatrixImage,A,D
Endif
For X=0 to MatTileX
For Z=0 to MatTileZ
Read String 1,H$
H = Val(H$)
Set Matrix Height MatNum,X,Z,H
Next Z
Next X
For X=0 to MatTileX-1
For Z=0 to MatTileZ-1
Read String 1,T$
T = Val(T$)
If T<=A*D and T>0
If Image$>""
Set Matrix Tile MatNum,X,Z,T
Endif
Endif
Next Z
Next X
Read String 1,Trim$
Trim# = Val(Trim$)
If Image$>""
Set Matrix Trim MatNum,Trim#,Trim#
Endif
Read String 1,Wireframe$
Read String 1,Trans$
Read String 1,Cull$
Read String 1,Fil$
Filter = Val(Fil$)
Read String 1,light$
Read String 1,fog$
Read String 1,amb$
Set matrix MatNum,Val(Wireframe$),Val(Trans$),Val(Cull$),Filter,Val(light$),Val(fog$),Val(amb$)
Read String 1,fog$
If Val(fog$) = 1 then Fog On
Read String 1,FogCol$
FogCol = Val(FogCol$)
Read String 1,FogDist$
Fog Distance Val(FogDist$)
Fog Color FogCol
Read String 1,CamRange$
CamRange = Val(CamRange$)
Set Camera Range 1,CamRange
Read String 1,Color$
Color = Val(Color$)
Color Backdrop Color
Read String 1,AmbScroll$
Set Ambient Light Val(AmbScroll$)
Read String 1,AmbCol$
If AmbCol$>""
Color Ambient Light Val(AmbCol$)
else
Color Ambient Light 16777215
Endif
Read String 1,Normalize$
Normalize = Val(Normalize$)
If Normalize = 1 then Normalize_Matrix(MatNum,MatTileX,MatTileZ)
Read String 1,IsWater$
IsWater = Val(IsWater$)
Read String 1,WaterSpeed$
WaterSpeed# = Val(WaterSpeed$)
Read String 1,WaterRise$
WaterRise# = Val(WaterRise$)
Read String 1,WaterHeight$
WaterHeight# = Val(WaterHeight$)
Read String 1,AlphaSlide$
WaterAlpha = Val(AlphaSlide$)
Read String 1,XScroll$
WaterXScroll# = Val(XScroll$)
Read String 1,ZScroll$
WaterZScroll# = Val(ZScroll$)
If IsWater = 1
AutoCam Off
WaterObject = Free_Object()
Make Object Plain WaterObject,MatX+MatX/2,MatZ+MatZ/2
XRotate Object WaterObject,90
Fix Object Pivot WaterObject
Texture Object WaterObject,WaterImNum
Position Object WaterObject,MatX/2,WaterHeight#,MatZ/2
Set Object Light WaterObject,0
Set Alpha Mapping On WaterObject,WaterAlpha
AutoCam On
Endif
Update Matrix 1
Close File 1
Endif
Endif
EndFunction
Function Normalize_Matrix(MatNum,TX,TZ)
rem Following Routine by Lee Bamber from Dark Basic Example Code
for z=1 to TZ
for x=1 to TX
h8#=get matrix height(MatNum,x,z-1)
h4#=get matrix height(MatNum,x-1,z)
h#=get matrix height(MatNum,x,z)
h2#=get matrix height(MatNum,x,z)
x1#=(x-1)*25.0 : y1#=h#
x2#=(x+0)*25.0 : y2#=h4#
dx#=x2#-x1#: dy#=y2#-y1#
ax#=atanfull(dx#,dy#)
ax#=wrapvalue(90-ax#)
z1#=(z-1)*25.0 : y1#=h2#
z2#=(z+0)*25.0 : y2#=h8#
dz#=z2#-z1#: dy#=y2#-y1#
az#=atanfull(dz#,dy#)
az#=wrapvalue(90-az#)
nx#=sin(ax#): ny#=cos(ax#): nz#=sin(az#)
Set matrix normal MatNum,x,z,nx#,ny#,nz#
next x
next z
Update Matrix MatNum
EndFunction
Function Free_Object()
Repeat
Inc i
If Object Exist(i)=0 Then found=1
Until found
Endfunction i
Function Free_Image()
Repeat
Inc i
If Image Exist(i)=0 Then found=1
Until found
Endfunction i
Function Free_Sprite()
Repeat
Inc i
If Sprite Exist(i)=0 Then found=1
Until found
Endfunction i
@VariableS, thanks for finding that, it will be fixed and a new version uploaded ASAP.
#EDIT, fixed it, its up now, if you downloaded it in the last 10mins then it may have been corrupted by me uplaoding the new one. Just the .exe is available at
http://redeye.dbspot.com/Downloads/maptrixexe.zip
for those who have already downloaded and would like the fix