Exemplo n.º 1
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // TODO: Add your update logic here
            handler.Update(gameTime);
            if (!done && Keyboard.GetState().IsKeyDown(Keys.W))
            {
                RigidBody shatterBody = handler.GetBodies()[0];
                Polygon[] shatter     = Polygon.FracturePolygon(shatterBody.CollisionPolygon, 2, new System.Random());

                StandardUVMap[] textureUVs;
                RigidBody[]     newBodies = RigidBody.ApplySplit(shatterBody, shatter, standardUVMaps[0], out textureUVs);

                handler.RemoveBody(shatterBody);
                foreach (RigidBody b in newBodies)
                {
                    handler.AddBody(b);
                }

                standardUVMaps.RemoveAt(0);
                standardUVMaps.AddRange(textureUVs);

                done = true;
            }

            base.Update(gameTime);
        }
Exemplo n.º 2
0
        private void click(object sender, MouseEventArgs e)
        {
            //gravity = true;
            //RigidBody[] bodies = handler.GetBodies();
            //foreach (RigidBody b in bodies)
            //{
            //    if (b != bound)
            //    {
            //        Vector2 origin = b.CollisionPolygon.CenterPoint;
            //        Polygon[] split = Polygon.FracturePolygon(b.CollisionPolygon, 10, random);
            //        if (split.Length > 1)
            //        {
            //            Material material = b.Material;
            //            handler.RemoveBody(b);

            //            RigidBody[] newBodies = RigidBody.ApplySplit(b, split);
            //            for (int i = 0; i < newBodies.Length; i++)
            //            {
            //                handler.AddBody(newBodies[i]);
            //            }
            //        }
            //    }
            //}

            PointF mousePoint = PointToClient(MousePosition);

            points.Add(new Vector2(mousePoint.X, mousePoint.Y));

            if (points.Count == 2)
            {
                //Split bodies on line
                RigidBody[] bodies = handler.GetBodies();
                foreach (RigidBody b in bodies)
                {
                    if (b != bound)
                    {
                        Polygon[] split = Polygon.SplitPolygon(b.CollisionPolygon, new LineSegment(points[0], points[1]).Line);
                        if (split.Length > 1)
                        {
                            handler.RemoveBody(b);

                            RigidBody[] splitBodies = RigidBody.ApplySplit(b, split);
                            for (int i = 0; i < splitBodies.Length; i++)
                            {
                                handler.AddBody(splitBodies[i]);
                            }
                        }
                    }
                }

                points.Clear();
            }
        }