PDA

Click to See Complete Forum and Search --> : need some help (Fox anyone?)


May 21st, 2000, 08:19 AM
ok, here's my problem, I've got a Pixel X Pixel scrolling engine, right now, it generates maps on the fly.. the tiles are loaded into a 'tile surface' (I'm using directx) and they load the tiles and give everytile a number, and so I've got 3 tiles so each tile's been assigned a number to it.. so basically the map format would look like this:

111231121
122131113
133321223
231312211

and so forth, it would interpret the numbers and then display the appropriate tile on the screen for example 1 is grass tile, 2 is water tile, 3 is mountain tile and so forth? do you understand? I hope you do, ok now my map is a 2 dimensional array. it's 100 x 100... Now I generate maps like this:


Dim Map(100,100) As Byte
Randomize
For i = 0 To UBound(Map, 1)
For j = 0 To UBound(Map, 2)
Map(i, j) = CByte(Rnd() * 3)
Next j
Next i


Now that would basically generate a map with random tiles on it.. What I want to do is, instead of making maps on the fly, i want to load it from a file, and asign the contents to the map array.. I've tried a couple of different ways to do it, but none works...

for example, I made a text file with the numbers (that are up there used as an example) and then loaded it, and it didn't load cause it was supposedly loading in one variable.. so I made another map and added commas ',' inthe numbers for example: 1,1,1,2,3,1,1,2,1

and then tried to load it, and still didn't work.. I've been trying and trying it doesn't work.. now I've come for help, so HELP ME PLEASE!!... Fox or anyone else who knows about tile engines and ****... C'mon Help me!

Fox
May 21st, 2000, 11:03 AM
I'm listening to thee ;)

ok, you shouldn't use the Print function or something. Instead open the file as binary and put the whole map in.
You should also store width and height in vars and make it any size...
Looks like this:

'Module
Global MapWidth as Long
Global MapHeight as Long
Global Map() as Byte 'I'd take integer here...

'In code
Dim FileNumber as Integer

FileNumber = FreeFile
Open File for Binary as Filenumber
'Map size
Put Filenumber,, MapWidth '100
Put Filenumber,, MapHeight 'also 100

'Put the map into the file
Put FileNumber,, Map
Close FileNumber


Now the important thing is while loading the map, attention:

Dim FileNumber as Integer

FileNumber = FreeFile
Open File for Binary as Filenumber
'Map size
Get Filenumber,, MapWidth '100
Get Filenumber,, MapHeight 'also 100

'Reserve memory for the map
ReDim Map( MapWidth, MapHeight )

'Get the map ;)
Get FileNumber,, Map
Close FileNumber

May 21st, 2000, 10:55 PM
Thanks, alright one more question...

well the loading function probably will help me out (I'm not at home so I can't try it out right now), but the saving function, since it saves the file in binary format, I don't think I'll be able to edit it using a text editor? because I dont have a map editor as of yet, well I basically have the hardest time in making a map editor for games then to make the game itself, so if you could probably help me out in this situation, I'd appreciate it, cause the saving function would probably work if I've got a map already generated, and the way i'd be able to do that is by randomly generating the map as before and then saving it... but if I could make a map editor that would be good, I don't have all the ideas of how I would make the map editor, I know that I'd probably use this same engine for it, but as far as the other things are concerned (figuring out how to put a tile and where to put it at), I'm clueless... can you point me to the right direction or help me out or something?

thanks for the reply though ;)

oh one more question: The above loading method works if the map is in 1,2,1,3,1,4 format?? (the map is binary but the content is similar?)

[Edited by WildGhost on 05-22-2000 at 11:57 AM]

Fox
May 21st, 2000, 11:15 PM
Well, you first have to know how you want to save the map / tiles. For example you can add the tile array to your map file, looks like this:

[Tiles]
2 'TileCount
0="Grass"
1="Water"
2="Lava"

[Map array]
4 3 'Size
0 0 0 1 'Data
2 0 0 1
2 0 0 0


So you have two parts, the first which determines which index stands for which tile and then the map itselves.

That's probably the easiest way to store a map... but it's on you what's the best for your game (maybe you want to use different tile sets for the same map so you only save the filename of your tile-file in the map-file)

However, if you want to make a map editor you should think about such basically things first.

Your question
Well, as you know in your computer everything is stored binary so also your map. What really happens is that VB writes the memory block where you map is stored to the file. Because the whole map are Bytes (or even Integers or whatever you want), you know how many memory you have to copy :).
Look at the example:

[Map like you see it (say it's a byte array)]
0 1 2
2 0 7
8 2 1

[Would look like this in binary]
00000000 00000001 00000010
00000010 00000000 00000111
00001000 00000010 00000001

As you can see you won't loose any data ;)

But you're right, you can't edit the map in Notepad (but in HexEdit ;))

Uh, long post... hope this helps ;)

May 22nd, 2000, 08:18 AM
Well, you first have to know how you want to save the map / tiles. For example you can add the tile array to your map file, looks like this:

[Tiles]
2 'TileCount
0="Grass"
1="Water"
2="Lava"

[Map array]
4 3 'Size
0 0 0 1 'Data
2 0 0 1
2 0 0 0


So you have two parts, the first which determines which index stands for which tile and then the map itselves.

That's probably the easiest way to store a map... but it's on you what's the best for your game (maybe you want to use different tile sets for the same map so you only save the filename of your tile-file in the map-file)

However, if you want to make a map editor you should think about such basically things first


well that's how my engine does maps.. it loads tiles then assigns them index numbers.. so that's how it works in the engine...



Well, you first have to know how you want to save the map / tiles. For example you can add the tile array to your map file, looks like this:

[Tiles]
2 'TileCount
0="Grass"
1="Water"
2="Lava"

[Map array]
4 3 'Size
0 0 0 1 'Data
2 0 0 1
2 0 0 0


So you have two parts, the first which determines which index stands for which tile and then the map itselves.

That's probably the easiest way to store a map... but it's on you what's the best for your game (maybe you want to use different tile sets for the same map so you only save the filename of your tile-file in the map-file)

However, if you want to make a map editor you should think about such basically things first.

Your question
Well, as you know in your computer everything is stored binary so also your map. What really happens is that VB writes the memory block where you map is stored to the file. Because the whole map are Bytes (or even Integers or whatever you want), you know how many memory you have to copy .
Look at the example:

[Map like you see it (say it's a byte array)]
0 1 2
2 0 7
8 2 1

[Would look like this in binary]
00000000 00000001 00000010
00000010 00000000 00000111
00001000 00000010 00000001

As you can see you won't loose any data

But you're right, you can't edit the map in Notepad (but in HexEdit )

Uh, long post... hope this helps


Well, This part is kinda confusing, let's say I'm able to make a map editor, where I choose a tile, and click on the screen and it draws the tile... now how do I save this to a file? ok this is kinda confusing...

Psuedo code for drawing on the screen.
if selected tile = grass then
if mouse button down then grass.flip primary screen

now that's easy, I might be able to do that, but how would I get that to save in a file? that's my problem, I dont' know how to make the machine understand/convert what's on the screen to numbers (binary) and put them in a file...

[Edited by WildGhost on 05-22-2000 at 09:20 PM]

Fox
May 22nd, 2000, 10:53 AM
Look at my first post on this thread, the first code block. There's the code for saving such a map. And like I said, you should also save the tiles anywhere. ;)

May 23rd, 2000, 02:17 AM
Ok thanks a lot for your help, I understand it 75% now, except for how I'm going to convert what I see on my screen to what machine understands, I can save that part, so I should know about 3 things in my point of view, to understand how to make a map maker...

1 - being able to draw the map on the screen
2 - Convert what you see on the screen to some kinda text format
3 - Save that converted form to text...


I know 1 and 3, but I"m still clueless on 2... well I'll try to find map editors and see how they do it... thanks for your help though... :)

Fox
May 23rd, 2000, 03:47 AM
Ah well, I think your problem is understanding the tiles... If so you can check out the scrolling demo from my website (http://foxmccloud.tsx.org), should be what you're looking for :). (You can't edit, but if you want I can make it an editor in a minute ;))

May 23rd, 2000, 08:20 AM
Thanks again, well let me try it out and I'll see what I can do, since I'm using DirectX to do the scrolling, I really don't want to put my head into bitblt.. I haven't checked your scrolling demo out yet, but I have a hinch it's bitblt, if it is, I'll check it out and see what I can do, if I need help, I'll just reply here and ask you to make it an editor... that is if you have the time or are willing to..
THANKS!! :)

Fox
May 23rd, 2000, 10:58 AM
*hehe* k

well, just let you know that you shouldn't think that bad about BitBlt. What really matters is the method, the system how I make scrolling. Which API or functions you later use to draw the thing is really another problem. (I coded my game in BitBlt first, was very easy, then it becames too slow and I changed to DX... didn't take me much time ;))