예제 #1
0
    public void PlayerUpdateVelocity(cpVect gravity, float damping, float dt)
    {
        bool jumpState = key.y > 0.0f;

        cpVect groundNormal = cpVect.Zero;

        mPlayerBody.EachArbiter((arbiter, o) => BodyArbiterIteratorFunc(arbiter, ref groundNormal), null);

        grounded = (groundNormal.y > ground);
        if (groundNormal.y < ground)
        {
            remainingBoost = ground;
        }

        bool   boost = (jumpState && remainingBoost > ground);
        cpVect g     = (boost ? cpVect.Zero : gravity);

        mPlayerBody.UpdateVelocity(g, damping, dt);


        float target_vx = PLAYER_VELOCITY * key.x;

        cpVect surface_v = new cpVect(-target_vx, 0.0f);

        mPlayerShape.surfaceV = surface_v;
        mPlayerShape.u        = (grounded ? PLAYER_GROUND_ACCEL / GRAVITY : ground);

        if (!grounded)
        {
            mPlayerBody.v.x = cp.cpflerpconst(mPlayerBody.v.x, target_vx, PLAYER_AIR_ACCEL * dt);
        }

        mPlayerBody.v.y = cp.cpfclamp(mPlayerBody.v.y, -FALL_VELOCITY, cp.Infinity);
    }
예제 #2
0
        void planetGravityVelocityFunc(cpBody body, cpVect gravity, float damping, float dt)
        {
            // Gravitational acceleration is proportional to the inverse square of
            // distance, and directed toward the origin. The central planet is assumed
            // to be massive enough that it affects the satellites but not vice versa.
            cpVect p      = body.GetPosition();
            float  sqdist = cpVect.cpvlengthsq(p);
            cpVect g      = cpVect.cpvmult(p, -gravityStrength / (sqdist * cp.cpfsqrt(sqdist)));

            body.UpdateVelocity(g, damping, dt);
        }
예제 #3
0
        public override void Update(long gametime)
        {
            physic.UpdateVelocity(space.GetGravity(), 1, 0.01f);
            physic.UpdatePosition(1);
            shp.Update(trsf);
            cpVect position = physic.GetPosition();

            InvokeOnMainThread(() => {
                SetPosition(position);
            });

            angle = (physic.GetAngle() % 360) / 57.2958f;
            if (position.y > 500)
            {
                physic.ApplyImpulse(new cpVect(1, -150), new cpVect(0.1f, 0.1f));
            }
        }
예제 #4
0
        public void playerUpdateVelocity(cpBody body, cpVect gravity, float damping, float dt)
        {
            bool jumpState = (CCMouse.Instance.dblclick);

            // Grab the grounding normal from last frame
            cpVect groundNormal = cpVect.Zero;

            playerBody.EachArbiter(
                (arbiter, o) => SelectPlayerGroundNormal(arbiter, ref groundNormal)
                , null);

            grounded = (groundNormal.y > 0.0f);
            if (groundNormal.y < 0.0f)
            {
                remainingBoost = 0f;
            }

            // Do a normal-ish update
            bool   boost = (jumpState && remainingBoost > 0.0f);
            cpVect g     = (boost ? cpVect.Zero : gravity);

            body.UpdateVelocity(g, damping, dt);

            // Target horizontal speed for air/ground control
            float target_vx = PLAYER_VELOCITY * ChipmunkDemoKeyboard.x;

            // Update the surface velocity and friction
            // Note that the "feet" move in the opposite direction of the player.
            cpVect surface_v = new cpVect(-target_vx, 0.0f);

            playerShape.surfaceV = surface_v;
            playerShape.u        = (grounded ? PLAYER_GROUND_ACCEL / GRAVITY : 0f);

            // Apply air control if not grounded
            if (!grounded)
            {
                // Smoothly accelerate the velocity
                playerBody.v.x = cp.cpflerpconst(playerBody.v.x, target_vx, PLAYER_AIR_ACCEL * dt);
            }

            body.v.y = cp.cpfclamp(body.v.y, -FALL_VELOCITY, cp.Infinity);
        }