コード例 #1
0
ファイル: CCPhysicsBody.cs プロジェクト: zhuruvl/CocosSharp
        /**
         * @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);
        }
コード例 #2
0
ファイル: CCPhysicsBody.cs プロジェクト: zhuruvl/CocosSharp
        /** 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);
        }
コード例 #3
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
 public CCPhysicsShape(float radius, CCPhysicsMaterial material, CCPoint offset)
 {
     // TODO: Complete member initialization
     this.radius   = radius;
     this.material = material;
     this.offset   = PhysicsHelper.CCPointToCpVect(offset);
 }
コード例 #4
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
        //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;
        }
コード例 #5
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
        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;
        }
コード例 #6
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
        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;
        }
コード例 #7
0
ファイル: CCPhysicsBody.cs プロジェクト: zhuruvl/CocosSharp
        /** 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);
        }
コード例 #8
0
ファイル: CCPhysicsBody.cs プロジェクト: zhuruvl/CocosSharp
        /** 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);
        }
コード例 #9
0
ファイル: CCPhysicsBody.cs プロジェクト: zhuruvl/CocosSharp
        /** 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);
        }
コード例 #10
0
ファイル: CCPhysicsBody.cs プロジェクト: zhuruvl/CocosSharp
        /** 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);
        }
コード例 #11
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
        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;
        }
コード例 #12
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
        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;
        }
コード例 #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;
        }
コード例 #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);
        }
コード例 #15
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
		public CCPhysicsShape(float radius, CCPhysicsMaterial material, CCPoint offset)
		{
			// TODO: Complete member initialization
			this.radius = radius;
			this.material = material;
            this.offset = PhysicsHelper.CCPointToCpVect(offset);
		}
コード例 #16
0
ファイル: CCPhysicsShape.cs プロジェクト: netonjm/CocosSharp
		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);
		}
コード例 #17
0
ファイル: CCPhysicsBody.cs プロジェクト: h7ing/CocosSharp
		/** 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;
		}
コード例 #18
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
		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;
		}
コード例 #19
0
ファイル: CCPhysicsShape.cs プロジェクト: netonjm/CocosSharp
		public void SetMaterial(CCPhysicsMaterial material)
		{
			SetDensity(material.density);
			SetRestitution(material.restitution);
			SetFriction(material.friction);
		}
コード例 #20
0
ファイル: CCPhysicsShape.cs プロジェクト: netonjm/CocosSharp
		public CCPhysicsShape(float radius, CCPhysicsMaterial material, cpVect offset)
		{
			// TODO: Complete member initialization
			this.radius = radius;
			this.material = material;
			this.offset = offset;
		}
コード例 #21
0
ファイル: CCPhysicsBody.cs プロジェクト: netonjm/CocosSharp
		/** 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;
		}
コード例 #22
0
ファイル: CCPhysicsShape.cs プロジェクト: netonjm/CocosSharp
		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);

		}
コード例 #23
0
ファイル: CCPhysicsBody.cs プロジェクト: h7ing/CocosSharp
		/**
		 * @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;
		}
コード例 #24
0
ファイル: CCPhysicsBody.cs プロジェクト: h7ing/CocosSharp
		/** 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;
		}
コード例 #25
0
 public void SetMaterial(CCPhysicsMaterial material)
 {
     SetDensity(material.density);
     SetRestitution(material.restitution);
     SetFriction(material.friction);
 }
コード例 #26
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
		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;
		}
コード例 #27
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
        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;
		}
コード例 #28
0
ファイル: CCPhysicsShape.cs プロジェクト: netonjm/CocosSharp
		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);
		}
コード例 #29
0
ファイル: PhysicsTest.cs プロジェクト: KevinHeyer/CocosSharp
 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;
 }
コード例 #30
0
ファイル: CCPhysicsShape.cs プロジェクト: netonjm/CocosSharp
		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);
		}
コード例 #31
0
ファイル: PhysicsTest.cs プロジェクト: KevinHeyer/CocosSharp
        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;
        }
コード例 #32
0
ファイル: CCPhysicsShape.cs プロジェクト: netonjm/CocosSharp
		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);
		}
コード例 #33
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
		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;

		}
コード例 #34
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
 public CCPhysicsShapePolygon(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
 {
     Init(vecs, count, material, radius);
 }
コード例 #35
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
		//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;

		}
コード例 #36
0
ファイル: CCPhysicsBody.cs プロジェクト: netonjm/CocosSharp
		/** 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;
		}
コード例 #37
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
		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;
		}
コード例 #38
0
ファイル: CCPhysicsBody.cs プロジェクト: h7ing/CocosSharp
		/** 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;
		}
コード例 #39
0
ファイル: CCPhysicsShape.cs プロジェクト: kkarol93/CocosSharp
		public CCPhysicsShapePolygon(CCPoint[] vecs, int count, CCPhysicsMaterial material, float radius)
		{
			Init(vecs, count, material, radius);

		}
コード例 #40
0
ファイル: CCPhysicsBody.cs プロジェクト: h7ing/CocosSharp
		/** 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;

		}
コード例 #41
0
ファイル: PhysicsTest.cs プロジェクト: KevinHeyer/CocosSharp
        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();
        }
コード例 #42
0
ファイル: CCPhysicsBody.cs プロジェクト: h7ing/CocosSharp
		/** 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;
		}
コード例 #43
0
ファイル: PhysicsTest.cs プロジェクト: KevinHeyer/CocosSharp
        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;
        }