Commit 92b17904 authored by Frederik Schwarzer's avatar Frederik Schwarzer

Use KgSound + add actual crash sound.

parent 5f923e5d
install(FILES
DESTINATION ${KDE_INSTALL_DATADIR}/bomber/sounds)
install(FILES crash.ogg
DESTINATION ${KDE_INSTALL_DATADIR}/bomber/sounds)
......@@ -258,6 +258,7 @@ void BomberBoard::crashed()
m_plane->setPosition(pos.x() + 1, pos.y());
m_plane->setState(Plane::State::Exploding);
QTimer::singleShot(PLANE_EXPLODE_TIME, this, SLOT(planeExploded()));
emit playCrashSound();
}
void BomberBoard::clear()
......
......@@ -103,6 +103,8 @@ signals:
*/
void onPlaneCrash();
void playCrashSound();
/**
* This signal is emitted when a bomb hits a building and before it's exploding
* animation starts
......
......@@ -87,6 +87,7 @@ void Bomber::initXMLUI()
KStandardAction::preferences(m_selector, SLOT(showAsDialog()), actionCollection());
m_soundAction = new KToggleAction(i18nc("Menu item used to disable or enable sound", "&Play Sounds"), this);
actionCollection()->addAction(QLatin1String("toggle_sound"), m_soundAction);
connect(m_soundAction, &KToggleAction::triggered, m_gameWidget, &BomberGameWidget::setSoundsEnabled);
QAction *dropBombAction = actionCollection()->addAction(QLatin1String("drop_bomb"));
dropBombAction->setText(i18nc("The name of the action used for dropping bombs", "&Drop bomb"));
......
......@@ -38,10 +38,11 @@ static const unsigned int OVERLAY_Z_VALUE = 1000;
BomberGameWidget::BomberGameWidget(KgThemeProvider *provider, QWidget *parent) :
QGraphicsView(parent), m_state(State::BeforeFirstGame), m_level(0), m_lives(0), m_time(0),
m_renderer(provider)
m_renderer(provider), m_soundCrash((QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("bomber/sounds/crash.ogg"))))
{
// Gameboard
m_board = new BomberBoard(&m_renderer, this, this);
connect(m_board, &BomberBoard::playCrashSound, this, &BomberGameWidget::playCrashSound);
connect(m_board, &BomberBoard::onPlaneCrash, this, &BomberGameWidget::onPlaneCrashed);
connect(m_board, &BomberBoard::onBombHit, this, &BomberGameWidget::onBombHit);
connect(m_board, &BomberBoard::levelCleared, this, &BomberGameWidget::onLevelCleared);
......@@ -145,6 +146,12 @@ void BomberGameWidget::settingsChanged()
m_board->settingsChanged();
}
void BomberGameWidget::setSoundsEnabled(bool enable)
{
BomberSettings::setPlaySounds(enable);
BomberSettings::self()->save();
m_board->settingsChanged();
}
void BomberGameWidget::onPlaneCrashed()
{
......@@ -155,6 +162,9 @@ void BomberGameWidget::onPlaneCrashed()
} else {
m_board->resetPlane();
}
if (BomberSettings::playSounds() == true) {
m_soundCrash.stop();
}
}
void BomberGameWidget::onBombHit()
......@@ -170,6 +180,13 @@ void BomberGameWidget::onBombHit()
}
}
void BomberGameWidget::playCrashSound()
{
if (BomberSettings::playSounds() == true) {
m_soundCrash.start();
}
}
void BomberGameWidget::tick()
{
static signed int ticks = TICKS_PER_SECOND;
......
......@@ -25,6 +25,8 @@
#include <QGraphicsView>
#include <QMouseEvent>
#include <KgSound>
class KgThemeProvider;
/**
......@@ -84,6 +86,11 @@ public slots:
*/
void settingsChanged();
/**
* Enabled or disabled the sounds
* \param enable True to enable the sounds, false to disable
*/
void setSoundsEnabled(bool enable);
/**
* Used to toggle the suspended game state. If val is true and the state is currently running,
......@@ -168,6 +175,8 @@ private:
void closeLevel();
void newLevel();
void playCrashSound();
State m_state;
unsigned int m_level;
unsigned int m_score;
......@@ -183,6 +192,7 @@ private:
BomberBoard *m_board;
QGraphicsPixmapItem *m_overlay;
KgSound m_soundCrash;
};
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment