void testApp::mouseReleased(int x, int y, int button){ ofVec2f target = ofVec2f(x,y); if(state==START_SCREEN){ ofRectangle startb = ofRectangle(START_BUTTON_POS); if( startb.inside(x, y)){ currentLevel = 0; nextLevel(); return; }else{ lines[currentLine].push_back( ofVec2f(x ,y )); } } if(state==PLAYING){ Silo * silo = bestSiloForTarget( target ); if (silo != NULL){ Missile *m = silo->launchMissile(); if(m != NULL){ launch.play(); m->startGood( target ); playerMissiles.push_back(m); }else{ empty.play(); } }else{ empty.play(); } } }
/// Check whether or not the game is over or the level was completed. void GameModel::checkLevel() { if (enemiesNearBase() or lives == 0) { gameOver = true; } if (enemiesShot == 55) { nextLevel(); } }
void connect(TreeLinkNode *root) { vector<TreeLinkNode *> roots; if(root){ roots.push_back(root); while(roots.size()!=0){ roots = nextLevel(roots); } } }
void KJezzball::newPercent( int percent ) { m_percentLCD->display( percent ); if ( percent>=75 ) { m_level.score = m_level.lifes*15 + (percent-75)*2*(m_game.level+5); nextLevel(); } }
void GravityJamRoot::endLevel(float dt) { // we will need all of the end of level graphics here // for now, just unload the level and load the next one closeLevel(); if(!nextLevel()) { printf("Error opening level %i", gj_level); faulted = true; } }
/** * Handles the Middle Button Presses */ static void select_click_handler(ClickRecognizerRef recognizer, void *context) { // If the Game didn't finish yet, handle the Logic, otherwise restart the game if (!status.end) nextLevel(); else { status.end = true; //free(status.timer); status.timer = NULL; layer_set_hidden(text_layer_get_layer(ui.messageLayer), true); window_stack_pop(true); scores_name_init(status.points); status.cleanScores = true; } }
OptimizationInfos::OptimizationInfos() { infos_[Optimization_Normal - 1].initNormalOptimizationInfo(); infos_[Optimization_AsmJS - 1].initAsmjsOptimizationInfo(); #ifdef DEBUG OptimizationLevel level = firstLevel(); while (!isLastLevel(level)) { OptimizationLevel next = nextLevel(level); JS_ASSERT(level < next); level = next; } #endif }
// adding 1 to counter of lines, builded by user void TetrisEngine:: addLine() { _linesCounter++; // if current lines tens are higher than _curLevel, emit nextLevel // max level is 10 if ( _linesCounter / 10 > _curLevel && _curLevel < 11) { _curLevel = _linesCounter / 10; _interval -= INTERVAL_STEP; timer.setInterval(_interval); emit nextLevel(); } emit linesCounterChanged(); }
void HeartGame::init() { m_win.create(sf::VideoMode(800u, 600u), "Heart", sf::Style::Titlebar | sf::Style::Close); m_win.setFramerateLimit(60u); m_font.loadFromFile("read/DejaVuSans.ttf"); m_hearttex.loadFromFile("read/heart.png"); m_brokenhearttex.loadFromFile("read/broken-heart.png"); m_heartcolor = kPrimaryColors[m_randomizer.getRandomUintBelow(3u)]; m_beatclock.restart(); m_points = 0; m_currentlevelpoints = 0; m_gameover = false; m_level = 0u; nextLevel(); setText("A and D to rotate\nSpace to shoot\nEscape to quit", sf::seconds(4.f)); }
OptimizationLevel OptimizationInfos::levelForScript(JSScript *script, jsbytecode *pc) const { OptimizationLevel prev = Optimization_DontCompile; while (!isLastLevel(prev)) { OptimizationLevel level = nextLevel(prev); const OptimizationInfo *info = get(level); if (script->getWarmUpCount() < info->compilerWarmUpThreshold(script, pc)) return prev; prev = level; } return prev; }
void Map::updateFO() { for (int i = 0; i < foVector.size(); i++) { //if falling object off screen if (foVector[i]->foSprite.getPosition().y - foVector[i]->foSprite.getGlobalBounds().height / 2 > window->getSize().y) { resetPosition(foVector[i]); curNumFO--; //check if all falling objects have been destroyed if (curNumFO == 0) { nextLevel(); } } else { foVector[i]->foSprite.setRotation(foVector[i]->foSprite.getRotation() + foVector[i]->randomNum); foVector[i]->foSprite.move(0, 15*foVector[i]->velY); foVector[i]->foCircle.move(0, 15*foVector[i]->velY); } } }
void Map::detectCollisionFG() { for (int i = 0; i < gbVector.size(); i++) { for (int j = 0; j < foVector.size(); j++) { if (!foVector[j]->intersected && intersects(foVector[j], gbVector[i]->gbSprite.getGlobalBounds(), 1)) { //collision detected sound.setBuffer(iBuffer); sound.play(); gbVector.erase(gbVector.begin() + i); curNumFO--; foVector[j]->intersected = true; resetPosition(foVector[j]); if (curNumFO == 0) { nextLevel(); } break; } } } }
void Map::detectCollisionFB(std::vector<Weapon::Bullet*> bullets) { for (int i = 0; i < bullets.size(); i++) { for (int j = 0; j < foVector.size(); j++) { if (!foVector[j]->intersected && intersects(foVector[j], bullets[i]->bulletSprite.getGlobalBounds(), 0)) { //collision detected sound.setBuffer(iBuffer); sound.play(); bullets.erase(bullets.begin() + i); score += 10; curNumFO--; foVector[j]->intersected = true; resetPosition(foVector[j]); if (curNumFO == 0) { nextLevel(); } break; } } } }
void GameState::detectCollisions() { // walls if (m_ball.position.x < 0 || m_ball.position.x > 1) { m_ball.velocity.x = -m_ball.velocity.x; g_sound_engine.playSound(PLINK); return; } // ceiling if (m_ball.position.y < 0) { m_ball.velocity.y = -m_ball.velocity.y; g_sound_engine.playSound(PLINK); return; } // paddle Rectangle paddle(m_paddle - 0.1, 0.95, m_paddle + 0.1, 0.98); if (detectCollision(paddle, true)) { g_sound_engine.playSound(PLUNK); return; } Block::List::iterator i = m_blocks.begin(); for (; i != m_blocks.end(); ++i) { if (detectCollision(i->location, false)) { g_sound_engine.playSound(PLONK); m_blocks.erase(i); ++m_blocks_destroyed; // have we completed the level? if (m_blocks.empty()) { nextLevel(); } return; } } }
Level::Level() { srand(time(NULL)); numbers_ = al_load_bitmap("pics/numbers.bmp"); al_convert_mask_to_alpha(numbers_, al_map_rgb(0, 0, 0)); hearts_ = al_load_bitmap("pics/hearts.bmp"); bunny_ = new Bunny(); spaceItem_ = new SpaceItem(NULL, 0); efactory_ = new EnemyFactory(bunny_); ifactory_ = new ItemFactory(); pfactory_ = new PickupFactory(); for (int i = 0; i < LVL_CNT; i++) { usedLevels_[i] = false; } levelsPlayed_ = 0; playing_ = true; nextLevel(); }
void HeartGame::updateHeartAndLevel() { if(m_currentlevelpoints < 0) { m_gameover = true; return; } if(m_rings.isEmpty()) nextLevel(); if(m_beatclock.getElapsedTime() >= sf::seconds(1.f)) { unsigned nextcolor = kPrimaryColors[m_randomizer.getRandomUintBelow(3u)]; while(m_heartcolor == nextcolor) nextcolor = kPrimaryColors[m_randomizer.getRandomUintBelow(3u)]; m_heartcolor = nextcolor; m_beatclock.restart(); } }
// Restarting board, tiles, and bricks void TetrisEngine::restart() { _linesCounter = 0; emit linesCounterChanged(); _endofgame = false; _rotatePos = 0; _curLevel = 0; emit nextLevel(); // initialize random table with 1 (same chance for every brick) for (int i = 0; i < 7; i++) { _randomTable[i] = 1; } for(int i = 0; i < _tiles.count(); i++) _tiles[i]->restart(); if (_nextBrick != NULL) { delete(_nextBrick); _nextBrick = NULL; } if (_curBrick != NULL) delete(_curBrick); _nextBrick = createNewBrick(); _curBrick = createNewBrick(); for (int i= 0; i < BRICKCOUNT; i++) { _tiles[_curBrick->brickPosition[i]]->setActive(resolveBrickColor(_curBrick->color)); } _interval = START_INTERVAL; timer.setInterval(_interval); timer.start(); qDebug() << "Undergone restart"; }
void MainWgt::luzg() { int c = ui->lcdSluzgano->intValue() + 1; if ( c >= nextLevelCount ){ nextLevelCount += nextLevelIncrement; semkoInterval -= 3; if (semkoInterval <= semkoIntervalMin){ semkoInterval = semkoIntervalMin; } int livesAdd = ui->lcdUnluzged->intValue() + 3; ui->lcdUnluzged->display ( livesAdd ); placeTimerInterval = placeTimerInterval - placeTimerIntervalDecrement; if (placeTimerInterval <= placeTimerIntervalMin){ placeTimerInterval = placeTimerIntervalMin; } placeSemkoTimer->stop(); placeSemkoTimer->setInterval(placeTimerInterval); placeSemkoTimer->start(); emit nextLevel(); } ui->lcdSluzgano->display ( c ); }
void Map::detectCollisionFC(sf::RectangleShape charShape) { for (int i = 0; i < foVector.size(); i++) { if (!foVector[i]->intersected && intersects(foVector[i], charShape.getGlobalBounds(), 0)) { foVector[i]->intersected = true; lives--; if (lives <= 0) { sound.setBuffer(dBuffer); sound.play(); gameOverB = true; } else { sound.setBuffer(oBuffer); sound.play(); } resetPosition(foVector[i]); curNumFO--; if (curNumFO == 0) { nextLevel(); } } } }
bool Game2D::event(QEvent *event){ //qDebug () << event->type(); if (event->type() == QEvent::KeyPress) { QKeyEvent *ke = static_cast<QKeyEvent *>(event); if (!state_) state_=1; else{ if (state_==2) start (); } switch (ke->key()){ case Qt::Key_Up: case Qt::Key_W: direction_=UP; break; case Qt::Key_Right: case Qt::Key_D: direction_=RIGHT; break; case Qt::Key_Down: case Qt::Key_S: direction_=DOWN; break; case Qt::Key_Left: case Qt::Key_A: direction_=LEFT; break; case Qt::Key_Shift: ship_.setFire(1); break; case Qt::Key_Tab: nextLevel (); break; case Qt::Key_Backspace: prevLevel (); break; case Qt::Key_Pause: setPause (); break; } return true; } return QWidget::event(event); }
void GameScreen::gameIsWon() { ball->object->stop(); paddle->object->stop(); time->stop(); gameWonLbl = new QLabel(this); gameWonLbl->setPixmap(*gameWonIcon); gameWonLbl->setGeometry(50, 60, 401, 351); gameWonLbl->show(); mainMenuBtn = new QPushButton(this); mainMenuBtn->setGeometry(75, 370, 75, 23); mainMenuBtn->setText("Main Menu"); mainMenuBtn->show(); connect(mainMenuBtn, SIGNAL(clicked()), this, SLOT(quitToMenu())); saveAndQuitBtn = new QPushButton(this); saveAndQuitBtn->setGeometry(165, 370, 81, 23); saveAndQuitBtn->setText("Save and Quit"); saveAndQuitBtn->show(); connect(saveAndQuitBtn, SIGNAL(clicked()), this, SLOT(saveAndQuit())); restartBtn = new QPushButton(this); restartBtn->setGeometry(261, 370, 75, 23); restartBtn->setText("Replay"); restartBtn->show(); connect(restartBtn, SIGNAL(clicked()), this, SLOT(restartLevel())); nextLvlBtn = new QPushButton(this); nextLvlBtn->setGeometry(355, 370, 75, 23); nextLvlBtn->setText("Next Level >"); nextLvlBtn->show(); connect(nextLvlBtn, SIGNAL(clicked()), this, SLOT(nextLevel())); }
void GameManager::tick() { capTimer.start(); // Calcuclate delta time auto lastFrame = currentFrame; currentFrame = hr_clock::now(); auto timeSpan = currentFrame - lastFrame; deltaTime = static_cast<float>(timeSpan.count()) / 1000000000.0f; //Calculate and correct fps auto avgFPS = countedFrames / (fpsTimer.getTicks() / 1000.f); if (avgFPS > 2000000) { avgFPS = 0; } /*************** * Movement ****************/ paddle.move(deltaTime); ball.move(paddle, deltaTime); SDL_Rect ballRect; ballRect.x = ball.getPosX(); ballRect.y = ball.getPosY(); ballRect.w = ball.mCollider.w; ballRect.h = ball.mCollider.h; // Check collision with the pieces for (auto & piece : pieces) { if (piece.isVisible) { auto hit = piece.hitByBall(&ball, ballRect); // We do not want to have more than 1 collision per frame if (hit) { totalBlocksDestroyed++; score.addScore(); break; } } } // Advance to the next level if (totalBlocksDestroyed == PIECES) { level++; nextLevel(level); } // Game over if (ball.getLivesLeft() == 0) { restart(); } int frameTicks = capTimer.getTicks(); if (frameTicks < SCREEN_TICKS_PER_FRAME) { // wait the remaining time SDL_Delay(SCREEN_TICKS_PER_FRAME - frameTicks); } // Update game HUD every 10 ticks if(frameTicks < 10) { updateHUD(); } }
void GameState::update( float dtFixed ) { // If the car is out of route points, generate a route updateRoute(); // check for win int currPosX, currPosY; currPosX = (int)m_carPos.x; currPosY = (int)m_carPos.y; if ((currPosX >= 0) && (currPosY>=0) && (currPosX < m_boardSizeX) && (currPosY < m_boardSizeY) && (m_tile[currPosX][currPosY].target)) { // win! nextLevel(); } // Move the car along the route vec2f targPos, targDir; if (m_carRoute.size()== 0 ) updateRoute(); targPos = m_carRoute.front(); targDir = targPos - m_carPos; if (LengthSquared(targDir) < 0.01) { // we've reached this route point, discard it m_carRoute.pop_front(); // update route to make sure there is data available updateRoute(); targPos = m_carRoute.front(); targDir = targPos - m_carPos; } targDir.Normalize(); // Adjust car dir float turnrate = 0.4f; // not entirely true, but close enough m_carDir = Lerp( m_carDir, targDir, turnrate ); m_carDir.Normalize(); // Update car pos float speed = 2.0; m_carPos += m_carDir * dtFixed * speed; // Now update player's tiles if (m_pickTiles.size() < m_maxTiles) { m_newTileTimeout -= dtFixed; if (m_newTileTimeout <= 0.0f) { // pick a tile at random (scrabble probabilities) const char *tiles = "AAAAAAAAABBCCDDDDEEEEEEEEEEEEFFGGHHIIIIIIIIIJKLLLLMMNNNNNNOOOOOOOOPPQRRRRRRSSSSTTTTTTUUUUVVWWXYYZ"; char letter = tiles[ (int)( ((float)rand() / (float)RAND_MAX) * strlen(tiles) ) ]; PickTile newtile; newtile.letter = letter; newtile.xpos = m_maxTiles; newtile.pending = false; m_pickTiles.push_back( newtile ); m_newTileTimeout = NEW_TILE_TIMEOUT; } } // fade error foreach_tile { if (m_tile[i][j].error > 0.0) { m_tile[i][j].error -= 0.01; } else { m_tile[i][j].error = 0.0; } } }
OptimizationLevel OptimizationInfos::firstLevel() const { return nextLevel(Optimization_DontCompile); }
void Game2D::timer(){ if (pause()) return; if (!evec_.size() && state_==1){ //if (level () >=2) state_=2; //else nextLevel (); } if (state_==1){ bool destroy=0; ship_.onFire(); ship_.timer(direction_, width (), height ()); for (int i=0; i<evec_.size(); i++){ int x1=evec_[i].x (); int y1=evec_[i].y (); int x2=evec_[i].x () + evec_[i].width(); int y2=evec_[i].y () + evec_[i].height(); //ship hit in vertical line if (direction_==1 || direction_==3){ if (isInInterval (ship_.y (), y1, y2) || isInInterval (ship_.y () + ship_.height()/2, y1, y2) || isInInterval (ship_.y () + ship_.height(), y1, y2)){ if (ship_.x() > x1) destroy=ship_.hitMinX(x2); //right else{ if (ship_.x() + ship_.width () > x1) destroy=ship_.hitMaxX(x1-ship_.width ()); //left } } } //ship hit in horizontal line if (direction_==0 || direction_==2){ if (isInInterval (ship_.x (), x1, x2) || isInInterval (ship_.x () + ship_.width()/2, x1, x2) || isInInterval (ship_.x () + ship_.width(), x1, x2)){ if (ship_.y() > y1) destroy=ship_.hitMinY(y2); //down else{ if (ship_.y() + ship_.height () > y1) destroy=ship_.hitMaxY(y1-ship_.height ()); //up } } } if (ship_.fire()){ bool damaged=0; QRect rc; ship_.getFireRect (rc, direction()); //in fire axis y if (direction_==1 || direction_==3){ if (isInInterval (rc.y(), y1, y2) || isInInterval (rc.y()+rc.height(), y1, y2)){ //cross fire line & left enemy || //cross fire line & right enemy if ((x1 > rc.x() && x1 < rc.x()+rc.width()) || (x2 < rc.x() && x2 > rc.x()+rc.width())){ damaged=1; } } } if (direction_==0 || direction_==2){ if (isInInterval (rc.x(), x1, x2) || isInInterval (rc.x()+rc.width(), x1, x2)){ //cross fire line & up enemy || //cross fire line & down enemy if ((y1 > rc.y() && y1 < rc.y()+rc.height()) || (y2 < rc.y() && y2 > rc.y()+rc.height())){ damaged=1; } } } if (damaged){ ++score_; evec_[i].addHealth (-(ship_.damage ())); if (evec_[i].health () == 0) evec_.erase (evec_.begin () + i); } } if (destroy){ state_=2; /*ship_.addHealth (-1); switch(direction_){ case 0: direction_=2; break; case 1: direction_=3; break; case 2: direction_=0; break; case 3: direction_=1; break; } if (ship_.health () == 0) state_=2; */ /*QMessageBox box; box.warning(0,"Game over", "Ship destroyed!", 0, 1); box.show(); */ } } incTime (); if (movable()) moveEnemy (); } }
MainWindow::MainWindow() : QMainWindow(){ // Initialize variables pvx = 0; pvy = 0; attack = 1; pattack = false; paused = false; maxhp = 10; level = 1; pauseMe = 0; human = NULL; anim = 0; // Master Timer timer = new QTimer; gameSpeed = 14; timer->setInterval(gameSpeed); srand(time(0)); // Secondary Timer timer2 = new QTimer; timer2->setInterval(100); // Load ALL THE PICTURES ab1 = new QPixmap("images/actualblue-1.png"); ab2 = new QPixmap("images/actualblue-2.png"); ag1 = new QPixmap("images/actualgreen-1.png"); ag2 = new QPixmap("images/actualgreen-2.png"); apl = new QPixmap("images/actualplayer.png"); ap = new QPixmap("images/actualpurple.png"); ar1 = new QPixmap("images/actualred-1.png"); ar2 = new QPixmap("images/actualred-2.png"); ar3 = new QPixmap("images/actualred-3.png"); ay = new QPixmap("images/actualyellow.png"); app = new QPixmap("images/actualpink.png"); pbullet = new QPixmap("images/bullet.png"); bbullet = new QPixmap("images/bluebullet.png"); gbullet = new QPixmap("images/greenbullet.png"); ppbullet = new QPixmap("images/pinkbullet.png"); ybullet = new QPixmap("images/yellowbullet.png"); widebulletpic = new QPixmap("images/redbullet.png"); heartpic = new QPixmap("images/heart.png"); rainbow = new QPixmap("images/rainbow.png"); bg1 = new QPixmap("images/background.png"); bg2 = new QPixmap("images/background2.png"); bg3 = new QPixmap("images/background3.png"); // This is for the hearts h1 = new QGraphicsPixmapItem(*heartpic); h1->setPos(400, 575); h1->setVisible(false); h2 = new QGraphicsPixmapItem(*heartpic); h2->setPos(375, 575); h2->setVisible(false); h3 = new QGraphicsPixmapItem(*heartpic); h3->setPos(350, 575); h3->setVisible(false); h4 = new QGraphicsPixmapItem(*heartpic); h4->setPos(325, 575); h4->setVisible(false); h5 = new QGraphicsPixmapItem(*heartpic); h5->setPos(300, 575); h5->setVisible(false); // Initialize the Scenes and Views gameScene = new GScene(this); gameView = new QGraphicsView(gameScene); mainScene = new QGraphicsScene; mainView = new QGraphicsView(mainScene); mainView->setWindowTitle("Starships (were meant to fly...)"); // Now add the hearts gameScene->addItem(h1); gameScene->addItem(h2); gameScene->addItem(h3); gameScene->addItem(h4); gameScene->addItem(h5); // Make the layouts holder = new QWidget; holder2 = new QWidget; holder3 = new QWidget; layout = new QVBoxLayout(holder); layout2 = new QHBoxLayout(holder2); layout3 = new QHBoxLayout(holder3); //Set the attributes to the game scene QBrush bg(*bg1); gameScene->setBackgroundBrush(bg); gameScene->setSceneRect(0,0,425,600); gameView->setFixedSize(430,605); gameView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); gameView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Make buttons // Players love buttons startB = new QPushButton("Start"); startB->setGeometry(160, 475, 100, 60); startB->setStyleSheet("background-color:rgba(0,0,0,0); color:#ffffff; font-size:36px;"); gameScene->addWidget(startB); restartB = new QPushButton("Start"); restartB->setFixedHeight(28); pauseB = new QPushButton("Pause"); pauseB->setFixedHeight(28); endB = new QPushButton("Quit"); endB->setFixedHeight(28); nameB = new QTextEdit; nameB->setFixedHeight(28); nameB->setStyleSheet("background-color:rgb(0,0,0); color:#ffffff;"); // Connecting the timers and buttons connect(timer, SIGNAL(timeout()), this, SLOT(handleTimer())); connect(timer2, SIGNAL(timeout()), this, SLOT(nextLevel())); connect(startB, SIGNAL(clicked()), this, SLOT(startGame())); connect(pauseB, SIGNAL(clicked()), this, SLOT(pauseGame())); connect(endB, SIGNAL(clicked()), this , SLOT(quitGame())); connect(restartB, SIGNAL(clicked()), this , SLOT(restartGame())); // Make the labels nameL = new QTextEdit; nameL->setStyleSheet("background-color:rgb(0,0,0); color:#ffffff;"); nameL->setFixedHeight(28); nameL->setFixedWidth(200); nameL->setReadOnly(true); layout3->addWidget(nameL); scoreL = new QTextEdit; scoreL->setStyleSheet("background-color:rgb(0,0,0); color:#ffffff;"); scoreL->setFixedHeight(28); scoreL->setFixedWidth(130); scoreL->setReadOnly(true); layout3->addWidget(scoreL); hpL = new QTextEdit; hpL->setStyleSheet("background-color:rgb(0,0,0); color:#ffffff;"); hpL->setFixedHeight(28); hpL->setFixedWidth(80); hpL->setReadOnly(true); layout3->addWidget(hpL); errorL = new QLabel; errorL->setStyleSheet("background-color:rgba(0,0,0,1); color:#ffffff; font-size:24px;"); errorL->setGeometry(QRect(60,520,380,80)); gameScene->addWidget(errorL); nextWave = new QLabel("Get ready for the next wave!"); nextWave->setStyleSheet("background-color:rgba(0,0,0,1); color:#ffffff; font-size:24px;"); nextWave->setGeometry(QRect(55,220,380,80)); nextWave->hide(); gameScene->addWidget(nextWave); endScore = new QLabel; endScore->setStyleSheet("background-color:rgba(0,0,0,1); color:#ffffff; font-size:26px;"); endScore->setGeometry(QRect(0,40,425,80)); endScore->setAlignment(Qt::AlignCenter); endScore->hide(); gameScene->addWidget(endScore); scoreList = new QLabel; scoreList->setStyleSheet("background-color:rgba(0,0,0,1); color:#ffffff; font-size:26px;"); scoreList->setGeometry(QRect(0,55,425,500)); scoreList->setAlignment(Qt::AlignCenter); scoreList->hide(); gameScene->addWidget(scoreList); // Set the layouts layout2->addWidget(restartB); layout2->addWidget(pauseB); layout2->addWidget(endB); layout->addWidget(holder2); layout->addWidget(gameView); layout->addWidget(nameB); holder3->setVisible(false); layout->addWidget(holder3); layout->setContentsMargins(0, 0, 0, 0); layout->setMargin(0); layout2->setContentsMargins(0, 0, 0, 0); layout2->setMargin(0); layout3->setContentsMargins(0, 0, 0, 0); layout3->setMargin(0); mainScene->addWidget(holder); mainView->setFixedSize(460,710); mainView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); mainView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); // Setting these for faster rendering gameView->setAttribute(Qt::WA_OpaquePaintEvent); gameView->setAttribute(Qt::WA_NoSystemBackground); mainView->setAttribute(Qt::WA_OpaquePaintEvent); mainView->setAttribute(Qt::WA_NoSystemBackground); mainView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); gameView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate); }
void PlayField::keyPressEvent(QKeyEvent * e) { int x=levelMap_->xpos(); int y=levelMap_->ypos(); switch (e->key()) { case Qt::Key_Up: if (e->state() & Qt::ControlModifier) step(x, 0); else if (e->state() & Qt::ShiftModifier) push(x, 0); else push(x, y-1); break; case Qt::Key_Down: if (e->state() & Qt::ControlModifier) step(x, MAX_Y); else if (e->state() & Qt::ShiftModifier) push(x, MAX_Y); else push(x, y+1); break; case Qt::Key_Left: if (e->state() & Qt::ControlModifier) step(0, y); else if (e->state() & Qt::ShiftModifier) push(0, y); else push(x-1, y); break; case Qt::Key_Right: if (e->state() & Qt::ControlModifier) step(MAX_X, y); else if (e->state() & Qt::ShiftModifier) push(MAX_X, y); else push(x+1, y); break; case Qt::Key_Q: KApplication::kApplication()->closeAllWindows(); break; case Qt::Key_Backspace: case Qt::Key_Delete: if (e->state() & Qt::ControlModifier) redo(); else undo(); break; #if 0 case Qt::Key_X: levelMap_->random(); levelChange(); repaint(false); break; case Qt::Key_R: level(levelMap_->level()); return; break; case Qt::Key_N: nextLevel(); return; break; case Qt::Key_P: previousLevel(); return; break; case Qt::Key_U: undo(); return; break; case Qt::Key_I: history_->redo(levelMap_); repaint(false); return; break; case Qt::Key_S: { QString buf; history_->save(buf); printf("%s\n", (char *) buf); } return; break; case Qt::Key_L: stopMoving(); history_->clear(); level(levelMap_->level()); { char buf[4096]="r1*D1*D1*r1*@r1*D1*"; //scanf("%s", buf); history_->load(levelMap_, buf); } updateStepsXpm(); updatePushesXpm(); repaint(false); return; break; #endif case Qt::Key_Print: HtmlPrinter::printHtml(levelMap_); break; default: e->ignore(); return; break; } }
void GameState::restartLevel() { m_level--; nextLevel(); }
bool gameLoop() { initLevelManager(); loadLevel(g_LevelManager, 0); initHUD(); bool done = false; int moveStartTime = SDL_GetTicks(); while(!done) { int startTime = SDL_GetTicks(); // handle game lose situation (timer has run out, eaten by monster) // now handled in cLevelManager::update() SDL_Event event; while(SDL_PollEvent(&event)) { //check for messages switch(event.type) { case SDL_QUIT: done = true; break; //check for keypresses case SDL_KEYDOWN: { //handle keypresses switch(event.key.keysym.sym) { case SDLK_ESCAPE: g_LevelManager.stop(); done = true; return true; break; case SDLK_m: g_LevelManager.stop(); done = true; return false; break; case SDLK_r: g_LevelManager.endLevel(); moveStartTime = SDL_GetTicks(); loadLevel(g_LevelManager, g_LevelManager.getCurrentLevel()); break; case SDLK_n: nextLevel(); moveStartTime = SDL_GetTicks(); break; case SDLK_p: prevLevel(); moveStartTime = SDL_GetTicks(); break; default: g_InputManager.updateKey(event.key.keysym.sym); break; } } } //end switch } //end of message processing //autoplay routine (if level autoplay enabled) if(g_LevelManager.activeLevel()->autoPlay()) { if(g_LevelManager.activePlayer()->moveNumber() < g_LevelManager.activePlayer()->movesSize()) { int moveCheckTime = SDL_GetTicks(); if(moveCheckTime - moveStartTime >= 300) { g_InputManager.update(); moveStartTime = moveCheckTime; } } } g_InputManager.autoUpdate(); //do game update /*****update graphics*****/ //clear screen SDL_FillRect(screen,0,SDL_MapRGB(screen->format,0,0,0)); //SDL_FillRect(display,0,SDL_MapRGB(display->format,0,0,0)); //draw image g_RenderManager.update(); int endTime = SDL_GetTicks(); if(endTime - startTime < 1000/fps) SDL_Delay(1000/fps - (endTime - startTime)); //end frame SDL_Flip(screen); //level win now handled in cLevelManager::update() if(g_LevelManager.checkWin()) { done = true; return false; } /* if(levelWon()) { nextLevel(); } */ } return done; //do exit }
SeaScene::SeaScene(QObject *parent) : QGraphicsScene(parent) { setItemPointersNull(); paused_ = false; screenLitKeeper_.keepScreenLit(true); QSettings settings; //set background QPixmap waves (":/pix/meri.png"); waves.scaled(20,20); setBackgroundBrush(QBrush(waves)); //set random seed qsrand(QTime::currentTime().msec()+2); //+2 to avoid setting it to 1 //Setup level sets QList<Level> levelList; Level level1(5,10); levelList.append(level1); Level level2(5,10,2,50); levelList.append(level2); Level level3(5,15,2,50); levelList.append(level3); Level level4(5,15,4,50); levelList.append(level4); Level level5(5,15,5,100); levelList.append(level5); Levelset set ("Original",levelList); availableLevelsets_.append(set); //Create another set of levels and place it in the available levelsets list levelList.clear(); Level set2level1(8,15,4,50); levelList.append(set2level1); Level set2level2(8,20,4,50); levelList.append(set2level2); Level set2level3(8,20,5,80); levelList.append(set2level3); Level set2level4(8,20,6,120); levelList.append(set2level4); Level set2level5(8,25,8,150); levelList.append(set2level5); Levelset set2("Difficult",levelList); availableLevelsets_.append(set2); //Setup starting levelset QString levelname = settings.value("levelset","Original").toString(); bool found = false; foreach (Levelset levelset, availableLevelsets_) { if (levelset.getName() == levelname) { levelset_ = levelset; found = true; break; } } if (!found) //The last used level is not available { levelset_ = availableLevelsets_.value(0); } currentLevel_ = 0; totalScore_ = 0; connect(this,SIGNAL(allGhostsPicked()),this,SLOT(nextLevel())); pVibrateAction_ = new QAction(tr("Vibration effects"),this); pVibrateAction_->setCheckable(true); connect(pVibrateAction_,SIGNAL(toggled(bool)),this,SLOT(vibrationActivate(bool))); pVibrateAction_->setChecked(settings.value("vibration",false).toBool()); pPauseAction_ = new QAction(tr("Pause"),this); pPauseAction_->setCheckable(true); connect(pPauseAction_,SIGNAL(toggled(bool)),this,SLOT(pause(bool))); deviceLockPollTimer_.setInterval(20*60); connect(&deviceLockPollTimer_,SIGNAL(timeout()),this,SLOT(pollDeviceLocked())); deviceLockPollTimer_.start(); autopauseTimer.setSingleShot(true); autopauseTimer.setInterval(15*60*1000); connect(&autopauseTimer,SIGNAL(timeout()),this,SLOT(turnPauseOn())); }