Esempio n. 1
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();
        }