Fade airplane sound pitch when motor is turned on and off.

lights3
Sven Eberhardt 2015-08-09 19:28:07 -04:00
parent 042d00c1d2
commit f873e81bf0
1 changed files with 50 additions and 14 deletions

View File

@ -143,7 +143,7 @@ public func ContainedStop(object clonk)
public func StartFlight(int new_throttle)
{
AddEffect("IntSoundDelay",this,1,1,this);
SetPropellerSpeedTarget(100);
SetAction("Fly");
throttle = new_throttle;
}
@ -151,8 +151,7 @@ public func StartFlight(int new_throttle)
public func StartInstantFlight(int angle, int new_throttle)
{
angle -= 10;
var effect = AddEffect("IntSoundDelay",this,1,1,this);
effect.Immediate = true;
SetPropellerSpeed(100);
SetAction("Fly");
throttle = new_throttle;
thrust = new_throttle;
@ -164,22 +163,12 @@ public func StartInstantFlight(int angle, int new_throttle)
public func CancelFlight()
{
RemoveEffect("IntSoundDelay",this);
Sound("PropellerLoop",0,100,nil,-1);
SetPropellerSpeedTarget(0);
SetAction("Land");
rdir = 0;
throttle = 0;
}
private func FxIntSoundDelayTimer(object target, effect, int timer)
{
if(timer >= 78 || (effect.Immediate && timer >= 5))
{
Sound("PropellerLoop",0,100,nil,1);
return -1;
}
}
private func FxIntPlaneTimer(object target, effect, int timer)
{
//Lift
@ -367,6 +356,53 @@ public func PlaneDismount(object clonk)
return true;
}
/* Propeller sound */
local prop_speed, prop_speed_target, prop_speed_timer; // current and target propeller speed [0, 100]
// Instantly set new propeller speed
private func SetPropellerSpeed(int new_speed)
{
if (prop_speed_timer)
{
RemoveTimer(this.PropellerSpeedTimer);
prop_speed_timer = false;
}
return SetPropellerSound(prop_speed = prop_speed_target = new_speed);
}
// Schedule fading to new propeller speed
private func SetPropellerSpeedTarget(int new_speed_target)
{
prop_speed_target = new_speed_target;
if (!prop_speed_timer) prop_speed_timer = AddTimer(this.PropellerSpeedTimer, 10);
return true;
}
// Execute fading to new propeller speed
private func PropellerSpeedTimer()
{
prop_speed = BoundBy(prop_speed_target, prop_speed - 10, prop_speed + 4);
if (prop_speed == prop_speed_target)
{
RemoveTimer(this.PropellerSpeedTimer);
prop_speed_timer = false;
}
return SetPropellerSound(prop_speed);
}
// Set propeller speed sound. 0 = off, 100 = max speed.
private func SetPropellerSound(int speed)
{
if (speed <= 0)
return Sound("PropellerLoop",0,100,nil,-1);
else
return Sound("PropellerLoop",0,100,nil,1,0,(speed-100)*2/3);
}
/* Properties */
func IsShipyardProduct() { return true; }
local ActMap = {