Bomberman block collition

Started by
6 comments, last by ravenx30 13 years ago
Hey!

Dear experts I am trying to create a bomberman type game and have done bits of it such as back ground using a tile engine and anmating sprites on the move. I have come across a problem when tring to make a block immpassible (like the bomberman grid ever 2 sprites should be a block which is none destructive). I can do the first tile as shown later but not the others, Below is my code snipet:



protected bool Collide()
{
int skullCollisionRectOffset = 0;
int tileRectOffset = 5;


Rectangle blockRect = new Rectangle( // Creates Rectangle around impassible block
tileWidth * 2, // reason i have *2 is because the first impassible tile is double the hieght and width from top left of screen lol...
tileHeight * 2, // this will only make the first block immpassible
tileWidth,
tileHeight);


Rectangle skullRect = new Rectangle( // Creates Rectangle around character
(int)skullPosition.X + skullCollisionRectOffset,
(int)skullPosition.Y + skullCollisionRectOffset,
skullFrameSize.X - (skullCollisionRectOffset *2),
skullFrameSize.Y - (skullCollisionRectOffset *2));

return blockRect.Intersects(skullRect);

}



I have come up with a few ideas none of which i can get to work... first idea is because im using a list to create my tiles and using a nested for loop to draw them something like:



int[,] map = {
{4, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5,}, // the numbers in this list refur to a tile sprite
{10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,},
{10, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2,},
{10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,},
{10, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2,},
{10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,},
{10, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2,},
{10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,},
{10, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2,},
{10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,},
{10, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2,},
{10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,},
{10, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 2,},
{10, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2,},
{6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,},


is there a way i can say something like:



if(map.value = 3) // where 3 is the impassive tile (not sure if .value is how you check for a certain number in the list?)
{

++x; // Increment x every time this is called

Rectangle blockRect[x] = new Rectangle( // make an array to store the rectangles? although xna isnt happy with this
tileWidth,
tileHeight,
tileWidth,
tileHeight);
}



basically this is an idea but I really havnt a clue what to do lol.. sorry for being a n00b at this but im learning...

Thanks in advance!
Advertisement
Come on guys,

This doesn't seem much of a challenge for you pros lol i managed to do it for one block... and there must be a way to draw rectangles around the other blocks using a loop and array or something? the above was an idea well the last snipet anyways im open to any suggestions :)

thanks!
My answer is going back to your other post. Same thing with a tile class. Define in it, if the tile is impassible. That way when you hit the tile, you can ask it if you can pass.

Instead of making all of these different arrays and lists for what you can and can't do, include it in the tile class. After all the tile should contain all of this information.

My answer is going back to your other post. Same thing with a tile class. Define in it, if the tile is impassible. That way when you hit the tile, you can ask it if you can pass.

Instead of making all of these different arrays and lists for what you can and can't do, include it in the tile class. After all the tile should contain all of this information.


question is though how can i make a certain tile impassible? can you change the propertys of the tile? not sure how you would go around doing that? could you give me an example using my code?

Many thanks btw your the only one who replys to my posts!

:)

public class Tile
{
bool passable;
Image backgroundImage;
List<Image> overlayImages;
int x_location;
int y_location;

public void Draw()
{
// Put your draw code here.

}

public bool CollisionTest(int x, int y)
{
// Do your collision test here.

}

}



That is how I would set up my tile. You can pass the location of the moving object to the tile and then see if the object can pass through the tile. This also help with your overlay problems.

theTroll


public class Tile
{
bool passable;
Image backgroundImage;
List<Image> overlayImages;
int x_location;
int y_location;

public void Draw()
{
// Put your draw code here.

}

public bool CollisionTest(int x, int y)
{
// Do your collision test here.

}

}



That is how I would set up my tile. You can pass the location of the moving object to the tile and then see if the object can pass through the tile. This also help with your overlay problems.

theTroll


Looks good but think im going a bit ahead of my ability so i found a program called 'D2D map editor' which is fairly simple but genarates the code for you including layers and impassible objects.. problem is lol im so stupid i dont know how to draw it using xna. below is the code it genarates:



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

// Tile
struct tile
{
int _id;
String _name;
Boolean _walkable;
String _path;

public tile(int id, String name, Boolean walkable, String path)
{
_id = id;
_name = name;
_walkable = walkable;
_path = path;
}

public int Id
{
get
{
return _id;
}
set
{
_id = value;
}
}

public String Name
{
get
{
return _name;
}
set
{
_name = value;
}
}

public Boolean Walkable
{
get
{
return _walkable;
}
set
{
_walkable = value;
}
}

public String Path
{
get
{
return _path;
}
set
{
_path = value;
}
}

}

tile[] myTiles = {
new tile(0, "0", false, "JingZhou\000.bmp"),
new tile(1, "1", false, "JingZhou\001.bmp"),
new tile(2, "2", false, "JingZhou\002.bmp"),
new tile(3, "3", false, "JingZhou\003.bmp"),
new tile(4, "4", false, "JingZhou\004.bmp"),
new tile(5, "5", false, "JingZhou\005.bmp"),
new tile(6, "6", true, "JingZhou\006.bmp"),
new tile(7, "7", false, "JingZhou\007.bmp"),
new tile(8, "8", false, "JingZhou\008.bmp"),
new tile(9, "9", false, "JingZhou\009.bmp")
};


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

// Map alpha
int mapAlpha = 100;

// Map Array
int [,] Layer1 = {
{ 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, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5},
{ 3, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 5},
{ 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5},
{ 3, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 5},
{ 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5},
{ 3, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 5},
{ 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5},
{ 3, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 5},
{ 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5},
{ 3, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 5},
{ 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5},
{ 3, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 4, 6, 5},
{ 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5},
{ 1, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 2}
};





And thats all it gives you. I understand how it works etc but this is only inicilising the map not drawing it. any change you could supply the code i have to put in draw method to run it? lol probably really simple but ive tried for hours being new to all of this with no avail :(

Do i have to inicialize each part for example walkible? open something which says what to do if its true or something?

If i could work out how do use the genarated code all my problems would be solved lol
A bit later today I will whip up a better class for you. You should be able to just plug it in and get it to work. Give me 3-6 hours or so to get up done.

A bit later today I will whip up a better class for you. You should be able to just plug it in and get it to work. Give me 3-6 hours or so to get up done.


ok cool thanks mate :D try and base it on the above then I can just use the editor to modify things and add layers etc :P

This topic is closed to new replies.

Advertisement