2D Map Saving/Loading

Blitz3D Forums/Blitz3D Beginners Area/2D Map Saving/Loading

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Hi, haven't been using blitz for a while and I just started again. I'm trying to create a tile-based map system for a platformer type game, and it's not really working. Can anyone help?

Thanks in advance, here's the code:

Global tnumber=0
Global maprx
Global mapry
Global maprmode

Graphics 640,480,32,1

SetBuffer BackBuffer()

ClsColor 134,156,175

;load tileset
tiles1=LoadAnimImage("C:/a/Co/Tiles/_A_TilesTest.bmp",32,32,0,16)
MaskImage tiles1,255,0,255

;;;;;;;;;;;;;

While Not KeyHit(1)

	Cls
	
	If KeyHit(200) And tnumber<15 Then tnumber=tnumber+1
	If KeyHit(208) And tnumber>0 Then tnumber=tnumber-1
	
	If KeyHit(57) Then
	
		SaveMap()
		Text 10,290,"Save"
		
	EndIf
	
	If KeyDown(51) Then
	
		LoadMap()
		Text 10,290,"Load"
		
	EndIf 
	
	Text 10,180,maprx
	Text 10,200,mapry
	Text 10,220,maprmode
	
	Color 45,200,75
	Rect MouseX(),MouseY(),32,32,0
	
	Text 10,10,MouseX()/32
	Text 10,30,MouseY()/32
	
	
	If MouseDown(1) Then
	
		hello.tile = New tile
		hello\xnum = MouseX()/32
		hello\ynum = MouseY()/32
		hello\mode = tnumber
		
	EndIf
	
	For hello.tile = Each tile
	
	
		DrawImage tiles1,hello\xnum*32,hello\ynum*32,hello\mode
				
		If ImageRectOverlap(tiles1,hello\xnum*32,hello\ynum*32,MouseX(),MouseY(),24,24) And MouseDown(2) Then
		
			Delete hello
			
		EndIf
	
	Next

	Flip
	
Wend

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Type tile

;position within grid
Field xnum
Field ynum

;type of tile: ground, water or danger
Field mode

End Type

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Function SaveMap()

	For hello.tile = Each tile
	
		mapout=WriteFile("C:\a\mapdata.txt")
	
		WriteInt(mapout,hello\xnum)
		WriteInt(mapout,hello\ynum)
		WriteInt(mapout,hello\mode)

	Next

End Function

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Function LoadMap()

	mapin=ReadFile("C:\a\mapdata.txt")
	
		maprx=ReadInt(mapin)
		mapry=ReadInt(mapin)
		maprmode=ReadInt(mapin)
		
		CloseFile(mapin)

End Function