diff options
author | orwell96 <orwell@bleipb.de> | 2017-12-06 13:23:55 +0100 |
---|---|---|
committer | orwell96 <orwell@bleipb.de> | 2017-12-06 13:23:55 +0100 |
commit | dc67ff7226a2836863a0e709a5b81c90c977f288 (patch) | |
tree | d1743a0f59fbc2ed4b4ab8359b1a2bf93c621c6a /advtrains/wagons.lua | |
parent | be8aca9fb8ee406d4728c470a1340be8f418e45f (diff) | |
download | advtrains-dc67ff7226a2836863a0e709a5b81c90c977f288.tar.gz advtrains-dc67ff7226a2836863a0e709a5b81c90c977f288.tar.bz2 advtrains-dc67ff7226a2836863a0e709a5b81c90c977f288.zip |
Implement sound api and some sounds
- Level crossing bell
- Horns
- Subway train driving and door sounds
...to be continued...
Diffstat (limited to 'advtrains/wagons.lua')
-rw-r--r-- | advtrains/wagons.lua | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/advtrains/wagons.lua b/advtrains/wagons.lua index 4306b50..b30d3d4 100644 --- a/advtrains/wagons.lua +++ b/advtrains/wagons.lua @@ -270,6 +270,18 @@ function wagon:on_step(dtime) if has_driverstand then
--regular driver stand controls
advtrains.on_control_change(pc, self:train(), self.wagon_flipped)
+ --sound horn when required
+ if self.horn_sound and pc.aux1 and not pc.sneak and not self.horn_handle then
+ self.horn_handle = minetest.sound_play(self.horn_sound, {
+ object = self.object,
+ gain = 1.0, -- default
+ max_hear_distance = 128, -- default, uses an euclidean metric
+ loop = true,
+ })
+ elseif not pc.aux1 and self.horn_handle then
+ minetest.sound_stop(self.horn_handle)
+ self.horn_handle = nil
+ end
else
-- If on a passenger seat and doors are open, get off when W or D pressed.
local pass = self.seatp[seatno] and minetest.get_player_by_name(self.seatp[seatno])
@@ -322,10 +334,12 @@ function wagon:on_step(dtime) -- if changed from 0 to +-1, play open anim. if changed from +-1 to 0, play close.
-- if changed from +-1 to -+1, first close and set 0, then it will detect state change again and run open.
if self.door_state == 0 then
+ if self.doors.open.sound then minetest.sound_play(self.doors.open.sound, {object = self.object}) end
at=self.doors.open[dstate]
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
self.door_state = dstate
else
+ if self.doors.close.sound then minetest.sound_play(self.doors.close.sound, {object = self.object}) end
at=self.doors.close[self.door_state or 1]--in case it has not been set yet
self.object:set_animation(at.frames, at.speed or 15, at.blend or 0, false)
self.door_state = 0
|