diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6ecc62e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.settings/* +.project +.buildpath diff --git a/init.lua b/init.lua index d3fc1da..e2c0b13 100644 --- a/init.lua +++ b/init.lua @@ -18,6 +18,7 @@ local cart = { old_pos = nil, old_velocity = nil, pre_stop_dir = nil, + sound_handle = nil, MAX_V = 6, -- Limit of the velocity } @@ -234,6 +235,19 @@ function cart:on_step(dtime) if not cart_func.v3:equal(self.velocity, {x=0,y=0,z=0}) then self.pre_stop_dir = cart_func:velocity_to_dir(self.velocity) + if self.sound_handle == nil then + self.sound_handle = minetest.sound_play("vcarts_cart_sound", { + object = self.object, + max_hear_distance = 2, + loop = true, + gain = 0.4, + }) + end + + elseif self.sound_handle ~= nil then + minetest.sound_stop(self.sound_handle) + self.sound_handle = nil + -- drop cart if its position is incorrect (e.g. floating in air) elseif cart_func:is_rail(pos) == false then self.object:remove() diff --git a/sounds/vcarts_cart_sound.ogg b/sounds/vcarts_cart_sound.ogg new file mode 100644 index 0000000..4146514 Binary files /dev/null and b/sounds/vcarts_cart_sound.ogg differ