/// <summary> /// Creates new Rectange Body /// </summary> /// <param name="height">Height of the Body</param> /// <param name="width">Width of the Body</param> /// <param name="mass">Mass of the Body</param> /// <param name="position">Initial Direction and Linear Position of the Body</param> /// <returns>Return the new value of the BasePolygonBody</returns> /// <remarks>The Guid of new Body will be stored in Body.Tags["Guid"]. The raw Colored Drawable of new Body will be stored in Body.Tags["Drawable"].</remarks> public static Body CreateRectangle(Scalar height, Scalar width, Scalar mass, ALVector2D position) { var vertices = VertexHelper.CreateRectangle(width, height); vertices = VertexHelper.Subdivide(vertices, Math.Min(height, width) / 5); var boxShape = ShapeFactory.GetOrCreateColoredPolygonShape(vertices, Math.Min(height, width) / 5); var newBody = new Body(new PhysicsState(position), boxShape, mass, Coefficients.Duplicate(), new Lifespan()); return(newBody); }
public static DisposeCallback BasicDemoSetup(DemoOpenInfo info) { DisposeCallback dispose = null; IShape bombShape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("rocket.png"), 2, 16, 3); dispose += DemoHelper.RegisterBombLaunching(info, bombShape, 120); dispose += DemoHelper.RegisterMousePicking(info); dispose += DemoHelper.RegisterBodyStreamSpawning(info, new Body(new PhysicsState(), ParticleShape.Default, 1, Coefficients.Duplicate(), new Lifespan(.5f)), 2, 120, 1000, Key.B); dispose += DemoHelper.RegisterMaintainSpawning(info, SdlDotNet.Input.Key.N, delegate(Vector2D position) { ExplosionLogic result = new ExplosionLogic(position, Vector2D.Zero, 9000, .1f, 600, new Lifespan(.25f)); info.Scene.Engine.AddLogic(result); return(result); }); List <RaySegment> segments = new List <RaySegment>(); for (Scalar angle = 0; angle < MathHelper.PiOver2; angle += .05f) { RaySegment seg = new RaySegment(); seg.Length = 500; seg.RayInstance = new Ray(Vector2D.Zero, Vector2D.FromLengthAndAngle(1, angle)); segments.Add(seg); } IShape rayShape = ShapeFactory.CreateRays(segments.ToArray()); dispose += DemoHelper.RegisterMaintainSpawning(info, SdlDotNet.Input.Key.M, delegate(Vector2D position) { Body lazer = new Body(new PhysicsState(), rayShape, 1, new Coefficients(1, 1), new Lifespan()); lazer.State.Position.Linear = position; lazer.State.Velocity.Angular = .91f; lazer.IgnoresGravity = true; lazer.ApplyPosition(); info.Scene.AddGraphic(CreateGraphic(lazer)); return(lazer); }); return(dispose); }