]> git.lizzy.rs Git - crafter_client.git/commitdiff
Add stream, splash, and scary cave sounds
authoroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 12 Apr 2020 23:35:56 +0000 (19:35 -0400)
committeroilboi <47129783+oilboi@users.noreply.github.com>
Sun, 12 Apr 2020 23:35:56 +0000 (19:35 -0400)
environment_effects.lua [new file with mode: 0644]
init.lua

diff --git a/environment_effects.lua b/environment_effects.lua
new file mode 100644 (file)
index 0000000..c98247a
--- /dev/null
@@ -0,0 +1,65 @@
+local old_node
+local in_water = false
+local old_in_water = false
+--this is to check if the player is exploring a cave
+--if exploring cave not near an open shaft then play a scary noise
+--every 5-7 minutes
+local scary_sound_player_timer = math.random(-120,0)
+
+
+--this is used for the water trickling effect
+local water_trickling_timer = 0
+local water_sound_handle = nil
+
+minetest.register_globalstep(function(dtime)
+       if not minetest.localplayer then
+               return
+       end
+       local vel = minetest.localplayer:get_velocity().y
+       local pos = minetest.localplayer:get_pos()
+       
+       local node = minetest.get_node_or_nil(pos)
+       if node then
+               local name = node.name
+               if name == "main:water" or name == "main:waterflow" then
+                       in_water = true
+                       if in_water == true and old_in_water == false and vel < 0 then
+                               minetest.sound_play("splash", {gain = 0.4, pitch = math.random(80,100)/100, gain = 0.05})
+                       end
+               else
+                       in_water = false
+               end
+       end
+       
+       old_node = node
+       old_in_water = in_water
+       
+       
+       ---------------------------------------------
+       --print(scary_sound_player_timer)
+       --try to play every 5-7 minutes
+       scary_sound_player_timer = scary_sound_player_timer + dtime
+       if scary_sound_player_timer > 300 then
+               scary_sound_player_timer = math.random(-120,0)
+               pos.y = pos.y + 1.625
+               local light = minetest.get_node_light(pos)
+               if pos.y < 0 and light <= 13 then
+                       minetest.sound_play("scary_noise",{gain=0.4,pitch=math.random(70,100)/100})
+               end     
+       end
+       
+       
+       --the water trickling timer
+       water_trickling_timer = water_trickling_timer + dtime
+       if water_trickling_timer > 1 then
+               water_trickling_timer = 0
+               local is_water_near = minetest.find_node_near(pos, 3, {"main:waterflow"})
+               if is_water_near and not water_sound_handle then
+                       water_sound_handle = minetest.sound_play("stream", {loop=true,gain=0})
+                       minetest.sound_fade(water_sound_handle, 0.25, 0.1)
+               elseif not is_water_near and water_sound_handle then
+                       minetest.sound_fade(water_sound_handle, -0.25, 0)
+                       water_sound_handle = nil
+               end
+       end
+end)
index 263784097edb263990146b7f4a9662244c06a20c..8dd290306ac0bde5344fd58a03ae6e53bb7a240a 100644 (file)
--- a/init.lua
+++ b/init.lua
@@ -10,31 +10,5 @@ player_movement_state = minetest.mod_channel_join("player.player_movement_state"
 local path = minetest.get_modpath("crafter_client")
 dofile(path.."/player_input.lua")
 dofile(path.."/weather_handling.lua")
+dofile(path.."/environment_effects.lua")
 
-local old_node
-local in_water = false
-local old_in_water = false
-minetest.register_globalstep(function(dtime)
-       if not minetest.localplayer then
-               return
-       end
-       
-       local vel = minetest.localplayer:get_velocity().y
-       local pos = minetest.localplayer:get_pos()
-       
-       local node = minetest.get_node_or_nil(pos)
-       if node then
-               local name = node.name
-               if name == "main:water" or name == "main:water_flowing" then
-                       in_water = true
-                       if in_water == true and old_in_water == false and vel < 0 then
-                               minetest.sound_play("splash", {gain = 0.4, pitch = math.random(80,100)/100, gain = 0.05})
-                       end
-               else
-                       in_water = false
-               end
-       end
-       
-       old_node = node
-       old_in_water = in_water
-end)