Create and save tile maps in XNA

I'm trying to create a dungeon-type demo, and this is my first time really doing anything outside of the Pong and Pak-Man clones. Now my big curl is creating a real level. I read a tutorial on how to draw tiles on the screen, but I can not find anything about where to go from there.

How do I switch from one screen to a larger dungeon? Any help is appreciated.

+5
source share
3 answers

You should consider starting with 2-dimensional arrays. This way you can easily visualize your data.

Start by initializing:

//2D array
int[,] array;

Some sample data:

array= new int[,]
        {
            {0, 2, 2, 0},
            {3, 0, 0, 3},
            {1, 1, 1, 1},
            {1, 0, 0, 0},
        };

, :

enum Tiles
{
    Undefined = 0,
    Dirt = 1,
    Water = 2,
    Rock = 3
}

. , , :

for (int i = 0; i < array.Count; i++)
{
    for (int j = 0; j < array[0].Count; j++)  //assuming always 1 row
    {
       if (array[i][j] == (int)Tiles.Undefined) continue;

       Texture = GetTexture(array[i][j]);  //implement this

       spriteBatch.Draw(Texture, new Vector2(i * Texture.Width, j * Texture.Height), null, Color.White, 0, Origin, 1.0f, SpriteEffects.None, 0f);
    }
}
+6

PSK http://msdn.microsoft.com/en-us/library/dd254918(v=xnagamestudio.31).aspx - , Microsoft, ASCII . . , .

:

.......
.....e.
xx...xx
..s....

- , s - , e - . , () 32x32 , 's' (2x32,3 * 32).

.

. , . , ascii .., .

+1

It will be easier to design your map if you implement save / load for a map-split file .

+1
source

All Articles