•      Sign In
• Create Account

# BlueSin

Member Since 17 Jan 2006
Offline Last Active Dec 26 2013 04:11 PM

### 2D Sorting map tiles into map chunks

26 December 2013 - 02:59 PM

So I am having a ridiculous problem I cannot seem to wrap my head around.  I have been working at it for days, and I know the solution is simple I just cannot see it, so I need an outside opinion.  I am working on procedural map generator.  When I generate the map, the first thing I am doing is initializing map chunks.  These chunks will contain several tiles each and will be used to only draw the chunks that are currently on the screen.  All other chunks will not be drawn.

So I begin by creating chunks:

```// Creates map chunks
private static Map CreateChunks(Map map)
{
// Initialize map chunk rows
map.Chunks = new MapChunk[map.GetMapWidth / MAP_CHUNK_WIDTH][];

// Traverse chunk rows
for (int chunkX = 0; chunkX < map.Chunks.Length; chunkX++)
{
// Initialize chunk column
map.Chunks[chunkX] = new MapChunk[map.GetMapHeight / MAP_CHUNK_HEIGHT];

// Traverse chunk columns
for (int chunkY = 0; chunkY < map.Chunks[chunkX].Length; chunkY++)
{
// Initialize chunk
map.Chunks[chunkX][chunkY] = new MapChunk(MAP_CHUNK_WIDTH, MAP_CHUNK_HEIGHT);
}
}

// Return map
return map;
}
```

Then I create tiles within those chunks:

```// Create map tiles
private static Map CreateTiles(Map map)
{
// The current X position of the map
float mapX = 0;
// The current Y position of the map
float mapY = 0;

// Traverse chunk rows
for (int chunkX = 0; chunkX < map.Chunks.Length; chunkX++)
{
// Traverse chunk columns
for (int chunkY = 0; chunkY < map.Chunks[chunkX].Length; chunkY++)
{
// Initialize tile rows
map.Chunks[chunkX][chunkY].Tiles = new MapTile[MAP_CHUNK_WIDTH][];

// Traverse chunk rows
for (int tileX = 0; tileX < map.Chunks[chunkX][chunkY].Tiles.Length; tileX++)
{
// Initialize tile columns
map.Chunks[chunkX][chunkY].Tiles[tileX] = new MapTile[MAP_CHUNK_HEIGHT];

// Traverse tile columns
for (int tileY = 0; tileY < map.Chunks[chunkX][chunkY].Tiles[tileX].Length; tileY++)
{
// initialize this tile
map.Chunks[chunkX][chunkY].Tiles[tileX][tileY] = new MapTile(
0, null, new Rectangle(
(int)mapX * map.GetTileWidth,
(int)mapY * map.GetTileHeight,
map.GetTileWidth, map.GetTileHeight
),
Noise.GetNoise(mapX * 0.1f, mapY * 0.1f, map.GetSeed));

// Increase mapY
mapY++;
}

// Increase mapX
mapX++;
// Reset map Y
mapY = 0f;
}
}
}

// Return map
return map;
}
```

So, in theory Chunk[0][0].Tile[0][0] should be positioned at Vector (0,0).  Which it is.  And in theory the second tile in the row Chunk[0][0].Tile[1][0] should be positioned at Vector (24, 0) (tiles are 24 x 24).  Which it is. The first tile in the second row Chunk[0][0].Tile[0][1] should be at Vector (0, 24).  Which it is.  All of that works fine.

The problem comes when we move on to the next chunk.  Chunk [1][0] is to the right of Chunk[0][0].  Chunk [0][1] should be below Chunk[0][0].  However the vector of Chunk[1][0].Tile[0][0] is  (18432, 0).  Chunk[0][1].Tile[0][0] has a Vector (0, 2304).  Which means they are reversed, in theory Chunk[1][0] should be Vector (2328, 0) (I need to increase mapX/mapY between chunk changes.  But given the way it stands now Chunk[0][1] is where Chunk[1][0] should be.  Chunk[1][0] current vector is just messed up.  I know I need to play around with the increase of mapX/mapY and reset of mapX/mapY to change it.  But I have tried every imaginable combination and it just isn't working.  Any help?

### Generic Class Questions

29 June 2013 - 01:53 PM

So I am reading the check marked reply on this post: http://gamedev.stackexchange.com/questions/30296/loading-class-instance-from-xml-with-texture2d

I have never used generic classes before and am absolutely confused on what he is talking about.  I read up on them and understand how they should be used, but the respondent's answer doesn't sound like it makes sense in a generic class.

What exactly is he saying I should be passing into the generic class' constructor?  Is he saying pass the Weapon instance into it, or the Texture instance?  Because if I pass a Weapon instance into it as T t, I cannot call t.TextureId because the Type is unknown.

### Map Editor Help

28 June 2013 - 07:53 AM

So I am preparing to create my own map editor for an XNA game I will be working on.  The map editor will need the ability to import graphic sprite sheets, allow me to pick various tiles on those sprite sheets and plot them on a virtual game map.  It will also need auto tiling and perhaps even other features later on.  Upon saving the map the editor will transform the tile ID's, map layer ID's and sprite sheet file data into a single .map file.

I don't want to embed XNA in a forms project, but I do want to be able to run my map in XNA by use of a play button on the editor interface, to test the map in XNA.

Herein lies the problem, I am not sure where to start.  Should I go with WPF? Or maybe forms and create a series of custom controls?  Or perhaps a forms project where I go batty with GDI+?  Or perhaps some other route for the editor.  I need an outside the box opinion here.

P.S. - I know these types of editors already exist, some for free and others to purchase.  However, I want to create a proprietary one that will be used for games created by my studio going forward.  Thus I am not interested in trying or buying any pre-made editors.

Thanks in advance!

### Map Editor Help

28 June 2013 - 07:48 AM

So I am preparing to create my own map editor for an XNA game I will be working on.  The map editor will need the ability to import graphic sprite sheets, allow me to pick various tiles on those sprite sheets and plot them on a virtual game map.  It will also need auto tiling and perhaps even other features later on.  Upon saving the map the editor will transform the tile ID's, map layer ID's and sprite sheet file data into a single .map file.

I don't want to embed XNA in a forms project, but I do want to be able to run my map in XNA by use of a play button on the editor interface, to test the map in XNA.

Herein lies the problem, I am not sure where to start.  Should I go with WPF? Or maybe forms and create a series of custom controls?  Or perhaps a forms project where I go batty with GDI+?  Or perhaps some other route for the editor.  I need an outside the box opinion here.

P.S. - I know these types of editors already exist, some for free and others to purchase.  However, I want to create a proprietary one that will be used for games created by my studio going forward.  Thus I am not interested in trying or buying any pre-made editors.

Thanks in advance!

### How to Use Perlin Simplex Noise?

26 April 2013 - 05:36 PM

I am incredibly new to noise, so please bear with me here.  So I used the code from http://cabbynode.net/2012/06/10/perlin-simplex-noise-for-c-and-xna/ to create my noise.  I simply filled a jagged float array with these values and used a white 16x16 texture colored on draw based on value to represent the result visually.  Here is that result:

So, it appears to be interpolating nicely enough.  But the question is how do I use this?  I can think of a couple of possibilities:

Each value is a block, and the material (i.e. - stone, dirt, etc.) of the block is based on that value.

OR

Each value is a chunk of the map, and the material (i.e. - stone, dirt, etc.) that the chunk is made of.

OR

I have completely no idea what I am doing and need the answer given to me lol.

On a side note, I changed the way I was looking at it so that if the value was >= 0.5 it was land, if not open space.  The result is what appears to be a pretty natural looking cave network.  So I guess I could use it that way as well, to tell me if there are caves.

PARTNERS