dancks 4 Light Poster

I originally asked this question at cplusplus.com but got no responses. In my program I have the main player and enemy tanks. When using the shotgun weapon it works fine for the main player but it kills the bad guy when they use the weapon. I don't understand how this is happening.

I'll show (what I believe to be) the relevant code snippet, the cplusplus.com link and also attached is the code in its entirety.

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;
}

cplusplus link:
http://www.cplusplus.com/forum/beginner/76662/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.