public static void UpdateLinearMovement(float dt, IControlable host)
        {
            if (dt == 0)
            {
                return;
            }
            ControlInput input = host.CurrentControlInput;

            if (input == null)
            {
                return;
            }
            if (input[InputAction.MoveForward])
            {
                ApplyThrust(dt, host, host.DirectionVector, input.ThrustPercent);
            }
            else if (input[InputAction.MoveBackwards])
            {
                ApplyThrust(dt, host, -host.DirectionVector, input.ThrustPercent);
            }
            else if (input[InputAction.MoveLeft])
            {
                ApplyThrust(dt, host, host.DirectionVector.LeftHandNormal, input.ThrustPercent);
            }
            else if (input[InputAction.MoveRight])
            {
                ApplyThrust(dt, host, host.DirectionVector.RightHandNormal, input.ThrustPercent);
            }
        }
Beispiel #2
0
        protected ControlableWave(ControlableWave copy)
            : base(copy)
        {
            this.Killed       = Functions.Clone <EventHandler>(copy.Killed);
            this.shipState    = new ShipState(copy.shipState);
            this.movementInfo = new ShipMovementInfo(copy.movementInfo);
            foreach (IControler controler in copy.controlers)
            {
                AddControler(null, (IControler)controler.Clone());
            }
            this.target         = copy.target;
            this.ControlHandler = Functions.Clone <IControlHandler>(copy.ControlHandler);

            this.currentControlInput              = copy.currentControlInput;
            this.direction                        = copy.direction;
            this.controlableType                  = copy.controlableType;
            this.controlableSounds                = copy.controlableSounds;
            this.attachedEffectCollection         = new EffectCollection(copy.attachedEffectCollection);
            this.contFlags                        = copy.contFlags;
            this.CollisionState.GenerateRayEvents = true;


            this.colors       = copy.colors;
            this.primaryColor = copy.primaryColor;
            if (copy.weaponInfo != null)
            {
                this.weaponInfo = (IWeaponsLogic)copy.weaponInfo.Clone();
            }
        }
Beispiel #3
0
 public ControlInput GetControlInput(float dt, ControlInput original)
 {
     count = base.Count;
     for (int pos = 0; pos < count; ++pos)
     {
         original = base[pos].GetControlInput(dt, original);
     }
     return(original);
 }
Beispiel #4
0
 public virtual void UpdateControlable(GameResult gameResult, float dt)
 {
     this.shipState.Update(dt);
     if (shipState.Health.IsEmpty)
     {
         Kill(gameResult);
         return;
     }
     currentControlInput = GetInput(dt);
     RunControlInput(gameResult, dt);
 }
Beispiel #5
0
        public void UpdateActions(GameResult gameResult, float dt, ControlInput currentControlInput)
        {
            count = base.Count;
            bool inputAction = currentControlInput[InputAction.Action];
            int  mincount    = Math.Min(currentControlInput.ActiveActions.Length, count);

            for (int pos = 0; pos < count; ++pos)
            {
                IAction action = base[pos];
                if (inputAction && pos < mincount && currentControlInput.ActiveActions[pos])
                {
                    action.OnAction(gameResult, dt);
                }
                else if (action.IsActive)
                {
                    action.OnAfterAction(gameResult, dt);
                }
            }
        }
        public static void UpdateAngularMovement(float dt, IControlable host)
        {
            if (dt == 0)
            {
                return;
            }
            ControlInput input = host.CurrentControlInput;

            float AV     = host.Current.Velocity.Angular;
            float AAccel = host.MovementInfo.MaxAngularAcceleration.Value * dt;
            float AbsAV  = MathHelper.Abs(AV);

            bool right = false;
            bool left  = false;

            if (input != null)
            {
                right = input[InputAction.RotateRight];
                left  = input[InputAction.RotateLeft];
            }
            bool thirdtest = (AbsAV <= host.MovementInfo.MaxAngularVelocity);

            if ((right ^ left) && thirdtest)
            {
                float newAV;
                AAccel *= input.TorquePercent;
                if (left)
                {
                    newAV = AV + AAccel;
                    if (newAV < host.MovementInfo.MaxAngularVelocity)
                    {
                        //host.current.Velocity.Angular = newAV;
                        ApplydAV(host, AAccel, dt);
                    }
                    else
                    {
                        //host.current.Velocity.Angular = host.MovementInfo.MaxAngularVelocity;
                        ApplydAV(host, host.MovementInfo.MaxAngularVelocity - AV, dt);
                    }
                }
                else
                {
                    newAV = AV - AAccel;
                    if (newAV > -host.MovementInfo.MaxAngularVelocity)
                    {
                        //host.current.Velocity.Angular = newAV;
                        ApplydAV(host, -AAccel, dt);
                    }
                    else
                    {
                        //host.current.Velocity.Angular = -host.MovementInfo.MaxAngularVelocity;
                        ApplydAV(host, -host.MovementInfo.MaxAngularVelocity - AV, dt);
                    }
                }
            }
            else
            {
                if (AbsAV <= AAccel)
                {
                    //host.current.Velocity.Angular = 0;
                    ApplydAV(host, 0 - AV, dt);
                }
                else
                {
                    //host.current.Velocity.Angular -= (float)Math.Sign(AV) * AAccel;
                    ApplydAV(host, -(float)Math.Sign(AV) * AAccel, dt);
                }
            }
        }