How to make a map editor with cubes

Started by
8 comments, last by Dragonsoulj 10 years, 9 months ago

I was given the advice to make a map editor for my game so I don't have to manually create the map, and it sounds like fun so I'm going to give it a shot. It'll be pretty simple, 3 types of cubes, a grid 1000x1000 and 60 high, and the ability to snap cubes to the grid. Now I think this could be pretty simple because it's all cubes. An empty map would display the grid, and when the grid is complete if a space isn't filled, just fill the rest with "empty" cubes. Exporting would be an issue though. I draw the cubes in my game using a 3d array, so somehow I'd have to export it like that.

Does anybody have any advice or tips to get me started?

If you see a post from me, you can safely assume its C# and XNA :)

Advertisement

Your implementation sounds very similar to how the GTA and GTA2 file format worked. I don't have the link off hand but if you google around you should be able to find the tech design document which details the level file format and how they stored and exported it.

You know the grid size. So all you need to save the infromation for each tile of the grid that is filled. I do not see what the confusion is.


I draw the cubes in my game using a 3d array, so somehow I'd have to export it like that.

Does anybody have any advice or tips to get me started?

editor save:

open file

for x=0 x<1000 x++

for z=0 z<1000 z++

for y= 0 y< 60 y++

writecube(x,y,z)

close file

game load:

open file

for x=0 x<1000 x++

for z=0 z<1000 z++

for y= 0 y< 60 y++

readcube(x,y,z)

close file

writecube() writes the data for one cube to your "level map" data file.
readcube() reads the data for one cube from your "level map" data file and puts it in the game's 3d array.
the file format is up to you. it can be text or binary. binary will be faster.
the slickest way is if the data structure (the 3d array) is the same in the editor and the game. then you can just blockwrite the entire 3d array as one binary blob of data, and blockread it directly into the game's 3d array. fastest possible load and save, just one line of code to load or save the whole thing. the downside is if the data structure of a cube changes, you have to convert existing level maps to the new cube data structure. an efficient workaround for this is to save the individual fields of a cube struct in order individually one at a time, instead of writing the whole struct in one shebang. then when you add a new variable to the struct, you just add the code to write that one variable to the end of the save routine. have the game init the 3d array with some default value for the new variable. then you load in your old levels, and save them out again. this writes them out with the new variable data in them. then you add the code to read the new variable data to your load routine, and your all done - new data structure, new load and save routines, and all old level maps are converted to new format with a default value for the new variable.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Hmm I didn't realize it'd be that simple. Every block over the height of 17~23 would be one type, blocks under 0 would be dirt, and the rest would be grass or empty. But how do I distinguish an empty block from a full one with a 3d array? (10, 5, 10) That would just be a position, not actually telling what type of block is in the array.

Another question, I know I can use windows forms with XNA, but would I just be able to copy and paste the code that renders my cubes into the map editor? I'd have to mess around with mouse rays and displaying a grid but that shouldn't be too hard

If you see a post from me, you can safely assume its C# and XNA :)

Build the editor into the engine, using the same rendering code for gameplay and editing, as well as the code that loads/saves maps.

Just export what block type is at what space, read in each block type and you will be fine.

Write out each 2D layer (you have 60), so you'd have 1000 different values per line, go down 1000 lines, then repeat 59 more times. If you intend to do a user readable format, that is.

The example Norman gives works fine. You are only exporting the type of block since you are exporting/importing in the same order, and have an empty block type. The position in the file would give you what coordinate it's at.

Build the editor into the engine, using the same rendering code for gameplay and editing, as well as the code that loads/saves maps.

Do not build the editor into the engine, Use the engine as the back end for the editor.

Whats the difference? Cant i just create a window with winforms that handles all the visual aspects of it?

If you see a post from me, you can safely assume its C# and XNA :)

The goal of using the game's engine is to have the same visual while designing as while playing.

This topic is closed to new replies.

Advertisement