示例#1
0
void MapHero::keyPressEvent(QKeyEvent *event){
    double cSize;
    switch(  event->key() ) {
    case Qt::Key_Right:
        moveBy(9, 0);
        heroImage = 3;
        if ( (cSize = collidingItems().size()) > 0){
            std::cout << cSize;
            moveBy(-9, 0);
            heroImage = 1;
        }
        break;
    case Qt::Key_Left:
        moveBy(-9, 0);
        heroImage = 1;
        if ( (collidingItems().size() > 0)){
            moveBy(9, 0);
            heroImage = 3;
        }
        break;
    case Qt::Key_Up:
        moveBy(0, -9);
        heroImage = 2;
        if ( (collidingItems().size() > 0)){
            moveBy(0, 9);
            heroImage = 0;
        }
        break;
    case Qt::Key_Down:
        moveBy(0, 9);
        heroImage = 0;
        if ( (collidingItems().size() > 0)){
            moveBy(0, -9);
            heroImage = 2;
        }
        break;
    case Qt::Key_P:
        pause->setModal(true);
        pause->exec();
        break;
    case Qt::Key_B:
        std::cout<<"b";
        //battle->setModal(true);
        battle->setModal(true);
        battle->startBattle('e',2,0,0,'h',2,1,1,'c',1,2,2);
        //battle->setGeometry(0,0,300,400);
        battle->exec();
        break;
    case Qt::Key_L:
        enemon->hide();
        break;
    default:
        break;
    }
        update();
}
示例#2
0
void Drum::keyPressEvent(QKeyEvent *event)
{
    if(event->key()==Qt::Key_J)
    {
        //刪除音符1
        QList<QGraphicsItem *> colliding_items = collidingItems();
        for (int i = 0, n = colliding_items.size(); i < n; ++i)
        {
            if (typeid(*(colliding_items[i])) == typeid(Bits))
            {
                scene()->removeItem(colliding_items[i]);
                delete colliding_items[i];
                game->score->increase();
                qDebug()<<"J";

                //播放消除音效
                if (sound1->state() == QMediaPlayer::PlayingState)
                {
                    sound1->setPosition(0);
                }
                else if (sound1->state() == QMediaPlayer::StoppedState)
                {
                    sound1->play();
                }
            }
        }
    }
    if(event->key()==Qt::Key_K)
    {
        qDebug()<<"K";
        //刪除音符2
        QList<QGraphicsItem *> colliding_items = collidingItems();
        for (int i = 0, n = colliding_items.size(); i < n; ++i)
        {
            if (typeid(*(colliding_items[i])) == typeid(Bits2))
            {
                scene()->removeItem(colliding_items[i]);
                delete colliding_items[i];
                game->score->increase();

                //播放消除音效
                if (sound2->state() == QMediaPlayer::PlayingState)
                {
                    sound2->setPosition(0);
                }
                else if (sound2->state() == QMediaPlayer::StoppedState)
                {
                    sound2->play();
                }
            }
        }
    }
}
示例#3
0
/*!
*   this method adds motion to the alienshipbullet
*/
void AlienShipBullet::advance(int phase)
{
    if(!phase) return;

    QList<QGraphicsItem*> listOfCollidingItems = collidingItems();

    // checks if there is a collision
    if (!listOfCollidingItems.isEmpty())
    {
        // if collision occurs with a space ship then alien ship bullet is removed from the scene
        if(listOfCollidingItems.first()->type() == ID_SPACESHIP)
        {
            this->scene()->removeItem(this);
        }
    }

    positionY+=directionY;

    // set the new position of the alien ship bullet
    setPos(positionX,positionY);

    // if position of the alien ship bullet is greater than 800 the mother ship bullet is removed from scene
    if (positionY > 1050)
    {
        this->scene()->removeItem(this);
    }
}
示例#4
0
void Hit2::check()
{
    // get a list of all the items currently colliding with this bullet
    QList<QGraphicsItem *> colliding_items = collidingItems();

    // if one of the colliding items is an Enemy, destroy both the bullet and the enemy
    for (int i = 0, n = colliding_items.size(); i < n; ++i){
        if (typeid(*(colliding_items[i])) == typeid(Taiko2)){
            // increase the score
            game->score->increase();

            // remove them from the scene (still on the heap)
            scene()->removeItem(colliding_items[i]);
            scene()->removeItem(this);

            // delete them from the heap to save memory
            delete colliding_items[i];
            delete this;

            // return (all code below refers to a non existint bullet)
            return;
        }
        else {
            scene()->removeItem(this);
            delete this;
        return;
        }
    }

}
示例#5
0
void Leaf_Gift::move() {

    // get a list of all the items currently colliding with this leaf gift
    QList<QGraphicsItem *> colliding_items = collidingItems();

    // if one of the colliding items is an player, destroy gift and increase the score
    for (int i = 0, n = colliding_items.size(); i < n; ++i) {
        if (typeid(*(colliding_items[i])) == typeid(ship_level_1)) {
            // qDebug()<<"colliding";

            // increase score
            game->score->increase(2);


            // remove them from the scene
            scene()->removeItem(this);
            delete this;

            return;
        }
    }

    setPos(x(),y()+10);
    // if the leaf is out of the screen
    if (pos().y() < 0) {
        scene()->removeItem(this);
        delete this;
    }
}
示例#6
0
void bullet::move(){
    //if bullet collides with enemy, destroy both
    QList<QGraphicsItem*> colliding_items=collidingItems();
    for(int i=0, n = colliding_items.size();i<n;i++){
        if(typeid(*(colliding_items[i])) == typeid(Enemy)){
            //increase the score
            game->score->increase();

            //remove them from the scene
            scene() ->removeItem(colliding_items[i]);
            scene() ->removeItem(this);

            delete colliding_items[i];
            delete this;
            return;
        }
    }

    setPos(x(),y());
    if(pos().y() + rect().height()<0){
        scene()->removeItem(this);
        delete this;
     //   qDebug()<<"de";
    }
}
示例#7
0
                    void bullet::move(){
                        //kill (Qclassiin item bolgon ooriin gesen collide gesen member functiontai baidag
                            QList<QGraphicsItem *>colliding_items=collidingItems();
                                for(int i=0, n=colliding_items.size(); i<n; ++i){
                                        if(typeid(Drum) == typeid(*(colliding_items[i]))){
                                                    //increase the score (game-iin objectruu nevtreh heregtei yagaad gevel game objected bidnii increase hiih geed bgaa score maan bgaa bolhoor)
                                                                togloom->score->increase();

                                                                            //sum bolon drum hoyriig ustgana
                                                                                        scene()->removeItem(colliding_items[i]);
                                                                                                    scene()->removeItem(this);
                                                                                                                delete colliding_items[i];
                                                                                                                            delete this;
                                                                                                                                        return;
                                                                                                                                                    //end yaagaad return bga ve gevel ende sum ed naraa ustgachaad yaj dahiad sumaa gargahiin tiimees return hiij dooshoogooh functionluu ochij chadaj bnaa gesen vg!
                                                                                                                                                            }


                                                                                                                                                                }


                                                                                                                                                                    //move bullet to ???
                                                                                                                                                                        setPos(x()+5,y());
                                                                                                                                                                            //sum n waste memory hiigeed bga bolhoor  sumiig delgetsees garanguut n ustgadag baiy
                                                                                                                                                                                if(pos().x()-10>180){
                                                                                                                                                                                        scene()->removeItem(this);
                                                                                                                                                                                                delete this;
                                                                                                                                                                                                    }

                                                                                                                                                                                                    }
void Bullet::move() {

    // check whether the bullet hit the enemy, if so destroy both
    QList<QGraphicsItem*> colliding_item = collidingItems();
    for(size_t i = 0, n = colliding_item.size(); i<n; ++i) {
        if(typeid(*(colliding_item[i])) == typeid(Enemy) || typeid(*(colliding_item[i])) == typeid(Doge)) {

            // remove item
            scene()->removeItem(colliding_item[i]);
            scene()->removeItem(this);

            // reallocate memory
            delete colliding_item[i];
            delete this;

            return;
        }
    }

    setPos(x()+10, y());
    if (pos().x() > 1000) {
        scene()->removeItem(this);
        delete this;
        qDebug()<<"deleted";
    }
}
示例#9
0
void MapEnemy::collisionEvent(){
    if ( (collidingItems().size() > 0))
    {
        this->hide();
    }
    update();
}
示例#10
0
文件: bird.cpp 项目: GLDsuh-a/qt-1
bool bird::checkCollide()
{
    if (!collidingItems().isEmpty())
        return true;
    else
        return false;
}
示例#11
0
/*!
    this method is called whenever the alienmothership needs to be drawn
*/
void AlienMotherShip::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    // can traverse to examine what collided with alienmothership
    QList<QGraphicsItem*> listOfCollidingItems = collidingItems();

    // paints the alienmothership image
    painter->drawPixmap(xPosition, yPosition, shipWidth, shipHeight, shipsImage);

    // checks to see if collisions occurs
    if (!listOfCollidingItems.isEmpty())
    {
        // if collision occurs with spaceshipmissile then decrements aliemMotherShipHit
        if(listOfCollidingItems.first()->type() == ID_SPACESHIPMISSILE)
        {
            shipHit--;
        }
    }

    // if alienMotherShipHit is 0 ship destoryed then changes alien motherships image and has ship explosion FX
    if (shipHit == 0)
    {
        shipsImage.load(":fire.png");
        painter->drawPixmap(xPosition, yPosition, shipWidth, shipHeight, shipsImage);

        QSound *shipExplosionFX = new QSound("explosion_2.wav", 0);
        shipExplosionFX->setLoops(1);
        shipExplosionFX->play();

        update();
    }
}
示例#12
0
void Bullet::move(){
    //if bullet collides with enemy, destroy both
    QList<QGraphicsItem *> colliding_items = collidingItems();
    for (int i = 0, n = colliding_items.size(); i < n; ++i){
        if (typeid(*(colliding_items[i])) == typeid(Enemy)){
            //increase the score
            game->score->increase();
            //remove from scene both
            scene()->removeItem(colliding_items[i]);
            scene()->removeItem(this);
            //delete both from heap
            delete colliding_items[i];
            delete this;

            //because all the code below referes to unexisting bullet
            return;
          }
      }


    //behaviour for each bullet to trigger every timeout
    setPos(x(), y()-10);
    if (pos().y() + rect().height() < 0){
        timer->stop();
        scene()->removeItem(this);
        this->deleteLater();
      }
}
示例#13
0
void AbstractClipItem::resizeEnd(int posx, bool /*emitChange*/)
{
    GenTime durationDiff = GenTime(posx, m_fps) - endPos();
    if (durationDiff == GenTime()) return;
    if (cropDuration() + durationDiff <= GenTime()) {
        durationDiff = GenTime() - (cropDuration() - GenTime(3, m_fps));
    }

    m_info.cropDuration += durationDiff;
    m_info.endPos += durationDiff;

    setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
    if (durationDiff > GenTime()) {
        QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
        bool fixItem = false;
        for (int i = 0; i < collisionList.size(); ++i) {
            if (!collisionList.at(i)->isEnabled()) continue;
            QGraphicsItem *item = collisionList.at(i);
            if (item->type() == type() && item->pos().x() > pos().x()) {
                GenTime diff = static_cast<AbstractClipItem*>(item)->startPos() - startPos();
                if (fixItem == false || diff < m_info.cropDuration) {
                    fixItem = true;
                    m_info.cropDuration = diff;
                }
            }
        }
        if (fixItem) setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
    }
}
示例#14
0
void Bullet::move()
{
    //if bullet hits enemy, delete both
    QList<QGraphicsItem *> colliding_items = collidingItems();
    for(QList<QGraphicsItem *>::iterator it = colliding_items.begin();
            it != colliding_items.end(); ++it) {
        if(typeid(*(*it)) == typeid(Enemy)) {
            //increase the score
            game->score->increase();
            //remove both
            scene()->removeItem(*it);
            scene()->removeItem(this);
            delete *it;
            *it = NULL;
            delete this;
            //this = NULL;
            return;
        }
    }

    this->setPos(this->x(), this->y() - 10);

    if(pos().y() + 10 < 0) {
        scene()->removeItem(this);
        delete this;
        qDebug() << "bullet deleted" << endl;
    }
}
示例#15
0
/**@brief moves the attack object to the right of the screen against oncoming enemies
 * also checks to see if it collides with an enemy and will remove both from the scene
*/
void Wrath::move() {
    //first check if the attack is colliding with an enemy
    //if it is colliding, we destroy both the attack and the enemy
    QList<QGraphicsItem*> colliding_items = collidingItems();
    for (auto x : colliding_items) {
        if (typeid(*(x)) == typeid(Enemy)) {
            //increment score
            game->increment_player_score();
            game->level->player_kills_text->setPlainText(QString("Enemies killed: ") + QString::number(game->get_player_kills()));

            //remove both
            scene()->removeItem(x);
            scene()->removeItem(this);

            delete x;
            delete this;
            return;
        }
    }

    //move bullet to the right
    setPos(x()+5,y());

    //check to see if object is off screen
    if (x() > 1024) {
        scene()->removeItem(this);
        delete this;
    }
}
示例#16
0
void Akseli::sijoitaKiskolle( RataKisko *kiskolle, qreal sijainti, RaiteenPaa::Suunta suunta)
{


    kiskolla_ = kiskolle;
    sijaintiKiskolla_ = sijainti;
    suuntaKiskolla_ = suunta;

    if(!kiskolle)
    {
        // Ei kiskolla !
        setPos(0,0);
        setVisible(false);
        return;
    }

    laskeSijainti();

    // Yhteenkytkeminen, jos osuu toiseen akseliin
    QList<QGraphicsItem*> lista = collidingItems();

    foreach( QGraphicsItem* item, lista)
    {
        Akseli* toinen = qgraphicsitem_cast<Akseli*>(item);
        if( toinen && toinen != toinenAkseli_ &&
                (toinenAkseli_ == 0 || toinenAkseli_ != toinen->kytkettyAkseli_))
        {
            // Liitetään yhteen
            kytkettyAkseli_ = toinen;
            toinen->kytkettyAkseli_=this;
            update( boundingRect());
            return;
        }
    }
示例#17
0
void AbstractClipItem::resizeEnd(int posx, bool /*emitChange*/)
{
    GenTime durationDiff = GenTime(posx, m_fps) - endPos();
    if (durationDiff == GenTime()) return;
    if (cropDuration() + durationDiff <= GenTime()) {
        durationDiff = GenTime() - (cropDuration() - GenTime(3, m_fps));
    }

    m_info.cropDuration += durationDiff;
    m_info.endPos += durationDiff;

    setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
    if (durationDiff > GenTime()) {
        QList <QGraphicsItem *> collisionList = collidingItems(Qt::IntersectsItemBoundingRect);
        bool fixItem = false;
        for (int i = 0; i < collisionList.size(); ++i) {
            if (!collisionList.at(i)->isEnabled()) continue;
            QGraphicsItem *item = collisionList.at(i);
            if (item->type() == type() && item->pos().x() > pos().x()) {
                //kDebug() << "/////////  COLLISION DETECTED!!!!!!!!!";
                //kDebug() << "/////////  CURRENT: " << startPos().frames(25) << "x" << endPos().frames(25) << ", RECT: " << rect() << "-" << pos();
                //kDebug() << "/////////  COLLISION: " << ((AbstractClipItem *)item)->startPos().frames(25) << "x" << ((AbstractClipItem *)item)->endPos().frames(25) << ", RECT: " << ((AbstractClipItem *)item)->rect() << "-" << item->pos();
                GenTime diff = ((AbstractClipItem *)item)->startPos() - startPos();
                if (fixItem == false || diff < m_info.cropDuration) {
                    fixItem = true;
                    m_info.cropDuration = diff;
                }
            }
        }
        if (fixItem) setRect(0, 0, cropDuration().frames(m_fps) - 0.02, rect().height());
    }
}
示例#18
0
void Bullet::move()
{
    // if bullet collides with enemy, destroy both
    QList<QGraphicsItem *> colliding_items = collidingItems();
    for (int i = 0, n = colliding_items.size(); i < n; ++i){
        if (typeid(*(colliding_items[i])) == typeid(Enemy)){
            //increase the score
            game->score->increase();

            // remove them both
            scene()->removeItem(colliding_items[i]);
            scene()->removeItem(this);
            // delete them both
            delete colliding_items[i];
            delete this;
            return;
        }
    }


    //move the bullet up
    setPos(x(), y()-10);
    if(pos().y() < 0){
        scene()->removeItem(this);
        delete this;
    }
}
void Bullet::move()
{
    // if bullet collides with enemy, destroy both
    QList<QGraphicsItem *> colliding_items = collidingItems();

    for (int var = 0, n = colliding_items.size(); var < n; ++var)
    {
        if( typeid(*(colliding_items[var])) == typeid(Enemy) )
        {
            // increase the score
            game->score->increase();

            // remove them from the scene
            scene()->removeItem(colliding_items[var]);
            scene()->removeItem(this);

            // delete them from the heap to save memory
            delete colliding_items[var];
            delete this;

            return;
        }
    }

    // move bullet up
    setPos(x(), y()-10);

    if( pos().y() + 40 < 0 )
    {
        scene()->removeItem(this);
        delete this;
    }
}
示例#20
0
/*!
    this method adds motion to the shipsbullet
*/
void ShipBullet::advance(int phase)
{
    if(!phase) return;

    QList<QGraphicsItem*> listOfCollidingItems = collidingItems();

    // checks if there is a collision
    if (!listOfCollidingItems.isEmpty())
    {
        // if collision occurs with a block then bullet bounces back
        if(listOfCollidingItems.first()->type() == BLOCKID)
        {
            directionY = 4;
        }

        // else if collision occurs with a spaceship then bullet is removed from scene
        else if (listOfCollidingItems.first()->type() == ID_SPACESHIP)
        {
            positionX += 700;
            this->scene()->removeItem(this);
        }

        // else if collision occurs with alienspaceship then bullet is removed from scene
        else if (listOfCollidingItems.first()->type() == ID_ALIENSPACESHIP)
        {
            positionX += 700;
            this->scene()->removeItem(this);
        }
    }
    positionY+=directionY;

    // set the new position of the ships bullet
    setPos(positionX+385,positionY);
}
示例#21
0
void PMBullet::move()
{
    QList<QGraphicsItem *> colliding_enemies=collidingItems();
    for(size_t i=0, n=colliding_enemies.size();i<n;i++){
        if((typeid(*(colliding_enemies[i]))==typeid(Enemy))||typeid(*(colliding_enemies[i]))==typeid(AttackableEnemy)){
            if(typeid(*(colliding_enemies[i]))==typeid(Enemy)){
                dynamic_cast<Enemy*>(colliding_enemies[i])->IsSlowedBy(SlowPower);
                dynamic_cast<Enemy*>(colliding_enemies[i])->IsHitBy(AttackPower);
            }
            else if(typeid(*(colliding_enemies[i]))==typeid(AttackableEnemy)){
                dynamic_cast<AttackableEnemy*>(colliding_enemies[i])->IsSlowedBy(SlowPower);
                dynamic_cast<AttackableEnemy*>(colliding_enemies[i])->IsHitBy(AttackPower);
            }
            playSound("Hit");               //sound for hit
            game->scene->removeItem(this);
            QTimer::singleShot(3000,this,SLOT(callDestructor()));
            return;
        }
    }
    double theta = rotation();                      //set theta

    double dy = STEP_SIZE*qSin(qDegreesToRadians(theta));
    double dx = STEP_SIZE*qCos(qDegreesToRadians(theta));

    setPos(x()+dx,y()+dy);
}
示例#22
0
/*!
  In \a phase 0, increment the missile's age and return if
  the missile has expired. If not, move the missile based
  on its current position and velocity. Then get the its
  list of colliding sprites and traverse the list. When a
  rock is found in the list, mark both the rock and the
  missile dead and return.

  In phase 1, if the missile is marked dead, delete it;
  \internal
 */
void KMissile::advance(int phase)
{
    if (phase == 0) {
	if (dying())
	    markDead();
	else
	    incrementAge();
	if (isDead())
	    return;
	KSprite::advance(phase);
        QList<QGraphicsItem*> hits = collidingItems();
        QList<QGraphicsItem*>::iterator i;
        for (i=hits.begin(); i!=hits.end(); ++i) {
	    if ((*i)->type() > ID_Base) {
		KSprite* sprite = (KSprite*)(*i);
		if (sprite->isRock()) {
		    sprite->markDead();
		    markDead();
		    break;
		}
	    }
        }
    }
    else if (isDead() || dying())
	delete this;
}
示例#23
0
void Bullet::move(){
    // get a list of all the items currently colliding with this bullet
    QList<QGraphicsItem *> colliding_items = collidingItems();

    // if one of the colliding items is an Enemy, destroy both the bullet and the enemy
    for (int i = 0, n = colliding_items.size(); i < n; ++i){
        if (typeid(*(colliding_items[i])) == typeid(Enemy)){
            // increase the score
            game->score->increase();

            // remove them from the scene (still on the heap)
            scene()->removeItem(colliding_items[i]);
            scene()->removeItem(this);

            // delete them from the heap to save memory
            delete colliding_items[i];
            delete this;

            // return (all code below refers to a non existint bullet)
            return;
        }
    }

    // if there was no collision with an Enemy, move the bullet forward
    setPos(x(),y()-10);
    // if the bullet is off the screen, destroy it
    if (pos().y()< 0){
        scene()->removeItem(this);
        delete this;
    }
}
示例#24
0
//collision
void Zombie::collision(){
    QList<QGraphicsItem *> colliding = collidingItems();
    for(int i=0, n=colliding.size();i<n;++i){

        //collision between zombie and player
        if(typeid(*(colliding[i])) == typeid(Player)){
            //stopping the game
            gameTimer->stop();
            moveTimer->stop();

            //deleting
            delete gameTimer;
            delete moveTimer;
            delete player1;
            delete game;
            delete score;
            delete scene();

            //restarting the game
            qApp->closeAllWindows();
            QStringList args = QApplication::arguments();
            args.removeFirst();
            QCoreApplication::quit();
            QProcess::startDetached(QApplication::applicationFilePath(), args);
        }
    }
}
示例#25
0
void Bullet::move()
{
    //impact!!
    QList<QGraphicsItem *> touchedItems = collidingItems();

    for (auto enemy : touchedItems)
    {
        if (typeid(*enemy) == typeid(Enemy))
        {
            game->score->increase();
            //clean up
            scene()->removeItem(enemy);
            scene()->removeItem(this);
            delete enemy;
            delete this;
            return;
        }
    }

    //moving
    setPos(x(), y()-10);
    if (pos().y() < 0)
    {
        scene()->removeItem(this);
        delete this;
        qDebug() << "Bullet out of scene. Deleted.";
    }
}
示例#26
0
void MachineItem::mouseReleaseEvent ( QGraphicsSceneMouseEvent * event )
{

    if (event->button() == Qt::LeftButton) {
        setColor(Qt::cyan);
        // force my box to snap to grid, just truncate the pixel number and
        // snap to the next lowest grid value

        if (fmod(_location.x(),_gridSpace) >_gridSpace/2)
            _location.setX( ( static_cast<int>(_location.x()+_gridSpace) / _gridSpace) * _gridSpace );
        else
            _location.setX( ( static_cast<int>(_location.x()) / _gridSpace) * _gridSpace );
        if (fmod(_location.y(),_gridSpace) >_gridSpace/2)
            _location.setY( ( static_cast<int>(_location.y()+_gridSpace) / _gridSpace) * _gridSpace );
        else
            _location.setY( ( static_cast<int>(_location.y()) / _gridSpace) * _gridSpace );


        foreach (QGraphicsItem *item, collidingItems()) {

                if (item->type() ==GroupItem::Type){

                    this->setPos(mapToItem(item,0,0));
                        setParentItem(item);

                } else {
                    this->setPos(mapToScene(0,0));
                    this->setParentItem(0);
                }
            }

        event->setAccepted(true);// tell the base class we are handling this event

    }
示例#27
0
bool rect1::soloAbajo(){
    QList<QGraphicsItem *> collitems=collidingItems();
    for(int cont=0; cont<collitems.size(); cont++){
        if(collitems[cont]->pos().y()>pos().y())
            return false;
    }
    return true;
}
示例#28
0
void MyItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_UNUSED(option);
    Q_UNUSED(widget);

    auto isCollided = !collidingItems().isEmpty();
    painter->setBrush(isCollided ? Qt::red : color);
    painter->drawEllipse(0, 0, 20, 20);
}
示例#29
0
//проверка на соударение объектов
QGraphicsItem * MvScene::itemCollidesWith(QGraphicsItem * item)
{
	QList<QGraphicsItem *> collisions = collidingItems(item);
	foreach (QGraphicsItem * it, collisions) {
        	if (it == item)
        	     continue;
		return it;
 	}
	return NULL;
}
示例#30
0
void Shuttle::itemCollisionHandling(){

    Item* Itemgetted;
    Itemgetted = itemSpawningLogicLocal->getItem();

     for(int i = 0; i < collidingItems().size(); i++){
        if(collidingItems()[i]->data(classTypeKey) == item){
            if(Itemgetted->ItemType == 0) {
                setShotStrategy(new ShotDouble(this));
            }

            else if(Itemgetted->ItemType == 1) {
                // 0.5 because function is called twice
                // when collision of shuttle with life item occurs
                life = life + 0.5;
            }
        }
    }
}