Пример #1
0
void Ball::advance(int phase)
{
    if (!phase)
        return;
    else if (collidesWithItem(gun1))
    {
        emit hit(x(), y(), 1, numOfDamage);
        scene()->removeItem(this);
        delete this;
    }
    else if (collidesWithItem(gun2))
    {
        emit hit(x(), y(), 2, numOfDamage);
        scene()->removeItem(this);
        delete this;
    }
    else if (y() > horizon - 5)
    {
        emit explosion(x(), radius, numOfDamage);
        scene()->removeItem(this);
        delete this;
    }
    else
    {
        double newX = t * vX + resis * t * t/2;
        double newY = t * vY - t * t;
        newY = newY * (- 1);
        setPos(startX + newX, startY + newY);
        t = t + 0.3;

        rotate(1);


    }
}
Пример #2
0
Cell::CellState Cell::shrinkOrGrow()
{
    int dishSize = qRound(parentItem()->boundingRect().width());
    int neighbours = 0;
    QListIterator<QGraphicsItem*> i(parentItem()->childItems());
    while (i.hasNext()) {
        QGraphicsItem *item = i.next();
        if (item != this && collidesWithItem(item))
            ++neighbours;
    }
    if (!neighbours || m_size > dishSize / 3)
        m_size *= randomReal(); // shrink - lonely or too big
    else if (neighbours < 4) // grow - happy
        m_size *= ((5 - neighbours) * randomReal());
    else // shrink - too crowded
        m_size *= ((1.0 / neighbours) + randomReal());

    QPainterPath path;
    qreal x = m_size * std::cos(AQP::radiansFromDegrees(1));
    qreal y = m_size * std::sin(AQP::radiansFromDegrees(1));
    path.moveTo(x, y);
    for (int angle = 1; angle < 360; ++angle) {
        qreal factor = m_size + ((m_size / 3) * (randomReal() - 0.5));
        x = factor * std::cos(AQP::radiansFromDegrees(angle));
        y = factor * std::sin(AQP::radiansFromDegrees(angle));
        path.lineTo(x, y);
    }
    path.closeSubpath();
    m_path = path;

    prepareGeometryChange();
    if (m_size < 5.0 && (qrand() % 20 == 0))
        return Die; // small ones randomly die
    return Live;
}
bool  QGraphicsEllipseItem_QtDShell::__override_collidesWithItem(const QGraphicsItem*  other0, int  mode1, bool static_call) const
{
    if (static_call) {
        return QGraphicsItem::collidesWithItem((const QGraphicsItem* )other0, (Qt::ItemSelectionMode )mode1);
    } else {
        return collidesWithItem((const QGraphicsItem* )other0, (Qt::ItemSelectionMode )mode1);
    }
}
Пример #4
0
bool Temple::collide(TreasureHunter *th){
  //if(th->getX()+th->getWidth()>=x && th->getX()<=x+width && th->getY()<=y+height && th->getY()+th->getHeight()>=y){
  if(collidesWithItem(th)){
    full = true;
    return true;
  }
  //std::cout << th->getX() << " " << th->getY() << " " << x << " " << y << std::endl;
  return false;
}
Пример #5
0
/*
    \reimp
*/
void QGraphicsVideoItem::paint(
        QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
    Q_D(QGraphicsVideoItem);

    Q_UNUSED(option);
    Q_UNUSED(widget);

    if (widget)
        d->watcher->setActiveWindow(widget->window());

    if (d->surface && d->rendererControl && d->updatePaintDevice) {
        d->updatePaintDevice = false;

#ifdef ENABLE_OVERLAY
        if (widget)
            d->rendererControl->setProperty("winId", qulonglong(widget->winId()));
#endif

#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_1_CL) && !defined(QT_OPENGL_ES_1)
        if (widget)
            connect(widget, SIGNAL(destroyed()), d->surface, SLOT(viewportDestroyed()));

        d->surface->setGLContext(const_cast<QGLContext *>(QGLContext::currentContext()));
#endif
        if (d->rendererControl->surface() != d->surface)
            d->rendererControl->setSurface(d->surface);
    }


    //overlay doesn't work reliably

    //check if the item is obscured:
#ifdef ENABLE_OVERLAY
    if (!isObscured()) {
        bool obscured = false;

        if (scene()) {
            foreach (QGraphicsItem *item,
                     scene()->items(mapToScene(boundingRect()), Qt::IntersectsItemBoundingRect) ) {
                if (item->flags() & QGraphicsItem::ItemHasNoContents)
                    continue;

                if (item == this)
                    break;

                if (collidesWithItem(item)) {
                    obscured = true;
                    break;
                }
            }
        }

        d->rendererControl->setProperty("overlayEnabled", !obscured);
    }
Пример #6
0
void Edge::updatePosition()
{
    QLineF line(mapFromItem(source, 0, 0), mapFromItem(destination, 0, 0));
    this->setLine(line);
    textV->setPos((mapFromItem(source, 0, 0).x()+mapFromItem(destination, 0, 0).x())/2 + 2, (mapFromItem(source, 0, 0).y()+mapFromItem(destination, 0, 0).y())/2 + 10);
    //qDebug() << textV->pos();
    if (collidesWithItem(textV, Qt::IntersectsItemShape))
    {
        //qDebug() << "collission";
        //textV->setPos((mapFromItem(source, 0, 0).x()+mapFromItem(destination, 0, 0).x())/2 + 2, (mapFromItem(source, 0, 0).y()+mapFromItem(destination, 0, 0).y())/2 -10);
    }
    //qDebug() << textV->pos();
}
Пример #7
0
void BonusBall::moveMe() //движение
{
    if (!painted_ || !showed_) return;
    bool crossBorder = !collidesWithItem(field_->circle(),Qt::ContainsItemShape);//если перестаёт пересекаться с кругом смерти
    bool crossPlatform[2];//если пересекается с одной из вагонеток
    //bool crossBall = collidesWithItem(field_->ball());
    for (int i=0; i<2; i++)//2 вагонетки
    {
        crossPlatform[i] = collidesWithItem(field_->circle()->platform(i));//пересекается ли с iтой вагонеткой
    }
    if (crossBorder)//если каснулся вагонеток, или перестал касаться круга смерти
    {
        double arc;//угол прямой к оси X от которой отражается шарик
        //угол касательной к окружности, в точке, где шарик перестаёт пересекаться с кругом смерти
        arc=acos(point_.y()/(sqrt(point_.x()*point_.x()+point_.y()*point_.y())));
        //угол к оси X прямой, от которой отражается шарик не больше 90
        arc=(arc>PI/2?PI-arc:arc);
        //изменение вектора движения шарика
        mirror(arc);
    }
    if (crossPlatform[0]||crossPlatform[1])
    {
        int gamer=-1;
        if(crossPlatform[0])
            gamer=1;
        else
            gamer=0;

        field_->setBonusTime(bonusType_,gamer);
        hide();
        return;
    }

    //изменение координат шарика в соответствии с вектором движения
    point_=QPointF(point_.x()+vx_,point_.y()+vy_);
}
Пример #8
0
void Texto::focusOutEvent(QFocusEvent *event)
{
    int i, tam, erro=0;

    QTextCursor cursor = textCursor();

    tam = listaTextos.size();
    for (i=0; i<tam; i++)
    {
        //if (listaTextos.at(i)->parentItem()->Type == Atributo::Type)) // não sei pq isso não funciona, se funcionasse poderíamos remover essa onda de tipoOwner
        if ((listaTextos.at(i) != this) &&
           (listaTextos.at(i)->document()->toPlainText().remove("\n") == cursor.document()->toPlainText().remove("\n")) &&
           (tipoOwner == 1))
        {
            erro = 1;
            break;
        }
    }

    if (erro)
    {
        QMessageBox a;
        a.setText("Erro! Ja existe atributo com mesmo nome.");
        a.exec();
        this->setFocus();
    }
    else
    {
        // o ideal seria aqui gerar um mouseReleaseEvent()
        if (collidesWithItem(this->parentItem(), Qt::ContainsItemShape) == false)
        {
            if ((this->tipoOwner != 1) && (this->tipoOwner != 2)) // não é atributo ou atributo_identificador
            {
                setPos(-(this->boundingRect().width() / 2), -(this->boundingRect().height() / 2));
            }
        }

        cursor.clearSelection();
        setTextCursor(cursor);
        setTextInteractionFlags(Qt::NoTextInteraction);
    }

    emit lostFocus(this);
    QGraphicsTextItem::focusOutEvent(event);
}
Пример #9
0
void Texto::mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
{
    if (( !getGenEspAtiva() ) && ( !getTabelaAtiva() ))
    {
        setTextInteractionFlags(Qt::TextEditorInteraction);
        this->setFocus(); // faz já começar a editar
    }

    if (collidesWithItem(this->parentItem(), Qt::ContainsItemShape) == false)
    {
        if ((this->tipoOwner != 1) && (this->tipoOwner != 2)) // não é atributo ou atributo_identificador
        {
            setPos(-(this->boundingRect().width() / 2), -(this->boundingRect().height() / 2));
        }
    }

    QGraphicsTextItem::mouseReleaseEvent(event);
}
Пример #10
0
void Object::gameLoop()
{
    if(_current_cooldown > 0)
    {
        _one_second += TICK;
        if(_one_second >= 1000)
        {
            _one_second -= 1000;
            --_current_cooldown;
        }

        _width = _height = 60;

        if(_frame_explode <= 15)
        {
            ++_frame_explode;

            _width = _height = 60;
        }

        _mini_map_view->setVisible(false);
    }
    else
    {
        _mini_map_view->setVisible(true);

        _step = (_step + 1) % _tileset.size();

        foreach(ITank* tank, _tanks)
        {
            if(tank->getStatus() != DEAD && collidesWithItem(tank))
            {
                Effect* effect_tank = new Effect(tank, tank, 0, 0, _bonus, 0, false, false, _time, _effect_animation);
                tank->addEffect(effect_tank);

                _current_cooldown = _cooldown;
                _frame_explode = 0;

                _sound->playSound2D(tank->pos(),tank->principalReference()->pos(), Configuration::volumeSound());
            }
        }
    }
}
Пример #11
0
/** Function that returns true when the Alien intersects with a Thing. If it does, it decrements the Thing's health by 10 while decrementing its own by 1
  @param rocket the Thing that the Alien is checking if its intersecting
*/
bool Alien::collidesWith(Thing* rocket){
  bool collide = collidesWithItem(rocket, Qt::IntersectsItemShape);

  // colliding with something that has the same pic (and therefore same classification as Alien) is the same as no collission
  if (rocket->getPic() == pic_)
    return false;
    
  if (collide && collisionCounts)
  {
    rocket->decrementHealth(5);
    decrementHealth(1);
    //collisionCounts = false;
    if (rocket->dead) // if rocket's health is 0, flags offScreen
      rocket->offScreen = true;
    return true;
  }
  else
    return false;
}
Пример #12
0
void Enemy::move()
{
    //check if enemy collides with player
    if(collidesWithItem(scene()->focusItem()))
    {
        emit collidedWithPlayer();
        //delete scene()->focusItem(); //get error when collided
        return;
    }

    setPos(pos().x(), pos().y() + oneMove);

    //check if enemy move over the scene
    if(pos().y() + rect().height() >= 600)
    {
        destroyEnemy();
        emit enemyPassTheDefense();
    }
}
Пример #13
0
bool DhQGraphicsItemGroup::DvhcollidesWithItem(const QGraphicsItem* x1, long x2) const {
  return collidesWithItem(x1, (Qt::ItemSelectionMode)x2);
}
Пример #14
0
bool DhQGraphicsItemGroup::DvhcollidesWithItem(const QGraphicsItem* x1) const {
  return collidesWithItem(x1);
}
Пример #15
0
bool DhQGraphicsEllipseItem::DvhcollidesWithItem(const QGraphicsItem* x1) const {
  return collidesWithItem(x1);
}
Пример #16
0
void Car::move () {
    //Updating variables that hold past states
	thirdToLastVT = secondToLastVT;
	secondToLastVT = lastVT;
	lastVT = vT;
	thirdToLastAngleDeg = secondToLastAngleDeg;
	secondToLastAngleDeg = lastAngleDeg;
	lastAngleDeg = angleDeg;
	thirdToLastX = secondToLastX;
	thirdToLastY = secondToLastY;
	secondToLastX = lastX;
	secondToLastY = lastY;
	lastX = x; lastY = y;
	
    //Updates speed based on controls
	if (control[0]) {
		if (vT < 0) vT += BRAKE_MULTI*PIX_PER_SEC_SQR_CAR*TIMER_INTERVAL/1000.0;
		else if (vT < PIX_PER_SEC_MAX_CAR) vT += PIX_PER_SEC_SQR_CAR*TIMER_INTERVAL/1000.0;
	} else if (control[2]) {
		if (vT > 0) vT -= BRAKE_MULTI*PIX_PER_SEC_SQR_CAR*TIMER_INTERVAL/1000.0;
		else if (vT > -PIX_PER_SEC_MAX_CAR*REVERSE_MULTI) vT -= REVERSE_MULTI*PIX_PER_SEC_SQR_CAR*TIMER_INTERVAL/1000.0;
	} else {
		if (vT > PIX_PER_SEC_SQR_CAR*TIMER_INTERVAL/1000.0) vT -= FRICT_MULTI*PIX_PER_SEC_SQR_CAR*TIMER_INTERVAL/1000.0;
		else if (vT < -PIX_PER_SEC_SQR_CAR*TIMER_INTERVAL/1000.0) vT += FRICT_MULTI*PIX_PER_SEC_SQR_CAR*TIMER_INTERVAL/1000.0;
		else vT = 0;
	}
	
	
	//Updates rotation based on controls
	if ((control[1] != control [3]) && vT != 0) {
		if (control[1]) {
			angleDeg -= (ROT_SPEED_PER_SEC*TIMER_INTERVAL/1000.0);
		} else {
			angleDeg += (ROT_SPEED_PER_SEC*TIMER_INTERVAL/1000.0);
		}
		
		setRotation(angleDeg);
		
	}
	
	
	//Updates velocity vector based on speed and angle
	vX = vT * cos(angleDeg*3.14159/180.0);
	vY = vT * sin(angleDeg*3.14159/180.0);
	
	//Updating position
	x += vX*TIMER_INTERVAL/1000.0; y += vY*TIMER_INTERVAL/1000.0;
	setPos(x,y);
	
    //Managing collision with track (Rollback three timer intervals)
	if (collidesWithItem(trackItem)) {
		x = thirdToLastX; y = thirdToLastY;
		angleDeg = thirdToLastAngleDeg;
		vT = -thirdToLastVT*BOUNCE_MULTI;
		vX = vT * cos(angleDeg*3.14159/180.0);
		vY = vT * sin(angleDeg*3.14159/180.0);
		x += vX*TIMER_INTERVAL/1000.0; y += vY*TIMER_INTERVAL/1000.0;
		setPos(x,y);
		lives--;
	}
	
    //Tracks car and counts laps
	relX = x-TRACK_CENTER_X;
	relY = y-TRACK_CENTER_Y;
	if(posTrack==3 && abs(relX)<MAX_TICKER_MOVE && relY>0) {
		posTrack = 0;
		lap++;
	} else if(posTrack==0 && abs(relY)<MAX_TICKER_MOVE && relX>0) {
		posTrack = 1;
	} else if(posTrack==1 && abs(relX)<MAX_TICKER_MOVE && relY<0) {
		posTrack = 2;
	} else if(posTrack==2 && abs(relY)<MAX_TICKER_MOVE && relX<0) {
		posTrack = 3;
	}
	
	
	
}