Skip to content

Commit

Permalink
Merge pull request #49 from yorugac/letter_sounds
Browse files Browse the repository at this point in the history
#38 add playing letter sound with a delay during pickup
  • Loading branch information
Jo Grimstad authored May 29, 2017
2 parents f4a220a + e9d9046 commit ac93269
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 5 deletions.
17 changes: 16 additions & 1 deletion VoltAir/logics/PickupLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "LevelProgression.h"
#include "PickupLogic.h"
#include "inputs/PlayerManager.h"
#include <QTimer>

void PickupLogic::setPickupValue(int value) {
mPickupValue = value;
Expand All @@ -40,6 +41,12 @@ void PickupLogic::setPickupSound(const QString& value) {
emit pickupSoundChanged();
}

void PickupLogic::setEchoSound(const QString& value) {
mEchoSound = value;
mEchoSoundInstance.reset(Engine::getInstance()->getSoundManager()->getSoundEffect(value));
emit echoSoundChanged();
}

void PickupLogic::reset() {
mPickedUp = false;
}
Expand Down Expand Up @@ -90,12 +97,20 @@ void PickupLogic::onPickupContacted(Body* otherBody, QPointF) {
game->updatePlayerScore(playerId, mPickupValue);
}

// Play the audio sound
// Play the audio sounds
mPickupSoundInstance.play();

if(!mEchoSound.isEmpty()) {
QTimer::singleShot(200, this, SLOT(playEcho()));
}

emit collected(otherActor);
} else if (mAllowNonPlayerPickup && !otherBody->isSensor()) {
mPickedUp = true;
emit collected(otherActor);
}
}

void PickupLogic::playEcho() {
mEchoSoundInstance.play();
}
23 changes: 23 additions & 0 deletions VoltAir/logics/PickupLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ class PickupLogic : public Logic {
Q_PROPERTY(QString pickupSound READ getPickupSound WRITE setPickupSound
NOTIFY pickupSoundChanged)

/**
* @brief Name of second sound asset to play upon collection, optional.
*/
Q_PROPERTY(QString echoSound READ getEchoSound WRITE setEchoSound
NOTIFY echoSoundChanged)
public:
/**
* @brief Returns #pickupValue.
Expand Down Expand Up @@ -81,6 +86,15 @@ class PickupLogic : public Logic {
* @param value String to set #pickupSound to
*/
void setPickupSound(const QString& value);
/**
* @brief Returns #echoSound.
*/
const QString& getEchoSound() const { return mEchoSound; }
/**
* @brief Sets #echoSound.
* @param value String to set #echoSound to
*/
void setEchoSound(const QString& value);

/**
* @brief Makes #actor collectable again.
Expand All @@ -94,6 +108,9 @@ class PickupLogic : public Logic {
*/
virtual void init() override;

public slots:
void playEcho();

signals:
/**
* @brief Emitted when #pickupValue changes.
Expand All @@ -107,6 +124,10 @@ class PickupLogic : public Logic {
* @brief Emitted when #pickupSound changes.
*/
void pickupSoundChanged();
/**
* @brief Emitted when #echoSound changes.
*/
void echoSoundChanged();
/**
* @brief Emitted when #actor is collected.
* @param otherActor Actor who collected #actor
Expand All @@ -121,6 +142,8 @@ private slots:
bool mAllowNonPlayerPickup = false;
QString mPickupSound;
SoundEffectInstance mPickupSoundInstance;
QString mEchoSound;
SoundEffectInstance mEchoSoundInstance;
bool mPickedUp = false;
};
Q_DECLARE_METATYPE(PickupLogic*)
Expand Down
14 changes: 10 additions & 4 deletions VoltAir/qml/actors/Orb.qml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,15 @@ Actor {

z: 4

property string chosenLetter: "0"

function chooseLetter() {
if(chosenLetter === "0")
chosenLetter = Game.getValidLetter(Math.random());
return chosenLetter;
}

AnimatedImageRenderer {
function chooseLetter() {
return Game.getValidLetter(Math.random());// > 0.5 ? "A" : "B";
}
id: graphic

sizeScale: 1.25
Expand All @@ -55,7 +60,7 @@ Actor {
VoltAirText {
id: letter
textElement.font.pixelSize: 1
textElement.text: Game.getValidLetter(Math.random())
textElement.text: chooseLetter()
}

CircleBody {
Expand Down Expand Up @@ -133,6 +138,7 @@ Actor {
PickupLogic {
id: pickupLogic
pickupSound: Util.getPathToSound("pickup.wav")
echoSound: Util.getPathToSound("en/letter_sound_" + chosenLetter + ".wav")
active: false

onCollected: {
Expand Down

0 comments on commit ac93269

Please sign in to comment.