Пример #1
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();
    }
}
Пример #2
0
/*!
    this method fires the alienmothership bullets
*/
void AlienMotherShip::fire()
{
    shipBullet = new MotherShipBullet ();
    shipBullet->setBulletPosition(xPosition - 145, yPosition + 280);
    this->scene()->addItem(shipBullet);

    QSound *alienShipFireFX = new QSound("laser_1.wav", 0);
    alienShipFireFX->setLoops(1);
    alienShipFireFX->play();
}
Пример #3
0
/* Constructeur de la classe MainWindow */
MainWindow::MainWindow(QString hote, QWidget * parent) : QMainWindow(parent)
{

    connection(hote);

    baseGravity = 1;
    largeur = 900;
    hauteur = 600;
    tailleC = 20;
    largeurG = largeur/tailleC;
    hauteurG = hauteur/tailleC;
    gravity = 0;
    grilleBrique.resize(largeurG);
    grilleBonus.resize(largeurG);
    controleur = new ToucheClavier();
    personnages.resize(2);
    end = 0;
    grabKeyboard();

    for(int i = 0; i<largeurG; i++){
        grilleBrique[i].resize(hauteurG);
        grilleBonus[i].resize(hauteurG);
    }

    scene = new QGraphicsScene(0, 0, largeur, hauteur, this);
    view = new QGraphicsView(scene, this);


    scene->setBackgroundBrush(QBrush(QPixmap("../Game1/ressource/fond_colline.jpg")));

    timer.start(5, this);
    view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    view->setFixedWidth(largeur);
    view->setFixedHeight(hauteur);
    view->show();

    this->setFixedSize(largeur, hauteur);

    QSound *musiquePrincipal = new QSound("../Game1/ressource/sons/fond.wav");
    musiquePrincipal->setLoops(-1);
    musiquePrincipal->play();
}