Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
2 | |
3 | DistantTrain = {} |
4 | |
5 | local DistantTrain_mt = Class(DistantTrain); |
6 | |
7 | function DistantTrain:onCreate(id) |
8 | g_currentMission:addUpdateable(DistantTrain:new(id)); |
9 | --print("created DistantTrain, id: ", id); |
10 | end; |
11 | |
12 | function DistantTrain:new(id) |
13 | local instance = {}; |
14 | setmetatable(instance, DistantTrain_mt); |
15 | |
16 | instance.nurbsId = getChildAt(id, 0); |
17 | instance.distantTrainId = getChildAt(id, 1) |
18 | instance.time = 1; |
19 | instance.currentDelay = math.random(20000, 120000) |
20 | |
21 | -- spline is a straight line, thus we only need to set the train's direction once |
22 | local dx, dy, dz = getSplineDirection(instance.nurbsId, 0.5); |
23 | setDirection(instance.distantTrainId, dx, 0, dz, 0, 1, 0); |
24 | |
25 | instance.trainSound = createAudioSource("trainSound", "data/maps/sounds/train.wav", 300, 1, 1, 0); |
26 | link(instance.distantTrainId, instance.trainSound); |
27 | |
28 | return instance; |
29 | end; |
30 | |
31 | function DistantTrain:delete() |
32 | |
33 | end; |
34 | |
35 | function DistantTrain:update(dt) |
36 | if self.currentDelay > 0 then |
37 | self.currentDelay = self.currentDelay - dt; |
38 | else |
39 | setVisibility(self.trainSound, true); |
40 | self.time = self.time - 0.0002 * dt; |
41 | if (self.time < 0) then |
42 | self.time = 1; |
43 | self.currentDelay = math.random(20000, 120000); |
44 | setVisibility(self.trainSound, false); |
45 | end; |
46 | local x, y, z = getSplinePosition(self.nurbsId, self.time); |
47 | setTranslation(self.distantTrainId, x, y, z); |
48 | end; |
49 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de