Collision detection kills the shooter?

Here's the snippet:
collisionhandler:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
unsigned long* collisionhandler::checkpellethit(int good, int *n)
{
	int z=0;
	unsigned long *dead = new unsigned long[weapons.size()];
	int q = weapons.size();
	for (int i=0;i<q;i++)
	{
		//printf("in collisionhandler, checkpellethit\n");
		if(weapons[i].type==3)
		{
			int r = players.size();
			for(int j=0;j<r;j++)
			{
				if(players[j].good!=good)
				{
					playerarea[!good]->setarea(players[j].x,players[j].y,players[j].theta);
					shotguns[good]->setarea(weapons[i].x,weapons[i].y,weapons[i].theta);
					fprintf(stdout,"pellet: x: %f, y: %f, good: %i. player: x: %f, y: %f, good: %i\n",weapons[i].x, weapons[i].y, weapons[i].good, players[j].x, players[j].y, players[j].good);
					if (playerarea[!good]->didhit(*shotguns[good]))
					{
						printf("Killed\n");
						dead[z]=weapons[i].idd;
						weapons.erase(weapons.begin()+i);
						player a = players[j];
						players.erase(players.begin()+j);
						a.hit=1;
						players.push_back(a);
						z++;
					}
				}
			}
		}
	}
	*n=z;
	return dead;
}

I know it can be pretty hard to read through my code I'll try and break it down:
algorithm:
find each pellet fired by a player thats good or evil (good=1, good=0), check it against each player on the opposite side with object collarea assigned to pellet and player that does the collision detection. If its a hit, delete the pellet from vector weapons (visible shot, bullets, rockets on screen) and update the struct player object to read hit. Its then read and culled by collisionhandler::checktankkill which is called by the appropriate object to delete the appropriate players.

This method seems perfectly written but I don't know where I should look next to see what it might be. the player objects are tank and eviltankhandler. I know that int good in tank and eviltankhandler are set correctly

If I uploaded the entire code somewhere could someone give me a couple of ideas?
Topic archived. No new replies allowed.