Skip to content

Commit

Permalink
added sounds on water
Browse files Browse the repository at this point in the history
  • Loading branch information
APercy committed Jul 12, 2022
1 parent f166cc2 commit a546bb8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
26 changes: 22 additions & 4 deletions init.lua
Expand Up @@ -99,9 +99,9 @@ function motorboat.engineSoundPlay(self)
--sound
if self.sound_handle then minetest.sound_stop(self.sound_handle) end
if self.object then
self.sound_handle = minetest.sound_play({name = "engine"},
self.sound_handle = minetest.sound_play({name = "motorboat_engine"},
{object = self.object, gain = 1.0,
pitch = 0.5 + ((self._power_lever/100)/3),
pitch = 0.5 + ((self._power_lever/100)/2),
max_hear_distance = 32,
loop = true,})
end
Expand Down Expand Up @@ -431,7 +431,7 @@ minetest.register_entity("motorboat:boat", {
if impact > 1 then
--self.damage = self.damage + impact --sum the impact value directly to damage meter
curr_pos = self.object:get_pos()
minetest.sound_play("collision", {
minetest.sound_play("motorboat_collision", {
--to_player = self.driver_name,
pos = curr_pos,
max_hear_distance = 8,
Expand Down Expand Up @@ -515,6 +515,24 @@ minetest.register_entity("motorboat:boat", {
local bob = motorboat.minmax(motorboat.dot(accel,hull_direction),0.8) -- vertical bobbing

if self.isinliquid then
if self._last_rnd == nil then self._last_rnd = math.random(1, 3) end
if self._last_water_touch == nil then self._last_water_touch = self._last_rnd end
if self._last_water_touch <= self._last_rnd then
self._last_water_touch = self._last_water_touch + self.dtime
end
if math.abs(bob) > 0.1 and self._last_water_touch >=self._last_rnd then
self._last_rnd = math.random(1, 3)
self._last_water_touch = 0
minetest.sound_play("default_water_footstep", {
--to_player = self.driver_name,
object = self.object,
max_hear_distance = 15,
gain = 0.07,
fade = 0.0,
pitch = 1.0,
}, true)
end

accel.y = accel_y + bob
newpitch = velocity.y * math.rad(6)

Expand Down Expand Up @@ -584,7 +602,7 @@ minetest.register_entity("motorboat:boat", {
--mobkit.hurt(self,toolcaps.damage_groups.fleshy - 1)
--mobkit.make_sound(self,'hit')
self.hp = self.hp - 10
minetest.sound_play("collision", {
minetest.sound_play("motorboat_collision", {
object = self.object,
max_hear_distance = 5,
gain = 1.0,
Expand Down
2 changes: 1 addition & 1 deletion motorboat_control.lua
Expand Up @@ -146,7 +146,7 @@ function motorboat.motorboat_control(self, dtime, hull_direction, longit_speed,
elseif self._engine_running == false and self._energy > 0 then
self._engine_running = true
-- sound and animation
self.sound_handle = minetest.sound_play({name = "engine"},
self.sound_handle = minetest.sound_play({name = "motorboat_engine"},
{object = self.object, gain = 1.0, pitch = 0.5, max_hear_distance = 32, loop = true,})
self.engine:set_animation_frame_speed(30)
end
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit a546bb8

Please sign in to comment.