示例#1
0
void Obstacle::Run(Weapon &weapon1,Player &player1,Weapon &weapon2,Player &player2)
{
    double b1x=weapon1.GetBullet()->x();
    double b1y=weapon1.GetBullet()->y();
    int p1x=player1.getX();
    int p1y=player1.getY();
    double b2x=weapon2.GetBullet()->x();
    double b2y=weapon2.GetBullet()->y();
    int p2x=player2.getX();
    int p2y=player2.getY();
    Draw(p1x,p1y,p2x,p2y);
    Move();
    CheckCollision(b1x,b1y,b2x,b2y);
    if (hstate1==1) {
        player1.health-=0.2;
        hstate1=0;
    }
    if (hstate2==1) {
        player2.health-=0.2;
        hstate2=0;
    }
    if (state1==1)
    {
        countdown+=0.9;
        if (countdown>1.2)
        {
            state1=0;
            countdown=0;
        }
    }
    if (state2==1)
    {
        countdown+=0.9;
        if (countdown>1.2)
        {
            state2=0;
            countdown=0;
        }
    }
}
示例#2
0
void Background::checkcollision(Weapon &gun1,Weapon &gun2)
{
    for (int i=0; i<nCube; i++)
    {
        // weapon1
        if (gun1.GetBullet()->x()>CubePtr[i].GetX()-gun1.GetBullet()->GetRadius()
                && gun1.GetBullet()->x()< CubePtr[i].GetX()+50
                && gun1.GetBullet()->y()<CubePtr[i].GetY()+gun1.GetBullet()->GetRadius()
                && gun1.GetBullet()->y()>CubePtr[i].GetY()-50-gun1.GetBullet()->GetRadius()
                && CubePtr[i].state==1
                && gun1.GetBullet()->GetLife()>0
           )
        {
            CubePtr[i].state=0;
            gun1.GetBullet()->ChangeLife();
        }
        // weapon2
        if (gun2.GetBullet()->x()>CubePtr[i].GetX()-gun1.GetBullet()->GetRadius()
                && gun2.GetBullet()->x()< CubePtr[i].GetX()+50
                && gun2.GetBullet()->y()<CubePtr[i].GetY()+gun1.GetBullet()->GetRadius()
                && gun2.GetBullet()->y()>CubePtr[i].GetY()-50-gun1.GetBullet()->GetRadius()
                && CubePtr[i].state==1
                && gun2.GetBullet()->GetLife()>0
           )
        {
            CubePtr[i].state=0;
            gun2.GetBullet()->ChangeLife();

        }
    }
}