Skip to content

Commit

Permalink
Add bg music, intro and outro.
Browse files Browse the repository at this point in the history
  • Loading branch information
MisterGC committed Oct 6, 2019
1 parent b711545 commit 67f3715
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 7 deletions.
38 changes: 33 additions & 5 deletions src/Player.qml
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,35 @@ VisualizedBoxBody
function stopLeft() { if (body.linearVelocity.x < 0) body.linearVelocity.x = 0; }
function stopRight() { if (body.linearVelocity.x > 0) body.linearVelocity.x = 0; }

function say(text) {
saidWordsComponent.createObject(coordSys,{text: text, player: thePlayer});
function say(text, timeToLive) {
let ttL = timeToLive ? timeToLive : 1000
saidWordsComponent.createObject(coordSys,{text: text, player: thePlayer, ttl: ttL});
}

Timer {
id: dialogPlayer
property var dialog: []
property int idx: 0
onRunningChanged: {
thePlayer.active = !running;
if (running) idx = 0;
}
repeat: true
triggeredOnStart: true
onTriggered: {
if (idx < dialog.length) {
thePlayer.say(dialog[idx], interval);
idx++;
}
else
stop();
}
}

function speakDialog(lines, ttlPerSentence) {
dialogPlayer.dialog = lines;
dialogPlayer.interval = ttlPerSentence;
dialogPlayer.restart();
}

signal caughtSounding(var sounding);
Expand Down Expand Up @@ -82,6 +109,7 @@ VisualizedBoxBody
id: saidWords

property var player: thePlayer
property int ttl: 1000
y: player ? player.y - height : 0
x: player ? player.x - (width - player.width) * .5 : 0

Expand All @@ -91,9 +119,9 @@ VisualizedBoxBody
font.bold: true
font.family: "Monospace"

Component.onCompleted: opacity = 0;
Behavior on opacity {NumberAnimation {duration: 1000}}
onOpacityChanged: { if (opacity < 0.05) saidWords.destroy(); }
Component.onCompleted: opacity = 0.5;
Behavior on opacity {NumberAnimation {duration: ttl}}
onOpacityChanged: { if (opacity < 0.505) saidWords.destroy(); }
}
}
}
39 changes: 38 additions & 1 deletion src/Sandbox.qml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
*
*/
import QtQuick 2.12
import QtMultimedia 5.12
import Box2D 2.0
import Clayground.SvgUtils 1.0
import Clayground.ScalingCanvas 1.0
Expand Down Expand Up @@ -75,10 +76,32 @@ CoordCanvas {
}
}

SoundEffect {
id: bgMusic
Component.onCompleted: play();
source: gameCfg.soundPath + "/bgmusic.wav"
loops: SoundEffect.Infinite
}

function onPlayerEnteredStage() {
bgMusic.stop();
theSheet.play();
player.say("Enjoy the Show!");
player.active = false;
let dialog = ['Enjoy the Show!',
'This is my new song ... ',
'... thanks man!',
'Unfortunately this game is such a ',
'short experience, but you know ',
'I had to start with nothing ;)',
'Click on the screen to restart!' ];
player.speakDialog(dialog, 2000);
}

MouseArea {
anchors.fill: parent
z: 99
onClicked: {theSvgInspector.spawnLocation = "south"; theSvgInspector.map = "map1"}
//enabled: player ? (!player.active && theSvgInspector.map === "map3") : false
}

Keys.forwardTo: gameCtrl
Expand Down Expand Up @@ -214,6 +237,20 @@ CoordCanvas {
o.entered.connect(world.onPlayerEnteredStage);
}
}
if (map === "map1") {
let dialog = ['Hi there, my name is Jimmy.',
'How are you?',
'I wanna compose a song ...',
'... but have no ideas :(',
'What about you Dude?',
'Use the cursor keys or ',
'the left anlog stick of your gamepad ',
'Ok, let\'s go and compose!'
];
player.speakDialog(dialog, 2000);
theSheet.notes = [];
bgMusic.play();
}
}

function _changeMap(map, location) {
Expand Down
2 changes: 1 addition & 1 deletion src/SheetOfMusic.qml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ Rectangle {
Timer {
id: trackPlayer

interval: 400
interval: 700
triggeredOnStart: true
repeat: true

Expand Down
Binary file added src/sound/bgmusic.wav
Binary file not shown.
Binary file modified src/sound/blue.wav
Binary file not shown.
Binary file modified src/sound/green.wav
Binary file not shown.
1 change: 1 addition & 0 deletions src/sound/sound.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<qresource prefix="/">
<file>blue.wav</file>
<file>green.wav</file>
<file>bgmusic.wav</file>
</qresource>
</RCC>

0 comments on commit 67f3715

Please sign in to comment.