Пример #1
0
        /**
         * Internal function for updating the position and speed of this object.
         * Useful for cases when you need to update this but are buried down in too many supers.
         */
        protected void updateMotion()
        {
            if (!moves)
            {
                return;
            }

            if (_solid)
            {
                refreshHulls();
            }
            onFloor = false;

            // Motion/physics
            angularVelocity = FlxU.computeVelocity(angularVelocity, angularAcceleration, angularDrag, maxAngular);
            angle          += angularVelocity * FlxG.elapsed;
            Vector2 thrustComponents;

            if (thrust != 0)
            {
                thrustComponents = FlxU.rotatePoint(-thrust, 0, 0, 0, angle);
                Vector2 maxComponents = FlxU.rotatePoint(-maxThrust, 0, 0, 0, angle);
                float   max           = Math.Abs(maxComponents.X);
                if (max > Math.Abs(maxComponents.Y))
                {
                    maxComponents.Y = max;
                }
                else
                {
                    max = Math.Abs(maxComponents.Y);
                }
                maxVelocity.X = Math.Abs(max);
                maxVelocity.Y = Math.Abs(max);
            }
            else
            {
                thrustComponents = Vector2.Zero;
            }
            velocity.X = FlxU.computeVelocity(velocity.X, acceleration.X + thrustComponents.X, drag.X, maxVelocity.X);
            velocity.Y = FlxU.computeVelocity(velocity.Y, acceleration.Y + thrustComponents.Y, drag.Y, maxVelocity.Y);
            x         += velocity.X * FlxG.elapsed;
            y         += velocity.Y * FlxG.elapsed;

            //Update collision data with new movement results
            if (!_solid)
            {
                return;
            }
            colVector.X     = velocity.X * FlxG.elapsed;
            colVector.Y     = velocity.Y * FlxG.elapsed;
            colHullX.width += ((colVector.X > 0) ? colVector.X : -colVector.X);
            if (colVector.X < 0)
            {
                colHullX.x += colVector.X;
            }
            colHullY.x       = x;
            colHullY.height += ((colVector.Y > 0) ? colVector.Y : -colVector.Y);
            if (colVector.Y < 0)
            {
                colHullY.y += colVector.Y;
            }
        }