Пример #1
0
        /// <summary>Enter this State</summary>
        public void Enter(T Entity)
        {
            //on enter, clear out last execute time, exit time, finish time
            LastExecuteTime = DateTime.MinValue;
            ExitTime        = DateTime.MinValue;
            FinishTime      = DateTime.MinValue;

            //Raise Entering event
            if (Entering != null)
            {
                Entering(this, StateEventArgs <T> .GetArgs(Entity));
            }

            //Update Enter Date/time
            EnterTime = DateTime.Now;

            //call DoEnter
            DoEnter(Entity);

            //Raise Entered
            if (Entered != null)
            {
                Entered(this, StateEventArgs <T> .GetArgs(Entity));
            }

            // Last call. Change status
            Status = StateConditions.STARTED;
        }
Пример #2
0
        /// <summary>Finish State</summary>
        public void Finish(T Entity)
        {
            //Raise Finishing event
            if (Finishing != null)
            {
                Finishing(this, StateEventArgs <T> .GetArgs(Entity));
            }

            //call DoFinish
            DoFinish(Entity);

            //Raise Finished
            if (Finished != null)
            {
                Finished(this, StateEventArgs <T> .GetArgs(Entity));
            }

            //Update Finish date/time at the end
            FinishTime = DateTime.Now;

            // Last call. Change status
            Status = StateConditions.FINISHED;
        }
Пример #3
0
        /// <summary>Exit State</summary>
        public void Exit(T Entity)
        {
            //Raise Exiting event
            if (Exiting != null)
            {
                Exiting(this, StateEventArgs <T> .GetArgs(Entity));
            }

            //call DoExecute
            DoExit(Entity);

            //Raise Exited
            if (Exited != null)
            {
                Exited(this, StateEventArgs <T> .GetArgs(Entity));
            }

            //Update Exit date/time at the end
            ExitTime = DateTime.Now;

            // Last call. Change status
            Status = StateConditions.TERMINATED;
        }
        // Update is called once per frame
        protected override void SpaxUpdate()
        {
            if (!stopTimer.IsTicking())
            {
                StateConditions curCond = data.GetStateConditions();

                //for holding change in velocity for faster access
                float accel = 0f;
                //holds the x-axis input for faster access
                int xInput = input.X();

                //if there is a frame to apply some stuff, do it


                //if the state allows for gravity application
                if ((curCond & StateConditions.APPLY_GRAV) > 0)
                {
                    if ((calcVelocity.y - data.GetGravForce()) <= (-1 * data.moveStats.maxFallSpeed))
                    {
                        calcVelocity.y = -1 * data.moveStats.maxFallSpeed;
                    }
                    else
                    {
                        calcVelocity.y -= data.GetGravForce();
                    }
                }

                //read if the player wants to move
                if (xInput != 0)
                {
                    //if the state allows for movement
                    if ((curCond & StateConditions.CAN_MOVE) > 0)
                    {
                        bool isWalking = (curCond & StateConditions.WALKING) == StateConditions.WALKING;

                        //hold the acceleration for quicker access
                        accel = data.GetAcceleration(isWalking);

                        //Debug.Log(isWalking+" | "+accel);


                        if (FPMath.Abs(calcVelocity.x + accel * xInput) >= (FP)data.GetMaxSpeed(isWalking))
                        {
                            calcVelocity.x = data.GetMaxSpeed(isWalking) * xInput;
                        }
                        else
                        {
                            calcVelocity.x += accel * xInput;
                        }
                    }
                }

                //if the state applies friction
                if ((curCond & StateConditions.APPLY_FRICTION) > 0)
                {
                    //accel will be (at least) close to 0 if the player an and wants to move
                    if (Mathf.Abs(accel) < 0.00001f)
                    {
                        //hold the friction for quicker access
                        accel = data.GetFriction();

                        if ((FPMath.Abs(calcVelocity.x) - accel) <= 0f)
                        {
                            calcVelocity.x = 0f;
                        }
                        else
                        {
                            //multiply by normalized to counter the current velocity
                            calcVelocity.x -= accel * calcVelocity.normalized.x;
                        }
                    }
                }
                //assign the new calculated velocity to the rigidbody
                rb.velocity = calcVelocity;


                //txt.text = data.GetStringPrevInputs();
            }
        }