Commit 88b6d9e1 authored by Ian Wadham's avatar Ian Wadham

Re-connect the sound effects, which were disconnected temporarily during development for KDE 4.3.

svn path=/trunk/KDE/kdegames/kgoldrunner/; revision=987440
parent fbe54360
......@@ -380,13 +380,11 @@ void KGoldrunner::setupActions()
// Sound effects on/off
#ifdef ENABLE_SOUND_SUPPORT
KToggleAction * setSounds = settingAction ("options_sounds", PLAY_SOUNDS,
settingAction ("options_sounds", PLAY_SOUNDS,
i18n ("&Play Sounds"),
i18n ("Play sound effects."),
i18n ("Play sound effects during the game."));
bool soundOnOff = gameGroup.readEntry ("Sound", false);
setSounds->setChecked (soundOnOff);
// Sounds and Checked state are further initialised in game->initGame().
#endif
// Demo at start on/off.
......
......@@ -82,6 +82,7 @@ KGrGame::KGrGame (KGrCanvas * theView,
demoType (DEMO),
startupDemo (false),
programFreeze (false),
effects (0),
fx (NumSounds),
editor (0)
{
......@@ -91,8 +92,6 @@ KGrGame::KGrGame (KGrCanvas * theView,
gameFrozen = false;
loadSounds();
dyingTimer = new QTimer (this);
connect (dyingTimer, SIGNAL (timeout()), SLOT (finalBreath()));
......@@ -422,6 +421,15 @@ void KGrGame::initGame()
n++;
}
// Set up sounds, if required in config.
bool soundOnOff = gameGroup.readEntry ("Sound", false);
kDebug() << "Sound" << soundOnOff;
if (soundOnOff) {
loadSounds();
effects->setMuted (false);
}
emit setToggle ("options_sounds", soundOnOff);
dbk1 << "Owner" << gameList.at (gameIndex)->owner
<< gameList.at (gameIndex)->name << level;
......@@ -831,26 +839,30 @@ void KGrGame::setupLevelPlayer()
void KGrGame::incScore (const int n)
{
#ifdef ENABLE_SOUND_SUPPORT
// I don't think this is the right place, but it's just for testing...
switch (n) {
case 250:
effects->play (fx[GoldSound]);
break;
default:
break;
}
#endif
score = score + n; // SCORING: trap enemy 75, kill enemy 75,
emit showScore (score); // collect gold 250, complete the level 1500.
}
void KGrGame::showHiddenLadders()
void KGrGame::playSound (const int n, const bool onOff)
{
// TODO - Move this line to KGrLevelPlayer.
effects->play (fx[LadderSound]);
#ifdef ENABLE_SOUND_SUPPORT
if (! effects) {
return; // Sound is off and not yet loaded.
}
static int fallToken = -1;
if (onOff) {
int token = effects->play (fx [n]);
if (n == FallSound) {
fallToken = token;
}
}
else {
effects->stop (fallToken);
fallToken = -1;
}
#endif
}
void KGrGame::endLevel (const int result)
{
dbk << "Return to KGrGame, result:" << result;
......@@ -898,24 +910,23 @@ void KGrGame::herosDead()
// Lose a life.
if ((--lives > 0) || playback) {
#ifdef ENABLE_SOUND_SUPPORT
effects->play (fx[DeathSound]);
#endif
// Demo mode or still some life left.
emit showLives (lives);
// Freeze the animation and let the player see what happened.
freeze (ProgramPause, true);
playSound (DeathSound);
dyingTimer->setSingleShot (true);
dyingTimer->start (1000);
}
else {
// Game over.
#ifdef ENABLE_SOUND_SUPPORT
effects->play (fx[GameOverSound]);
#endif
emit showLives (lives);
freeze (ProgramPause, true);
playSound (GameOverSound);
checkHighScore(); // Check if there is a high score for this game.
// Offer the player a chance to start this level again with 5 new lives.
......@@ -968,9 +979,8 @@ void KGrGame::repeatLevel()
void KGrGame::levelCompleted()
{
#ifdef ENABLE_SOUND_SUPPORT
effects->play (fx[CompletedSound]);
#endif
playSound (CompletedSound);
dbk << "Connecting fadeFinished()";
connect (view, SIGNAL (fadeFinished()), this, SLOT (goUpOneLevel()));
dbk << "Calling view->fadeOut()";
......@@ -992,6 +1002,8 @@ void KGrGame::goUpOneLevel()
if (level >= levelMax) {
KGrGameData * gameData = gameList.at (gameIndex);
freeze (ProgramPause, true);
playSound (VictorySound);
KGrMessage::information (view, gameData->name,
i18n ("<b>CONGRATULATIONS !!!!</b>"
"<p>You have conquered the last level in the "
......@@ -1061,6 +1073,9 @@ void KGrGame::toggleSoundsOnOff()
soundOnOff = (! soundOnOff);
gameGroup.writeEntry ("Sound", soundOnOff);
#ifdef ENABLE_SOUND_SUPPORT
if (soundOnOff && (effects == 0)) {
loadSounds();
}
effects->setMuted (! soundOnOff);
#endif
}
......@@ -1780,37 +1795,6 @@ void KGrGame::dbgControl (const int code)
}
}
/******************************************************************************/
/**************************** MISC SOUND HANDLING ***************************/
/******************************************************************************/
void KGrGame::heroDigs()
{
effects->play (fx[DigSound]);
}
void KGrGame::heroStep (bool climbing)
{
if (climbing) {
effects->play (fx[ClimbSound]);
}
else {
effects->play (fx[StepSound]);
}
}
void KGrGame::heroFalls (bool starting)
{
static int token = -1;
if (starting) {
token = effects->play (fx[FallSound]);
}
else {
effects->stop (token);
token = -1;
}
}
bool KGrGame::initGameLists()
{
// Initialise the lists of games (i.e. collections of levels).
......@@ -2091,11 +2075,6 @@ void KGrGame::loadSounds()
"themes/default/death.wav"));
fx[GameOverSound] = effects->loadSound (KStandardDirs::locate ("appdata",
"themes/default/gameover.wav"));
// REPLACE - 9/1/09 Hero's sound connections.
// connect(hero, SIGNAL (stepDone (bool)), this, SLOT (heroStep (bool)));
// connect(hero, SIGNAL (falling (bool)), this, SLOT (heroFalls (bool)));
// connect(hero, SIGNAL (digs()), this, SLOT (heroDigs()));
#endif
}
......
......@@ -67,6 +67,9 @@ public slots:
void incScore (const int n); // Update the score.
// Play or stop sound. Default is play: only FallSound can be stopped.
void playSound (const int n, const bool onOff = true);
private:
void quickStartDialog();
......@@ -106,8 +109,6 @@ private:
QString getDirectory (Owner o);
void showHiddenLadders(); // Show hidden ladders (nuggets gone).
void herosDead(); // Hero was caught or he quit (key Q).
void levelCompleted(); // Hero completed the level.
......@@ -129,10 +130,6 @@ private slots:
void repeatLevel(); // Hero is dead: repeat the level.
void goUpOneLevel(); // Start next level.
void heroStep (bool climbing); // The hero has put a foot on the floor.
void heroFalls (bool startStop); // The hero has started/stopped falling.
void heroDigs(); // The hero is digging.
signals:
// These signals go to the GUI in most cases.
void showScore (long); // For main window to show the score.
......@@ -220,18 +217,6 @@ private:
/******************************* SOUND SUPPORT *******************************/
/******************************************************************************/
KGrSoundBank * effects;
enum {
GoldSound,
StepSound,
ClimbSound,
FallSound,
DigSound,
LadderSound,
DeathSound,
CompletedSound,
VictorySound,
GameOverSound,
NumSounds };
QVector<int> fx;
public slots:
......
......@@ -23,7 +23,7 @@
#include <QByteArray>
#include <QString>
// #define ENABLE_SOUND_SUPPORT // Ian W. moved it here - 31 May 2008.
#define ENABLE_SOUND_SUPPORT // Ian W. moved it here - 31 May 2008.
enum Owner {SYSTEM, USER};
......@@ -48,14 +48,10 @@ const char EDIT_TEST = '2';
const int FIELDWIDTH = 28;
const int FIELDHEIGHT = 20;
const int DIGDELAY = 200;
const int STEP = 4;
const int gameCycle = 4; // Animation frames per playfield tile.
const int graphicsCycle = 8; // Animation frames per running cycle.
const double DROPNUGGETDELAY = 70.0; // Enemy holds gold for avg. 12.5 cells.
// Keyboard action codes
enum KBAction {KB_UP, KB_DOWN, KB_LEFT, KB_RIGHT,
KB_DIGLEFT, KB_DIGRIGHT, KB_STOP};
......@@ -70,6 +66,10 @@ const char TraditionalRules = 'T';
const char KGoldrunnerRules = 'K';
const char ScavengerRules = 'S';
// Codes and array indices for the sounds of the game.
enum {GoldSound, StepSound, ClimbSound, FallSound, DigSound, LadderSound,
DeathSound, CompletedSound, VictorySound, GameOverSound, NumSounds};
/// Centralised message functions: implementations in kgrdialog.cpp.
class QWidget;
class KGrMessage
......
......@@ -255,6 +255,10 @@ void KGrLevelPlayer::init (KGrCanvas * view, const int mode,
game, SLOT (incScore (const int)));
}
// Connect the sounds.
connect (hero, SIGNAL (soundSignal (const int, const bool)),
game, SLOT (playSound (const int, const bool)));
// Connect the level player to the animation code (for use with dug bricks).
connect (this, SIGNAL (startAnimation (int, bool, int, int, int,
Direction, AnimationType)),
......
......@@ -245,12 +245,24 @@ HeroStatus KGrHero::run (const int scaledTime)
return NORMAL;
}
if ((currDirection != STAND) && (! falling)) {
int step = ((currAnimation == RUN_R) || (currAnimation == RUN_L)) ?
StepSound : ClimbSound;
emit soundSignal (step);
}
// Continue to the next cell.
char cellType = nextCell();
if (cellType == NUGGET) {
nuggets = levelPlayer->runnerGotGold (spriteId, gridI, gridJ, true);
emit incScore (250); // Add to the human player's score.
if (nuggets > 0) {
emit soundSignal (GoldSound);
}
else {
emit soundSignal (LadderSound);
}
}
Direction nextDirection;
......@@ -258,7 +270,7 @@ HeroStatus KGrHero::run (const int scaledTime)
bool newFallingState = setNextMovement (HERO, cellType, nextDirection,
nextAnimation, interval);
if (newFallingState != falling) {
// emit soundSignal (FALLING, newFallingState); // Start/stop falling.
emit soundSignal (FallSound, newFallingState); // Start/stop falling.
falling = newFallingState;
}
timeLeft += interval;
......@@ -317,6 +329,10 @@ bool KGrHero::dig (const Direction diggingDirection, int & i, int & j)
j = gridJ + 1;
result = true;
}
if (true) {
emit soundSignal (DigSound);
}
return result; // Tell the levelPlayer whether & where to open a hole.
}
......
......@@ -211,6 +211,8 @@ public:
*/
void showState();
signals:
void soundSignal (const int n, const bool onOff = true);
private:
int nuggets; // Number of gold pieces remaining.
};
......
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