Exemplo n.º 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);
        }
Exemplo n.º 2
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);
        }
Exemplo n.º 3
0
 public CCPhysicsShape(float radius, CCPhysicsMaterial material, CCPoint offset)
 {
     // TODO: Complete member initialization
     this.radius   = radius;
     this.material = material;
     this.offset   = PhysicsHelper.CCPointToCpVect(offset);
 }
Exemplo n.º 4
0
        //protected cpVect _offset;
        #endregion

        #region PUBLIC METHODS

        public CCPhysicsShapeBox(CCSize size, CCPhysicsMaterial material, float radius)
        {
            cpVect wh = PhysicsHelper.size2cpv(size);

            _type = PhysicsType.BOX;

            cpVect[] vec =
            {
                new cpVect(-wh.x / 2.0f, -wh.y / 2.0f),
                new cpVect(-wh.x / 2.0f, wh.y / 2.0f),
                new cpVect(wh.x / 2.0f,  wh.y / 2.0f),
                new cpVect(wh.x / 2.0f, -wh.y / 2.0f)
            };

            cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.SharedBody, 4, vec, radius);

            _info.Add(shape);

            //_offset = offset;
            _area   = CalculateArea();
            _mass   = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
            _moment = CalculateDefaultMoment();

            Material = material;
        }
Exemplo n.º 5
0
        public CCPhysicsShapeEdgeBox(CCSize size, CCPhysicsMaterial material, CCPoint offset, float border = 1)
        {
            _type = PhysicsType.EDGEBOX;

            List <cpVect> vec = new List <cpVect>()
            {
                new cpVect(-size.Width / 2 + offset.X, -size.Height / 2 + offset.Y),
                new cpVect(+size.Width / 2 + offset.X, -size.Height / 2 + offset.Y),
                new cpVect(+size.Width / 2 + offset.X, +size.Height / 2 + offset.Y),
                new cpVect(-size.Width / 2 + offset.X, +size.Height / 2 + offset.Y)
            };


            int i = 0;

            for (; i < 4; ++i)
            {
                cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody, vec[i], vec[(i + 1) % 4],
                                                   border);
                _info.Add(shape);
            }

            _offset = offset;
            _mass   = CCPhysicsBody.MASS_DEFAULT;
            _moment = CCPhysicsBody.MOMENT_DEFAULT;

            Material = material;
        }
Exemplo n.º 6
0
        public CCPhysicsShapeEdgePolygon(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1)
        {
            _type = PhysicsType.EDGEPOLYGEN;

            int i    = 0;
            var vecs = PhysicsHelper.CCPointsTocpVects(vec);

            for (; i < count; ++i)
            {
                cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody, vecs[i], vecs[(i + 1) % count],
                                                   border);

                if (shape == null)
                {
                    break;
                }

                shape.SetElasticity(1.0f);
                shape.SetFriction(1.0f);

                _info.Add(shape);
            }

            _mass   = cp.Infinity;
            _moment = cp.Infinity;

            Material = material;
        }
Exemplo n.º 7
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);
        }
Exemplo n.º 8
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);
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
Exemplo n.º 11
0
        public CCPhysicsShapeCircle(CCPhysicsMaterial material, float radius, CCPoint offset)
        {
            _type = PhysicsType.CIRCLE;

            cpShape shape = new cpCircleShape(CCPhysicsShapeInfo.SharedBody, radius, PhysicsHelper.CCPointToCpVect(offset));

            _info.Add(shape);

            _area   = CalculateArea();
            _mass   = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
            _moment = CalculateDefaultMoment();

            Material = material;
        }
Exemplo n.º 12
0
        public void Init(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
        {
            _type = PhysicsType.POLYGEN;

            cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.SharedBody, count, PhysicsHelper.CCPointsTocpVects(vecs), radius);


            _info.Add(shape);

            _area   = CalculateArea();
            _mass   = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
            _moment = CalculateDefaultMoment();

            Material = material;
        }
Exemplo n.º 13
0
        public CCPhysicsShapeEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1)
        {
            cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody,
                                               PhysicsHelper.CCPointToCpVect(a),
                                               PhysicsHelper.CCPointToCpVect(b),
                                               border);

            _type = PhysicsType.EDGESEGMENT;

            _info.Add(shape);

            _mass   = cp.Infinity;
            _moment = cp.Infinity;

            Material = material;
        }
Exemplo n.º 14
0
        public CCPhysicsShapeEdgeChain(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1)
        {
            _type = PhysicsType.EDGECHAIN;
            var vecs = PhysicsHelper.CCPointsTocpVects(vec);
            int i    = 0;

            for (; i < count; ++i)
            {
                cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vecs[i], vecs[i + 1],
                                                   border);
                shape.SetElasticity(1.0f);
                shape.SetFriction(1.0f);

                _info.add(shape);
            }

            _mass   = cp.Infinity;
            _moment = cp.Infinity;

            SetMaterial(material);
        }
Exemplo n.º 15
0
		public CCPhysicsShape(float radius, CCPhysicsMaterial material, CCPoint offset)
		{
			// TODO: Complete member initialization
			this.radius = radius;
			this.material = material;
            this.offset = PhysicsHelper.CCPointToCpVect(offset);
		}
Exemplo n.º 16
0
		public CCPhysicsShapeEdgeChain(cpVect[] vec, int count, CCPhysicsMaterial material, float border = 1)
		{

			_type = PhysicsType.EDGECHAIN;

			int i = 0;
			for (; i < count; ++i)
			{
				cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vec[i], vec[i + 1],
											  border);
				shape.SetElasticity(1.0f);
				shape.SetFriction(1.0f);

				_info.add(shape);
			}

			_mass = cp.Infinity;
			_moment = cp.Infinity;

			SetMaterial(material);
		}
Exemplo n.º 17
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;
		}
Exemplo n.º 18
0
		public CCPhysicsShapeEdgeSegment(CCPoint a, CCPoint b, CCPhysicsMaterial material, float border = 1)
		{

			cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody,
                PhysicsHelper.CCPointToCpVect(a),
                PhysicsHelper.CCPointToCpVect(b),
										   border);

			_type = PhysicsType.EDGESEGMENT;


			_info.Add(shape);

			_mass = cp.Infinity;
			_moment = cp.Infinity;

			Material = material;
		}
Exemplo n.º 19
0
		public void SetMaterial(CCPhysicsMaterial material)
		{
			SetDensity(material.density);
			SetRestitution(material.restitution);
			SetFriction(material.friction);
		}
Exemplo n.º 20
0
		public CCPhysicsShape(float radius, CCPhysicsMaterial material, cpVect offset)
		{
			// TODO: Complete member initialization
			this.radius = radius;
			this.material = material;
			this.offset = offset;
		}
Exemplo n.º 21
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;
		}
Exemplo n.º 22
0
		public void Init(cpVect[] vecs, int count, CCPhysicsMaterial material, float radius)
		{
			_type = PhysicsType.POLYGEN;

			cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.getSharedBody(), count, vecs, radius);


			_info.add(shape);

			_area = CalculateArea();
			_mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
			_moment = CalculateDefaultMoment();

			SetMaterial(material);

		}
Exemplo n.º 23
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;
		}
Exemplo n.º 24
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;
		}
Exemplo n.º 25
0
 public void SetMaterial(CCPhysicsMaterial material)
 {
     SetDensity(material.density);
     SetRestitution(material.restitution);
     SetFriction(material.friction);
 }
Exemplo n.º 26
0
		public CCPhysicsShapeEdgeChain(CCPoint[] vec, int count, CCPhysicsMaterial material, float border = 1)
		{

			_type = PhysicsType.EDGECHAIN;
            var vecs = PhysicsHelper.CCPointsTocpVects(vec);
			int i = 0;
			for (; i < count; ++i)
			{
				cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody, vecs[i], vecs[i + 1],
											  border);
				shape.SetElasticity(1.0f);
				shape.SetFriction(1.0f);

				_info.Add(shape);
			}

			_mass = cp.Infinity;
			_moment = cp.Infinity;

			Material = material;
		}
Exemplo n.º 27
0
        public CCPhysicsShapeEdgeBox(CCSize size, CCPhysicsMaterial material, CCPoint offset, float border = 1)
		{

			_type = PhysicsType.EDGEBOX;

			List<cpVect> vec = new List<cpVect>() {
                new cpVect(-size.Width/2+offset.X, -size.Height/2+offset.Y),
                new cpVect(+size.Width/2+offset.X, -size.Height/2+offset.Y),
                new cpVect(+size.Width/2+offset.X, +size.Height/2+offset.Y),
                new cpVect(-size.Width/2+offset.X, +size.Height/2+offset.Y)
          };


			int i = 0;
			for (; i < 4; ++i)
			{
				cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.SharedBody, vec[i], vec[(i + 1) % 4],
												   border);
				_info.Add(shape);
			}

			_offset = offset;
			_mass = CCPhysicsBody.MASS_DEFAULT;
			_moment = CCPhysicsBody.MOMENT_DEFAULT;

			Material = material;
		}
Exemplo n.º 28
0
		public CCPhysicsShapeEdgeBox(CCSize size, CCPhysicsMaterial material, float border /* = 1 */, cpVect offset)
		{

			_type = PhysicsType.EDGEBOX;

			List<cpVect> vec = new List<cpVect>() {
              new cpVect(-size.Width/2+offset.x, -size.Height/2+offset.y),
              new cpVect(+size.Width/2+offset.x, -size.Height/2+offset.y),
              new cpVect(+size.Width/2+offset.x, +size.Height/2+offset.y),
              new cpVect(-size.Width/2+offset.x, +size.Height/2+offset.y)
          };


			int i = 0;
			for (; i < 4; ++i)
			{
				cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(), vec[i], vec[(i + 1) % 4],
												   border);
				_info.add(shape);
			}

			_offset = offset;
			_mass = CCPhysicsBody.MASS_DEFAULT;
			_moment = CCPhysicsBody.MOMENT_DEFAULT;

			SetMaterial(material);
		}
Exemplo n.º 29
0
 public CCSprite MakeBall(CCPoint point, float radius, CCPhysicsMaterial material)
 {
     CCSprite ball = new CCSprite("Images/ball");
     ball.Scale = 0.13f * radius;
     var body = CCPhysicsBody.CreateCircle(radius, material, CCPoint.Zero);
     ball.PhysicsBody = body;
     ball.Position = point;// new cpVect(point.X, point.Y);
     return ball;
 }
Exemplo n.º 30
0
		public CCPhysicsShapeEdgeSegment(cpVect a, cpVect b, CCPhysicsMaterial material, float border = 1)
		{

			cpShape shape = new cpSegmentShape(CCPhysicsShapeInfo.getSharedBody(),
										   a,
										   b,
										   border);

			_type = PhysicsType.EDGESEGMENT;


			_info.add(shape);

			_mass = cp.Infinity;
			_moment = cp.Infinity;

			SetMaterial(material);
		}
Exemplo n.º 31
0
        public CCSprite MakeTriangle(CCPoint point, CCSize size, int color, CCPhysicsMaterial material)
        {
            bool yellow = false;
            if (color == 0)
            {
                yellow = CCRandom.Float_0_1() > 0.5f;
            }
            else
            {
                yellow = color == 1;
            }

            var triangle = yellow ? new CCSprite("Images/YellowTriangle") : new CCSprite("Images/CyanTriangle");

            if (size.Height == 0)
            {
                triangle.Scale = size.Width / 100.0f;
            }
            else
            {
                triangle.ScaleX = size.Width / 50.0f;
                triangle.ScaleY = size.Height / 43.5f;
            }

            CCPoint[] vers = new CCPoint[] {
        new CCPoint(0, size.Height/2), 
        new CCPoint(size.Width/2, -size.Height/2),
        new CCPoint(-size.Width/2, -size.Height/2)
    };

            var body = CCPhysicsBody.CreateEdgePolygon(vers, 3, material);
            triangle.PhysicsBody = body;
            triangle.Position = new CCPoint(point.X, point.Y);

            return triangle;
        }
Exemplo n.º 32
0
		public CCPhysicsShapeCircle(CCPhysicsMaterial material, float radius, cpVect offset)
		{

			_type = PhysicsType.CIRCLE;

			cpShape shape = new cpCircleShape(CCPhysicsShapeInfo.getSharedBody(), radius, offset);

			_info.add(shape);

			_area = CalculateArea();
			_mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
			_moment = CalculateDefaultMoment();

			SetMaterial(material);
		}
Exemplo n.º 33
0
		public void Init(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
		{
			_type = PhysicsType.POLYGEN;

            cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.SharedBody, count, PhysicsHelper.CCPointsTocpVects(vecs), radius);


			_info.Add(shape);

			_area = CalculateArea();
			_mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
			_moment = CalculateDefaultMoment();

			Material = material;

		}
Exemplo n.º 34
0
 public CCPhysicsShapePolygon(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
 {
     Init(vecs, count, material, radius);
 }
Exemplo n.º 35
0
		//protected cpVect _offset;
		#endregion

		#region PUBLIC METHODS

		public CCPhysicsShapeBox(CCSize size, CCPhysicsMaterial material, float radius)
		{

			cpVect wh = PhysicsHelper.size2cpv(size);

			_type = PhysicsType.BOX;

			cpVect[] vec = {
                             
							new cpVect( -wh.x/2.0f,-wh.y/2.0f),
							new cpVect(   -wh.x/2.0f, wh.y/2.0f),
							new cpVect(   wh.x/2.0f, wh.y/2.0f),
							new cpVect(   wh.x/2.0f, -wh.y/2.0f)

                          };

			cpShape shape = new cpPolyShape(CCPhysicsShapeInfo.SharedBody, 4, vec, radius);

			_info.Add(shape);

			//_offset = offset;
			_area = CalculateArea();
			_mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
			_moment = CalculateDefaultMoment();

			Material = material;

		}
Exemplo n.º 36
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;
		}
Exemplo n.º 37
0
		public CCPhysicsShapeCircle(CCPhysicsMaterial material, float radius, CCPoint offset)
		{

			_type = PhysicsType.CIRCLE;

            cpShape shape = new cpCircleShape(CCPhysicsShapeInfo.SharedBody, radius, PhysicsHelper.CCPointToCpVect(offset));

			_info.Add(shape);

			_area = CalculateArea();
			_mass = material.density == cp.Infinity ? cp.Infinity : material.density * _area;
			_moment = CalculateDefaultMoment();

			Material = material;
		}
Exemplo n.º 38
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;
		}
Exemplo n.º 39
0
		public CCPhysicsShapePolygon(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
		{
			Init(vecs, count, material, radius);

		}
Exemplo n.º 40
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;

		}
Exemplo n.º 41
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();
        }
Exemplo n.º 42
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;
		}
Exemplo n.º 43
0
        public CCSprite MakeBox(CCPoint point, CCSize size, int color, CCPhysicsMaterial material)
        {

            bool yellow = (color == 0) ? CCRandom.Float_0_1() > 0.5f : color == 1;

            CCSprite box = new CCSprite(yellow ? "Images/YellowSquare" : "Images/CyanSquare");

            box.ScaleX = size.Width / 100.0f;
            box.ScaleY = size.Height / 100.0f;

            var body = CCPhysicsBody.CreateBox(size, material, 0.0f);
            box.PhysicsBody = body;
            box.Position = point;// new cpVect(point.X, point.Y);

            return box;
        }