here is my terrain editor so far. I took some of Mike Shah's Code and edited it to my needs.
flush video memory
sync on
backdrop on
set display mode 640,480,32
set window size 640,480
#Constant Dimensions 17
#Constant TileSize 32
#Constant MapSizeX 20
#Constant MapSizeY 15
dim Grid(MapSizeX,MapSizeY)
dim Display(Dimensions,Dimensions)
beginning:
`Assign a random value to the Grid array.
for x = 0 to MapSizeX
for y = 0 to MapSizeY
Grid(x,y)=1
next x
next y
cls rgb(0,0,192)
get image 1,0,0,32,32
ImageCount=ImageCount+1
load image "Media\grass.bmp",2
ImageCount=ImageCount+1
load image "Media\patch.bmp",3
ImageCount=ImageCount+1
load image "Media\Fence_Beginning_End.bmp",4
ImageCount=ImageCount+1
load image "Media\Fence_Middle.bmp",5
ImageCount=ImageCount+1
load image "Media\Fence_End.bmp",6
ImageCount=ImageCount+1
load image "Media\Chair_With_Red_Seating_Material.bmp",7
ImageCount=ImageCount+1
load image "Media\Wooden_Chair.bmp",8
ImageCount=ImageCount+1
load image "Media\Kings_Throne.bmp",9
ImageCount=ImageCount+1
do
cls
if leftkey()=1 and currentx>0
currentx=currentx-1
endif
if rightkey()=1 and currentx<MapSizeX
currentx=currentx+1
endif
if downkey()=1 and currenty<(MapSizeY-1)
currenty=currenty+1
endif
if upkey()=1 and currenty>0
currenty=currenty-1
endif
if inkey$()="p"
if pass_on=1
pass_on=0
else
pass_on=1
endif
repeat
until scancode()=0
endif
for x = 0 to Dimensions
for y = 0 to Dimensions
if currentx+x>MapSizeX or currenty+y>MapSizeY `Ensure we're not out of bounds on our array.
Display(x,y)=Grid(MapSizeX,MapSizeY) `If we are, just assign the last GRID value.
else `If we're not out of bounds, shift values
`to the DISPLAY array.
Display(x,y)=Grid(x+currentx,y+currenty)
endif
for ImageNumber=1 to ImageCount
if Display(x,y)=ImageNumber then paste image ImageNumber,x*TileSize,y*TileSize
next ImageNumber
next x
next y
if spacekey()=0
for x=0 to Dimensions
for y=0 to Dimensions
text x*TileSize,y*TileSize,str$(Display(x,y))
next x
next y
endif
TileX=((mousex()+(currentx*32))/TileSize)*1.0
TileY=((mousey()+(currenty*32))/TileSize)*1.0
`Remember earlier when I mentioned relative tile coordinates in the DISPLAY array?
`Well, here they are so we can use them for general debugging perposes if necessary.
relativeTileX=(mousex()/TileSize)*1.0
relativeTileY=(mousey()/TileSize)*1.0
if mouseclick()=1 and TileX<=MapSizeX and TileY<=MapSizeY
inc Grid(TileX,TileY),1
wait 100
endif
if mouseclick()=2 and TileX<=MapSizeX and TileY<=MapSizeY
dec Grid(TileX,TileY),1
wait 100
endif
text 580,0,str$(currentx+relativeTileX)
text 580,20,str$(currenty+relativeTileY)
text 580,40,str$(relativeTileX)
text 580,60,str$(relativeTileY)
if shiftkey()=1 then SaveLevel(Dimensions, TileSize, MapSizeX, MapSizeY)
if controlkey()=1 then LoadLevel()
sync
loop
wait key
function SaveLevel( _Dimensions, _TileSize, _MapSizeX, _MapSizeY)
input "",filename$
if file exist(filename$) then delete file filename$
open to write 1,filename$
write string 1,str$(_Dimensions)
write string 1,str$(_TileSize)
write string 1,str$(_MapSizeX)
write string 1,str$(_MapSizeY)
for x = 0 to MapSizeX
for y = 0 to MapSizeY
if Grid(x,y)=90
write string 1,"W"
inc x,1
inc y,1
endif
write string 1,str$(Grid(x,y))
next x
next y
close file 1
endfunction
`Our load level function.
function LoadLevel()
input "",filename$
if file exist(filename$) then open to read 1,filename$
read string 1,str$(_Dimensions)
read string 1,str$(_TileSize)
read string 1,str$(_MapSizeX)
read string 1,str$(_MapSizeY)
close file 1
endfunction
Ok, now when I save the file it puts it all 1 line per string...so its like
Quote: "
1
1
W
1
1
W
1
1
etc. etc.
"
I want it to do it like this
Quote: "
1 1 1 W 1 1 W 1 1
"
I need it to be 20 acrros and 17 down...anyone have any suggestions on how to do that?
do you love video games a lot ¿¿¿ then comeon down too game zone252 @ http://www.freewebs.com/gamezone252/