File indexing completed on 2024-05-12 04:03:07

0001 /*
0002     SPDX-FileCopyrightText: 2007-2008 Fela Winkelmolen <fela.kde@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #include "gameengine.h"
0008 
0009 // own
0010 #include "kbreakout_debug.h"
0011 #include "levelloader.h"
0012 // Qt
0013 #include <QTimer>
0014 #include <QTime>
0015 
0016 GameEngine::GameEngine(QObject *parent)
0017     : QObject(parent)
0018 {
0019     m_levelLoader = new LevelLoader(this);
0020     connect(m_levelLoader, &LevelLoader::newLine, this, &GameEngine::newLine);
0021     connect(m_levelLoader, &LevelLoader::newGift, this, &GameEngine::newGift);
0022 }
0023 
0024 GameEngine::~GameEngine()
0025 {
0026     deleteAllObjects();
0027     delete m_levelLoader;
0028 }
0029 
0030 void GameEngine::start(const QString &l)
0031 {
0032     m_levelLoader->setLevelset(l);
0033     m_levelLoader->setLevel(0);
0034 
0035     Q_EMIT loadingNewGame();
0036 
0037     loadLevel();
0038 }
0039 
0040 void GameEngine::loadLevel()
0041 {
0042     deleteAllObjects();
0043 
0044     m_levelLoader->loadLevel();
0045 
0046     Q_EMIT ready();
0047 }
0048 
0049 void GameEngine::loadNextLevel()
0050 {
0051     QTimer::singleShot(200, this, &GameEngine::loadLevel);
0052 }
0053 
0054 inline void GameEngine::deleteAllObjects()
0055 {
0056     /*qCDebug(KBREAKOUT_General) << "all object deleted";
0057     deleteMovingObjects();
0058     qDeleteAll(m_bricks);
0059     m_bricks.clear();
0060     qDeleteAll(m_gifts);
0061     m_gifts.clear();*/
0062 }
0063 
0064 #include "moc_gameengine.cpp"