aboutsummaryrefslogtreecommitdiff
path: root/wagons.lua
diff options
context:
space:
mode:
authororwell96 <mono96.mml@gmail.com>2016-06-09 17:35:06 +0200
committerorwell96 <mono96.mml@gmail.com>2016-06-09 17:35:06 +0200
commita879ce8d3c179b5c6b88c9db610d560228d1e5b4 (patch)
tree477a062c99baca9673b4127e89f49dab3e1d148c /wagons.lua
parente449704a92c8c1931fb687e58f095bea27db3ddc (diff)
downloadadvtrains-a879ce8d3c179b5c6b88c9db610d560228d1e5b4.tar.gz
advtrains-a879ce8d3c179b5c6b88c9db610d560228d1e5b4.tar.bz2
advtrains-a879ce8d3c179b5c6b88c9db610d560228d1e5b4.zip
Fix train collision and coupling on opposing trains, and try to implement animation (currently does not work)
Diffstat (limited to 'wagons.lua')
-rw-r--r--wagons.lua14
1 files changed, 14 insertions, 0 deletions
diff --git a/wagons.lua b/wagons.lua
index 31a07b2..69504a1 100644
--- a/wagons.lua
+++ b/wagons.lua
@@ -268,6 +268,9 @@ function wagon:on_step(dtime)
self.object:setvelocity(velocityvec)
self.object:setyaw(yaw)
self.updatepct_timer=2
+ if self.update_animation then
+ self:update_animation(gp.velocity)
+ end
end
self.old_velocity_vector=velocityvec
@@ -336,6 +339,11 @@ advtrains.register_wagon("greenwagon", "steam",{textures = {"green.png"}})
advtrains.register_wagon("redwagon", "steam",{textures = {"red.png"}})
advtrains.register_wagon("yellowwagon", "steam",{textures = {"yellow.png"}})
]]
+
+--[[
+ wagons can define update_animation(self, velocity) if they have a speed-dependent animation
+ this function will be called when the velocity vector changes or every 2 seconds.
+]]
advtrains.register_wagon("newlocomotive", "steam",{
mesh="newlocomotive.b3d",
textures = {"advtrains_newlocomotive.png"},
@@ -345,6 +353,12 @@ advtrains.register_wagon("newlocomotive", "steam",{
visual_size = {x=1, y=1},
wagon_span=1.85,
collisionbox = {-1.0,-0.5,-1.0, 1.0,2.5,1.0},
+ update_animation=function(self, velocity)
+ if self.old_anim_velocity~=advtrains.abs_ceil(velocity) then
+ self.object:set_animation({x=1,y=60}, math.floor(velocity))
+ self.old_anim_velocity=advtrains.abs_ceil(velocity)
+ end
+ end
})
advtrains.register_wagon("wagon_default", "steam",{
mesh="wagon.b3d",