示例#1
0
 void OnGearChange(ForkliftType.Gear oldGear, ForkliftType.Gear newGear)
 {
     if (!firstTick && Life != 0)
     {
         bool   up        = Math.Abs(newGear.Number) > Math.Abs(oldGear.Number);
         string soundName = up ? Type.SoundGearUp : Type.SoundGearDown;
         SoundPlay3D(soundName, .7f, true);
     }
 }
示例#2
0
        /// <summary>Overridden from <see cref="Engine.EntitySystem.Entity.OnPostCreate(Boolean)"/>.</summary>
        protected override void OnPostCreate(bool loaded)
        {
            base.OnPostCreate(loaded);
            AddTimer();
            if (!EngineApp.Instance.IsResourceEditor)
            {
                if (PhysicsModel == null)
                {
                    Log.Error("Forklift: Physics model not exists.");
                    return;
                }

                forkliftBody = PhysicsModel.GetBody("forklift");
                if (forkliftBody == null)
                {
                    Log.Error("Forklift: \"forklift\" body not exists.");
                    return;
                }

                leftwheelBody      = PhysicsModel.GetBody("leftwheel");
                rightwheelBody     = PhysicsModel.GetBody("rightwheel");
                forkBody           = PhysicsModel.GetBody("fork");
                up1Body            = PhysicsModel.GetBody("up1");
                up2Body            = PhysicsModel.GetBody("up2");
                b2Body             = PhysicsModel.GetBody("b2");
                b1Body             = PhysicsModel.GetBody("b1");
                wheelRearRightBody = PhysicsModel.GetBody("wheelRearRight");
                wheelRearLeftBody  = PhysicsModel.GetBody("wheelRearLeft");
                foreach (MapObjectAttachedObject attachedObject in AttachedObjects)
                {
                    if (attachedObject.Alias == "leftWheel")
                    {
                        leftWheel.wheelHelpers.Add((MapObjectAttachedHelper)attachedObject);
                    }
                    if (attachedObject.Alias == "rightWheel")
                    {
                        rightWheel.wheelHelpers.Add((MapObjectAttachedHelper)attachedObject);
                    }
                }

                if (leftWheel.wheelHelpers.Count != 0)
                {
                    wheelsPositionYOffset = Math.Abs(leftWheel.wheelHelpers[0].PositionOffset.Y);
                }
            }
            //initialize currentGear
            currentGear = Type.Gears.Find(delegate(ForkliftType.Gear gear)
            {
                return(gear.Number == 0);
            });
        }
示例#3
0
        void TickCurrentGear()
        {
            //currently gears used only for sounds

            if (currentGear == null)
            {
                return;
            }

            if (motorOn)
            {
                Vec3  Velocity = forkliftBody.LinearVelocity * forkliftBody.Rotation.GetInverse();
                float speed    = Velocity.X * 1;

                ForkliftType.Gear newGear = null;

                if (speed < currentGear.SpeedRange.Minimum || speed > currentGear.SpeedRange.Maximum)
                {
                    //find new gear
                    newGear = Type.Gears.Find(delegate(ForkliftType.Gear gear)
                    {
                        return(speed >= gear.SpeedRange.Minimum && speed <= gear.SpeedRange.Maximum);
                    });
                }

                if (newGear != null && currentGear != newGear)
                {
                    //change gear
                    ForkliftType.Gear oldGear = currentGear;
                    OnGearChange(oldGear, newGear);
                    currentGear = newGear;
                }
            }
            else
            {
                if (currentGear.Number != 0)
                {
                    currentGear = Type.Gears.Find(delegate(ForkliftType.Gear gear)
                    {
                        return(gear.Number == 0);
                    });
                }
            }
        }