void Game::onPelletEaten() { m_score += 10; Level *level = m_levels.at(m_currentLevel); int eatenPellets = level->eatenPellets() +1; level->setEatenPellets(eatenPellets); switch (eatenPellets) { case 30: inky->setFree(true); break; case 80: clyde->setFree(true); break; } }
void Game::nextGameFrame() { static float chaseTimer = 0.0; static QTime lastFrameTime; if(!lastFrameTime.isNull()) { chaseTimer += lastFrameTime.msecsTo(QTime::currentTime())/1000.0; } lastFrameTime = QTime::currentTime(); Level *level = m_levels.at(m_currentLevel); // Mouvements QList<Ghost*> collision; level->movePacman(); level->moveGhosts(); collision.append(level->checkUnitsPositions()); level->updateTimer(); // if(level->eatenPellets() == level->pelletCount()) { m_timer->stop(); m_currentLevel++; if(m_currentLevel == m_levels.size()) { m_victory = true; emit gameFinished(); return; } else { m_isChangingLevel = true; m_currentLevelImageReady = false; Level *level = m_levels.at(m_currentLevel); level->startLevel(); return; } } if(collision.size() > 0) { if(!Ghost::areGhostsScared()) { m_lifes--; if(m_lifes>0) { level->resetUnitsPosition(); } else { m_defeat = true; emit gameFinished(); return; } m_timer->stop(); } else { for(int i=0; i<collision.size(); i++) { m_score += 200 * qPow(2, m_consecutivesEnergizers); m_consecutivesEnergizers ++; QTimer::singleShot(500, this, SLOT(resumeGame())); m_timer->stop(); } } } if(!Ghost::areGhostsScared()) m_consecutivesEnergizers = 0; QPixmap *image = level->render(); m_image = *image; delete image; m_currentLevelImageReady = true; }