コード例 #1
0
ファイル: Game.cpp プロジェクト: dmonopoly/survive-space-game
// Turns state to GAME_ON and makes objects fall
// Called from states of MAIN_MENU
void Game::startGame() {
	state = GAME_ON;
	setFallingObjectsOn(true); // make objects fall

	// Starts a timer and returns a timer identifier, or returns zero if it could not start a timer.
	mainTimerId = startTimer(mainTimerLevel);

	// Start the music!
	music.play();
	enableship.play(); // ship enabling sound
}
コード例 #2
0
ファイル: Game.cpp プロジェクト: dmonopoly/survive-space-game
// Detects collisions and sets collision flags
void Game::detectCollisions() {
	if (invCount == 0) { // invincible count; when zero, player is not invincible; used when player just died and has some invincibility
		bool cont = true; // "shouldContinue"

		// Items
		for (unsigned int i=0; i < items.size(); i++) {
			if (!items[i]->isObtained() && player->collidedWith(*items[i])) {
				respondToItem(items[i]);
				cont = false;
				break;
			}
		}

		// Asteroids
		if (cont) { // don't check these if already collided
			for (unsigned int i=0; i < asteroids.size(); i++) {
				if (player->collidedWith(*asteroids[i])) {
					justLostLife = true;
					cont = false;
					crash.play(); // crash sound!
					break;
				}
			}
		}

		// Attackers
		if (cont) { // don't check these if already collided
			for (unsigned int i=0; i < attackers.size(); i++) {
				if (player->collidedWith(*attackers[i])) {
					justLostLife = true;
					cont = false;
					crash.play(); // crash sound!
					break;
				}

				// Check this attacker's projectiles
				if (cont) {
					vector<Projectile *> projectiles = attackers[i]->getProjectiles(); // Danger - be careful.
					for (unsigned int i=0; i < projectiles.size(); i++) {
						if (player->collidedWith(*projectiles[i])) {
							justLostLife = true;
							cont = false;
							explosion.play(); // play sound for death by enemy attack!
							break;
						}
					}
				}
			} // end attacker for loop
		}

	} // end if invCount
}
コード例 #3
0
ファイル: myThread.cpp プロジェクト: MakSim345/QT-Dev
void MyThread::PlaySoundQt()
{
    /*The wrapper for QSound PLAY method. Given parameter is *.wav filename.*/
    // print "create QtGui.QSound for ", file
    QSound *snd = new QSound(file);
    snd->play();
}
コード例 #4
0
ファイル: mainwindow.cpp プロジェクト: Amyya/pd2-Angrybird
void MainWindow::showEvent(QShowEvent *)
{
    // Setting the QGraphicsScene
    scene = new QGraphicsScene(0,0,width(),ui->graphicsView->height());
    ui->graphicsView->setScene(scene);
    scene->setBackgroundBrush(QBrush(QImage(":/image/background.png")));
    // Create world
    world = new b2World(b2Vec2(0.0f, -9.8f));  //橫跟直的重力
    // Setting Size
    GameItem::setGlobalSize(QSizeF(32,18),size());   //size of BOX2D windowsize
    QSound *music =new QSound("angrybird.wav");
    music->play();

    initial();

    // Timer
    connect(&timer,SIGNAL(timeout()), this, SLOT(tick()));
    connect(this,SIGNAL(quitGame()), this, SLOT(QUITSLOT()));
    //connect(&timerpig, SIGNAL(timeout()), this, SLOT(deletepig()));
    timer.start(100/6);
    //timerpig.start(1000);

    //create the restart button
    /*QPushButton *restartButton = new QPushButton;
    restartButton->setGeometry(QRect(QPoint(100,50),QSize(100, 100)));
    QPixmap pixmap(":/image/restart.jpg");
    QIcon ButtonIcon(pixmap);
    restartButton->setIcon(ButtonIcon);
    restartButton->setIconSize(pixmap.rect().size());
    scene->addWidget(restartButton);
    connect(restartButton,SIGNAL(clicked(bool)),this,SLOT(restart()));*/

}
コード例 #5
0
ファイル: glwidget.cpp プロジェクト: idxExtropy/duel-reality
/*******************************************************
* hitUnit()
*
* Description: Handles the "kill unit" event triggered
* by the UI and managed by the mechanics modules.
*
* Inputs: Attacker and victim coordinates.
*
* Outputs: none.
*
* Return: none.
*******************************************************/
void GLWidget::killUnit(int vLocation, int hLocation, int vAttackerLoc, int hAttackerLoc)
{
    iEventCounter = 0;
    isEffect = true;
    effectType = EFFECT_ATTACK;
    isPending = false;

    attack_vLoc = vLocation;
    attack_hLoc = hLocation;

    battleMap.gridCell[attack_vLoc][attack_hLoc].unit->status = NO_UNIT;

    battleMap.gridCell[vAttackerLoc][hAttackerLoc].unit->isPending = false;
    battleMap.gridCell[vAttackerLoc][hAttackerLoc].unit->actionTime = 0;

    // Clear the old cell.
    battleMap.gridCell[attack_vLoc][attack_hLoc].unit = new Unit;
    battleMap.gridCell[attack_vLoc][attack_hLoc].isUnit = false;
    battleMap.gridCell[attack_vLoc][attack_hLoc].unit->vLocation = -1;
    battleMap.gridCell[attack_vLoc][attack_hLoc].unit->hLocation = -1;
    battleMap.gridCell[attack_vLoc][attack_hLoc].unit->isPending = false;

    // Play 'hit' sound.
    QSound *soundBkgnd = new QSound("sounds/Action_Hit.wav");
    soundBkgnd->play();
}
コード例 #6
0
ファイル: glwidget.cpp プロジェクト: idxExtropy/duel-reality
/*******************************************************
* moveUnit()
*
* Description: Handles the "move unit" event triggered
* by the UI and managed by the mechanics modules.
*
* Inputs: Previous and new grid coordinates.
*
* Outputs: none.
*
* Return: none.
*******************************************************/
void GLWidget::moveUnit(int vLocPrev, int hLocPrev, int vLocNext, int hLocNext)
{
    iEventCounter = 0;
    isEffect = true;
    effectType = EFFECT_MOVE;
    isPending = false;

    move_vLocNext = vLocNext;
    move_hLocNext = hLocNext;

    // Update the new cell.
    battleMap.gridCell[move_vLocNext][move_hLocNext].unit = battleMap.gridCell[vLocPrev][hLocPrev].unit;
    battleMap.gridCell[move_vLocNext][move_hLocNext].unit->vLocation = vLocNext;
    battleMap.gridCell[move_vLocNext][move_hLocNext].unit->hLocation = hLocNext;
    battleMap.gridCell[move_vLocNext][move_hLocNext].unit->isPending = false;
    battleMap.gridCell[move_vLocNext][move_hLocNext].unit->actionTime = 0;
    battleMap.gridCell[move_vLocNext][move_hLocNext].isUnit = true;

    // Clear the old cell.
    battleMap.gridCell[vLocPrev][hLocPrev].unit = new Unit;
    battleMap.gridCell[vLocPrev][hLocPrev].isUnit = false;
    battleMap.gridCell[vLocPrev][hLocPrev].unit->vLocation = -1;
    battleMap.gridCell[vLocPrev][hLocPrev].unit->hLocation = -1;
    battleMap.gridCell[vLocPrev][hLocPrev].unit->isPending = false;

    // Remove mask temporarily.
    moveMask = battleMap.gridCell[move_vLocNext][move_hLocNext].unit->maskFileName;
    battleMap.gridCell[move_vLocNext][move_hLocNext].unit->mask_image.load("sprites/white.png");

    // Play 'move' sound.
    QSound *soundBkgnd = new QSound("sounds/Action_Move.wav");
    soundBkgnd->play();
}
コード例 #7
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();
    }
}
コード例 #8
0
ファイル: sound.cpp プロジェクト: FractalBobz/focuswriter
void Sound::play(int name)
{
	if (!f_enabled) {
		return;
	}

	Sound* sound = f_sound_objects.value(name);
	if (!sound || !sound->isValid()) {
		return;
	}

	QSound* qsound = 0;
	QList<QSound*>& sounds = f_sounds[sound->m_id];
	int count = sounds.count();
	for (int i = 0; i < count; ++i) {
		if (sounds.at(i)->isFinished()) {
			qsound = sounds.at(i);
			break;
		}
	}
	if (qsound == 0) {
		qsound = new QSound(sounds.first()->fileName());
		sounds.append(qsound);
	}
	qsound->play();
}
コード例 #9
0
ファイル: Game.cpp プロジェクト: dmonopoly/survive-space-game
void Game::makeMothershipVisible() {
	Attacker *a;
	for (unsigned int i=0; i < attackers.size(); i++) {
		a = dynamic_cast<Mothership*> (attackers[i]);
		if (a != NULL)
			attackers[i]->setVisible(true);
	}
	mothershipArrivalSound.play();
}
コード例 #10
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();
}
コード例 #11
0
ファイル: glwidget.cpp プロジェクト: idxExtropy/duel-reality
/*******************************************************
* paintGL()
*
* Description: The primary painting function for the
* OpenGL widget.  Everything is drawn here at the
* specified update rate.
*
* Inputs: none
*
* Outputs: none
*
* Return: none
*******************************************************/
void GLWidget::paintGL()
{
    // Handle title screen.
    if (!isBattle)
    {
        updateTitleScreen();
        return;
    }

    // Capture pending status.
    if (!isPending && !isEffect)
    {
        for (int i = 0; i < MAX_MAP_UNITS; i++)
        {
            // Update the action time (unitTest).
            if (unit[i].actionTime >= 100 && unit[i].status==UNIT_OK) //the dead shall not move :o
            {
                if (unit[i].team == USER_UNIT)
                {
                    // Play 'ready' sound.
                    QSound *soundBkgnd = new QSound("sounds/blip.wav");
                    soundBkgnd->play();
                }

                // The unit is ready to go, so pause the game.
                battleMap.gridCell[unit[i].vLocation][unit[i].hLocation].unit->isPending = true;
                isPending = true;

                // Tell mechanics to handle AI.
                mech->handleAI();
                break;
            }
            unit[i].actionTime += 0.005 * unit[i].actionRate;
        }
    }

    // Clear the background.
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Draw items.
    drawBackground();
    drawGrid();
    drawUnits();
    drawHeaderInfo();

    if (isEffect)
    {
        drawEffects();
    }
}
コード例 #12
0
ファイル: sound.cpp プロジェクト: neoriddle/focuswriter
void Sound::play()
{
	QSound* sound = 0;
	foreach (QSound* s, m_sounds) {
		if (s->isFinished()) {
			sound = s;
			break;
		}
	}
	if (sound == 0) {
		sound = new QSound(m_filename, this);
		m_sounds.append(sound);
	}
	sound->play();
}
コード例 #13
0
ファイル: glwidget.cpp プロジェクト: idxExtropy/duel-reality
/*******************************************************
* hitUnit()
*
* Description: Handles the "hit unit" event triggered
* by the UI and managed by the mechanics modules.
*
* Inputs: Attacker and victim coordinates as well as
* the damage to be done.
*
* Outputs: none.
*
* Return: none.
*******************************************************/
void GLWidget::hitUnit(int vLocation, int hLocation, int damage, int vAttackerLoc, int hAttackerLoc)
{
    iEventCounter = 0;
    isEffect = true;
    effectType = EFFECT_ATTACK;
    isPending = false;

    attack_vLoc = vLocation;
    attack_hLoc = hLocation;

    battleMap.gridCell[attack_vLoc][attack_hLoc].unit->hitPoints -= damage;

    battleMap.gridCell[vAttackerLoc][hAttackerLoc].unit->isPending = false;
    battleMap.gridCell[vAttackerLoc][hAttackerLoc].unit->actionTime = 0;

    // Play 'hit' sound.
    QSound *soundBkgnd = new QSound("sounds/Action_Hit.wav");
    soundBkgnd->play();
}
コード例 #14
0
ファイル: mainwindow.cpp プロジェクト: CQuentin/QBomberMan
/* 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();
}
コード例 #15
0
ファイル: my_scene.cpp プロジェクト: LitvinovaE/4sem
void StepComp()
{
    int x = 0, y = 0;

    if((igra->last_hit_x != -1) && (igra->last_hit_y != -1))
        ChooseWay();
    else
    {
        if(igra->difficultly_level == HARD)
        {
            x = qrand() % SIZE_FIELD_SQUARE;
            y = 4 - ((x + 1) % 4) + (qrand() % 3) * 4;                  //smart rand
            if(y > 9)
                y %= 4;

            int k = 0;
            while((MyField[y][x] == MISS) || (MyField[y][x] == HIT))
            {
                if (k < 500)
                {
                    x = qrand() % SIZE_FIELD_SQUARE;
                    y = 4 - ((x + 1) % 4) + (qrand() % 3) * 4;
                    if(y > 9)
                        y %= 4;
                    k++;
                }
                else
                {
                    igra->difficultly_level = MEDIUM;
                    break;
                }
            }
        }
        if(igra->difficultly_level == MEDIUM)
        {
            x = qrand() % SIZE_FIELD_SQUARE;
            y = 4 - ((x + 3) % 4) + (qrand() % 3) * 4;                  //smart rand
            if(y > 9)
                y %= 4;

            int k = 0;
            while((MyField[y][x] == MISS) || (MyField[y][x] == HIT))
            {
                if(k < 500)
                {
                    x = qrand() % SIZE_FIELD_SQUARE;
                    y = 4 - ((x + 3) % 4) + (qrand() % 3) * 4;
                    if(y > 9)
                        y %= 4;
                    k++;
                }
                else
                {
                    igra->difficultly_level = EASY;
                    break;
                }
            }
        }
        if(igra->difficultly_level == EASY)
        {
            x = qrand() % SIZE_FIELD_SQUARE;
            y = qrand() % SIZE_FIELD_SQUARE;
            int k = 0;
            while(((MyField[y][x] == MISS) || (MyField[y][x] == HIT)) && (k < 500))
            {
                x = qrand() % SIZE_FIELD_SQUARE;
                y = qrand() % SIZE_FIELD_SQUARE;
                k++;
            }
            if(k == 500)
            {
                for(int i(0); i < SIZE_FIELD_SQUARE; i++)
                    for(int j(0); j < SIZE_FIELD_SQUARE; j++)
                    {
                        if((MyField[i][j] == EMPTY) || (MyField[i][j] == BUSY))
                        {
                            x = j;
                            y = i;
                        }
                    }
            }
        }

        if(MyField[y][x] == EMPTY)
        {
            MyField[y][x] = MISS;
            addCell(x, y, igra->scene1);
            igra->miss->play();
            while(!igra->miss->isFinished())
                Delay();
            igra->currentMove = true;
        }

        if(MyField[y][x] == BUSY)
        {
            MyField[y][x] = HIT;
            igra->last_hit_x = x;
            igra->last_hit_y = y;
            addCell(x, y, igra->scene1);
            if(isCrashed(x, y, MyField, igra->scene1))
                igra->kill->play();
            else
                igra->hit->play();
            while((!igra->hit->isFinished()) || (!igra->kill->isFinished()))
                Delay();
            igra->comp_win++;

            if(isCrashed(x, y, MyField, igra->scene1))
            {
                igra->last_hit_x = -1;
                igra->last_hit_y = -1;
            }
            StepComp();
        }
    }

    if(igra->comp_win == 20)    //if computer won
    {
        QSound *lose = new QSound("music/lose.wav");
        lose->play();
        QMessageBox::information(0, "Result", "You lose!");
        while(!lose->isFinished())
            Delay();
        igra->currentMove = true;
        //igra->comp_win++;
        igra->finish = true;
    }
}
コード例 #16
0
/* 构造函数:构造 Qt 界面 */
Emulator::Emulator(QWidget* parent) : QWidget(parent) {
    START = 0;
    QLabel* labelP;
    labelP = new QLabel("Elevator:", this);
    int bias = 20 + 150;
    labelP->move(40 + bias, 530);
    nEle = new QLabel("0       ", this);
    nEle->move(100 + bias, 530);
    
    labelP = new QLabel("Passenger:", this);
    labelP->move(150 + bias, 530);
    nPas = new QLabel("0       ", this);
    nPas->move(220 + bias, 530);
    
    labelP = new QLabel("Average wait:", this);
    labelP->move(260 + bias, 530);
    avWt = new QLabel("0       ", this);
    avWt ->move(345 + bias, 530);
    
    labelP = new QLabel("Max wait:", this);
    labelP->move(405 + bias, 530);
    mxWt = new QLabel("0       ", this);
    mxWt->move(470 + bias, 530);
    
    labelP = new QLabel("Average duration:", this);
    labelP->move(40 + bias, 550);
    avDur = new QLabel("0       ", this);
    avDur->move(160 + bias, 550);
    
    labelP = new QLabel("Max duration:", this);
    labelP->move(210 + bias, 550);
    mxDur = new QLabel("0       ", this);
    mxDur->move(305 + bias, 550);
    
    labelP = new QLabel("Min duration:", this);
    labelP->move(365 + bias, 550);
    mnDur = new QLabel("0       ", this);
    mnDur->move(465 + bias, 550);
    
    labelP = new QLabel("Average throughput:", this);
    labelP->move(40 + bias, 570);
    avThr = new QLabel("0              ", this);
    avThr->move(bias + 180, 570);
    
    start = new QPushButton("START", this);
    start->setGeometry(720, 550, 60, 20);
    
    QPushButton *quit = new QPushButton("Quit ", this);
    quit->setGeometry(720, 570, 60, 20);
    
    fcfs = new QPushButton("FCFS", this);
    fcfs->setGeometry(800, 550, 60, 20);
    
    scan = new QPushButton("SCAN", this);
    scan->setGeometry(800, 570, 60, 20);
    
    costflow = new QPushButton("COSTFLOW", this);
    costflow->setGeometry(860, 550, 80, 20);
    
    pickup = new QPushButton("PICKUP", this);
    pickup->setGeometry(860, 570, 80, 20);
    
    connect(quit, SIGNAL(clicked()), qApp, SLOT(quit()));
    connect(start, SIGNAL(clicked()), this, SLOT(startEmulationSlots()));
    connect(fcfs, SIGNAL(clicked()), this, SLOT(useFcfs()));
    connect(scan, SIGNAL(clicked()), this, SLOT(useScan()));
    connect(costflow, SIGNAL(clicked()), this, SLOT(useCostflow()));
    connect(pickup, SIGNAL(clicked()), this, SLOT(usePickup()));
    timer = 0;
    
//    QSound *sound = new QSound("../../Muisc/style.mp3", this);
//    sound->play();
    
    QSound *style = new QSound("style.mp3", this);
    style->play();
    startTimer(10);
}
コード例 #17
0
ファイル: Game.cpp プロジェクト: dmonopoly/survive-space-game
void Game::levelCheck() {
	int firstLevel = 400;
	int scoreInterval = 400;

	if (level == 1 && score > firstLevel) {
		level++;
		speedUpFallingObjects();
		msg = "LEVEL UP!!!";
		levelup.play();
	} else if (level == 2 && score > firstLevel+scoreInterval) {
		level++;
		speedUpFallingObjects();

		// Show leviathan!
		makeLeviathanVisible();

		msg = "LEVEL UP - Beware...";

		levelup.play();
	} else if (level == 3 && score > firstLevel+scoreInterval*2) {
		level++;
		speedUpFallingObjects();
		msg = "LEVEL UP - NEW WORLD REACHED";

		// set background
		palette.setBrush(this->backgroundRole(), QBrush(QImage(BACKGROUND2.c_str())));
		this->setPalette(palette);

		levelup.play();
	} else if (level == 4 && score > firstLevel+scoreInterval*3) {
		level++;
		speedUpFallingObjects();

		// Show terrier!
		makeTerrierVisible();

		msg = "LEVEL UP!!!";

		levelup.play();
	} else if (level == 5 && score > firstLevel+scoreInterval*4) {
		level++;
		speedUpFallingObjects();
		msg = "LEVEL UP!!!";

		levelup.play();
	} else if (level == 6 && score > firstLevel+scoreInterval*5) {
		level++;
		speedUpFallingObjects();
		msg = "LEVEL UP - NEW WORLD REACHED";

		// set background
		palette.setBrush(this->backgroundRole(), QBrush(QImage(BACKGROUND3.c_str())));
		this->setPalette(palette);

		levelup.play();
	} else if (level == 7 && score > firstLevel+scoreInterval*6) {
		level++;
		speedUpFallingObjects();

		// Show mothership!
		makeMothershipVisible();

		msg = "LEVEL UP!!!";

		levelup.play();
	}
}