示例#1
0
        protected virtual void InitializeEntity(bool addToManagers)
        {
            LoadStaticContent(ContentManagerName);
            mAxisAlignedRectangleInstance      = new FlatRedBall.Math.Geometry.AxisAlignedRectangle();
            mAxisAlignedRectangleInstance.Name = "mAxisAlignedRectangleInstance";
            mBallCatchArea      = new FlatRedBall.Math.Geometry.Circle();
            mBallCatchArea.Name = "mBallCatchArea";
            SpriteInstance      = new FlatRedBall.Sprite();
            SpriteInstance.Name = "SpriteInstance";

            // this provides default controls for the platformer using either keyboad or 360. Can be overridden in custom code:
            this.InitializeInput();

            BeforeGroundMovementSet += (newValue) =>
            {
                if (mGroundMovement != null && mGroundMovement == mValuesJumpedWith)
                {
                    mValuesJumpedWith = newValue;
                }
            };

            BeforeAirMovementSet += (newValue) =>
            {
                if (mAirMovement != null && mAirMovement == mValuesJumpedWith)
                {
                    mValuesJumpedWith = newValue;
                }
            };

            BeforeAfterDoubleJumpSet += (newValue) =>
            {
                if (mAfterDoubleJump != null && mAfterDoubleJump == mValuesJumpedWith)
                {
                    mValuesJumpedWith = newValue;
                }
            };

            AfterGroundMovementSet  += (not, used) => UpdateCurrentMovement();
            AfterAirMovementSet     += (not, used) => UpdateCurrentMovement();
            AfterAfterDoubleJumpSet += (not, used) => UpdateCurrentMovement();


            PostInitialize();
            if (addToManagers)
            {
                AddToManagers(null);
            }
        }
示例#2
0
        private void UpdateCurrentMovement()
        {
            if (mCurrentMovement?.MaxSpeedX > 0)
            {
                lastNonZeroPlatformerHorizontalMaxSpeed = mCurrentMovement.MaxSpeedX;
            }

            switch (mMovementType)
            {
            case MovementType.Ground:
                mCurrentMovement = GroundMovement;
                break;

            case MovementType.Air:
                mCurrentMovement = AirMovement;
                break;

            case MovementType.AfterDoubleJump:
                mCurrentMovement = AfterDoubleJump;
                break;
            }
        }
示例#3
0
        /// <summary>
        /// Applies the jump input to control vertical velocity and state.
        /// </summary>
        private void ApplyJumpInput()
        {
            bool jumpPushed = JumpInput.WasJustPressed && InputEnabled;
            bool jumpDown   = JumpInput.IsDown && InputEnabled;

            if (jumpPushed && mIsOnGround && VerticalInput?.Value < -.5 && CurrentMovement.CanFallThroughCloudPlatforms && CurrentMovement.CloudFallThroughDistance > 0)
            {
                // try falling through the ground
                cloudCollisionFallThroughY = this.Y - CurrentMovement.CloudFallThroughDistance;
            }
            // Test for jumping up
            else if (jumpPushed && // Did the player push the jump button
                     CurrentMovement.JumpVelocity > 0 &&
                     (
                         mIsOnGround ||
                         AfterDoubleJump == null ||
                         (AfterDoubleJump != null && mHasDoubleJumped == false) ||
                         (AfterDoubleJump != null && AfterDoubleJump.JumpVelocity > 0)

                     )

                     )
            {
                cloudCollisionFallThroughY = null;

                mTimeJumpPushed   = CurrentTime;
                this.YVelocity    = CurrentMovement.JumpVelocity;
                mValuesJumpedWith = CurrentMovement;

                mCanContinueToApplyJumpToHold = true;

                if (JumpAction != null)
                {
                    JumpAction();
                }

                if (CurrentMovementType == MovementType.Air)
                {
                    mHasDoubleJumped = true;
                }
            }


            double secondsSincePush = CurrentTime - mTimeJumpPushed;

            if (mValuesJumpedWith != null &&
                mCanContinueToApplyJumpToHold &&
                secondsSincePush < mValuesJumpedWith.JumpApplyLength &&
                (mValuesJumpedWith.JumpApplyByButtonHold == false || JumpInput.IsDown)
                )
            {
                this.YVelocity = mValuesJumpedWith.JumpVelocity;
            }
            else
            {
                mCanContinueToApplyJumpToHold = false;
            }

            if (mValuesJumpedWith != null && mValuesJumpedWith.JumpApplyByButtonHold &&
                (!JumpInput.IsDown || mHitHead)
                )
            {
                mValuesJumpedWith = null;
            }

            this.YVelocity = System.Math.Max(-CurrentMovement.MaxFallSpeed, this.YVelocity);
        }