public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); Vertices rect1 = PolygonTools.CreateRectangle(2f, 2f); Vertices rect2 = PolygonTools.CreateRectangle(2f, 2f); Vector2 trans = new Vector2(-2f, 0f); rect1.Translate(ref trans); trans = new Vector2(2f, 0f); rect2.Translate(ref trans); List<Vertices> vertices = new List<Vertices>(2); vertices.Add(rect1); vertices.Add(rect2); _rectangles = BodyFactory.CreateCompoundPolygon(World, vertices, 1f); _rectangles.BodyType = BodyType.Dynamic; SetUserAgent(_rectangles, 200f, 200f); // create sprite based on rectangle fixture _rectangleSprite = new Sprite(ScreenManager.Assets.TextureFromVertices(rect1, MaterialType.Squares, Color.Orange, 1f)); _offset = new Vector2(ConvertUnits.ToDisplayUnits(2f), 0f); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 20f); _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); Vector2 _position = new Vector2(-15f, -8f); float _restitution = 0f; for (int i = 0; i < 6; ++i) { _circle[i] = BodyFactory.CreateCircle(World, 1.5f, 1f, _position); _circle[i].BodyType = BodyType.Dynamic; _circle[i].Restitution = _restitution; _position.X += 6f; _restitution += 0.2f; } // create sprite based on body _circleSprite = new Sprite(ScreenManager.Assets.TextureFromShape(_circle[0].FixtureList[0].Shape, MaterialType.Waves, Color.Brown, 1f)); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 20f); _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); _ramps = new List<Body>(); _ramps.Add(BodyFactory.CreateEdge(World, new Vector2(-20f, -11.2f), new Vector2(10f, -3.8f))); _ramps.Add(BodyFactory.CreateEdge(World, new Vector2(12f, -5.6f), new Vector2(12f, -3.2f))); _ramps.Add(BodyFactory.CreateEdge(World, new Vector2(-10f, 4.4f), new Vector2(20f, -1.4f))); _ramps.Add(BodyFactory.CreateEdge(World, new Vector2(-12f, 2.6f), new Vector2(-12f, 5f))); _ramps.Add(BodyFactory.CreateEdge(World, new Vector2(-20f, 6.8f), new Vector2(10f, 11.5f))); float[] friction = new[] { 0.75f, 0.45f, 0.28f, 0.17f, 0.0f }; for (int i = 0; i < 5; ++i) { _rectangle[i] = BodyFactory.CreateRectangle(World, 1.5f, 1.5f, 1f); _rectangle[i].BodyType = BodyType.Dynamic; _rectangle[i].Position = new Vector2(-18f + 5.2f * i, -13.0f + 1.282f * i); _rectangle[i].Friction = friction[i]; } // create sprite based on body _rectangleSprite = new Sprite(ScreenManager.Assets.TextureFromShape(_rectangle[0].FixtureList[0].Shape, MaterialType.Squares, Color.ForestGreen, 0.8f)); }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); //load texture that will represent the physics body _polygonTexture = ScreenManager.Content.Load<Texture2D>("Samples/object"); //Create an array to hold the data from the texture uint[] data = new uint[_polygonTexture.Width * _polygonTexture.Height]; //Transfer the texture data to the array _polygonTexture.GetData(data); //Find the vertices that makes up the outline of the shape in the texture Vertices textureVertices = PolygonTools.CreatePolygon(data, _polygonTexture.Width, false); //The tool return vertices as they were found in the texture. //We need to find the real center (centroid) of the vertices for 2 reasons: //1. To translate the vertices so the polygon is centered around the centroid. Vector2 centroid = -textureVertices.GetCentroid(); textureVertices.Translate(ref centroid); //2. To draw the texture the correct place. _origin = -centroid; //We simplify the vertices found in the texture. textureVertices = SimplifyTools.ReduceByDistance(textureVertices, 4f); //Since it is a concave polygon, we need to partition it into several smaller convex polygons List<Vertices> list = BayazitDecomposer.ConvexPartition(textureVertices); //Adjust the scale of the object for WP7's lower resolution #if WINDOWS_PHONE _scale = 0.6f; #else _scale = 1f; #endif //scale the vertices from graphics space to sim space Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * _scale; foreach (Vertices vertices in list) { vertices.Scale(ref vertScale); } //Create a single body with multiple fixtures _compound = BodyFactory.CreateCompoundPolygon(World, list, 1f, BodyType.Dynamic); _compound.BodyType = BodyType.Dynamic; }
public override void LoadContent() { base.LoadContent(); HasCursor = false; World.Gravity = new Vector2(0, 9.82f); _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); _walker = new TheoJansenWalker(World, this, Vector2.Zero); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 20f); _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); _ragdoll = new Ragdoll(World, this, Vector2.Zero); LoadObstacles(); SetUserAgent(_ragdoll.Body, 1000f, 400f); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 20f); _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); _agent = new Agent(World, this, new Vector2(-6.9f, -11f)); LoadObstacles(); SetUserAgent(_agent.Body, 1000f, 400f); }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); //Cat1=Circles, Cat2=Rectangles, Cat3=Gears, Cat4=Stars _agent = new Agent(World, this, Vector2.Zero); //Collide with all but stars _agent.CollisionCategories = Category.All & ~Category.Cat4; _agent.CollidesWith = Category.All & ~Category.Cat4; Vector2 startPosition = new Vector2(-20f, -11f); Vector2 endPosition = new Vector2(20, -11f); _circles = new Objects(World, this, startPosition, endPosition, 15, 0.6f, ObjectType.Circle); //Collide with itself only _circles.CollisionCategories = Category.Cat1; _circles.CollidesWith = Category.Cat1; startPosition = new Vector2(-20, 11f); endPosition = new Vector2(20, 11f); _rectangles = new Objects(World, this, startPosition, endPosition, 15, 1.2f, ObjectType.Rectangle); //Collides with itself only _rectangles.CollisionCategories = Category.Cat2; _rectangles.CollidesWith = Category.Cat2; startPosition = new Vector2(-20, 7); endPosition = new Vector2(-20, -7); _gears = new Objects(World, this, startPosition, endPosition, 5, 0.6f, ObjectType.Gear); //Collides with stars _gears.CollisionCategories = Category.Cat3; _gears.CollidesWith = Category.Cat3 | Category.Cat4; startPosition = new Vector2(20, 7); endPosition = new Vector2(20, -7); _stars = new Objects(World, this, startPosition, endPosition, 5, 0.6f, ObjectType.Star); //Collides with gears _stars.CollisionCategories = Category.Cat4; _stars.CollidesWith = Category.Cat3 | Category.Cat4; SetUserAgent(_agent.Body, 1000f, 400f); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0, 9.82f); _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); #if WINDOWS || XBOX _spiderweb = new Spiderweb(World, Vector2.Zero, ConvertUnits.ToSimUnits(12), 5, 12); #elif WINDOWS_PHONE _spiderweb = new Spiderweb(World, Vector2.Zero, ConvertUnits.ToSimUnits(8), 5, 12); #endif _spiderweb.LoadContent(ScreenManager.Content); }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); _rectangle = BodyFactory.CreateRectangle(World, 5f, 5f, 1f); _rectangle.BodyType = BodyType.Dynamic; SetUserAgent(_rectangle, 100f, 100f); // create sprite based on body _rectangleSprite = new Sprite(ScreenManager.Assets.TextureFromShape(_rectangle.FixtureList[0].Shape, MaterialType.Squares, Color.Orange, 1f)); }
public override void LoadContent() { base.LoadContent(); World.Gravity = new Vector2(0f, 20f); _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); _agent = new Agent(World, this, new Vector2(0f, 10f)); _spiders = new Spider[8]; for (int i = 0; i < _spiders.Length; i++) { _spiders[i] = new Spider(World, this, new Vector2(0f, 8f - (i + 1) * 2f)); } SetUserAgent(_agent.Body, 1000f, 400f); }
public override void LoadContent() { base.LoadContent(); World.Gravity = Vector2.Zero; _border = new Border(World, this, ScreenManager.GraphicsDevice.Viewport); _breakableObject = new List<List<Vertices>>(); Texture2D alphabet = ScreenManager.Content.Load<Texture2D>("Samples/alphabet"); uint[] data = new uint[alphabet.Width * alphabet.Height]; alphabet.GetData(data); List<Vertices> list = PolygonTools.CreatePolygon(data, alphabet.Width, 3.5f, 20, true, true); float yOffset = -5f; float xOffset = -14f; for (int i = 0; i < list.Count; i++) { if (i == 9) { yOffset = 0f; xOffset = -14f; } if (i == 18) { yOffset = 5f; xOffset = -12.25f; } Vertices polygon = list[i]; Vector2 centroid = -polygon.GetCentroid(); polygon.Translate(ref centroid); //polygon = SimplifyTools.CollinearSimplify(polygon); // this breaks the split hole function polygon = SimplifyTools.ReduceByDistance(polygon, 4); List<Vertices> triangulated = BayazitDecomposer.ConvexPartition(polygon); #if WINDOWS_PHONE const float scale = 0.6f; #else const float scale = 1f; #endif Vector2 vertScale = new Vector2(ConvertUnits.ToSimUnits(1)) * scale; foreach (Vertices vertices in triangulated) { vertices.Scale(ref vertScale); } BreakableBody breakableBody = new BreakableBody(triangulated, World, 1); breakableBody.MainBody.Position = new Vector2(xOffset, yOffset); breakableBody.Strength = 100; breakableBody.MainBody.UserData = i; World.AddBreakableBody(breakableBody); polygon.Scale(ref vertScale); _breakableObject.Add(polygon.SplitAtHoles()); xOffset += 3.5f; } }