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

D2D map editor

Started by ravenx30 Mar 30, 2011 at 3:00 PM 4 replies 2.1k views
Original Post
ravenx30
ravenx30
Hi guys,

I am using a simple program called 'd2d map editor' which basically draws your tiles and sorts out collition then genarates some code for it.

The problem im having is how to actually make it work? below is the code it genarates:



// This C++ code is generated by D2D Map Editor

// Tile
struct tile
{
int id;
string name;
bool walkable;
string path;
};

tile myTiles[10];

myTiles[0].id = 0;
myTiles[0].name = "0";
myTiles[0].walkable = false;
myTiles[0].path = "Untitled\000.bmp";

myTiles[1].id = 1;
myTiles[1].name = "1";
myTiles[1].walkable = false;
myTiles[1].path = "Untitled\001.bmp";

myTiles[2].id = 2;
myTiles[2].name = "2";
myTiles[2].walkable = false;
myTiles[2].path = "Untitled\002.bmp";

myTiles[3].id = 3;
myTiles[3].name = "3";
myTiles[3].walkable = false;
myTiles[3].path = "Untitled\003.bmp";

myTiles[4].id = 4;
myTiles[4].name = "4";
myTiles[4].walkable = false;
myTiles[4].path = "Untitled\004.bmp";

myTiles[5].id = 5;
myTiles[5].name = "5";
myTiles[5].walkable = false;
myTiles[5].path = "Untitled\005.bmp";

myTiles[6].id = 6;
myTiles[6].name = "6";
myTiles[6].walkable = true;
myTiles[6].path = "Untitled\006.bmp";

myTiles[7].id = 7;
myTiles[7].name = "7";
myTiles[7].walkable = false;
myTiles[7].path = "Untitled\007.bmp";

myTiles[8].id = 8;
myTiles[8].name = "8";
myTiles[8].walkable = false;
myTiles[8].path = "Untitled\008.bmp";

myTiles[9].id = 9;
myTiles[9].name = "9";
myTiles[9].walkable = false;
myTiles[9].path = "Untitled\009.bmp";


// Map size
const int mapWidth = 25;
const int mapHeight = 15;

// Map alpha
int mapAlpha = 100;

// Map Array
int Layer1[mapWidth][mapHeight] = {
{ 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9},
{ 3, 6, 6, 6, 6, 6, 6, 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, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 2}
};





But dont know what I would but in the load, draw/updates methods to get this code to actually work in xna?
yewbie
yewbie
I have never used XNA but check out this tutorial its pretty much covering what your doing.

XNA Tile Tutorial
ravenx30
ravenx30

I have never used XNA but check out this tutorial its pretty much covering what your doing.

XNA Tile Tutorial


thanks for the reply although that link dont really help that much as doesnt deal with structs etc. Ive now managed to draw the map to the screen and my character but not sure if i done it right. I now just need help with the collition aspect. Ill show you how i managed to draw it below:



// EXTRA VARIBLES ADDED

List<Texture2D> tiles = new List<Texture2D>();



This is so i can handle the grid array (Layer1)



// LOAD METHOD

for (int n = 0; n < 10; n++)
{
tiles.Add(Content.Load<Texture2D>(myTiles[n].Path));
}



basically adds all the file name paths declared in the struct.



// DRAW METHOD

spriteBatch.Begin();
for (int y = 0; y < Layer1.GetLength(0); y++)
{
for (int x = 0; x < Layer1.GetLength(1); x++)
{
spriteBatch.Draw(tiles[Layer1[y, x]],
new Rectangle(
x * 32,
y * 32,
32,
32),
Color.White);
}
}
spriteBatch.End();



Nested loop to run through and draw each row and colum of the array.

I feel i havnt used the previous code fully by implementing a list and the way I used the load method but none the less it does display the genarated tiles. problem is now when I add a charater to the equation declaring it in the stuct the same way as the tiles im not sure how to manage the collition as unfortunitly you can just do:



if (chararcter.walkibe.intersects(myTiles.walkible))
{

// collition();

}



I feel that I have gone about all of this totally wrong and there is a really simple solution lol but ive scoured the net and looked at many guides with no joy..
ravenx30
ravenx30
Can i not do something like:



for(int n = 0; n < 10; n++)
{

if (!myTiles[n].Walkable)
{
Rectangle blockRect = new Rectangle(myTiles[n].,0,32,32); // NOT FINISHED/ UNSURE

if(mskull.Bounds.Intersects(blockRect))
skullPosition.X += 5;
}

else
skullPosition.X -= skullSpeed;
}



checks all the tiles for which ones which are not passible. It then creates a rectangle around the immpasible tile which is used for a collition test
against the character. If collition test = true then the postion is altered.

was thinking about putting this code when the user goes left. i then can use similar to do the other directions?

logic sounds ok but not sure how to create the rectangle for the tiles in question. the first if makes sure im looking at the immpasible tile but how
do I draw a rectangle around it not knowing the start x and y cords?
TheTroll
TheTroll
Sorry didn't get a chance to work on that class, got two sick kids.

The way I do it is to have in the tile a variable for each direction, N, NE, E, SE, S, SW, W, NW. Put the tile that it can travel to in each variable. This will take a little more time when loading the map. But the advantage is that during game play you have the location to test if they can move at all time. So if you want to move E, you just go E.CanMove and that would let you know if E is passable.
ravenx30
ravenx30

Sorry didn't get a chance to work on that class, got two sick kids.

The way I do it is to have in the tile a variable for each direction, N, NE, E, SE, S, SW, W, NW. Put the tile that it can travel to in each variable. This will take a little more time when loading the map. But the advantage is that during game play you have the location to test if they can move at all time. So if you want to move E, you just go E.CanMove and that would let you know if E is passable.


Sorry that your kids are unwell,

If you send me a message with your email ill forward what Ive done so far as im totally sick.. tried doing this simple tile map for over a week and cant even get the basics to work. Im trying to make a bomberman type game but its a lot harder than first thought. My code is a bit messed up as been trying to get the fire mechanism working as couldn't get the tile enginne working lol couldn't even do that..

Ah well it is my first c# game I bet many were fustrated when trying to create there first game. cant upload *.zip files on here or code files so if you send me ur email via private messaging on gamedev ill fire it across

Topic Locked

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

Sign in to reply to this topic.