Exemplo n.º 1
0
        static cpSpace NoCollide(cpSpace space)
        {
            space.SetIterations(10);

            var handler = space.AddCollisionHandler(2, 2);

            //, (a, s, o) => NoCollide_begin(a, s, o), null, null, null);
            handler.beginFunc = NoCollide_begin;
            float radius     = 4.5f;
            var   staticBody = space.GetStaticBody();

            space.AddShape(new cpSegmentShape(staticBody, new cpVect(-330 - radius, -250 - radius), new cpVect(330 + radius, -250 - radius), 0.0f)).SetElasticity(1.0f);
            space.AddShape(new cpSegmentShape(staticBody, new cpVect(330 + radius, 250 + radius), new cpVect(330 + radius, -250 - radius), 0.0f)).SetElasticity(1.0f);
            space.AddShape(new cpSegmentShape(staticBody, new cpVect(330 + radius, 250 + radius), new cpVect(-330 - radius, 250 + radius), 0.0f)).SetElasticity(1.0f);
            space.AddShape(new cpSegmentShape(staticBody, new cpVect(-330 - radius, -250 - radius), new cpVect(-330 - radius, 250 + radius), 0.0f)).SetElasticity(1.0f);

            for (int x = -320; x <= 320; x += 20)
            {
                for (int y = -240; y <= 240; y += 20)
                {
                    space.AddShape(new cpCircleShape(staticBody, radius, new cpVect(x, y)));
                }
            }

            for (int y = 10 - 240; y <= 240; y += 40)
            {
                float  mass = 7.0f;
                cpBody body = space.AddBody(new cpBody(mass, cp.MomentForCircle(mass, 0.0f, radius, cpVect.Zero)));
                body.SetPosition(new cpVect(-320.0f, y));
                body.SetVelocity(new cpVect(100.0f, 0.0f));

                cpShape shape = space.AddShape(new cpCircleShape(body, radius, cpVect.Zero));
                shape.SetElasticity(1.0f);
                shape.SetCollisionType(2);
            }

            for (int x = 30 - 320; x <= 320; x += 40)
            {
                float  mass = 7.0f;
                cpBody body = space.AddBody(new cpBody(mass, cp.MomentForCircle(mass, 0.0f, radius, cpVect.Zero)));

                body.SetPosition(new cpVect(x, -240.0f));
                body.SetVelocity(new cpVect(0.0f, 100.0f));

                cpShape shape = space.AddShape(new cpCircleShape(body, radius, cpVect.Zero));
                shape.SetElasticity(1.0f);
                shape.SetCollisionType(2);
            }
            return(space);
        }