Ejemplo n.º 1
0
        public static DisposeCallback RegisterMousePicking(DemoOpenInfo info, MouseButton button)
        {
            FixedHingeJoint joint = null;

            EventHandler<ViewportMouseButtonEventArgs> mouseDown = delegate(object sender, ViewportMouseButtonEventArgs e)
            {
                if (e.Button == button)
                {
                    IntersectionInfo temp;
                    Body body = null;
                    foreach (Body b in info.Scene.Engine.Bodies)
                    {
                        Vector2D bodyVertex = b.Matrices.ToBody * e.Position;
                        if (b.Shape.CanGetIntersection &&
                           !b.IsBroadPhaseOnly &&
                           !b.IgnoresPhysicsLogics &&
                           b.Shape.TryGetIntersection(bodyVertex, out temp))
                        {
                            body = b;
                            break;
                        }
                    }
                    if (body != null)
                    {
                        joint = new FixedHingeJoint(body, e.Position, new Lifespan());
                        info.Scene.Engine.AddJoint(joint);
                    }
                }
            };
            EventHandler<ViewportMouseMotionEventArgs> mouseMotion = delegate(object sender, ViewportMouseMotionEventArgs e)
            {
                if (joint != null)
                {
                    joint.Anchor = e.Position;
                }
            };
            EventHandler<ViewportMouseButtonEventArgs> mouseUp = delegate(object sender, ViewportMouseButtonEventArgs e)
            {
                if (e.Button == button)
                {
                    if (joint != null)
                    {
                        joint.Lifetime.IsExpired = true;
                        joint = null;
                    }
                }
            };

            info.Viewport.MouseDown += mouseDown;
            info.Viewport.MouseUp += mouseUp;
            info.Viewport.MouseMotion += mouseMotion;
            return delegate()
            {
                info.Viewport.MouseDown -= mouseDown;
                info.Viewport.MouseUp -= mouseUp;
                info.Viewport.MouseMotion -= mouseMotion;
            };
        }
Ejemplo n.º 2
0
 void Events_MouseButtonUp(object sender, SdlDotNet.Input.MouseButtonEventArgs e)
 {
     if (e.Button == SdlDotNet.Input.MouseButton.SecondaryButton)
     {
         sparkle = false;
     }
     else if (e.Button == SdlDotNet.Input.MouseButton.PrimaryButton)
     {
         if (cursorJoint != null)
         {
             cursorJoint.Lifetime.IsExpired = true;
             cursorJoint = null;
         }
     }
 }
Ejemplo n.º 3
0
		void OnGotContactCapture(object sender, ContactEventArgs e)
		{
			FrameworkElement element = (FrameworkElement)e.Source;
			FrameworkElement container = ItemsControl.ContainerFromElement(null, element) as FrameworkElement;
			if (container != null)
				element = container;

			Body body;
			if (elementToBody.TryGetValue(element, out body))
			{
				Point position = e.GetPosition(this);
				Vector2D contactPoint = position.ToVector2D();
				if (body.Shape.CanGetIntersection)
				{
					Vector2D temp = body.Matrices.ToBody * contactPoint;
					IntersectionInfo intersectionInfo;
					if (body.Shape.TryGetIntersection(temp, out intersectionInfo))
					{
						FixedHingeJoint joint = new FixedHingeJoint(body, contactPoint, new Lifespan());
						joint.Softness = 0.3;
						engine.AddJoint(joint);
						contactJoints[e.Contact.Id] = joint;
					}
				}
			}
			SetZTop(element);
		}
Ejemplo n.º 4
0
        void DemoS()
        {
            BeginDemoChange();
            Reset();
            AddGravityField();
            AddFloor(new ALVector2D(0, new Vector2D(700, 750)));

            Sprite blockSprite = GetSprite("fighter.png");
            Vector2D[][] vertexes = blockSprite.Polygons;
            MultiPolygonShape shape = new MultiPolygonShape(vertexes, 4);
            shape.Tag = blockSprite;
            for (int i = 128 * 3; i > -128; i -= 128)
            {
                Body b = AddShape(shape, 40, new ALVector2D(0, new Vector2D(600, 272 + i)));

            }



            Body lever = AddRectangle(20, 100, 9, new ALVector2D(0, 275, 300));
            FixedAngleJoint joint1 = new FixedAngleJoint(lever, new Lifespan());
            FixedHingeJoint joint2 = new FixedHingeJoint(lever, new Vector2D(200, 300), new Lifespan());
            joint1.Softness = .95f;
            engine.AddJointRange(new Joint[] { joint1, joint2 });

            lever = AddRectangle(20, 100, 9, new ALVector2D(0, 385, 300));
            joint1 = new FixedAngleJoint(lever, new Lifespan());
            joint2 = new FixedHingeJoint(lever, new Vector2D(460, 300), new Lifespan());
            joint1.Softness = .95f;
            engine.AddJointRange(new Joint[] { joint1, joint2 });


            Body ball = AddShape(new CircleShape(80, 20), 4000, new ALVector2D(0, new Vector2D(1028, 272)));
            ball.Transformation *= Matrix2x3.FromScale(new Vector2D(1, .8f));

            EndDemoChange();
            /*   BeginDemoChange();
               Reset(false);
               AddGravityField();
               engine.AddLogic(new GlobalFluidLogic(.45f, .02f, Vector2D.Zero, new Lifespan()));

               BoundingRectangle rect = this.clippersShape.Rectangle;
               rect.Min.X -= 75;
               rect.Min.Y -= 75;
               rect.Max.X += 75;
               rect.Max.Y += 75;
               AddShell(rect, 100, Scalar.PositiveInfinity).ForEach(delegate(Body b) { b.IgnoresGravity = true; });
            
               Sprite blockSprite = GetSprite("fighter.png");
               Vector2D[][] vertexes = blockSprite.Polygons;
               MultipartPolygon shape = new MultipartPolygon(vertexes, 4);
               shape.Tag = blockSprite;

               AddShape(shape, 40, new ALVector2D(0, new Vector2D(200, 300)));
               AddShape(shape, 40, new ALVector2D(0, new Vector2D(500, 300)));
               AddRectangle(50, 50, 50, new ALVector2D(0, 600, 600));
               AddRectangle(50, 50, 500, new ALVector2D(0, 600, 450));
               AddCircle(10, 9, 5, new ALVector2D(0, 600, 600));
               AddCircle(10, 9, 50, new ALVector2D(0, 500, 600));
               AddCircle(10, 9, 500, new ALVector2D(0, 400, 600));
               AddCircle(10, 9, 5000, new ALVector2D(0, 300, 600));



               EndDemoChange();*/
        }
Ejemplo n.º 5
0
 void Events_MouseButtonDown(object sender, SdlDotNet.Input.MouseButtonEventArgs e)
 {
     if (e.Button == SdlDotNet.Input.MouseButton.PrimaryButton)
     {
         Vector2D point = new Vector2D(e.X, e.Y);
         IntersectionInfo info;
         foreach (Body b in engine.Bodies)
         {
             if (b.IsCollidable && !b.IsBroadPhaseOnly &&
                 b.Shape.CanGetIntersection)
             {
                 Vector2D temp = b.Matrices.ToBody * point;
                 if (b.Shape.TryGetIntersection(temp, out info))
                 {
                     //cursorJoint = new PivotJoint(b, b.State.Position.Linear, new Lifespan());
                     cursorJoint = new FixedHingeJoint(b, point, new Lifespan());
                     cursorJoint.Softness = .01f;
                     engine.AddJoint(cursorJoint);
                     break;
                 }
             }
         }
     }
     else if (e.Button == SdlDotNet.Input.MouseButton.SecondaryButton)
     {
         sparkPoint = new Vector2D(e.X, e.Y);
         sparkle = true;
     }
     else if ((e.Button == SdlDotNet.Input.MouseButton.MiddleButton))
     {
         bombTarget = new Vector2D(e.X, e.Y);
         bomb.Lifetime.IsExpired = true;
     }
 }
Ejemplo n.º 6
0
 public static FixedHingeJoint FixedHingeJointFactory(Body body, Vector2D anchor, Lifespan lifetime)
 {
     FixedHingeJoint joint = new FixedHingeJoint(body, anchor, lifetime);
     joint.Softness = TangramInformation.Softness;
     joint.BiasFactor = TangramInformation.BiasFactor - 0.1f;
     return joint;
 }
Ejemplo n.º 7
0
		public void OnNewContact(IntPtr windowHandle, Multitouch.Contracts.IContact contact)
		{
			Window window = GetWindow(windowHandle);
			if (window != null)
			{
				window.Contacts.Add(new WindowContact(contact));

				Body body;
				if (windowToBody.TryGetValue(window, out body))
				{
					NativeMethods.POINT point = new NativeMethods.POINT((int)contact.X, (int)contact.Y);

					Vector2D contactPoint = point.ToVector2D();

					if (body.Shape.CanGetIntersection)
					{
						Vector2D temp = body.Matrices.ToBody * contactPoint;
						IntersectionInfo intersectionInfo;
						if (body.Shape.TryGetIntersection(temp, out intersectionInfo))
						{
							FixedHingeJoint joint = new FixedHingeJoint(body, contactPoint, new Lifespan());
							engine.AddJoint(joint);
							contactJoints[contact.Id] = joint;
						}
					}
				}
			}
		}
Ejemplo n.º 8
0
		void OnContactRemoved(object sender, ContactEventArgs e)
		{
			if (e.Contact.Id == firstContactId)
			{
				scrollJoint.Lifetime.IsExpired = true;
				scrollJoint = null;
				firstContactId = null;
			}
		}
Ejemplo n.º 9
0
		void OnNewContact(object sender, NewContactEventArgs e)
		{
			if (!firstContactId.HasValue)
			{
				firstContactId = e.Contact.Id;

				startPoint = e.GetPosition(this);
				startOffset.X = HorizontalOffset;
				startOffset.Y = VerticalOffset;

				Vector2D contactPoint = startPoint.ToVector2D();
				scrollJoint = new FixedHingeJoint(Body, contactPoint, new Lifespan());
				engine.AddJoint(scrollJoint);
			}
		}
Ejemplo n.º 10
0
Archivo: Game1.cs Proyecto: MrPhil/LD18
        private void Restart()
        {
            engine.Clear();
            bullets.Clear();
            enemies.Clear();

            player = new Player();
            player.Position = new Vector2(400, 525);
            engine.AddBody(player.Body);
            player.Body.ApplyImpulse(new Vector2D(0, 10));

            beam = new Beam(this, 395, 480);
            engine.AddBody(beam.Body);
            FixedHingeJoint fixedHingeJoint = new FixedHingeJoint(beam.Body, new Vector2D(395, 480), new Lifespan());
            engine.AddJoint(fixedHingeJoint);

            waves = new bool[] { false, false, false, false, false, false };

            gameOver = false;
            youWin = false;
            enemyTimer = DateTime.Now;
        }