Esempio n. 1
0
        public override void Load()
        {
            // Ground body
            Body ground;
            {
                ground = Physics.NewBody(m_world);

                // outline
                Physics.NewFixture(ground,
                                   Physics.NewChainShape(true, new Vector2[]
                {
                    new Vector2(0.0f, -2.0f),
                    new Vector2(8.0f, 6.0f),
                    new Vector2(8.0f, 20.0f),
                    new Vector2(-8.0f, 20.0f),
                    new Vector2(-8.0f, 6.0f),
                }), 0);
            }

            // Flippers
            {
                var p1 = new Vector2(-2.0f, 0.0f);
                var p2 = new Vector2(2.0f, 0.0f);


                Body leftFlipper  = Physics.NewBody(m_world, p1.X, p1.Y, BodyType.Dynamic);
                Body rightFlipper = Physics.NewBody(m_world, p2.X, p2.Y, BodyType.Dynamic);

                var box = Physics.NewRectangleShape(1.75f * 2, 0.1f * 2);
                Physics.NewFixture(leftFlipper, box, 1.0f);
                Physics.NewFixture(rightFlipper, box, 1.0f);

                lrj = Physics.NewRevoluteJoint(ground, leftFlipper, p1);
                lrj.SetMotorSpeed(0);
                lrj.SetMotorEnabled(true);
                lrj.SetLimitsEnabled(true);
                lrj.SetMaxMotorTorque(1000.0f);
                lrj.SetLimits(-30.0f * Mathf.PI / 180.0f, 5.0f * Mathf.PI / 180.0f);

                rrj = Physics.NewRevoluteJoint(ground, rightFlipper, p2);
                rrj.SetMotorSpeed(0);
                rrj.SetMotorEnabled(true);
                rrj.SetLimitsEnabled(true);
                rrj.SetMaxMotorTorque(1000.0f);
                rrj.SetLimits(-5.0f * Mathf.PI / 180.0f, 30.0f * Mathf.PI / 180.0f);
            }

            // Circle character
            {
                var body = Physics.NewBody(m_world, 1.0f, 15.0f, BodyType.Dynamic);
                body.SetBullet(true);
                Physics.NewFixture(body, Physics.NewCircleShape(0.2f), 1.0f);
            }
        }
Esempio n. 2
0
        public override void Load()
        {
            genDT = 0;
            Body ground = Physics.NewBody(m_world);

            {
                Body body = Physics.NewBody(m_world, 0.0f * scale, 10.0f * scale, BodyType.Dynamic);
                body.SetSleepingAllowed(false);

                Physics.NewFixture(body,
                                   NewRectShape(body, 10.0f * scale, 0.0f * scale, 0.5f * 2 * scale, 10.0f * 2 * scale),
                                   5.0f * scale);

                Physics.NewFixture(body,
                                   NewRectShape(body, -10.0f * scale, 0.0f * scale, 0.5f * 2 * scale, 10.0f * 2 * scale),
                                   5.0f * scale);

                Physics.NewFixture(body,
                                   NewRectShape(body, 0.0f * scale, 10.0f * scale, 10.0f * 2 * scale, 0.5f * 2 * scale),
                                   5.0f * scale);

                Physics.NewFixture(body,
                                   NewRectShape(body, 0.0f * scale, -10.0f * scale, 10.0f * 2 * scale, 0.5f * 2 * scale),
                                   5.0f * scale);

                //RevoluteJoint jd = Physics.NewRevoluteJoint(ground, body,
                //    new Vector2(0.0f, 10.0f) * scale,
                //    new Vector2(0.0f, 0.0f) * scale
                //    );
                RevoluteJoint jd = Physics.NewRevoluteJoint(ground, body,
                                                            new Vector2(0.0f, 10.0f) * scale,
                                                            new Vector2(0.0f, 10.0f) * scale
                                                            );
                jd.SetMotorSpeed(-0.05f * Mathf.PI);
                jd.SetMaxMotorTorque(1e8f * scale);
                jd.SetMotorEnabled(true);
            }

            m_count = 0;
        }