diff options
author | cheapie <no-email-for-you@example.com> | 2024-04-25 12:57:07 -0500 |
---|---|---|
committer | cheapie <no-email-for-you@example.com> | 2024-04-25 12:57:07 -0500 |
commit | 0f81ed5f77e3b55f4240a0236832d863edf424dc (patch) | |
tree | 127349a2adc7e3340128bdf6caf2a91471d56f5a | |
parent | 67449e63495dea49a16b3b3ac6eb39a20107f616 (diff) | |
download | celevator-0f81ed5f77e3b55f4240a0236832d863edf424dc.tar celevator-0f81ed5f77e3b55f4240a0236832d863edf424dc.tar.gz celevator-0f81ed5f77e3b55f4240a0236832d863edf424dc.tar.bz2 celevator-0f81ed5f77e3b55f4240a0236832d863edf424dc.tar.xz celevator-0f81ed5f77e3b55f4240a0236832d863edf424dc.zip |
Add car motion sounds
-rw-r--r-- | drive_entity.lua | 45 | ||||
-rw-r--r-- | sounds/celevator_car_run.ogg | bin | 0 -> 65310 bytes | |||
-rw-r--r-- | sounds/celevator_car_start.ogg | bin | 0 -> 78428 bytes | |||
-rw-r--r-- | sounds/celevator_car_stop.ogg | bin | 0 -> 91529 bytes |
4 files changed, 45 insertions, 0 deletions
diff --git a/drive_entity.lua b/drive_entity.lua index fb8521e..7d8763a 100644 --- a/drive_entity.lua +++ b/drive_entity.lua @@ -5,6 +5,8 @@ celevator.drives.entity = { buzzsoundhandles = {}, movementsoundhandles = {}, movementsoundstate = {}, + carsoundhandles = {}, + carsoundstate = {}, entityinfo = {}, sheaverefs = {}, } @@ -117,6 +119,47 @@ local function motorsound(pos,newstate) celevator.drives.entity.movementsoundstate[hash] = newstate end +local function carsound(pos,newstate,speed) + if speed < 0.5 then return end + local hash = minetest.hash_node_position(pos) + local oldstate = celevator.drives.entity.carsoundstate[hash] + oldstate = oldstate or "idle" + if oldstate == newstate then return end + if not celevator.drives.entity.entityinfo[hash] then return end + local eref = celevator.drives.entity.entityinfo[hash].handles[1] + if not eref:get_pos() then return end + local oldhandle = celevator.drives.entity.carsoundhandles[hash] + local gain = math.min(1,speed/6) + if newstate == "accel" then + if oldhandle then minetest.sound_stop(oldhandle) end + celevator.drives.entity.carsoundhandles[hash] = minetest.sound_play("celevator_car_start",{ + object = eref, + gain = gain, + }) + minetest.after(3,function() + if celevator.drives.entity.carsoundstate[hash] == "accel" then + carsound(pos,"run",speed) + end + end) + elseif newstate == "run" then + if oldhandle then minetest.sound_stop(oldhandle) end + celevator.drives.entity.carsoundhandles[hash] = minetest.sound_play("celevator_car_run",{ + object = eref, + loop = true, + gain = gain, + }) + elseif newstate == "decel" then + if oldhandle then minetest.sound_stop(oldhandle) end + celevator.drives.entity.carsoundhandles[hash] = minetest.sound_play("celevator_car_stop",{ + object = eref, + gain = gain, + }) + elseif newstate == "stopped" then + if oldhandle then minetest.sound_stop(oldhandle) end + end + celevator.drives.entity.carsoundstate[hash] = newstate +end + local function compareexchangesound(pos,compare,new) local hash = minetest.hash_node_position(pos) local oldstate = celevator.drives.entity.movementsoundstate[hash] @@ -356,6 +399,7 @@ function celevator.drives.entity.step(dtime) celevator.drives.entity.entityinfo[hash] = { handles = handles, } + carsound(pos,"accel",maxvel) meta:set_string("state","running") celevator.drives.entity.sheavetoentity(carid) elseif state == "running" then @@ -398,6 +442,7 @@ function celevator.drives.entity.step(dtime) vel = math.min(dremain,maxvel) if celevator.drives.entity.movementsoundstate[hash] == "fast" or celevator.drives.entity.movementsoundstate[hash] == "accel" then decelsound(pos) + carsound(pos,"decel",maxvel) end elseif dmoved+0.1 > maxvel then vel = maxvel diff --git a/sounds/celevator_car_run.ogg b/sounds/celevator_car_run.ogg Binary files differnew file mode 100644 index 0000000..f7b1dc5 --- /dev/null +++ b/sounds/celevator_car_run.ogg diff --git a/sounds/celevator_car_start.ogg b/sounds/celevator_car_start.ogg Binary files differnew file mode 100644 index 0000000..2c1f208 --- /dev/null +++ b/sounds/celevator_car_start.ogg diff --git a/sounds/celevator_car_stop.ogg b/sounds/celevator_car_stop.ogg Binary files differnew file mode 100644 index 0000000..7a64392 --- /dev/null +++ b/sounds/celevator_car_stop.ogg |