Volume control and playing sounds

This commit is contained in:
Heather 2025-08-26 22:05:02 +01:00
parent b21d144c77
commit 1c8a840a7f
43 changed files with 442 additions and 66 deletions

View file

@ -1,9 +1,12 @@
{
:code {
:find {
:term "speed"
:term "gui.set_position"
}
}
:search-in-files {
:term "{"
}
:workflow {
:recent-files [
[
@ -11,11 +14,19 @@
:scene
]
[
"/main/level3.script"
"/main/mummy.script"
:code
]
[
"/main/mummy.script"
"/main/entername.collection"
:scene
]
[
"/main/scoreboard.collection"
:scene
]
[
"/main/level3.script"
:code
]
[
@ -23,15 +34,35 @@
:code
]
[
"/main/level1.collection"
"/main/level3.collection"
:scene
]
[
"/main/player.script"
"/main/graphics.atlas"
:scene
]
[
"/main/debug.gui"
:scene
]
[
"/main/entername.gui"
:scene
]
[
"/main/entername.gui_script"
:code
]
[
"/main/curse.script"
"/main/score.gui_script"
:code
]
[
"/main/scoreboard.gui_script"
:code
]
[
"/main/startscreen.gui_script"
:code
]
[
@ -39,7 +70,39 @@
:scene
]
[
"/main/level3.collection"
"/main/level1.script"
:code
]
[
"/main/player.script"
:code
]
[
"/main/level1.collection"
:scene
]
[
"/main/settings.gui"
:scene
]
[
"/main/settings.collection"
:scene
]
[
"/main/curse.script"
:code
]
[
"/main/settings.gui_script"
:code
]
[
"/main/main.script"
:code
]
[
"/main/main.collection"
:scene
]
]

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 @@
šr
rlocal Movement = {
x
þwlocal Movement = {
STILL_LEFT = "STILL_LEFT",
STILL_RIGHT = "STILL_RIGHT",
MOVING_LEFT = "MOVING_LEFT",
@ -123,6 +123,7 @@ function init(self)
self.paused = false
self.current_movement = Movement.STILL_RIGHT
self.current_level = "level1"
go.set_position(vmath.vector3(100,100,0.2))
end
@ -245,8 +246,18 @@ function update(self, dt)
elseif pos.x > 1030 then
pos.x = 1030
end
if pos.y < 0 then
--if pos.y < 0 then
--pos.y = 100
--end
if pos.y < -20 then
pos.y = 100
pos.x = 100
msg.post("main:/controller#main", "LifeLost")
self.current_movement = Movement.MOVING_RIGHT
handleInput(self, Actions.RIGHT_ARROW_RELEASE)
go.set_position(vmath.vector3(100,100,0.2))
self.regenerating = true
self.regen_timer = 3
end
local centre = vmath.vector3(pos.x, pos.y - 10, 0)
@ -359,6 +370,7 @@ function on_message(self, message_id, message, sender)
self.amulet_timer = 5
msg.post("holding_amulet", "enable_sprite")
--print("collision with amulet")
msg.post("main:/controller#main", "play amulet sound")
end
if message.group == hash("mummy") then
msg.post("main:/controller#main", "LevelCompleted")
@ -369,7 +381,7 @@ function on_message(self, message_id, message, sender)
if message.dying == false then
msg.post("/holding_amulet#holdingamulet", "disable_sprite")
msg.post("main:/controller#main", "LifeLost")
msg.post("main:/controller#main", "play dying sound")
--else
self.current_movement = Movement.MOVING_RIGHT
handleInput(self, Actions.RIGHT_ARROW_RELEASE)
@ -385,6 +397,13 @@ function on_message(self, message_id, message, sender)
if message_id == hash("unpause") then
self.paused = false
end
if message_id == hash("level1") then
self.current_level = "level1"
elseif message_id == hash("level2") then
self.current_level = "level2"
elseif message_id == hash("level3") then
self.current_level = "level3"
end
end
function on_input(self, action_id, action)
@ -409,7 +428,9 @@ function on_input(self, action_id, action)
end
if action_id == hash("jump") and action.pressed and not self.jumped and not self.climbing then
self.velocity.y = self.jump_velocity
self.speed = 500
if self.current_level == "level2" or self.current_level == "level3" then
self.speed = 500
end
self.jumped = true
end
if action_id == hash("climb_up") then

Binary file not shown.

BIN
graphics/music.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.8 KiB

BIN
graphics/slider.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 399 B

BIN
graphics/slider_bar.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

BIN
graphics/sound.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.9 KiB

BIN
graphics/volume.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

View file

@ -16,6 +16,10 @@ embedded_instances {
" texture: \\\"/main/graphics.atlas\\\"\\n"
"}\\n"
"\"\n"
" scale {\n"
" x: 1.17877\n"
" y: 1.169797\n"
" }\n"
"}\n"
""
}

View file

@ -12,8 +12,8 @@ nodes {
z: 1.0
}
scale {
x: 0.7
y: 0.7
x: 0.9
y: 0.9
}
size {
x: 200.0
@ -32,13 +32,13 @@ nodes {
}
nodes {
position {
x: 794.0
y: 302.0
x: 825.0
y: 200.0
z: 1.0
}
scale {
x: 0.7
y: 0.7
x: 0.9
y: 0.9
}
size {
x: 200.0

View file

@ -3,7 +3,7 @@ function init(self)
-- Learn more: https://defold.com/manuals/script/
-- Remove this function if not needed
local node = gui.get_node("enter")
gui.set_position(node, vmath.vector3(450,250,1))
gui.set_position(node, vmath.vector3(425,200,1))
gui.set_color(gui.get_node("enter"), vmath.vector4(0.4118, 0.2863, 0.0706, 1.0))
end

View file

@ -88,6 +88,21 @@ images {
images {
image: "/graphics/platformsegmentup.png"
}
images {
image: "/graphics/music.png"
}
images {
image: "/graphics/slider.png"
}
images {
image: "/graphics/slider_bar.png"
}
images {
image: "/graphics/sound.png"
}
images {
image: "/graphics/volume.png"
}
animations {
id: "run_left"
images {

View file

@ -760,3 +760,19 @@ embedded_instances {
"}\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

@ -15,6 +15,8 @@ function init(self)
createamulets(self)
msg.post("level1:/pause#sprite", "disable")
msg.post("/player#player", "level1")
print("level1")
end
function createamulets(self)

View file

@ -1482,3 +1482,19 @@ embedded_instances {
"}\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

@ -15,6 +15,8 @@ function init(self)
createamulets(self)
msg.post("level2:/pause#sprite", "disable")
msg.post("/player#player", "level2")
print("level2")
end
function createamulets(self)

View file

@ -1619,3 +1619,19 @@ embedded_instances {
"}\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

@ -15,6 +15,8 @@ function init(self)
createamulets(self)
msg.post("level3:/pause#sprite", "disable")
msg.post("/player#player", "level3")
print("level3")
end
function createamulets(self)

View file

@ -148,3 +148,20 @@ embedded_instances {
"}\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"
"looping: 1\\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

@ -3,10 +3,8 @@ function init(self)
-- show the title screen when the game is loaded
msg.post("#startscreen_proxy", "load")
-- msg.post("#level2_proxy", "load")
self.collection_to_load = ""
self.current_collection = "#startscreen_proxy"
-- self.current_collection = "#level2_proxy"
--msg.post("#level2_proxy", "load")
--self.collection_to_load = ""
@ -35,6 +33,8 @@ function init(self)
self.current_level = "level1"
self.current_score = 0
self.hide_banner = true
self.volume = 717
end
function final(self)
@ -66,6 +66,9 @@ function on_message(self, message_id, message, sender)
if message_id == hash("proxy_loaded") then
msg.post(sender, "enable")
-- load the correct collection when a message is received
if self.current_collection == "#settings_proxy" then
msg.post("settings:/background#settings1", "new_volume", { new_volume = self.volume })
end
elseif message_id == hash("show level1 screen") then
-- title screen
msg.post(self.current_collection, "unload")
@ -74,7 +77,7 @@ function on_message(self, message_id, message, sender)
self.current_lives = 3
self.current_level = "level1"
self.hide_banner = false
--load game over scsreen when character is dead
--load game over screen when character is dead
elseif message_id == hash("NoMoreLives") then
self.hide_banner = true
local show_gameover = true
@ -144,6 +147,14 @@ function on_message(self, message_id, message, sender)
elseif message_id == hash("add 100 points") then
self.current_score = self.current_score + 100
--print(self.current_score)
elseif message_id == hash("play amulet sound") then
sound.play("sound#amulet_sound", {loopcount = 0, speed = 1, gain = (self.volume - 547)/(887 - 547)})
elseif message_id == hash("play dying sound") then
sound.play("sound#dying_sound", {speed = 1, gain = (self.volume - 547)/(887 - 547)})
elseif message_id == hash("new_volume") then
self.volume = message.new_volume
local scaled_volume = (self.volume - 547)/(887 - 547)
sound.set_group_gain("sounds", scaled_volume)
end
end

View file

@ -121,6 +121,7 @@ function init(self)
self.paused = false
self.current_movement = Movement.STILL_RIGHT
self.current_level = "level1"
go.set_position(vmath.vector3(100,100,0.2))
end
@ -243,8 +244,18 @@ function update(self, dt)
elseif pos.x > 1030 then
pos.x = 1030
end
if pos.y < 0 then
--if pos.y < 0 then
--pos.y = 100
--end
if pos.y < -20 then
pos.y = 100
pos.x = 100
msg.post("main:/controller#main", "LifeLost")
self.current_movement = Movement.MOVING_RIGHT
handleInput(self, Actions.RIGHT_ARROW_RELEASE)
go.set_position(vmath.vector3(100,100,0.2))
self.regenerating = true
self.regen_timer = 3
end
local centre = vmath.vector3(pos.x, pos.y - 10, 0)
@ -357,6 +368,7 @@ function on_message(self, message_id, message, sender)
self.amulet_timer = 5
msg.post("holding_amulet", "enable_sprite")
--print("collision with amulet")
msg.post("main:/controller#main", "play amulet sound")
end
if message.group == hash("mummy") then
msg.post("main:/controller#main", "LevelCompleted")
@ -367,7 +379,7 @@ function on_message(self, message_id, message, sender)
if message.dying == false then
msg.post("/holding_amulet#holdingamulet", "disable_sprite")
msg.post("main:/controller#main", "LifeLost")
msg.post("main:/controller#main", "play dying sound")
--else
self.current_movement = Movement.MOVING_RIGHT
handleInput(self, Actions.RIGHT_ARROW_RELEASE)
@ -383,6 +395,13 @@ function on_message(self, message_id, message, sender)
if message_id == hash("unpause") then
self.paused = false
end
if message_id == hash("level1") then
self.current_level = "level1"
elseif message_id == hash("level2") then
self.current_level = "level2"
elseif message_id == hash("level3") then
self.current_level = "level3"
end
end
function on_input(self, action_id, action)
@ -407,7 +426,9 @@ function on_input(self, action_id, action)
end
if action_id == hash("jump") and action.pressed and not self.jumped and not self.climbing then
self.velocity.y = self.jump_velocity
self.speed = 500
if self.current_level == "level2" or self.current_level == "level3" then
self.speed = 500
end
self.jumped = true
end
if action_id == hash("climb_up") then

View file

@ -9,8 +9,8 @@ fonts {
}
nodes {
position {
x: 669.0
y: 433.0
x: 627.5
y: 446.0
z: 1.0
}
scale {
@ -29,8 +29,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 403.0
x: 627.5
y: 406.0
z: 1.0
}
scale {
@ -49,8 +49,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 373.0
x: 627.5
y: 366.0
}
scale {
x: 0.4
@ -68,8 +68,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 343.0
x: 627.5
y: 326.0
}
scale {
x: 0.4
@ -87,8 +87,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 313.0
x: 627.5
y: 286.0
}
scale {
x: 0.4
@ -106,8 +106,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 283.0
x: 627.5
y: 246.0
}
scale {
x: 0.4
@ -125,8 +125,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 253.0
x: 627.5
y: 206.0
}
scale {
x: 0.4
@ -144,8 +144,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 223.0
x: 627.5
y: 166.0
}
scale {
x: 0.4
@ -163,8 +163,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 193.0
x: 627.5
y: 126.0
}
scale {
x: 0.4
@ -182,8 +182,8 @@ nodes {
}
nodes {
position {
x: 669.0
y: 163.0
x: 627.5
y: 86.0
}
scale {
x: 0.4
@ -201,8 +201,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 431.0
x: 427.5
y: 442.0
}
scale {
x: 0.55
@ -220,8 +220,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 401.0
x: 427.5
y: 402.0
}
scale {
x: 0.55
@ -239,8 +239,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 371.0
x: 427.5
y: 362.0
}
scale {
x: 0.55
@ -258,8 +258,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 341.0
x: 427.5
y: 322.0
}
scale {
x: 0.55
@ -277,8 +277,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 311.0
x: 427.5
y: 282.0
}
scale {
x: 0.55
@ -296,8 +296,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 281.0
x: 427.5
y: 242.0
}
scale {
x: 0.55
@ -315,8 +315,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 251.0
x: 427.5
y: 202.0
}
scale {
x: 0.55
@ -334,8 +334,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 221.0
x: 427.5
y: 162.0
}
scale {
x: 0.55
@ -353,8 +353,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 191.0
x: 427.5
y: 122.0
}
scale {
x: 0.55
@ -372,8 +372,8 @@ nodes {
}
nodes {
position {
x: 423.0
y: 161.0
x: 427.5
y: 82.0
}
scale {
x: 0.55

View file

@ -6,6 +6,10 @@ embedded_instances {
" id: \"settings\"\n"
" component: \"/main/settings.script\"\n"
"}\n"
"components {\n"
" id: \"settings1\"\n"
" component: \"/main/settings.gui\"\n"
"}\n"
"embedded_components {\n"
" id: \"sprite\"\n"
" type: \"sprite\"\n"
@ -21,5 +25,25 @@ embedded_instances {
" y: 345.0\n"
" }\n"
"}\n"
"embedded_components {\n"
" id: \"sprite1\"\n"
" type: \"sprite\"\n"
" data: \"default_animation: \\\"volume\\\"\\n"
"material: \\\"/builtins/materials/sprite.material\\\"\\n"
"textures {\\n"
" sampler: \\\"texture_sampler\\\"\\n"
" texture: \\\"/main/graphics.atlas\\\"\\n"
"}\\n"
"\"\n"
" position {\n"
" x: 522.0\n"
" y: 450.0\n"
" z: 0.1\n"
" }\n"
" scale {\n"
" x: 0.4\n"
" y: 0.4\n"
" }\n"
"}\n"
""
}

100
main/settings.gui Normal file
View file

@ -0,0 +1,100 @@
script: "/main/settings.gui_script"
textures {
name: "graphics"
texture: "/main/graphics.atlas"
}
nodes {
position {
x: 311.0
y: 341.0
}
scale {
x: 0.5
y: 0.5
}
type: TYPE_BOX
texture: "graphics/sound"
id: "sound"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 717.0
y: 339.0
}
scale {
x: 0.4
y: 0.4
}
type: TYPE_BOX
texture: "graphics/slider_bar"
id: "sound_slider"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 719.0
y: 341.0
}
scale {
x: 0.4
y: 0.4
}
type: TYPE_BOX
texture: "graphics/slider"
id: "sound_bar"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 311.0
y: 208.0
}
scale {
x: 0.483616
y: 0.483616
z: 0.967232
}
type: TYPE_BOX
texture: "graphics/music"
id: "music"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 717.0
y: 206.0
}
scale {
x: 0.386893
y: 0.386893
z: 0.967232
}
type: TYPE_BOX
texture: "graphics/slider_bar"
id: "music_slider"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
}
nodes {
position {
x: 719.0
y: 208.0
}
scale {
x: 0.386893
y: 0.386893
z: 0.967232
}
type: TYPE_BOX
texture: "graphics/slider"
id: "music_bar"
inherit_alpha: true
size_mode: SIZE_MODE_AUTO
}
material: "/builtins/materials/gui.material"
adjust_reference: ADJUST_REFERENCE_PARENT

46
main/settings.gui_script Normal file
View file

@ -0,0 +1,46 @@
function init(self)
end
function final(self)
-- Add finalization code here
-- Learn more: https://defold.com/manuals/script/
-- Remove this function if not needed
end
function update(self, dt)
--gui.set_position(gui.get_node("sound_bar"), pos)
end
function on_message(self, message_id, message, sender)
if message_id == hash("new_volume") then
self.volume = message.new_volume
local volume_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))
end
end
function on_input(self, action_id, action)
if action_id == hash("touch") and action.pressed then
if gui.pick_node(gui.get_node("sound_bar"), action.x, action.y) then
self.dragging = true
end
elseif action.released then
self.dragging = false
end
if self.dragging then
local volume_pos = gui.get_position(gui.get_node("sound_bar"))
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))
msg.post("main:/controller#main", "new_volume", { new_volume = action.x })
end
-- print(volume)
-- msg.post("main:/controller#main", "set_volume", { volume = volume })
end
end
function on_reload(self)
-- Add reload-handling code here
-- Learn more: https://defold.com/manuals/hot-reload/
-- Remove this function if not needed
end