Sign in to follow this  

Crazyness is happening!!

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Greetings. I am working on my game, the pacman style one, and I have come across another stupid problem. Usualy the slimes will collide with eachoterh and bounce of eachother, which is what supposed to happen. Occasionaly though, the slimes will bump into one another and then suddenly have the ability to walk through walls and get caught in an infinite loop. Why this happens I have no idea. Heres a bit of the code
// Wall collision detection which works.

for(int a = 0; a < Evasion::numSlimes; a++)
	{ 
		if(a != entity.s_num)
		{
			PX = x + 9; 
			PWidth = 20; 
			PY = y + 9; 
			PHeight = 20; 
			SX = Evasion::Slimes[a].X + 9; 
			SWidth = 20; 
			SY = Evasion::Slimes[a].Y + 9; 
			SHeight = 20; 

			if(PX + PWidth < SX)
				continue;
			if(PX >= SX + SWidth)
				continue;
			if(PY + PHeight < SY)
				continue;
			if(PY >= SY + SHeight)
				continue;
			return COL_SLIME;
		}
	}

	return COL_NONE;
Look familier? It's pretty much the same as my normal collision detection code with the player. Now heres where I execute the moves and compute what they will do
for(int i = 0; i < Evasion::numSlimes; i++)
	{		
		if(Evasion::Slimes[i].s_dir < 0 || Evasion::Slimes[i].s_dir > 3)
			Evasion::Slimes[i].s_dir = rand() % 4;

		if(Evasion::Slimes[i].s_dir == 0)
		{
			if(TestCollisionSlimes(Evasion::Slimes[i], Evasion::Slimes[i].X, Evasion::Slimes[i].Y + 1) == COL_NONE)
				Evasion::Slimes[i].Y++;
			else
				Evasion::Slimes[i].s_dir = rand() % 4;
		}
// Repeat for the other directions

Any ideas why this happens and how to fix it? Thanks.

Share this post


Link to post
Share on other sites
instead of doing
Evasion::Slimes[i].s_dir = rand() % 4;
when they collude why dont you do something like:
Evasion::Slimes[i].s_dir = (Evasion::Slimes[i].s_dir+1) % 4;?
Also try to check for a condition where s_dir =0,1,2,3 all fail !

not sure how much a help this could be but these are some remarks from what i saw..

Share this post


Link to post
Share on other sites
if(Evasion::Slimes[i].s_dir == 0) {
if(TestCollisionSlimes(Evasion::Slimes[i], Evasion::Slimes[i].X, Evasion::Slimes[i].Y + 1) == COL_NONE)
Evasion::Slimes[i].Y++;
else
Evasion::Slimes[i].s_dir = rand() % 4; <--- oops! What if I pick 0 again?
} else if ...
}

Basically, there are several ways in which you could get through the if-test without successfully moving in any direction, because you change the value of the s_dir in between checks of the s_dir.

Using a switch statement here instead of cascaded ifs should help.

Also, I'm a little suspicious of your TestCollisionSlimes() function. Why does it need to know which slime is trying to move into the square?

Also, the collision detection you posted seems to be for colliding one slime against the others, not against walls.

Also, for Pac-Man you probably don't really need bounding-box collision. Everything's laid out on a grid and your players, slimes and walls are all the same "cell size". That was deliberate on the part of the original Pac-Man authors back in '80 or so. :)

Share this post


Link to post
Share on other sites
Ill try chaning that

I should really stop calling it Pacman style because everyone says that. Mines different that way. You dont move on a grid. The map is loaded like a grid but during playing, the grid is discared. It is only use for loading the map.

Share this post


Link to post
Share on other sites
It is with slimes. The comment was misleading. Basicly I have collision detection with the walls there before the one with a slime.

I tried changing it to a switch statement and I still have no luck. What should I change to get rid of the error where it doesnt make it in any direction?

Share this post


Link to post
Share on other sites
You should start to look at logging for debugging especially full screen stuff.

Track the Position X Y and all other Slime Information. Also see if you can track inside the TestCollisionSlimes() function.


// You can get hundreds of text files or
//you could make your own logging system that stores the info onto a list for later output
// remark out the following line to stop logging
define JTDEBUG 1
static int numDebug = 1000;
.....
#ifdef JTDEBUG
char show[80];
sprintf(show, "%d%s", numDebug++, "SlimInfo.txt");
FILE *fp = fopen(show, "wt"); fprintf(fp,"Slimenum :%d X:%d Y:%d \n", a, Evasion::Slimes[a].X + 9, Evasion::Slimes[a].Y + 9 ); fclose(fp); // debug string
#endif


For the infinite loop, I think it's the case where the slime gets out of the Area and can't get back in.

ZoomBoy
Developing a iso-tile 2D RPG with skills, weapons, and adventure. See my old Hex-Tile RPG GAME, character editor, diary, 3D Art resources at Check out my web-site

Share this post


Link to post
Share on other sites
I've decide to trash the way I'm doing it and break it into two functions. One that tests for collisions with walls, and one that tests for collisions with other slimes. Heres what I have now:

void ExecuteAI()
{
for(int i = 0; i < Evasion::numSlimes; i++)
{
if(!TestWallCollision(Evasion::Slimes[i].X + 1, Evasion::Slimes[i].Y))
{
if(TestCollisionSlimes(Evasion::Slimes[i], Evasion::Slimes[i].X + 1, Evasion::Slimes[i].Y)
== COL_NONE)
Evasion::Slimes[i].Y--;
}
else if(!TestWallCollision(Evasion::Slimes[i].X - 1, Evasion::Slimes[i].Y))
{
if(TestCollisionSlimes(Evasion::Slimes[i], Evasion::Slimes[i].X - 1, Evasion::Slimes[i].Y)
== COL_SLIME)
Evasion::Slimes[i].Y++;
}

else if(!TestWallCollision(Evasion::Slimes[i].X, Evasion::Slimes[i].Y + 1))
{
if(TestCollisionSlimes(Evasion::Slimes[i], Evasion::Slimes[i].X, Evasion::Slimes[i].Y + 1)
== COL_SLIME)
Evasion::Slimes[i].X--;
}
else if(!TestWallCollision(Evasion::Slimes[i].X, Evasion::Slimes[i].Y - 1))
{
if(TestCollisionSlimes(Evasion::Slimes[i], Evasion::Slimes[i].X, Evasion::Slimes[i].Y - 1)
== COL_SLIME)
Evasion::Slimes[i].X++;
}
}
}


Right now they can still move through eachother and occasionaly they stop moving for some reason. Any thoughts?

Share this post


Link to post
Share on other sites

This topic is 4832 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this