Example #1
0
        /**
         * @brief Create a body contains a polygon shape.
         * points is an array of cpVect structs defining a convex hull with a clockwise winding.
         */
        public static CCPhysicsBody CreatePolygon(CCPoint[] points, int count, CCPhysicsMaterial material, float radius)
        {
            CCPhysicsBody body = new CCPhysicsBody();

            body.AddShape(new CCPhysicsShapePolygon(points, count, material, radius));
            return(body);
        }
Example #2
0
        /** Create a body contains a circle shape. */
        public static CCPhysicsBody CreateCircle(float radius, CCPhysicsMaterial material, CCPoint offset)
        {
            CCPhysicsBody body = new CCPhysicsBody();

            body.AddShape(new CCPhysicsShapeCircle(material, radius, offset));
            return(body);
        }
Example #3
0
        /** Create a body contains a box shape. */
        public static CCPhysicsBody CreateBox(CCSize size, CCPhysicsMaterial material, float radius)
        {
            CCPhysicsBody body = new CCPhysicsBody();

            body.AddShape(new CCPhysicsShapeBox(size, material, radius));
            return(body);
        }
Example #4
0
        /** Create a body contains a EdgeChain shape. */
        public static CCPhysicsBody CreateEdgeChain(CCPoint[] points, int count, CCPhysicsMaterial material, float border = 1)
        {
            CCPhysicsBody body = new CCPhysicsBody();

            body.AddShape(new CCPhysicsShapeEdgeChain(points, count, material, border));
            body.IsDynamic = false;
            return(body);
        }
Example #5
0
        /** Create a body contains a EdgeBox shape. */
        public static CCPhysicsBody CreateEdgeBox(CCSize size, CCPhysicsMaterial material, float border, CCPoint offset)
        {
            CCPhysicsBody body = new CCPhysicsBody();

            body.AddShape(new CCPhysicsShapeEdgeBox(size, material, offset, border));
            body.IsDynamic = false;
            return(body);
        }
Example #6
0
        /** Create a body contains a EdgeSegment shape. */
        public static CCPhysicsBody CreateEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1)
        {
            CCPhysicsBody body = new CCPhysicsBody();

            body.AddShape(new CCPhysicsShapeEdgeSegment(a, b, material, border));
            body.IsDynamic = false;
            return(body);
        }
Example #7
0
		/** Create a body contains a EdgeSegment shape. */
		public static CCPhysicsBody CreateEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1)
		{

			CCPhysicsBody body = new CCPhysicsBody();

            body.AddShape(new CCPhysicsShapeEdgeSegment(a, b, material, border));
			body.IsDynamic = false;
			return body;

		}
Example #8
0
		/**
		 * @brief Create a body contains a polygon shape.
		 * points is an array of cpVect structs defining a convex hull with a clockwise winding.
		 */
		public static CCPhysicsBody CreatePolygon(CCPoint[] points, int count, CCPhysicsMaterial material, float radius)
		{

			CCPhysicsBody body = new CCPhysicsBody();
			body.AddShape(new CCPhysicsShapePolygon(points, count, material, radius));
			return body;
		}
Example #9
0
		/** Create a body contains a box shape. */
		public static CCPhysicsBody CreateBox(CCSize size, CCPhysicsMaterial material, float radius)
		{
			CCPhysicsBody body = new CCPhysicsBody();
			body.AddShape(new CCPhysicsShapeBox(size, material, radius));
			return body;
		}
Example #10
0
		/** Create a body contains a circle shape. */
		public static CCPhysicsBody CreateCircle(float radius, CCPhysicsMaterial material, CCPoint offset)
		{
			CCPhysicsBody body = new CCPhysicsBody();
            body.AddShape(new CCPhysicsShapeCircle(material, radius, offset));
			return body;
		}
Example #11
0
		/** Create a body contains a circle shape. */
		public static CCPhysicsBody CreateCircle(float radius, CCPhysicsMaterial material, cpVect offset)
		{

			CCPhysicsBody body = new CCPhysicsBody();
			body.SetMass(MASS_DEFAULT);
			body.AddShape(new CCPhysicsShapeCircle(material, radius, offset));
			return body;
		}
Example #12
0
        public override void OnEnter()
        {
            base.OnEnter();

            float width = (VisibleBoundsWorldspace.Size.Width - 10) / 4;
            float height = (VisibleBoundsWorldspace.Size.Height - 50) / 4;

            Scene.PhysicsWorld.DebugDrawMask = PhysicsDrawFlags.Shapes | PhysicsDrawFlags.Joints;

            CCNode node = new CCNode();
            CCPhysicsBody box = new CCPhysicsBody();
            node.PhysicsBody = box;
            box.IsDynamic = false;
            node.Position = CCPoint.Zero;
            AddChild(node);

            CCPhysicsJoint joint;
            CCSprite sp1, sp2;

            for (int i = 0; i < 4; i++)
            {

                for (int j = 0; j < 4; j++)
                {

                    CCPoint offset = new CCPoint(
                        0 + 5 + j * width + width / 2,
                        0 + 50 + i * height + height / 2
                    );
                    //CCPoint offset = new CCPoint()
                    box.AddShape(
                        new CCPhysicsShapeEdgeBox(
                            new CCSize(width, height), CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT,
                            offset, 1)
                    );

                    switch (i * 4 + j)
                    {
                        case 0:

                            sp1 = MakeBall(offset - new CCPoint(30, 0), 10);
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBall(offset + new CCPoint(30, 0), 10);
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            joint = CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, offset);
                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);

                            break;

                        case 1:


                            sp1 = MakeBall(offset - new CCPoint(30, 0), 10);
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            joint = CCPhysicsJointFixed.Construct(sp1.PhysicsBody, sp2.PhysicsBody, offset);
                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);

                            break;

                        case 2:


                            sp1 = MakeBall(offset - new CCPoint(30, 0), 10);
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            joint = CCPhysicsJointDistance.Construct(sp1.PhysicsBody, sp2.PhysicsBody, CCPoint.Zero, CCPoint.Zero);
                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);


                            break;

                        case 3:

                            sp1 = MakeBall(offset - new CCPoint(30, 0), 10);
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            joint =
                                CCPhysicsJointSpring.Construct(sp1.PhysicsBody,
                                    sp2.PhysicsBody, CCPoint.Zero, CCPoint.Zero, 500, 0.3f);
                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);


                            break;

                        case 4:


                            sp1 = MakeBall(offset - new CCPoint(30, 0), 10);
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            joint = CCPhysicsJointGroove.Construct(sp1.PhysicsBody, sp2.PhysicsBody, new CCPoint(30, 15), new CCPoint(30, -15), new CCPoint(-30, 0));
                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);


                            break;

                        case 5:

                            sp1 = MakeBall(offset - new CCPoint(30, 0), 10);
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            joint = CCPhysicsJointGroove.Construct(sp1.PhysicsBody, sp2.PhysicsBody, new CCPoint(30, 15), new CCPoint(30, -15), new CCPoint(-30, 0));
                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);

                            break;

                        case 6:

                            sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10));
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            joint = CCPhysicsJointRotarySpring.Construct(sp1.PhysicsBody, sp2.PhysicsBody, 3000.0f, 60.0f);

                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);

                            break;
                        case 7:

                            sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10));
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            joint = CCPhysicsJointRotaryLimit.Construct(sp1.PhysicsBody, sp2.PhysicsBody, 0.0f, ChipmunkSharp.cp.M_PI_2);

                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);

                            break;
                        case 8:

                            sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10));
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            joint = CCPhysicsJointRatchet.Construct(sp1.PhysicsBody, sp2.PhysicsBody, 0.0f, ChipmunkSharp.cp.M_PI_2);

                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);

                            break;
                        case 9:

                            sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10));
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            joint = CCPhysicsJointGear.Construct(sp1.PhysicsBody, sp2.PhysicsBody, 0.0f, 2f);

                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);

                            break;
                        case 10:

                            sp1 = MakeBox(offset - new CCPoint(30, 0), new CCSize(30, 10));
                            sp1.PhysicsBody.Tag = DRAG_BODYS_TAG;
                            sp2 = MakeBox(offset + new CCPoint(30, 0), new CCSize(30, 10));
                            sp2.PhysicsBody.Tag = DRAG_BODYS_TAG;

                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            Scene.PhysicsWorld.AddJoint(CCPhysicsJointPin.Construct(sp1.PhysicsBody, sp2.PhysicsBody, sp1.Position));
                            joint = CCPhysicsJointMotor.Construct(sp1.PhysicsBody, sp2.PhysicsBody, ChipmunkSharp.cp.M_PI_2);

                            Scene.PhysicsWorld.AddJoint(joint);

                            AddChild(sp1);
                            AddChild(sp2);

                            break;


                        default:
                            break;
                    }



                }

            }

            Schedule();


        }
Example #13
0
        public override void OnEnter()
        {
            base.OnEnter();
            ToggleDebug();

            _distance = 0.0f;
            _rotationV = 0.0f;

            Scene.Scale = 0.5f;

            //Create a boundin box container room
            var node = new CCNode();
            var body = new CCPhysicsBody();
            body.IsDynamic = false;

            CCPhysicsMaterial staticMaterial = new CCPhysicsMaterial(cp.PHYSICS_INFINITY,
                0, 0.5f);

            body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(50, 0), LeftTop + new CCPoint(50, -130), staticMaterial, 2.0f));
            body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(190, 0), LeftTop + new CCPoint(100, -50), staticMaterial, 2.0f));
            body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(100, -50), LeftTop + new CCPoint(100, -90), staticMaterial, 2.0f));
            body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(50, -130), LeftTop + new CCPoint(100, -145), staticMaterial, 2.0f));
            body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(100, -145), LeftBottom + new CCPoint(100, 80), staticMaterial, 2.0f));
            body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(150, -80), LeftBottom + new CCPoint(150, 80), staticMaterial, 2.0f));
            body.AddShape(new CCPhysicsShapeEdgeSegment(LeftTop + new CCPoint(150, -80), RightTop + new CCPoint(-100, -150), staticMaterial, 2.0f));

            body.SetCategoryBitmask(0x01);

            for (int i = 0; i < 6; ++i)
            {
                var ball = MakeBall(LeftTop + new CCPoint(75 + CCRandom.Float_0_1() * 90, 0), 22, new CCPhysicsMaterial(0.05f, 0, 0.1f));
                ball.PhysicsBody.Tag = DRAG_BODYS_TAG;
                AddChild(ball);
            }

            node.PhysicsBody = body;
            AddChild(node);

            CCPoint[] vec = new CCPoint[4] {
				new CCPoint(LeftTop + new CCPoint(102,-148)),
				new CCPoint(LeftTop + new CCPoint(148,-161)),
				new CCPoint(LeftBottom + new CCPoint(148,20)),
				new CCPoint(LeftBottom + new CCPoint(102,20))
			};

            var world = Scene.PhysicsWorld;

            // small gear
            var sgear = new CCNode();// Node::create();
            var sgearB = CCPhysicsBody.CreateCircle(44, CCPoint.Zero);
            sgear.PhysicsBody = sgearB;
            sgear.Position = LeftBottom + new CCPoint(125, 0);
            this.AddChild(sgear);
            //sgearB.SetCategoryBitmask(0x04);
            //sgearB.SetCollisionBitmask(0x04);
            sgearB.Tag = 1;
            world.AddJoint(CCPhysicsJointPin.Construct(body, sgearB, sgearB.Position));

            // big gear
            var bgear = new CCNode();
            var bgearB = CCPhysicsBody.CreateCircle(100);
            bgear.PhysicsBody = (bgearB);
            bgear.Position = LeftBottom + new CCPoint(275, 0);
            this.AddChild(bgear);
            //bgearB.SetCategoryBitmask(0x04);
            world.AddJoint(CCPhysicsJointPin.Construct(body, bgearB, bgearB.Position));

            // pump
            var pump = new CCNode();
            var center = CCPhysicsShape.GetPolygonCenter(vec, 4);
            pump.Position = center;
            var pumpB = CCPhysicsBody.CreatePolygon(vec, 4, CCPhysicsMaterial.PHYSICSSHAPE_MATERIAL_DEFAULT, 0.0f);
            pump.PhysicsBody = pumpB;
            this.AddChild(pump);
            //pumpB.SetCategoryBitmask(0x02);
            pumpB.SetGravityEnable(false);
            world.AddJoint(CCPhysicsJointDistance.Construct(pumpB, sgearB, new CCPoint(0, 0), new CCPoint(0, -44)));

            // plugger
            CCPoint[] seg = new CCPoint[] { LeftTop + new CCPoint(75, -120), LeftBottom + new CCPoint(75, -100) };
            CCPoint segCenter = (seg[1] + seg[0]) / 2;
            seg[1] -= segCenter;
            seg[0] -= segCenter;
            var plugger = new CCNode();
            var pluggerB = CCPhysicsBody.CreateEdgeSegment(seg[0], seg[1], new CCPhysicsMaterial(0.01f, 0.0f, 0.5f), 20);
            pluggerB.IsDynamic = true;
            pluggerB.SetMass(30);
            pluggerB.Moment = 100000;
            plugger.PhysicsBody = pluggerB;
            plugger.Position = segCenter;
            this.AddChild(plugger);
            //pluggerB.SetCategoryBitmask(0x02);
            //sgearB.SetCollisionBitmask(0x04 | 0x01);
            world.AddJoint(CCPhysicsJointPin.Construct(body, pluggerB, LeftBottom + new CCPoint(75, -90)));
            world.AddJoint(CCPhysicsJointDistance.Construct(pluggerB, sgearB, pluggerB.World2Local(LeftBottom + new CCPoint(75, 0)), new CCPoint(44, 0)));

            //drops a grosini sprite on center on window

            Schedule();
        }
Example #14
0
		/** Create a body contains a EdgePolygon shape. */
		public static CCPhysicsBody CreateEdgePolygon(cpVect[] points, int count, CCPhysicsMaterial material, float border = 1)
		{
			CCPhysicsBody body = new CCPhysicsBody();
			body.AddShape(new CCPhysicsShapeEdgePolygon(points, count, material, border));
			body._dynamic = false;
			return body;
		}
Example #15
0
		/** Create a body contains a EdgeBox shape. */
		public static CCPhysicsBody CreateEdgeBox(CCSize size, CCPhysicsMaterial material, float border, CCPoint offset)
		{
			CCPhysicsBody body = new CCPhysicsBody();
            body.AddShape(new CCPhysicsShapeEdgeBox(size, material, offset, border));
			body.IsDynamic = false;
			return body;
		}
Example #16
0
		/** Create a body contains a EdgeChain shape. */
		public static CCPhysicsBody CreateEdgeChain(CCPoint[] points, int count, CCPhysicsMaterial material, float border = 1)
		{
			CCPhysicsBody body = new CCPhysicsBody();
            body.AddShape(new CCPhysicsShapeEdgeChain(points, count, material, border));
			body.IsDynamic = false;
			return body;
		}
Example #17
0
        public CCPhysicsBody j2cpBody( JObject bodyValue)
        {
            CCPhysicsBody body = new CCPhysicsBody();
            SetBodyTypeFromInt(body, (int)bodyValue.GetValue("type"));
            //int i = 0;

            JArray fixtureValues = (JArray)bodyValue["fixture"];
            if (null != fixtureValues)
            {
                List<CCPhysicsShape> shape;
                int numFixtureValues = fixtureValues.Count;
                for (int i = 0; i < numFixtureValues; i++)
                {
                    JObject fixtureValue = (JObject)fixtureValues[i];
                    shape = j2cpShape(fixtureValue, body.BodyType);
                    readCustomPropertiesFromJson(shape, fixtureValue);
                    body.AddShape(shape,true);
                }
            }

            body.Position = jsonToPoint("position", bodyValue);
            body.SetAngle(jsonToFloat("angle", bodyValue));
            body.SetVelocity(jsonToPoint("linearVelocity", bodyValue));
            body.SetAngularVelocity( jsonToFloat("angularVelocity", bodyValue));
            //body. linearDamping = jsonToFloat("linearDamping", bodyValue, -1, 0);
            //body.set angularDamping = jsonToFloat("angularDamping", bodyValue, -1, 0);
            //body.gravityScale = jsonToFloat("gravityScale", bodyValue, -1, 1);

            //body.allowSleep = bodyValue["allowSleep"] == null ? false : (bool)bodyValue["allowSleep"];
            //body.awake =;
            var awake = bodyValue["awake"] == null ? false : (bool)bodyValue["awake"];
            if (!awake)
                body.Body.Sleep();

            var fixedRotation = bodyValue["fixedRotation"] == null ? false : (bool)bodyValue["fixedRotation"];
            if (fixedRotation)
                body.Moment = cp.Infinity;

            //body.bullet = bodyValue["bullet"] == null ? false : (bool)bodyValue["bullet"];

            //bodyDef.active = bodyValue["active"] == null ? false : (bool)bodyValue["active"];

            //body.active = true;

            String bodyName = bodyValue["name"] == null ? "" : (string)bodyValue["active"];
            if (!string.IsNullOrEmpty(bodyName))
                SetBodyName(body, bodyName);

            // may be necessary if user has overridden mass characteristics
            //b2MassData massData = new b2MassData();
            if (body.BodyType == cpBodyType.DYNAMIC)
            body.Body.SetMass(jsonToFloat("massData-mass", bodyValue));
            //massData.mass = ;
            body.Body.SetCenterOfGravity(jsonToVec("massData-center", bodyValue));
            //massData.center =;

            return body;
        }