From 0f81ed5f77e3b55f4240a0236832d863edf424dc Mon Sep 17 00:00:00 2001 From: cheapie Date: Thu, 25 Apr 2024 12:57:07 -0500 Subject: Add car motion sounds --- drive_entity.lua | 45 +++++++++++++++++++++++++++++++++++++++++ sounds/celevator_car_run.ogg | Bin 0 -> 65310 bytes sounds/celevator_car_start.ogg | Bin 0 -> 78428 bytes sounds/celevator_car_stop.ogg | Bin 0 -> 91529 bytes 4 files changed, 45 insertions(+) create mode 100644 sounds/celevator_car_run.ogg create mode 100644 sounds/celevator_car_start.ogg create mode 100644 sounds/celevator_car_stop.ogg 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 new file mode 100644 index 0000000..f7b1dc5 Binary files /dev/null and b/sounds/celevator_car_run.ogg differ diff --git a/sounds/celevator_car_start.ogg b/sounds/celevator_car_start.ogg new file mode 100644 index 0000000..2c1f208 Binary files /dev/null and b/sounds/celevator_car_start.ogg differ diff --git a/sounds/celevator_car_stop.ogg b/sounds/celevator_car_stop.ogg new file mode 100644 index 0000000..7a64392 Binary files /dev/null and b/sounds/celevator_car_stop.ogg differ -- cgit v1.2.3