diff --git a/init.lua b/init.lua index 90b44b9..557b31a 100644 --- a/init.lua +++ b/init.lua @@ -191,19 +191,25 @@ local sounds = { gain = 2.2, max_hear_distance = 10, loop = false, + pitch = 1, }, engine_boost = { sound_name = "sum_airship_lip_trill", gain = 40, max_hear_distance = 10, loop = false, + pitch = 1, }, } function boat.sound_play(self, sound_obj, sound_instance) - local params = sound_obj - params.object = self.object - sound_instance.handle = minetest.sound_play(sound_obj.sound_name, params) + sound_instance.handle = minetest.sound_play(sound_obj.sound_name, { + gain = sound_obj.gain, + max_hear_distance = sound_obj.max_hear_distance, + loop = sound_obj.loop, + pitch = sound_obj.pitch or 1, + object = self.object, + }) sound_instance.playing = true sound_instance.time_elapsed = 0 end @@ -220,7 +226,7 @@ end function boat.update_sound(self, dtime, forward) local fuel = self._fuel local is_thrust = forward ~= 0 and self._driver - if not fuel or not type(fuel) == "number" then return false end + if not fuel or not type(fuel) == "number" then self._fuel = 0 end if self._sounds.engine.time_elapsed > 2.1 and self._sounds.engine.handle @@ -251,23 +257,6 @@ function boat.update_sound(self, dtime, forward) end end --- function boat.update_sound(self, forward, dtime) --- if math.abs(forward) > 0 then --- if not self._sounds.engine.playing then --- self._sounds.engine.playing = true --- self._sounds.engine.handle = minetest.sound_play("sum_airship_lip_trill", { --- gain = 0.3, --- object = self.object, --- max_hear_distance = 10, --- loop = true, --- }) --- end --- elseif forward == 0 and self._sounds.engine.playing then --- minetest.sound_stop(self._sounds.engine.handle) --- self._sounds.engine.playing = false --- end --- end - minetest.register_on_respawnplayer(detach_object) function boat.on_rightclick(self, clicker) @@ -285,7 +274,6 @@ function boat.on_rightclick(self, clicker) gain = 1, object = self.object, }) - elseif self._passenger or not clicker or clicker:get_attach() then else attach_object(self, clicker) end @@ -536,9 +524,8 @@ function boat.on_step(self, dtime, moveresult) self.object:set_acceleration(vel) local chimney_pos = boat.get_chimney_pos(self) - if true or has_controls then -- only do it if you got the input - boat.update_sound(self, dtime, forward) - end + + boat.update_sound(self, dtime, forward) local is_thrust = self._driver and forward ~= 0 @@ -619,6 +606,21 @@ for b=1, #boat_ids do end local boat = minetest.add_entity(pos, "sum_airship:boat") local texture = "sum_airship_texture_"..images[b].."_boat.png" + local luaent = boat:get_luaentity() + luaent._sounds = { -- workaround for copy vs reference issue + engine = { + handle = nil, + gain = 0.1, + playing = false, + time_elapsed = 0, + }, + engine_stop = { + handle = nil, + gain = 0.1, + playing = false, + time_elapsed = 0, + }, + } boat:get_luaentity()._itemstring = itemstring boat:set_properties({textures = { texture, texture, texture, texture, texture }}) boat:set_yaw(placer:get_look_horizontal())