Public Group

# Crazyness is happening!!

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

## 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.s_dir < 0 || Evasion::Slimes.s_dir > 3)
Evasion::Slimes.s_dir = rand() % 4;

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


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

##### Share on other sites
Evasion::Slimes.s_dir = rand() % 4;
when they collude why dont you do something like:
Evasion::Slimes.s_dir = (Evasion::Slimes.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 on other sites
if(Evasion::Slimes.s_dir == 0) {
if(TestCollisionSlimes(Evasion::Slimes, Evasion::Slimes.X, Evasion::Slimes.Y + 1) == COL_NONE)
Evasion::Slimes.Y++;
else
Evasion::Slimes.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.

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 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 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 on other sites
Anyone? This is still my first serious game and I'm still unsure how to fix some of the runtime errors.

##### 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 loggingdefine JTDEBUG 1static int numDebug = 1000;.....#ifdef JTDEBUGchar 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 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.X + 1, Evasion::Slimes.Y))		{			if(TestCollisionSlimes(Evasion::Slimes, Evasion::Slimes.X + 1, Evasion::Slimes.Y)				== COL_NONE)				Evasion::Slimes.Y--;		}		else if(!TestWallCollision(Evasion::Slimes.X - 1, Evasion::Slimes.Y))		{			if(TestCollisionSlimes(Evasion::Slimes, Evasion::Slimes.X - 1, Evasion::Slimes.Y)				== COL_SLIME)				Evasion::Slimes.Y++;		}					else if(!TestWallCollision(Evasion::Slimes.X, Evasion::Slimes.Y + 1))		{			if(TestCollisionSlimes(Evasion::Slimes, Evasion::Slimes.X, Evasion::Slimes.Y + 1)				== COL_SLIME)				Evasion::Slimes.X--;		}		else if(!TestWallCollision(Evasion::Slimes.X, Evasion::Slimes.Y - 1))		{			if(TestCollisionSlimes(Evasion::Slimes, Evasion::Slimes.X, Evasion::Slimes.Y - 1)				== COL_SLIME)				Evasion::Slimes.X++;		}	}}

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

• 21
• 15
• 9
• 17
• 13