reading a map

Blitz3D Forums/Blitz3D Programming/reading a map

I am confused about a process.

Lets say, in bad pseudo code I have a text map file that is 79X79.

I want to open this file and read the contents into an array THEN use that array to create a dungeon map.

So first:

dim dungeon (79,79)
open map.txt
for x = 1 to 79 read map.txt
next
for y = 1 to 79 read map.txt
next

THEN

OK I am stumped... how do I get the computer to look at the array and put map pieces according to number in the array???

-RZ

You know, that'd only read the 'first' column and row.

You should structure it like so:

Dim Dungeon$(79,79)
For X = 1 to 79
    For Y = 1 To 79
        Dungeon(X,Y) = ReadSomeInfoOrWhateverFromTheMapFile()
    Next
Next

For X = 1 To 79
    For Y = 1 To 79
        ProcessThing(Dungeon(X,Y))
    Next
Next


Or something like that. Basically, I can't do anything without seeing the structure of these map files.

I used a program called ddungeon.exe to generate a text map file like in ROGUE / NETHACK.

This is what I did.
; Hi Mom
;
mapfile = OpenFile ("map1a.txt")

Dim mapper(79,79)

map1=CreateBank(6241)

ReadBytes map1,mapfile,0,6241

CloseFile mapfile
x=1
For row = 1 To 79
	For m = x To x + 79
		Print PeekByte (map1,x):x=x+1
	Next
Next

While Not KeyHit(1)

	
	UpdateWorld
	RenderWorld
	Flip

Wend
End
but the printout is a long list of the number 49...

Oh the file??? It looks like this EXACTLY... you can prob cut and paste!
1111111111111111111111111111111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111113222222231111111111111
1111111111111111111111111111111111111111111111111111111112000000021111111111111
1111111111111111111111111111111111111111111111111111111112000000021111111111111
1111111111111111111111111111111111111111111111111111111112000000021111111111111
1111111111111111111111111111111111111111111111111111111112000000021111111111111
1111111111111111111111111111111111111111111111111111111112000000021111111111111
1111111111111111111111111111111111111111111111111111111112000000021111111111111
1111111111111111111111111111111111111111111111322222223112000000021111111111111
1111111111111111111111111111111111111111111111200000085006000000021111111111111
1111111111111111111111111111111111111111111111200000002112000000021111111111111
1111111111111111111111111111111111111111111111200000002112090000021111111111111
1111111111111111111111111111111111111111111111322522223113222222231111111111111
1111111111111111111111111111111111111111111111111011111111111111111111111111111
1111111111111111111111111111111111111111111111111011111111111111111111111111111
1111111111111111111111111111111111111111111111111011111111111111111111111111111
1111111111111111111111111111111111111111132222222531111111111111111111111111111
1111111111111111111111111111111111111111120000000021111111111111111111111111111
1111111111111111111111111111111111111111120000000021111111111111111111111111111
1111111111111111111111111111111111111111120000000021111111111111111111111111111
1111111111111111111111111111111111111111120000000021113222222223111111111111111
1111111111111111111111111111111111111111120000000050005000000002111111111111111
1111111111111111111111111111111111111111132252222231112000000002111111111111111
1111111111111111111111111111111111111111111101111111112000000002111111111111111
1111111111111111111111111111111111111111111101111111112000000002111111111111111
1111111111111111111111111111111111111111322262222223112000000002111111111111111
1111111111111111111111111111111111111111200000090002112000000002111111111111111
1111111111111111111111111111111111111111200000000002112000000002111111111111111
1111111111111111111111111111111111111111200000000002112000000002111111111111111
1111111111111111111111111111111111111111322222222223113222522223111111111111111
1111111111111111111111111111111111111111111111111111111111011111111111111111111
1111111111111111111111111111111111111111111111111111111111011111111111111111111
1111111111111111111111111111322222311111111111111111111111011111111111111111111
1111111111111111111111111111200000211111111113222222231111011111111111111111111
1111111111111111111111111111200000211111111112000000021111011111111132222231111
1111111111111111111111111111200000211111111112000000021132522222311120000021111
1111111111111111111111111111200000500000000005000000050050000000500050000021111
1111111111111111111111111111325222311111111112000000021120000000211120000021111
1111111111111111111111111111110111111111111112000000021120000000211132252231111
1111111111111111111111111111110111111111111112000000021120000000211111101111111
1111111111111111111111111111110111111111111112000000021120000000211111101111111
1111111111111111111111111322226311111111111113222222231132222522311111101111111
1111111111111111111111111200000211111111111111111111111111111011111111101111111
1111111111111111111111111200000211111111111111111111113222222631111111101111111
1111111111111111111111111200000211132222222222222311112000000021111111101111111
1111111111111111111111111200000211120000000000000211112000000021111111101111111
1111111111111111111111111200000211120000000000000211112000000021111111101111111
1111111111111111111111111200000211120000000000000211112900000021111111101111111
1111111111111111111111111200090211120000000000000211113222222231111111101111111
1111111111111111111111111200000211120000000000000211111111111111111111101111111
1111111111111111111111111200000211120000000000000211111111111111111111352222311
1113222222222222231111111200000211120000000000000213222222231111111111200000211
1112000000000000021111111200000211120000000000000212000000021111111111200000211
1112000000000000021111111200000211120000000000000212000709021111111111200000211
1112000000000000021111111322222311120000000000000506000000021111111111200000211
1112009000000000021111111111111111120000000000000212000000021111111111200000211
1112000000000000021111111111111111120000000000000212000000021111111111200000211
1112000000000000021111111111111111120000000000000212000000021111111111200000211
1112000000000000021111111111111111120000000000000212000000021111111111322225311
1113222622222222231111111111111111132252222222222312000000021111111111111110111
1111111011111111111113222311111111111101111111111112000000021111111111111110111
1111111011111111111112000211111111111101111111111112000000021111111111111110111
1111111011111111111112000211111111111101111111111112000000021111111111111110111
1111111011111111111112900211111113222252222223111113222222231111111111111110111
1111111011111111111112000600000005000000000002111111111111111111111111111135223
1111111011111111111113222311111112000000000002111132222222222222222223111120002
1111111011111111111111111111111112000000000002111120000000000000000002111120002
1111111011111111111111111111111112000000000002111120000000000000000005000050002
1111111011111111111111111111111112000000000002111120000000000000000002111132223
3222222531111111322222222223111112000000000002111120000000000000000002111111111
2000000021111111200000000002111112000000000002111120000000000000000002111111111
2000000021111111200000000002111112000000000002111120000000000000000002111111111
2000000021111111200000000002111112000000000005000050000000000000000002111111111
2000000050000000500000000005000005000000000002111132222222222222222223111111111
2000000021111111200000000002111113222222222223111111111111111111111111111111111
3222222231111111200000000002111111111111111111111111111111111111111111111111111
1111111111111111200000000002111111111111111111111111111111111111111111111111111
1111111111111111322222222223111111111111111111111111111111111111111111111111111
1111111111111111111111111111111111111111111111111111111111111111111111111111111
I get no joy! I think the main problem is with print... there is no way to force it to stay on the same line so maybe use TEXT???
-RZ

You need Write :)

I though write only wrote to a file not to the screen???
-RZ

Description:
Writes a string to the front buffer (i.e. the screen), but doesn't then start a new line (unlike Print).



WRITE tries to work... now can someone explain why it only writes "494949494949494949494...."" until I get a memory access violation???
-RZ

OK I made a change or two... this is acting weird!
; Hi Mom
;
Graphics3D 800,600
SetBuffer BackBuffer()


mapfile = OpenFile ("map1.txt")

Dim mapper(79,79)

map1=CreateBank(6241)

ReadBytes map1,mapfile,0,6241

CloseFile mapfile
x=1
For row = 1 To 79
	For m = x To x + 79
		Write PeekByte (map1,x) 
	Next
	x = x + 1
	Print " "
Next

While Not KeyHit(1)

	
	UpdateWorld
	RenderWorld
	Flip

Wend
End
Yes... write does the trick and it seems to read the file but the numbers make no sense!
-RZ

your getting the Ascii value of 1, which is 49!

you need to render the file using writebyte

try this


; Hi Mom
;
Graphics3D 800,600
SetBuffer BackBuffer()


mapfile = OpenFile ("map1.txt")

efont = LoadFont("Courier",4)
SetFont efont

Dim mapper(80,80)

buffer$ = ""
;map1=CreateBank(6421)

;ReadBytes map1,mapfile,0,6241

	x=1
	For row = 0 To 80

		For x=0 To 80
			buffer = ReadByte(mapfile) - 48
			
			If buffer=>0 Then 
				mapper(x,row ) = buffer
				If (mapper(x,row ) <> 1) Then
					Write Int(mapper(x,row ))
				Else 
					Write " "
				End If
			End If

 		Next
		;x = x + 1
		Print ""
	Next

CloseFile mapfile


While Not KeyHit(1)

	
	UpdateWorld
	RenderWorld
	Flip

Wend
End


Yeah for Neomancer!!! Now to convert it to a program that creates a dungeon in 3d and remake ROGUE/NETHACK the B3D way!

-RZ

Well, at least thats what I hope to do... actually I am just hoping to learn how to program better. ;)

hehe, you "could" do it using boxes, but i have never seen ROGUE so i dont know it works or looks like :(

I used to write those types of dungeons games back on the amiga