From e9d9046a67e9294d756874c1a0e052c00d0ee6e6 Mon Sep 17 00:00:00 2001 From: Olha Yevtushenko Date: Mon, 29 May 2017 15:10:42 +0300 Subject: [PATCH] add playing letter sound with a delay during pickup --- VoltAir/logics/PickupLogic.cpp | 17 ++++++++++++++++- VoltAir/logics/PickupLogic.h | 23 +++++++++++++++++++++++ VoltAir/qml/actors/Orb.qml | 14 ++++++++++---- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/VoltAir/logics/PickupLogic.cpp b/VoltAir/logics/PickupLogic.cpp index 9fc1b41..f3a67a5 100644 --- a/VoltAir/logics/PickupLogic.cpp +++ b/VoltAir/logics/PickupLogic.cpp @@ -23,6 +23,7 @@ #include "LevelProgression.h" #include "PickupLogic.h" #include "inputs/PlayerManager.h" +#include void PickupLogic::setPickupValue(int value) { mPickupValue = value; @@ -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; } @@ -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(); +} diff --git a/VoltAir/logics/PickupLogic.h b/VoltAir/logics/PickupLogic.h index e0e8555..99823f0 100644 --- a/VoltAir/logics/PickupLogic.h +++ b/VoltAir/logics/PickupLogic.h @@ -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. @@ -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. @@ -94,6 +108,9 @@ class PickupLogic : public Logic { */ virtual void init() override; +public slots: + void playEcho(); + signals: /** * @brief Emitted when #pickupValue changes. @@ -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 @@ -121,6 +142,8 @@ private slots: bool mAllowNonPlayerPickup = false; QString mPickupSound; SoundEffectInstance mPickupSoundInstance; + QString mEchoSound; + SoundEffectInstance mEchoSoundInstance; bool mPickedUp = false; }; Q_DECLARE_METATYPE(PickupLogic*) diff --git a/VoltAir/qml/actors/Orb.qml b/VoltAir/qml/actors/Orb.qml index ae0ba2c..cc017ae 100644 --- a/VoltAir/qml/actors/Orb.qml +++ b/VoltAir/qml/actors/Orb.qml @@ -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 @@ -55,7 +60,7 @@ Actor { VoltAirText { id: letter textElement.font.pixelSize: 1 - textElement.text: Game.getValidLetter(Math.random()) + textElement.text: chooseLetter() } CircleBody { @@ -133,6 +138,7 @@ Actor { PickupLogic { id: pickupLogic pickupSound: Util.getPathToSound("pickup.wav") + echoSound: Util.getPathToSound("en/letter_sound_" + chosenLetter + ".wav") active: false onCollected: {