Sounds and background music

This commit is contained in:
Heather 2025-08-27 00:22:09 +01:00
parent 1c8a840a7f
commit 20ccd7debc
21 changed files with 106 additions and 60 deletions

View file

@ -1,7 +1,7 @@
{ {
:code { :code {
:find { :find {
:term "gui.set_position" :term "testing"
} }
} }
:search-in-files { :search-in-files {
@ -25,14 +25,6 @@
"/main/scoreboard.collection" "/main/scoreboard.collection"
:scene :scene
] ]
[
"/main/level3.script"
:code
]
[
"/main/level2.script"
:code
]
[ [
"/main/level3.collection" "/main/level3.collection"
:scene :scene
@ -69,18 +61,18 @@
"/main/level2.collection" "/main/level2.collection"
:scene :scene
] ]
[
"/main/level1.script"
:code
]
[
"/main/player.script"
:code
]
[ [
"/main/level1.collection" "/main/level1.collection"
:scene :scene
] ]
[
"/main/level2.script"
:code
]
[
"/main/level3.script"
:code
]
[ [
"/main/settings.gui" "/main/settings.gui"
:scene :scene
@ -90,11 +82,19 @@
:scene :scene
] ]
[ [
"/main/curse.script" "/main/settings.gui_script"
:code :code
] ]
[ [
"/main/settings.gui_script" "/main/level1.script"
:code
]
[
"/main/holdingamulet.script"
:code
]
[
"/main/curse.script"
:code :code
] ]
[ [
@ -105,6 +105,10 @@
"/main/main.collection" "/main/main.collection"
:scene :scene
] ]
[
"/main/player.script"
:code
]
] ]
} }
} }

Binary file not shown.

BIN
Sounds/curse.wav Normal file

Binary file not shown.

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -1,6 +1,6 @@
x ‡y
þwlocal Movement = { ïxlocal Movement = {
STILL_LEFT = "STILL_LEFT", STILL_LEFT = "STILL_LEFT",
STILL_RIGHT = "STILL_RIGHT", STILL_RIGHT = "STILL_RIGHT",
MOVING_LEFT = "MOVING_LEFT", MOVING_LEFT = "MOVING_LEFT",
@ -253,6 +253,7 @@ function update(self, dt)
pos.y = 100 pos.y = 100
pos.x = 100 pos.x = 100
msg.post("main:/controller#main", "LifeLost") msg.post("main:/controller#main", "LifeLost")
msg.post("main:/controller#main", "play dying sound")
self.current_movement = Movement.MOVING_RIGHT self.current_movement = Movement.MOVING_RIGHT
handleInput(self, Actions.RIGHT_ARROW_RELEASE) handleInput(self, Actions.RIGHT_ARROW_RELEASE)
go.set_position(vmath.vector3(100,100,0.2)) go.set_position(vmath.vector3(100,100,0.2))
@ -428,6 +429,7 @@ function on_input(self, action_id, action)
end end
if action_id == hash("jump") and action.pressed and not self.jumped and not self.climbing then if action_id == hash("jump") and action.pressed and not self.jumped and not self.climbing then
self.velocity.y = self.jump_velocity self.velocity.y = self.jump_velocity
msg.post("main:/controller#main", "play jump sound")
if self.current_level == "level2" or self.current_level == "level3" then if self.current_level == "level2" or self.current_level == "level3" then
self.speed = 500 self.speed = 500
end end

View file

@ -115,6 +115,7 @@ function on_message(self, message_id, message, sender)
if message_id == hash("testing_amulet_response") then if message_id == hash("testing_amulet_response") then
if message.visible == true then if message.visible == true then
sprite.play_flipbook("#sprite", hash("explosion")) sprite.play_flipbook("#sprite", hash("explosion"))
msg.post("main:/controller#main", "play curse dying sound")
self.deleted = true self.deleted = true
self.dying = true self.dying = true
msg.post("main:/controller#main", "add 100 points") msg.post("main:/controller#main", "add 100 points")

View file

@ -760,19 +760,3 @@ embedded_instances {
"}\n" "}\n"
"" ""
} }
embedded_instances {
id: "sound"
data: "embedded_components {\n"
" id: \"amulet_sound\"\n"
" type: \"sound\"\n"
" data: \"sound: \\\"/Sounds/mixkit-player-jumping-in-a-video-game-2043.wav\\\"\\n"
"\"\n"
"}\n"
"embedded_components {\n"
" id: \"dying_sound\"\n"
" type: \"sound\"\n"
" data: \"sound: \\\"/Sounds/mixkit-arcade-retro-game-over-213.wav\\\"\\n"
"\"\n"
"}\n"
""
}

View file

@ -16,6 +16,7 @@ function init(self)
createamulets(self) createamulets(self)
msg.post("level1:/pause#sprite", "disable") msg.post("level1:/pause#sprite", "disable")
msg.post("/player#player", "level1") msg.post("/player#player", "level1")
msg.post("main:/controller#main", "play background music")
print("level1") print("level1")
end end

View file

@ -16,6 +16,7 @@ function init(self)
createamulets(self) createamulets(self)
msg.post("level2:/pause#sprite", "disable") msg.post("level2:/pause#sprite", "disable")
msg.post("/player#player", "level2") msg.post("/player#player", "level2")
msg.post("main:/controller#main", "play background music")
print("level2") print("level2")
end end

View file

@ -16,6 +16,7 @@ function init(self)
createamulets(self) createamulets(self)
msg.post("level3:/pause#sprite", "disable") msg.post("level3:/pause#sprite", "disable")
msg.post("/player#player", "level3") msg.post("/player#player", "level3")
msg.post("main:/controller#main", "play background music")
print("level3") print("level3")
end end

View file

@ -154,7 +154,6 @@ embedded_instances {
" id: \"amulet_sound\"\n" " id: \"amulet_sound\"\n"
" type: \"sound\"\n" " type: \"sound\"\n"
" data: \"sound: \\\"/Sounds/mixkit-player-jumping-in-a-video-game-2043.wav\\\"\\n" " data: \"sound: \\\"/Sounds/mixkit-player-jumping-in-a-video-game-2043.wav\\\"\\n"
"looping: 1\\n"
"\"\n" "\"\n"
"}\n" "}\n"
"embedded_components {\n" "embedded_components {\n"
@ -163,5 +162,28 @@ embedded_instances {
" data: \"sound: \\\"/Sounds/mixkit-arcade-retro-game-over-213.wav\\\"\\n" " data: \"sound: \\\"/Sounds/mixkit-arcade-retro-game-over-213.wav\\\"\\n"
"\"\n" "\"\n"
"}\n" "}\n"
"embedded_components {\n"
" id: \"curse_dying_sound\"\n"
" type: \"sound\"\n"
" data: \"sound: \\\"/Sounds/mixkit-short-explosion-1694.wav\\\"\\n"
"\"\n"
"}\n"
"embedded_components {\n"
" id: \"jump_sound\"\n"
" type: \"sound\"\n"
" data: \"sound: \\\"/Sounds/350905__cabled_mess__jump_c_05.wav\\\"\\n"
"\"\n"
"}\n"
""
}
embedded_instances {
id: "music"
data: "embedded_components {\n"
" id: \"background_music\"\n"
" type: \"sound\"\n"
" data: \"sound: \\\"/Sounds/curse.wav\\\"\\n"
"looping: 1\\n"
"\"\n"
"}\n"
"" ""
} }

View file

@ -34,7 +34,8 @@ function init(self)
self.current_score = 0 self.current_score = 0
self.hide_banner = true self.hide_banner = true
self.volume = 717 self.sounds_volume = 717
self.music_volume = 717
end end
function final(self) function final(self)
@ -67,7 +68,8 @@ function on_message(self, message_id, message, sender)
msg.post(sender, "enable") msg.post(sender, "enable")
-- load the correct collection when a message is received -- load the correct collection when a message is received
if self.current_collection == "#settings_proxy" then if self.current_collection == "#settings_proxy" then
msg.post("settings:/background#settings1", "new_volume", { new_volume = self.volume }) msg.post("settings:/background#settings1", "sounds_volume", { sounds_volume = self.sounds_volume })
msg.post("settings:/background#settings1", "music_volume", { music_volume = self.music_volume })
end end
elseif message_id == hash("show level1 screen") then elseif message_id == hash("show level1 screen") then
-- title screen -- title screen
@ -141,6 +143,7 @@ function on_message(self, message_id, message, sender)
msg.post("main:/controller#main", "NoMoreLives") msg.post("main:/controller#main", "NoMoreLives")
end end
elseif message_id == hash("proxy_unloaded") then elseif message_id == hash("proxy_unloaded") then
sound.stop("music#background_music", {speed = 1})
msg.post(self.collection_to_load, "load") msg.post(self.collection_to_load, "load")
self.current_collection = self.collection_to_load self.current_collection = self.collection_to_load
self.collection_to_load = "" self.collection_to_load = ""
@ -148,13 +151,23 @@ function on_message(self, message_id, message, sender)
self.current_score = self.current_score + 100 self.current_score = self.current_score + 100
--print(self.current_score) --print(self.current_score)
elseif message_id == hash("play amulet sound") then elseif message_id == hash("play amulet sound") then
sound.play("sound#amulet_sound", {loopcount = 0, speed = 1, gain = (self.volume - 547)/(887 - 547)}) sound.play("sound#amulet_sound", {speed = 1, gain = (self.sounds_volume - 547)/(887 - 547)})
elseif message_id == hash("play dying sound") then elseif message_id == hash("play dying sound") then
sound.play("sound#dying_sound", {speed = 1, gain = (self.volume - 547)/(887 - 547)}) sound.play("sound#dying_sound", {speed = 1, gain = (self.sounds_volume - 547)/(887 - 547)})
elseif message_id == hash("new_volume") then elseif message_id == hash("play curse dying sound") then
self.volume = message.new_volume sound.play("sound#curse_dying_sound", {speed = 0.5, gain = (self.sounds_volume - 547)/(887 - 547)})
local scaled_volume = (self.volume - 547)/(887 - 547) elseif message_id == hash("play jump sound") then
sound.set_group_gain("sounds", scaled_volume) sound.play("sound#jump_sound", {speed = 1, gain = (self.sounds_volume - 547)/(887 - 547)})
elseif message_id == hash("play background music") then
sound.play("music#background_music", {speed = 1, gain = (self.music_volume - 547)/(887 - 547)})
elseif message_id == hash("sounds_volume") then
self.sounds_volume = message.sounds_volume
-- local scaled_volume = (self.sounds_volume - 547)/(887 - 547)
-- sound.set_group_gain("sounds", scaled_volume)
elseif message_id == hash("music_volume") then
self.music_volume = message.music_volume
-- local scaled_volume = (self.music_volume - 547)/(887 - 547)
-- sound.set_group_gain("music", scaled_volume)
end end
end end

View file

@ -251,6 +251,7 @@ function update(self, dt)
pos.y = 100 pos.y = 100
pos.x = 100 pos.x = 100
msg.post("main:/controller#main", "LifeLost") msg.post("main:/controller#main", "LifeLost")
msg.post("main:/controller#main", "play dying sound")
self.current_movement = Movement.MOVING_RIGHT self.current_movement = Movement.MOVING_RIGHT
handleInput(self, Actions.RIGHT_ARROW_RELEASE) handleInput(self, Actions.RIGHT_ARROW_RELEASE)
go.set_position(vmath.vector3(100,100,0.2)) go.set_position(vmath.vector3(100,100,0.2))
@ -426,6 +427,7 @@ function on_input(self, action_id, action)
end end
if action_id == hash("jump") and action.pressed and not self.jumped and not self.climbing then if action_id == hash("jump") and action.pressed and not self.jumped and not self.climbing then
self.velocity.y = self.jump_velocity self.velocity.y = self.jump_velocity
msg.post("main:/controller#main", "play jump sound")
if self.current_level == "level2" or self.current_level == "level3" then if self.current_level == "level2" or self.current_level == "level3" then
self.speed = 500 self.speed = 500
end end

View file

@ -1,5 +1,6 @@
function init(self) function init(self)
self.sounds_volume = 0
self.music_volume = 0
end end
function final(self) function final(self)
@ -13,29 +14,43 @@ function update(self, dt)
end end
function on_message(self, message_id, message, sender) function on_message(self, message_id, message, sender)
if message_id == hash("new_volume") then if message_id == hash("sounds_volume") then
self.volume = message.new_volume self.sounds_volume = message.sounds_volume
local volume_pos = gui.get_position(gui.get_node("sound_bar")) local sounds_pos = gui.get_position(gui.get_node("sound_bar"))
gui.set_position(gui.get_node("sound_bar"), vmath.vector3(self.volume, volume_pos.y, volume_pos.z)) gui.set_position(gui.get_node("sound_bar"), vmath.vector3(self.sounds_volume, sounds_pos.y, sounds_pos.z))
end
if message_id == hash("music_volume") then
self.music_volume = message.music_volume
local music_pos = gui.get_position(gui.get_node("music_bar"))
gui.set_position(gui.get_node("music_bar"), vmath.vector3(self.music_volume, music_pos.y, music_pos.z))
end end
end end
function on_input(self, action_id, action) function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then if action_id == hash("touch") and action.pressed then
if gui.pick_node(gui.get_node("sound_bar"), action.x, action.y) then if gui.pick_node(gui.get_node("sound_bar"), action.x, action.y) then
self.dragging = true self.dragging_sound = true
end
if gui.pick_node(gui.get_node("music_bar"), action.x, action.y) then
self.dragging_music = true
end end
elseif action.released then elseif action.released then
self.dragging = false self.dragging_sound = false
self.dragging_music = false
end end
if self.dragging then if self.dragging_sound then
local volume_pos = gui.get_position(gui.get_node("sound_bar")) local sounds_pos = gui.get_position(gui.get_node("sound_bar"))
if action.x >= 547 and action.x <= 887 then if action.x >= 547 and action.x <= 887 then
gui.set_position(gui.get_node("sound_bar"), vmath.vector3(action.x, volume_pos.y, volume_pos.z)) gui.set_position(gui.get_node("sound_bar"), vmath.vector3(action.x, sounds_pos.y, sounds_pos.z))
msg.post("main:/controller#main", "new_volume", { new_volume = action.x }) msg.post("main:/controller#main", "sounds_volume", { sounds_volume = action.x })
end
end
if self.dragging_music then
local music_pos = gui.get_position(gui.get_node("music_bar"))
if action.x >= 547 and action.x <= 887 then
gui.set_position(gui.get_node("music_bar"), vmath.vector3(action.x, music_pos.y, music_pos.z))
msg.post("main:/controller#main", "music_volume", { music_volume = action.x })
end end
-- print(volume)
-- msg.post("main:/controller#main", "set_volume", { volume = volume })
end end
end end