trying to make a "free hand" map editor =P

Blitz3D Forums/Blitz3D Beginners Area/trying to make a "free hand" map editor =P

AvestheFox(Posted 2005) [#1]
er something of the sort... my problem is getting the darn file to save properly and then load it into another code.

What I've made so far is a 'test' program in an attempt to see what I can whip up. I want the program to save the 'x' and 'y' coordinates of each new object that I put on the edit screen.. then reload them into the loading program where it will place the graphics exactly where I placed them in the main editor..

If that didnt confuse you.. then let me go ahead and send the two pieces of code. Please note, I started coding this just yesturday.. so if it looks a bit newbish, please forgive me =P I'm still getting the hang of Blitz

The Editor:
Graphics 400,400

Type tile
Field ent
Field x
Field y
End Type 

tile=CreateImage(20,20,1)

SetBuffer ImageBuffer(tile)
Color 0,0,100
Rect 0,0,20,20,1
Color 200,200,200
Rect 0,0,20,20,0

SetBuffer BackBuffer()

While Not KeyHit(1)

If MouseHit(1) Then
ob=ob+1
t.tile=New tile
t\ent=CopyImage(tile) 
DrawImage t\ent,MouseX(),MouseY(),0
t\x=MouseX()
t\y=MouseY()
EndIf

If KeyHit(57)
For t.tile= Each tile
fileout=WriteFile("test3.dat")
WriteInt(fileout,ob)
WriteInt(fileout,t\x)
WriteInt(fileout,t\y)
CloseFile(fileout)
Next 
EndIf 

Flip
Wend



the loader:
Graphics 400,400

Type tile
Field ent
Field x
Field y
End Type

tile=CreateImage(20,20,1)

SetBuffer ImageBuffer(tile)
Color 0,0,100
Rect 0,0,20,20,1
Color 200,200,200
Rect 0,0,20,20,0

SetBuffer BackBuffer()

While Not KeyHit(1)

filein=ReadFile("test3.dat")
ob=ReadInt(filein)
If ob>0
For tt=1 To ob 
t.tile=New tile 
t\ent=CopyImage(tile)
t\x=ReadInt(filein)
t\y=ReadInt(filein)
DrawImage t\ent,t\x,t\y,0
ob=ob-1
Next
EndIf

Flip
Wend





splinux(Posted 2005) [#2]
The error is here:

Type tile
Field ent
Field x
Field y
End Type 

tile=CreateImage(20,20,1)


You must create a new tile, first:

t.tile = new tile
...



AvestheFox(Posted 2005) [#3]
I dont quiet understand.. do you mean I need to make a new tile before creating the tile image?

Is that in the editor or loader? or both?

thanks for helping btw


Shambler(Posted 2005) [#4]
With as little alteration to your code as possible...

Editor
Graphics 400,400

Type tile
Field ent
Field x
Field y
End Type 

tile=CreateImage(20,20,1)

SetBuffer ImageBuffer(tile)
Color 0,0,100
Rect 0,0,20,20,1
Color 200,200,200
Rect 0,0,20,20,0

SetBuffer BackBuffer()

While Not KeyHit(1)

If MouseHit(1) Then
ob=ob+1
t.tile=New tile
t\ent=CopyImage(tile) 
DrawImage t\ent,MouseX(),MouseY(),0
t\x=MouseX()
t\y=MouseY()
EndIf

If KeyHit(57)
fileout=WriteFile("test3.dat")
WriteInt(fileout,ob)
For t.tile= Each tile
WriteInt(fileout,t\x)
WriteInt(fileout,t\y)
Next 
CloseFile(fileout)
EndIf

Flip
Wend


Loader
Graphics 400,400

Type tile
Field ent
Field x
Field y
End Type

tile=CreateImage(20,20,1)

SetBuffer ImageBuffer(tile)
Color 0,0,100
Rect 0,0,20,20,1
Color 200,200,200
Rect 0,0,20,20,0

SetBuffer BackBuffer()

While Not KeyHit(1)

filein=ReadFile("test3.dat")
ob=ReadInt(filein)
If ob>0
For tt=1 To ob 
t.tile=New tile 
t\ent=CopyImage(tile)
t\x=ReadInt(filein)
t\y=ReadInt(filein)
DrawImage t\ent,t\x,t\y,0

Next
EndIf

Flip
Wend



AvestheFox(Posted 2005) [#5]
Ah... that's more like it! ^^

thanks Shambler!


WolRon(Posted 2005) [#6]
Fox, if you don't understand Types, or saving/loading data, then how about checking out the references on my programming tutorial. May help some.


AvestheFox(Posted 2005) [#7]
Thanks, Ron.. I looked through your site and learned a few things ^^ I saved it to my favorites for future reference

again.. thanks!