summaryrefslogtreecommitdiff
path: root/advtrains_train_subway/init.lua
diff options
context:
space:
mode:
authororwell96 <orwell@bleipb.de>2017-12-06 13:23:55 +0100
committerorwell96 <orwell@bleipb.de>2017-12-06 13:23:55 +0100
commitac3d4dffeb5ca5c78db92e1292e1eade0bb057a5 (patch)
tree8550c9ec93220ff5dee45612bbdf4fed8a61648a /advtrains_train_subway/init.lua
parent34429b8154e45bc6acafd4d3af7a4f9b99f8b5c4 (diff)
downloadbasic_trains-ac3d4dffeb5ca5c78db92e1292e1eade0bb057a5.tar.gz
basic_trains-ac3d4dffeb5ca5c78db92e1292e1eade0bb057a5.tar.bz2
basic_trains-ac3d4dffeb5ca5c78db92e1292e1eade0bb057a5.zip
Implement sound api and some sounds
- Level crossing bell - Horns - Subway train driving and door sounds ...to be continued...
Diffstat (limited to 'advtrains_train_subway/init.lua')
-rw-r--r--advtrains_train_subway/init.lua30
1 files changed, 24 insertions, 6 deletions
diff --git a/advtrains_train_subway/init.lua b/advtrains_train_subway/init.lua
index e3c73c9..f8e5e3b 100644
--- a/advtrains_train_subway/init.lua
+++ b/advtrains_train_subway/init.lua
@@ -59,11 +59,13 @@ advtrains.register_wagon("subway_wagon", {
doors={
open={
[-1]={frames={x=0, y=20}, time=1},
- [1]={frames={x=40, y=60}, time=1}
+ [1]={frames={x=40, y=60}, time=1},
+ sound = "advtrains_subway_dopen",
},
close={
[-1]={frames={x=20, y=40}, time=1},
- [1]={frames={x=60, y=80}, time=1}
+ [1]={frames={x=60, y=80}, time=1},
+ sound = "advtrains_subway_dclose",
}
},
door_entry={-1, 1},
@@ -73,10 +75,26 @@ advtrains.register_wagon("subway_wagon", {
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
is_locomotive=true,
drops={"default:steelblock 4"},
- --custom_on_activate = function(self, dtime_s)
- -- atprint("subway custom_on_activate")
- -- self.object:set_animation({x=1,y=80}, 15, 0, true)
- --end,
+ horn_sound = "advtrains_subway_horn",
+ custom_on_velocity_change = function(self, velocity, old_velocity)
+ if old_velocity == 0 and velocity > 0 then
+ minetest.sound_play("advtrains_subway_depart", {object = self.object})
+ end
+ if velocity < 2 and (old_velocity >= 2 or old_velocity == velocity) and not self.sound_arrive_handle then
+ self.sound_arrive_handle = minetest.sound_play("advtrains_subway_arrive", {object = self.object})
+ elseif (velocity > old_velocity) and self.sound_arrive_handle then
+ minetest.sound_stop(self.sound_arrive_handle)
+ self.sound_arrive_handle = nil
+ end
+ if velocity > 0 and not self.sound_loop_handle then
+ self.sound_loop_handle = minetest.sound_play({name="advtrains_subway_loop", gain=0.3}, {object = self.object, loop=true})
+ elseif velocity==0 then
+ if self.sound_loop_handle then
+ minetest.sound_stop(self.sound_loop_handle)
+ self.sound_loop_handle = nil
+ end
+ end
+ end,
}, S("Subway Passenger Wagon"), "advtrains_subway_wagon_inv.png")
--wagons