Exemplo n.º 1
0
        public void Update()
        {
            lock (UpdateLock)
            {
                var tries = 5;
                try
                {
                    if (_reindexStatic)
                    {
                        _space.ReindexStatic();
                        _reindexStatic = false;
                    }

                    _space.Step(Game.TickDurationMs * 0.001f);

                    AssureLimits();
                    RecheckCollisions();
                }
                catch (Exception exception)
                {
                    Log.Error(exception);
                    tries--;
                    if (tries <= 0)
                    {
                        throw;
                    }
                }
            }
        }
Exemplo n.º 2
0
    private void update(cpSpace space, float dt)
    {
        bool jumpState = (key.y > 0.0f);

        if (jumpState && !lastJumpState && grounded)
        {
            float jump_v = cp.cpfsqrt((float)2.0 * JUMP_HEIGHT * GRAVITY);
            mPlayerBody.v = cpVect.cpvadd(mPlayerBody.v, new cpVect(0.0f, jump_v));

            remainingBoost = JUMP_BOOST_HEIGHT / jump_v;
        }

        space.Step(dt);

        remainingBoost -= dt;
        lastJumpState   = jumpState;
    }
Exemplo n.º 3
0
    static void Main(string[] args)
    {
        cpSpace space = new cpSpace();

        space.SetGravity(new cpVect(0, -100));

        cpShape shape = cpShape.NewSegment(space.StaticBody, new cpVect(-20, 5), new cpVect(20, -5), 0);

        shape.SetFriction(1);

        space.AddShape(shape);

        double radius = 5;
        double mass   = 1;
        double moment = cpUtil.MomentForCircle(mass, 0, radius, cpVect.Zero);

        cpBody ballBody = new cpBody(mass, moment);

        space.AddBody(ballBody);
        ballBody.Position = new cpVect(0, 15);

        cpShape ballShape = cpShape.NewCircle(ballBody, radius, cpVect.Zero);

        space.AddShape(ballShape);
        ballShape.SetFriction(0.7);

        double timeStep = 1 / 60d;

        for (double time = 0; time < 2; time += timeStep)
        {
            cpVect pos = ballBody.Position;
            cpVect vel = ballBody.Velocity;
            Console.WriteLine("Time is {0:F2}. ballBody is at ({1:F2}, {2:F2}). It's velocity is ({3:F2}, {4:F2})",
                              time, pos.X, pos.Y, vel.X, vel.Y
                              );
            space.Step(timeStep);
        }

        Console.ReadKey();
    }
Exemplo n.º 4
0
 protected override void OnUpdate(long tick)
 {
     spc.Step(1 / 60);
     square.Update(tick);
     ground.Update(tick);
 }
Exemplo n.º 5
0
        }                                                          // 0 == _space.locked ? false : true; }

        public void Step(float delta)
        {
            _space.Step(delta);
        }