Collision detection in c#
Posted: Mon Jan 23, 2012 4:36 am
So i'm working on a roguelike and it is coming along pretty good. However something extremely odd happened.
Essentially the way I have map generation setup is the game will generate a series of random numbers, and based on those numbers It will turn certain holes or monsters on or off. So lets say the first number it generates is 14.
It will then go through a series of if statements to pick which hole tile to turn on, and since the number is less than 20 it will turn on a hole at 205, 105.
So in order to get the player to not be able to walk through the hole, I had a collision detection code setup like this
So when the player presses the up button it checks to see if the player is already at the top of the map, Then if the player isn't it checks to see if its below a Hole at X205 and Y105, and if that hole is on (The maps get randomly generated so a hole in that location can either be on or off) The player will not move up.
That code worked perfectly until I added another if statement to check for a different hole.
Now The user cannot pass through the second hole, but can walk right through the first hole.
This is a screenshot of the game thus far if it helps

Essentially the way I have map generation setup is the game will generate a series of random numbers, and based on those numbers It will turn certain holes or monsters on or off. So lets say the first number it generates is 14.
It will then go through a series of if statements to pick which hole tile to turn on, and since the number is less than 20 it will turn on a hole at 205, 105.
So in order to get the player to not be able to walk through the hole, I had a collision detection code setup like this
Code: Select all
private void btnDown_Click(object sender, EventArgs e)
{
if (HeroLocation.Y != 455)
{
if (HeroLocation.Y == 55 & HeroLocation.X == 205 & HoleX205Y105.Visible == true)
{
}
else
{
HeroLocation.Y = HeroLocation.Y + 50;
Hero.Location = new Point(HeroLocation.X, HeroLocation.Y);
}
}
That code worked perfectly until I added another if statement to check for a different hole.
Code: Select all
private void btnDown_Click(object sender, EventArgs e)
{
if (HeroLocation.Y != 455)
{
if (HeroLocation.Y == 55 & HeroLocation.X == 205 & HoleX205Y105.Visible == true)
{
}
if(HoleX505Y205.Visible == true & HeroLocation.X == 505 & HeroLocation.Y == 155)
{
}
else
{
HeroLocation.Y = HeroLocation.Y + 50;
Hero.Location = new Point(HeroLocation.X, HeroLocation.Y);
}
}
This is a screenshot of the game thus far if it helps
