Пример #1
0
        public void Handleinput(EnvironmentInputs inputs, Level level)
        {
            bool leftButtonDown  = inputs.CurrentInput.Contains(CocosSharp.CCKeys.Left);
            bool rightButtonDown = inputs.CurrentInput.Contains(CocosSharp.CCKeys.Right);
            bool upButtonDown    = inputs.CurrentInput.Contains(CocosSharp.CCKeys.Up);
            bool downButtonDown  = inputs.CurrentInput.Contains(CocosSharp.CCKeys.Down);

            leftVelocityX  = UpdateVelocity(leftButtonDown, leftVelocityX);
            rightVelocityX = UpdateVelocity(rightButtonDown, rightVelocityX);
            upVelocityY    = UpdateVelocity(upButtonDown, upVelocityY);
            downVelocityY  = UpdateVelocity(downButtonDown, downVelocityY);

            // adjust for max total speed
            var reduction = GetSpeedReduction(tempVelocityX, tempVelocityY);

            // adjust for level's edge
            VelocityX = AdjustVelocityForlevelEdge(CoordinateX, tempVelocityX, level.LevelWidth, reduction.ReductionX);
            VelocityY = AdjustVelocityForlevelEdge(CoordinateY, tempVelocityY, level.LevelHeight, reduction.ReductionY);

            // direction of the character
            FacingDirection = GetDirectionIndexFourDirections(reduction.Angle, VelocityX, VelocityY);

            // set position
            CoordinateX += VelocityX;
            CoordinateY += VelocityY;
        }
Пример #2
0
        public void Handleinput(EnvironmentInputs inputs, Level level)
        {
            bool leftButtonDown  = inputs.CurrentInput.Contains(CocosSharp.CCKeys.Left);
            bool rightButtonDown = inputs.CurrentInput.Contains(CocosSharp.CCKeys.Right);
            bool upButtonDown    = inputs.CurrentInput.Contains(CocosSharp.CCKeys.Up);
            bool downButtonDown  = inputs.CurrentInput.Contains(CocosSharp.CCKeys.Down);

            leftVelocityX  = UpdateVelocity(leftButtonDown, leftVelocityX);
            rightVelocityX = UpdateVelocity(rightButtonDown, rightVelocityX);
            upVelocityY    = UpdateVelocity(upButtonDown, upVelocityY);
            downVelocityY  = UpdateVelocity(downButtonDown, downVelocityY);


            VelocityX = AdjustVelocityForlevelEdge(PositionX, (rightVelocityX - leftVelocityX), level.LevelWidth);
            VelocityY = AdjustVelocityForlevelEdge(PositionY, (upVelocityY - downVelocityY), level.LevelHeight);

            // set position
            PositionX += VelocityX;
            PositionY += VelocityY;
        }