Jump to content
  • Advertisement
Sign in to follow this  
ChristianFrantz

Setting coordinates in map editor

This topic is 2039 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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?

Edited by burnt_casadilla

Share this post


Link to post
Share on other sites
Advertisement

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 ;-)

Edited by xnafan

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!