Skip to main content
GameDev.net gamedev.net
🔒 Locked

Setting coordinates in map editor

Started by ChristianFrantz May 11, 2013 at 7:20 AM 0 replies 1.1k views
Original Post
ChristianFrantz
ChristianFrantz

I'm editing this map editor http://xnafan.net/2013/01/2d-map-generation-for-xna/ to suit the needs of a game I'm trying to make. The map as it stands, generates random points in a 50x50 map and right clicking smooths out the points to make a hilly texture.

What I'm trying to do is edit it so that I can set my own points at each square individually, and currently the program doesnt allow you to do this. I figured out how to set all points to zero, but I don't know how to set each point individually. I there a way that I can create a border around the map 10 blocks in width and set them all to 50? The editor will do the rest and smooth them out to look like hills

The editor also exports maps as a text file, but only with spaces and x's. I want to export the map with numbers representing the height of the square.


for (int y = 0; y < map.GetLength(1); y++)
            {
                //first element in a row has no comma in front of it
                string separator = "";

                for (int x = 0; x < map.GetLength(0); x++)
                {
                    //write simple "X" if the map is above oceanlevel or a space otherwise
                     builder.Append(separator + (map[x, y] > oceanLevel ? "X" : " "));

                    //all remaining elements in row have a comma before them
                    separator = ",";
                }
                //add a new line
                builder.AppendLine();
            }
            try
            {
                //write the save game file.
                using (StreamWriter writer = File.CreateText(path)) { writer.Write(builder.ToString()); }
            }
            catch (Exception ex)
            {
                throw new Exception("Error writing to file '" + path + "'. Error is: " + ex.ToString());
            }
        }

Could I alter the for loops to look at each block and read the height that its set to?

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

Hi Burnt_casadilla smile.png

You can change the line:


builder.Append(separator + (map[x, y] > oceanLevel ? "X" : " "));

to


builder.Append(separator + map[x, y]);

This will look up the value in the double array at position x,y and add that to the StringBuilders buffer for later retrieval.

EDIT: I added an extended version of the editor to the blogpost (at the bottom), which supports saving the heightmap (and you can look at the code for loading from the file as well, though the application doesn't support it).

as for adding a border - you can do this with a for-loop, iterating through zero to max on both the Y and X axis, and setting the value there to 50 if either the X or the Y value is either zero or max.

If that doesn't make sense, ask again smile.png

Kind regards - Jakob Krarup ;-)

www.xnafan.net - tutorials, tools and code samples for making games :)

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.