Exemple #1
0
void Bullet::checkCollision()
{
    QList<QGraphicsItem *> l=scene()->items();
    foreach(QGraphicsItem *item, l) {
        if ( (item->type()==man_type) && item->collidesWithItem(this, Qt::IntersectsItemBoundingRect) ) {
            Man* deadman = (Man*)item;
            if (deadman->frame() != 5) return;
            deadman->done();
            emit score(10);
            setShotCount(shotcount+1);
            nobullets--;
            deleteLater();
            return;
        }
        else if ( (item->type()==helicopter_type) && item->collidesWithItem(this, Qt::IntersectsItemBoundingRect) ) {
            Helicopter* deadchopper = (Helicopter*) item;
            deadchopper->done();
            emit score(50);
            setShotCount(shotcount+1);
            nobullets--;
            deleteLater();
            return;
        }
    }
    //check shot is not out of bounds
    if ( (y() < 0) || (x() < 0) ||
        (y() > scene()->height()) ||
        ( x() > scene()->width()))  {
        nobullets--;
        deleteLater();
        return;
    }
}
Exemple #2
0
void Bullet::checkCollision()
{
    QCanvasItem* item;
    QCanvasItemList l=collisions(FALSE);
      for (QCanvasItemList::Iterator it=l.begin(); it!=l.end(); ++it) {
          item = *it;
          if ( (item->rtti()== 1500) && (item->collidesWith(this)) ) {
               Man* deadman = (Man*)item;
               if (deadman->frame() != 5) return;
               deadman->done();
	       emit score(10);
               setShotCount(shotcount+1);
               setAnimated(false);
               nobullets--;
               delete this;
               return;
          }
          else if ( (item->rtti()==1900) && (item->collidesWith(this)) ) {
               Helicopter* deadchopper = (Helicopter*) item;
               deadchopper->done();
	       emit score(50);
               setAnimated(false);
               nobullets--;
               delete this;
               return;
         }
      }
      //check shot is not out of bounds
     if ( (y() < 0) || (x() < 0) ||
          (y() > canvas()->height()) ||
          ( x() > canvas()->width()))  {
          setAnimated(false);
          nobullets--;
          delete this;
          return;
     }
}