TileMap question

BlitzMax Forums/BlitzMax Programming/TileMap question

MarkSponge(Posted 2006) [#1]
Whats the best way to do tile maps?

Is it using a .csv file with fields like x,y,z,GXF blah blah.
Or is there a better way?

Also would the MaxGUI be a good option for making a level editor?

Thanks in advance.


CS_TBL(Posted 2006) [#2]
MaxGUI is an excellent option for a level editor, so is Blitz+, but Max is the future anyway. If you don't require much functionality apart from filling a 2d-array, you can have a functional editor within a day.

Simplest way is to fill a 2d array. This can either be a real array (easy) or a bank (less easy, since it requires some map-related functionality). As long as you keep in mind that a 2d map is just a 2d array then most of the thinkwork is already done.


MarkSponge(Posted 2006) [#3]
Thanks CS_TBL.

What is the best way of importing the map? What format is the map saved as?


CS_TBL(Posted 2006) [#4]
Depends on your format. (I dunno any .csv format btw, since I make my own map-editors rather than using a ready-made tool)

A very simple format would be:

1 short for the width of the map
1 short for the height of the map
1 byte for the tiletype/tilesize (e..g 1 for byte, 2 for short, 4 for int)
and for the rest just raw mapdata..

This give you the opportunity to create simple single-layer maps with a maximum 65536*65536 dimension with byte, short or int tiles. Quite enough I think..

But you need to be a little bit more specific about what you require from a map, based on that you can define a format.


MarkSponge(Posted 2006) [#5]
.csv format (comma separated file) is basically a text file with one record on each line. Each field is separated by a comma.

What do you mean when you say "raw mapdata"? I think i'm more confused now then before. Do you have any code examples?

Thanks.


CS_TBL(Posted 2006) [#6]
ehm ehm ehm.. mm.. just for sure: are you an advanced user? average? beginner? Might have to adjust my explanation to that.. :P


MarkSponge(Posted 2006) [#7]
I have wrote a small game from scratch using BlitzMax so probably I'm of average ability. I have good programming knowledge as I am a programmer (C++, php, mysql ect... ) by day.

Just to check we are on the same wave length let me rephrase my question.

I want to make a hex based tile game which would support multiple levels (upstairs, downstairs, basement). I can do the code for drawing the map with off setting and pixel perfect hexagon selection.

The questions:
What is the best way to make and store maps?
Using the MaxGUI to make a map editor where would I start do you know of any tutorials?


Regular K(Posted 2006) [#8]
Using the MaxGUI to make a map editor where would I start do you know of any tutorials?


http://blitzbasic.com/Community/posts.php?topic=54579
This should do it.


CS_TBL(Posted 2006) [#9]
Ah, hex tiles, you didn't mention that before. I don't have experience with those, only 2d, tho I think they're not much different as they can be stored like a 2d map, it's just that drawing odd maplines is a shifted, so the difference is mainly visually.

Anyway, here's a tut: http://www.blitzbasic.co.nz/Community/posts.php?topic=45336

How to store? I'd just do a binary format, basically what I described above but then with another header variable with the amount of layers (for your basements etc.)

E.G. you get a header to define the width of the map, the height of the map, amount of floors (256 floors enough I bet?) and the tiletype.

Then your file would look like:
[mwid][mhei][fl][ty][........................mapdata...............]

Where [____] is a short and [__] is a byte. The rest is mapdata, stored like map:short[x,y,floor] in case you choose the short tiletype.

Have a look at the bmax help for TStream, Writefile etc.

Actually I don't quite know how to explain things to a daily programmer as I don't quite have figured out why there are things you don't know. ^_^


Defoc8(Posted 2006) [#10]
If your working with a custom map the easiest way to
handle this is to record the dimensions of the map in terms
of tiles - 10 tiles wide, 10 tiles high... after this dump the
tile index values one after another into the file...in this case
we have 100 index values to record (10x10).
The index value simply refers to a tile within a large image,
in the same way as drawimage(image,x,y,frame/index)
works.
Assuming you have loaded this data into bmax + want to
render it - for x=0 to 9
for y=0 to 9
drawimage(maptiles,x*32,y*32,map[x,y])

assuming the tiles within the image are 32x32..

blah blah...theres lots more you can do + other problems
to solve...but thats the basic idea..

er..this is what you wanted to know right? :/ :p


Scott Shaver(Posted 2006) [#11]
maxgui map editor with source

http://www.scottshaver2000.com/forum/viewtopic.php?t=140

and you'll need the map module from here

http://www.scottshaver2000.com/blitz/bmaxmods/sas.mod.zip


Smurftra(Posted 2006) [#12]
I'm interested in pixel perfect hex detection :)

I treat mines as squares

I have a solution for pixel perfect that is simple but im not sure is good:

Have an image that represent the hex, have the 4 triangles painted colors 1 to 4 and the hex painted color 0

detect pixel position, and depending on the result, chose the right hex. i dunno how to really explain..


new try:

this is my picture:
____
|/ \|
|\ /|
''''''''''

i figure out where am i in the picture relative to screen/mouse cursor

so lets say i'm at 310x200 and my hexs are 30x30

x = 310 mod 30 = 10
y = 200 mod 30 = 20

so i look at pixel 10,20, and depending on color i know if im on the hex, or if i'm on one of the adjacent hex.

anyways, i havent used that as i figured it wasnt too appearant in my game (you dont see the mouse cursor) and using squares was fine.

but anyways, im interested in other solutions you have. Sorry to hijack thread.