[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: playground/games/granatier/src
From: Mathias Kraus <k.hias () gmx ! de>
Date: 2009-09-26 7:44:52
Message-ID: 1253951092.920813.7292.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 1028190 by mkraus:
now the game has a round time and after the time expired, bombs are dropped at random \
places. this will keep lazy players moving *evil laughing*
M +71 -0 game.cpp
M +22 -0 game.h
M +39 -14 gamescene.cpp
M +1 -0 gamescene.h
M +43 -13 generalsettings.ui
M +4 -0 granatier.kcfg
M +1 -1 mainwindow.cpp
--- trunk/playground/games/granatier/src/game.cpp #1028189:1028190
@@ -64,6 +64,8 @@
soundBufferWilhelmScream = new KALBuffer(KStandardDirs::locate("appdata", \
"sounds/wilhelmscream.ogg")); soundDie = new KALSound(soundBufferDie, soundEngine);
soundWilhelmScream = new KALSound(soundBufferWilhelmScream, soundEngine);
+ gluonDieTimer = new QTimer(this);
+ gluonDieTimer->setSingleShot(true);
#else
for(int i = 0; i < 3; i++)
{
@@ -126,6 +128,7 @@
m_arena = new Arena();
m_roundFinished = 0;
+ m_remainingTime = Settings::roundTime();
// Create the parser that will parse the XML file in order to initialize the \
Arena instance // This also creates all the characters
@@ -151,6 +154,11 @@
m_timer->start();
m_state = RUNNING;
+ m_roundTimer = new QTimer(this);
+ m_roundTimer->setInterval(1000);
+ connect(m_roundTimer, SIGNAL(timeout()), this, \
SLOT(decrementRemainingRoundTime())); + m_roundTimer->start();
+
// Init the characters coordinates on the Arena
for (int i = 0; i < m_players.size(); i++)
{
@@ -182,6 +190,7 @@
delete soundDie;
delete soundBufferWilhelmScream;
delete soundBufferDie;
+ delete gluonDieTimer;
#else
while(!(m_phononPutBomb.isEmpty()))
{
@@ -215,6 +224,8 @@
m_arena = 0;
delete m_timer;
m_timer = 0;
+ delete m_roundTimer;
+ m_roundTimer = 0;
}
void Game::setGameScene(GameScene* p_gameScene)
@@ -227,6 +238,7 @@
// Restart the Game timer
m_timer->start();
m_state = RUNNING;
+ m_roundTimer->start();
emit(pauseChanged(false, false));
}
@@ -234,6 +246,7 @@
{
// Stop the Game timer
m_timer->stop();
+ m_roundTimer->stop();
if (p_locked)
{
m_state = PAUSED_LOCKED;
@@ -273,6 +286,11 @@
return m_timer;
}
+int Game::getRemainingTime() const
+{
+ return m_remainingTime;
+}
+
Arena* Game::getArena() const
{
return m_arena;
@@ -401,6 +419,7 @@
{
// At the beginning, the timer is stopped but the Game isn't paused (to \
allow keyPressedEvent detection) m_timer->stop();
+ m_roundTimer->stop();
m_state = RUNNING;
// Initialize the Player coordinates
for(int i = 0; i < m_players.size(); i++)
@@ -439,6 +458,7 @@
{
// Start the game
m_timer->start();
+ m_roundTimer->start();
emit(gameStarted());
}
else if (m_state == PAUSED_LOCKED)
@@ -506,6 +526,52 @@
}
}
+void Game::decrementRemainingRoundTime()
+{
+ m_remainingTime--;
+ if(m_remainingTime >= 0)
+ {
+ emit(infoChanged(TimeInfo));
+ }
+ else
+ {
+ if(m_remainingTime % 2 == 0)
+ {
+ //create bombs at randoms places
+ int nRow;
+ int nCol;
+ bool bFound = false;
+ do
+ {
+ nRow = m_arena->getNbRows() * (qrand()/1.0)/RAND_MAX;
+ nCol = m_arena->getNbColumns() * (qrand()/1.0)/RAND_MAX;
+ if(m_arena->getCell(nRow, nCol).getType() == Cell::GROUND)
+ {
+ if(m_arena->getCell(nRow, nCol).getElement() == 0 || \
m_arena->getCell(nRow, nCol).getElement()->getType() != Element::BLOCK) + \
{ + bFound = true;
+ }
+ }
+ }
+ while (!bFound);
+
+ Bomb* bomb = new Bomb((nCol + 0.5) * Cell::SIZE, (nRow + 0.5) * \
Cell::SIZE, m_arena, 1000); // time in ms + bomb->setBombRange(1);
+ emit bombCreated(bomb);
+ connect(bomb, SIGNAL(bombDetonated(Bomb*)), this, \
SLOT(bombDetonated(Bomb*))); + m_bombs.append(bomb);
+ if(m_remainingTime > -100 && m_roundTimer->interval() > 150)
+ {
+ m_roundTimer->setInterval(m_roundTimer->interval() + \
m_remainingTime); + }
+ else if (m_roundTimer->interval() > 40)
+ {
+ m_roundTimer->setInterval(m_roundTimer->interval() - 1);
+ }
+ }
+ }
+}
+
void Game::playerDeath(Player* player)
{
//wait some time until the game stops
@@ -514,6 +580,10 @@
if(m_soundEnabled)
{
#ifdef GRANATIER_USE_GLUON
+ if(gluonDieTimer->isActive())
+ {
+ return;
+ }
if(m_wilhelmScream)
{
soundWilhelmScream->play();
@@ -522,6 +592,7 @@
{
soundDie->play();
}
+ gluonDieTimer->start(10);
#else
qint64 nLastRemainingTime;
int nIndex = 0;
--- trunk/playground/games/granatier/src/game.h #1028189:1028190
@@ -73,6 +73,9 @@
/** The Game main timer */
QTimer* m_timer;
+ /** The Round timer */
+ QTimer* m_roundTimer;
+
/** The gamecene */
GameScene* m_gameScene;
@@ -97,6 +100,9 @@
/** The points which are needed to win */
int m_winPoints;
+ /** The remaining time for a round */
+ int m_remainingTime;
+
/** Flag if the round is over */
int m_roundFinished;
@@ -121,6 +127,7 @@
KALBuffer* soundBufferDie;
KALBuffer* soundBufferWilhelmScream;
KALSound* soundDie;
+ QTimer* gluonDieTimer;
KALSound* soundWilhelmScream;
#else
/** Use Phonon for sound */
@@ -203,6 +210,11 @@
QTimer* getTimer() const;
/**
+ * @return the remaining round time
+ */
+ int getRemainingTime() const;
+
+ /**
* @return true if the Game is paused, false otherwise
*/
bool isPaused() const;
@@ -302,6 +314,11 @@
*/
void bombDetonated(Bomb* bomb);
+ /**
+ * Decrement the remaining round time
+ */
+ void decrementRemainingRoundTime();
+
signals:
/**
@@ -331,6 +348,11 @@
* Emitted when a bomb was removed.
*/
void bombRemoved(Bomb* bomb);
+
+ /**
+ * Emitted when something to display has changed.
+ */
+ void infoChanged(const Game::InformationTypes p_info);
};
#endif
--- trunk/playground/games/granatier/src/gamescene.cpp #1028189:1028190
@@ -43,6 +43,7 @@
connect(p_game, SIGNAL(gameStarted()), this, SLOT(start()));
connect(p_game, SIGNAL(pauseChanged(bool, bool)), this, SLOT(setPaused(bool, \
bool)));
connect(p_game, SIGNAL(bombCreated(Bomb*)), this, SLOT(createBombItem(Bomb*)));
+ connect(p_game, SIGNAL(infoChanged(Game::InformationTypes)), this, \
SLOT(updateInfo(const Game::InformationTypes)));
// Set the pixmap cache limit to improve performance
setItemIndexMethod(NoIndex);
@@ -97,25 +98,22 @@
m_pauseLabel->setFont(QFont("Helvetica", 35, QFont::Bold, false));
m_pauseLabel->setDefaultTextColor(QColor("#FFFF00"));
m_pauseLabel->setZValue(1001);
-
+ // The remaining time
+ m_remainingTime = new QGraphicsTextItem(i18n("0:00"));
+ m_remainingTime->setFont(QFont("Helvetica", 15, QFont::Bold, false));
+ m_remainingTime->setDefaultTextColor(QColor("#FFFF00"));
+ m_remainingTime->setZValue(0);
+
// Display each PlayerItem
for (int i = 0; i < m_playerItems.size(); i++)
{
addItem(m_playerItems[i]);
}
- // Initialize the information labels (score, lives and label)
- // Display the score label
- //addItem(m_scoreLabel);
- //m_scoreLabel->setPos(Cell::SIZE, height() + Cell::SIZE);
- // Display the lives label
- //addItem(m_livesLabel);
- //m_livesLabel->setPos(width() - m_livesLabel->boundingRect().width() - 20 , \
height() - Cell::SIZE - m_livesLabel->boundingRect().height() / 2);
- // Display the level label
- //addItem(m_levelLabel);
- //m_levelLabel->setPos((width() - m_levelLabel->boundingRect().width()) / 2 , \
height() - Cell::SIZE - m_levelLabel->boundingRect().height() / 2);
-
init();
+
+ setSceneRect(sceneRect().x(), sceneRect().y() - \
m_remainingTime->boundingRect().height(), sceneRect().width(), sceneRect().height() + \
m_remainingTime->boundingRect().height()); + \
m_dimmOverlay->setRect(sceneRect().x(), sceneRect().y(), width(), height()); }
void GameScene::init()
@@ -248,11 +246,19 @@
}
m_introLabel2->setPos((width() - m_introLabel2->boundingRect().width()) / 2, \
(height() - m_introLabel2->boundingRect().height() + \
m_introLabel->boundingRect().height()) / 2);
+ if (!items().contains(m_remainingTime))
+ {
+ addItem(m_remainingTime);
+ }
+ m_remainingTime->setDefaultTextColor(QColor("#FFFF00"));
+ int nTime = m_game->getRemainingTime();
+ m_remainingTime->setPlainText(QString("%1:%2").arg(nTime/60).arg(nTime%60, 2, \
10, QChar('0'))); + m_remainingTime->setPos((width() - \
m_remainingTime->boundingRect().width()), - \
m_remainingTime->boundingRect().height()); +
if (!items().contains(m_dimmOverlay))
{
addItem(m_dimmOverlay);
}
- m_dimmOverlay->setRect(0, 0, width(), height());
}
GameScene::~GameScene()
@@ -273,6 +279,7 @@
delete m_introLabel2;
delete m_introLabel3;
delete m_pauseLabel;
+ delete m_remainingTime;
delete m_dimmOverlay;
delete m_cache;
@@ -361,6 +368,10 @@
{
removeItem(m_introLabel3);
}
+ if(items().contains(m_remainingTime))
+ {
+ removeItem(m_remainingTime);
+ }
}
void GameScene::showScore(int p_winPoints)
@@ -445,7 +456,7 @@
{
addItem(m_dimmOverlay);
}
- m_dimmOverlay->setRect(0, 0, width(), height());
+ m_dimmOverlay->setRect(sceneRect().x(), sceneRect().y(), width(), height());
// Stop player animation
for (int i = 0; i < m_playerItems.size(); i++)
{
@@ -511,6 +522,20 @@
void GameScene::updateInfo(const Game::InformationTypes p_info)
{
+ if(p_info == Game::TimeInfo)
+ {
+ int nTime = m_game->getRemainingTime();
+ if(nTime > 0)
+ {
+ m_remainingTime->setPlainText(QString("%1:%2").arg(nTime/60).arg(nTime%60, \
2, 10, QChar('0'))); + }
+ else
+ {
+ m_remainingTime->setPlainText("Sudden Death");
+ m_remainingTime->setDefaultTextColor(QColor("#FF0000"));
+ m_remainingTime->setPos((width() - \
m_remainingTime->boundingRect().width()), - \
m_remainingTime->boundingRect().height()); + }
+ }
}
void GameScene::createBombItem(Bomb* bomb)
--- trunk/playground/games/granatier/src/gamescene.h #1028189:1028190
@@ -74,6 +74,7 @@
QGraphicsTextItem* m_introLabel2;
QGraphicsTextItem* m_introLabel3;
QGraphicsTextItem* m_pauseLabel;
+ QGraphicsTextItem* m_remainingTime;
/** The pixmap cache */
KPixmapCache* m_cache; //TODO: check if the cache is used
--- trunk/playground/games/granatier/src/generalsettings.ui #1028189:1028190
@@ -7,28 +7,31 @@
<x>0</x>
<y>0</y>
<width>388</width>
- <height>63</height>
+ <height>141</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
- <item row="0" column="0">
- <widget class="QLabel" name="label_2">
- <property name="text">
- <string>Points to win the game</string>
- </property>
- </widget>
- </item>
- <item row="0" column="1">
- <widget class="QSpinBox" name="kcfg_PointsToWin"/>
- </item>
- <item row="0" column="2">
+ <item row="0" column="2" rowspan="3">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>0</width>
+ <height>20</height>
+ </size>
+ </property>
</spacer>
</item>
- <item row="1" column="0" colspan="3">
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_3">
+ <property name="text">
+ <string>Round Time in Seconds</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="0" colspan="3">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
@@ -41,6 +44,33 @@
</property>
</spacer>
</item>
+ <item row="0" column="1" rowspan="2">
+ <widget class="QSpinBox" name="kcfg_PointsToWin">
+ <property name="minimum">
+ <number>1</number>
+ </property>
+ <property name="maximum">
+ <number>20</number>
+ </property>
+ </widget>
+ </item>
+ <item row="2" column="1">
+ <widget class="QSpinBox" name="kcfg_RoundTime">
+ <property name="minimum">
+ <number>30</number>
+ </property>
+ <property name="maximum">
+ <number>600</number>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="0" rowspan="2">
+ <widget class="QLabel" name="label_2">
+ <property name="text">
+ <string>Points to win the game</string>
+ </property>
+ </widget>
+ </item>
</layout>
</widget>
<resources/>
--- trunk/playground/games/granatier/src/granatier.kcfg #1028189:1028190
@@ -21,6 +21,10 @@
<label>The points a user needs to win the game.</label>
<default>3</default>
</entry>
+ <entry name="RoundTime" type="Int" key="RoundTime">
+ <label>Time for a round.</label>
+ <default>180</default>
+ </entry>
<entry name="Sounds" type="Bool" key="Sounds">
<label>Whether sound effects should be played.</label>
<default>true</default>
--- trunk/playground/games/granatier/src/mainwindow.cpp #1028189:1028190
@@ -172,7 +172,7 @@
// Player
settingsDialog->addPage(new PlayerSelector(settingsDialog, m_playerSettings), \
i18n("Player"), "games-config-custom");
- connect(settingsDialog, SIGNAL(settingsChanged(const QString&)), this, \
SLOT(loadSettings())); + connect(settingsDialog, SIGNAL(settingsChanged(const \
QString&)), this, SLOT(applyNewSettings()));
connect(settingsDialog, SIGNAL(cancelClicked()), this, \
SLOT(settingsDialogCanceled())); settingsDialog->show();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic