Exemple #1
0
void next_wave(){
	currentWave++;
	if(currentWave > 99){ //Max
		currentWave = 99;
	}
	int numEnemies = currentWave;
	if(numEnemies > getMaxEntities() - 1){
		numEnemies = getMaxEntities() - 1;
	}
	createEnemies(numEnemies);

	display_wave_screen(currentWave);
	if(currentWave > highscore){
		highscore = currentWave;
	}
	map_generate();
	spawnAllEntities();
	int wavetime = 10 + currentWave;
	if(wavetime > 3600){ //Max
		wavetime = 3600;
	}
	setCurrentWaveTime(wavetime);
	resetDigCd();
	resetSecondsElapsed();
}
void GameLogic::nextWave()
{
	missiles.clear();
	waveOver = false;
	waveCount++;
	createEnemies();
}
MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    mainLayout = new QVBoxLayout();
    window = new QWidget();

    gameView = new GameView();
    gameModel = new GameModel();
    topbar = new Topbar();

    QObject::connect(gameModel, SIGNAL(sig_createMap(std::vector<std::shared_ptr<Tile> >)),
                     gameView, SLOT(createWorldMap(std::vector<std::shared_ptr<Tile> >)));
    QObject::connect(gameModel, SIGNAL(sig_putEnemies(std::vector<std::shared_ptr<Enemy> >)),
                     gameView, SLOT(createEnemies(std::vector<std::shared_ptr<Enemy> >)));
    QObject::connect(gameModel, SIGNAL(sig_putHealPck(std::vector<std::shared_ptr<Tile> >)),
                      gameView, SLOT(createHealPcks(std::vector<std::shared_ptr<Tile> >)));
    QObject::connect(gameModel, SIGNAL(sig_getBoundary(int,int)),
                     gameView, SLOT(setBoundary(int,int)));
    QObject::connect(gameModel, SIGNAL(sig_createProta(int,int)),
                     gameView, SLOT(createProta(int,int)));
    QObject::connect(gameModel, SIGNAL(sig_changeProtaPos(int,int)),
                     gameView, SLOT(changeProtaPos(int,int)));
    QObject::connect(gameModel, SIGNAL(sig_changeProtaHealth(float)),
                     gameView, SLOT(changeProtaHealth(float)));
    QObject::connect(gameModel, SIGNAL(sig_changeProtaEnergy(float)),
                     gameView, SLOT(changeProtaEnergy(float)));
    QObject::connect(gameModel,SIGNAL(sig_fightEnemy(std::shared_ptr<Enemy>)),
                     gameView,SLOT(fightEnemy(std::shared_ptr<Enemy>)));
    QObject::connect(gameModel,SIGNAL(sig_recovery(std::shared_ptr<Tile>)),
                     gameView,SLOT(recovery(std::shared_ptr<Tile>)));
    QObject::connect(gameModel, SIGNAL(sig_findPath(std::vector<std::shared_ptr<PathNode>>)),
                     gameView, SLOT(highlightPath(std::vector<std::shared_ptr<PathNode>>)));

    QObject::connect(gameView, SIGNAL(sig_changeProtaPosbyMouse(int,int)),
                     gameModel, SLOT(goDestinationByMouse(int,int)));
    QObject::connect(gameModel,SIGNAL(sig_stopMoving()),
                     gameView, SLOT(stopMoving()));

    gameModel->initialGame();
    mainLayout->addWidget(gameView);

//------------------------test-------------------
    //gameModel->doAnimation(0,0,24,16);
   // gameView->removeHighlight();



      mainLayout->addWidget(topbar);
      QObject::connect(gameModel,SIGNAL(sig_changeProtaHealth(float)),
                       topbar,SLOT(changeHealthValue(float)));
      QObject::connect(gameModel,SIGNAL(sig_changeProtaEnergy(float)),
                       topbar,SLOT(changeEnergyValue(float)));
      QObject::connect(topbar->getAnimation_slider(),SIGNAL(valueChanged(int)),
                        gameModel,SLOT(setAnimationTime(int)));
    window->setLayout(mainLayout);
    this->setCentralWidget(window);

}
Exemple #4
0
Game::Game(): QGraphicsView(){
move_timer = new QTimer(this);

    move_timer->start(20);

    //create a scene
    scene = new QGraphicsScene(this);
    scene->setSceneRect(0,0,920,720);

    //set the scene
    setScene(scene);

    //set cursor
    cursor = nullptr;
    building = nullptr;
    setMouseTracking(true);

    //alter window
    setFixedSize(920,720);
    setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);

    //split screen into playfield and menu
    field_menu << QPointF(720,0) << QPointF(720,720);
    for(size_t i=0, n = field_menu.size()-1; i < n; i++){
        //create a line
        QLineF line(field_menu[i],field_menu[i+1]);
        QGraphicsLineItem * lineItem = new QGraphicsLineItem(line);

        QPen pen;
        pen.setWidth(5);
        pen.setColor(Qt::black);

        lineItem->setPen(pen);

        scene->addItem(lineItem);
    }

    //create gridpoints
    for(gPoint_x=0; gPoint_x<20; gPoint_x++){
        for(gPoint_y=0; gPoint_y<20; gPoint_y++){
            Gridpoint *gPoint = new Gridpoint;
            gPoint->setPos(x()+12+(36*gPoint_x),y()+12+(36*gPoint_y));
            scene->addItem(gPoint);
        }
    }

    //creat enemy
    spawnTimer = new QTimer(this);
    enemiesSpawned = 0;
    maxNumberOfEnemies = 0;
    pointsToFollow  << QPointF(18,18) << QPointF(18,414) << QPointF(198,414)<<  QPointF(594,414) << QPointF(594,54) << QPointF(800,54)<< QPointF(594,54);



    for(int i=0;i<=(pointsToFollow.length()-2);i++){
        QPointF temp;
        double test;
        temp=((pointsToFollow[i+1])-(pointsToFollow[i]));
        temp=temp;
        direction[i][0]=temp.x()/(sqrt(pow(temp.x(),2)+pow(temp.y(),2)));
        direction[i][1]=temp.y()/(sqrt(pow(temp.x(),2)+pow(temp.y(),2)));

    }


    createEnemies(20);

    //create Road
    createRoad();

    //create Tower-Icon
    BuildRedTowerIcon * rt = new BuildRedTowerIcon();
    BuildGreenTowerIcon * gt = new BuildGreenTowerIcon();
    BuildBlueTowerIcon * bt = new BuildBlueTowerIcon();
    BuildBlackTowerIcon * bkt = new BuildBlackTowerIcon();
    BuildWhiteTowerIcon * wt = new BuildWhiteTowerIcon();
    BuildYellowTowerIcon * yt = new BuildYellowTowerIcon();

    //move tower icons
    rt->setPos(x()+850,y());
    gt->setPos(x()+850,y()+50);
    bt->setPos(x()+850,y()+100);
    bkt->setPos(x()+850,y()+150);
    yt->setPos(x()+850,y()+200);
    wt->setPos(x()+850,y()+250);

    scene->addItem(rt);
    scene->addItem(gt);
    scene->addItem(bt);
    scene->addItem(bkt);
    scene->addItem(yt);
    scene->addItem(wt);

}
void HoldLine::startGame(){
  if(!gameStarted) { 
     prot->resetState();
     arrowCount = 0;
     remainingArrows = 8;
     trapCount = 0;
     remainingTraps = 5;
     enemyCount = 0;
     crossedLine = 0;
     prot->setHealth();
     level++;

     if(level == 1){
          createEnemies(MAXENEMIES);

         for(int i = 0; i < arrowList.size(); i++)
            arrowList[i]->setDestroyed(true);

         for(int i = 0; i < trapList.size(); i++)
            trapList[i]->setDestroyed(true);

         for(int i = 0; i < bulletList.size(); i++)
            bulletList[i]->setDestroyed(true); 

         protectItem->setDestroyed(true);
         protect->setDestroyed(true);

     }

     else if(level == 2){
         for(int i = 0; i < enemyList.size(); i++){
             enemyList[i]->setDestroyed(false);
             enemyList[i]->setDir(0,3);
             enemyList[i]->resetState();
         }
         createEnemies(13);
 
         MAXENEMIES += 13;

         deleteArrows();
         arrowList.resize(0);
         createArrows(8);

         deleteTraps();
         trapList.resize(0);
         createTraps(5);


         for(int i = 0; i < arrowList.size(); i++)
            arrowList[i]->setDestroyed(true);

         for(int i = 0; i < trapList.size(); i++)
            trapList[i]->setDestroyed(true);

         for(int i = 0; i < bulletList.size(); i++)
            bulletList[i]->setDestroyed(true); 

         protectItem->setDestroyed(true);
         protect->setDestroyed(true);
     }//end level 2

     else if(level == 3){
         EnemyObject* f;

         for(int i = 0; i < enemyList.size(); i++){
             enemyList[i]->setDestroyed(false);
             f = dynamic_cast <Enemy*> (enemyList[i]);

             if(f != NULL)
                 enemyList[i]->setDir(0,3);

             enemyList[i]->resetState();
         }

         createEnemies(12);

         MAXENEMIES += 12;

         deleteArrows();
         arrowList.resize(0);
         createArrows(8);

         deleteTraps();
         trapList.resize(0);
         createTraps(5);

         for(int i = 0; i < arrowList.size(); i++)
            arrowList[i]->setDestroyed(true);

         for(int i = 0; i < trapList.size(); i++)
            trapList[i]->setDestroyed(true);

         protectItem->setDestroyed(true);
         protect->setDestroyed(true);
     }//end level 3
     

     startTimers();

     gameOver = false;
     gameWon = false;
     gameStarted = true;
  }
}