public static Body AddCircle(DemoOpenInfo info, Scalar radius, int vertexCount, Scalar mass, ALVector2D position) { CircleShape shape = ShapeFactory.CreateColoredCircle(radius, vertexCount); Body result = new Body(new PhysicsState(position), shape, mass, Coefficients.Duplicate(), new Lifespan()); info.Scene.AddGraphic(CreateGraphic(result)); return(result); }
public static BaseModelBody CreateCircle(Scalar radius, ushort verticesCount, Scalar mass, Guid modelId) { var shape = ShapeFactory.CreateColoredCircle(radius, verticesCount); var newBody = new BaseModelBody(new PhysicsState(), shape, mass, Coefficients.Duplicate(), new Lifespan(), modelId); return(newBody); }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); IShape shape = ShapeFactory.CreateColoredCircle(8, 15); DemoHelper.AddGrid(DemoInfo, shape, 40, new BoundingRectangle(-200, -200, 1100, 1100), 5, 5); }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); IShape shape = ShapeFactory.CreateColoredCircle(8, 15); List <Body> bodies = DemoHelper.AddGrid(DemoInfo, shape, 40, new BoundingRectangle(100, 100, 600, 600), 40, 40); MoveToPointLogic logic = null; dispose += DemoHelper.RegisterSpawning(this.DemoInfo, SdlDotNet.Input.Key.H, delegate(Vector2D position) { if (logic != null) { logic.Lifetime.IsExpired = true; } logic = new MoveToPointLogic(bodies[0], position, 90, 200000); this.DemoInfo.Scene.Engine.AddLogic(logic); return(logic); }); List <MoveToPointLogic> logics = new List <MoveToPointLogic>(); dispose += DemoHelper.RegisterSpawning(this.DemoInfo, SdlDotNet.Input.Key.J, delegate(Vector2D position) { foreach (MoveToPointLogic logic2 in logics) { logic2.Lifetime.IsExpired = true; } logics.Clear(); Vector2D center = Vector2D.Zero; foreach (Body body in bodies) { center += body.State.Position.Linear; } center *= (1f / (Scalar)bodies.Count); foreach (Body body in bodies) { MoveToPointLogic logic2 = new MoveToPointLogic(body, position + body.State.Position.Linear - center, 90000, Scalar.MaxValue, true, new Lifespan()); logics.Add(logic2); this.DemoInfo.Scene.Engine.AddLogic(logic2); } return(null); }); }
protected override void Open() { IShape shape = ShapeFactory.CreateColoredCircle(8, 15); DemoHelper.AddGrid(DemoInfo, shape, 40, new BoundingRectangle(-500, 200, 800, 800), 50, 50); Viewport viewport2 = new Viewport(new Rectangle(Window.Size.Width / 2, 0, Window.Size.Width / 2, Window.Size.Height), Matrix2x3.Identity, Scene, new Lifespan()); Window.AddViewport(viewport2); Viewport.Rectangle = new Rectangle(0, 0, Window.Size.Width / 2, Window.Size.Height); IShape furyShape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("starfury.png"), 2, 16, 3); Body b1 = DemoHelper.AddShape(DemoInfo, furyShape, 400, new ALVector2D(0, 0, 0)); Body b2 = DemoHelper.AddShape(DemoInfo, furyShape, 400, new ALVector2D(0, 0, 0)); dispose += DemoHelper.RegisterBodyTracking(DemoInfo, b1, Matrix2x3.FromRotationZ(-MathHelper.PiOver2) * Matrix2x3.FromScale(new Vector2D(.5f, .5f))); dispose += DemoHelper.RegisterBodyMovement(DemoInfo, b1, new ALVector2D(1000000, 100000, 0), Key.W, Key.S, Key.A, Key.D); DoGuns(b1, b2, Key.Q); dispose += DemoHelper.RegisterBodyTracking( new DemoOpenInfo(Window, viewport2, Scene) , b2, Matrix2x3.FromRotationZ(-MathHelper.PiOver2) * Matrix2x3.FromScale(new Vector2D(.5f, .5f))); dispose += DemoHelper.RegisterBodyMovement( DemoInfo, b2, new ALVector2D(1000000, 100000, 0)); DoGuns(b2, b1, Key.Return); b1.State.Position.Linear = new Vector2D(200, 0); b2.State.Position = new ALVector2D(MathHelper.Pi, 1, 0); b1.ApplyPosition(); b2.ApplyPosition(); DemoHelper.AddShell(DemoInfo, new BoundingRectangle(-700, -700, 1000, 1000), 90, Scalar.PositiveInfinity); dispose += delegate() { viewport2.Lifetime.IsExpired = true; Viewport.Rectangle = new Rectangle(0, 0, Window.Size.Width, Window.Size.Height); }; DemoHelper.AddStarField(DemoInfo, 1000, new BoundingRectangle(-1000, -1000, 1300, 1300)); }
protected override void Open() { IShape bombShape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("rocket.png"), 2, 16, 3); dispose += DemoHelper.RegisterBombLaunching(DemoInfo, bombShape, 120); dispose += DemoHelper.RegisterMousePicking(DemoInfo); IShape shape = ShapeFactory.CreateColoredCircle(8, 15); DemoHelper.AddGrid(DemoInfo, shape, 40, new BoundingRectangle(200, 200, 1100, 1100), 5, 5); Body b = DemoHelper.AddShape(DemoInfo, bombShape, 400, new ALVector2D(0, 0, 0)); DemoHelper.RegisterBodyTracking(DemoInfo, b, Matrix2x3.FromRotationZ(-MathHelper.PiOver2)); DemoHelper.RegisterBodyMovement(DemoInfo, b, new ALVector2D(50000, 50000, 0)); DemoHelper.AddStarField(DemoInfo, 1000, new BoundingRectangle(-1000, -1000, 2300, 2300)); }
protected override void Open() { dispose += DemoHelper.BasicDemoSetup(DemoInfo); Rectangle rect1 = Viewport.Rectangle; BoundingRectangle rect = new BoundingRectangle(rect1.Left, rect1.Top, rect1.Right, rect1.Bottom); rect.Min.X -= 75; rect.Min.Y -= 75; rect.Max.X += 75; rect.Max.Y += 75; DemoHelper.AddShell(DemoInfo, rect, 100, Scalar.PositiveInfinity).ForEach(delegate(Body b) { b.IgnoresGravity = true; }); rect.Min.X += 110; rect.Min.Y += 110; rect.Max.X -= 110; rect.Max.Y -= 110; IShape shape = ShapeFactory.CreateColoredCircle(3, 7); DemoHelper.AddGrid(DemoInfo, shape, 40, rect, 1, 1).ForEach(delegate(Body b) { b.State.Velocity.Linear = new Vector2D(DemoHelper.Rand.Next(-100, 100), DemoHelper.Rand.Next(-100, 100)); }); }
public static DisposeCallback CreateTank(DemoOpenInfo info, Vector2D position, List <Body> result) { Lifespan avatarLifespan = new Lifespan(); IShape shape = ShapeFactory.CreateSprite(Cache <SurfacePolygons> .GetItem("tank.png"), 4, 18, 2); ObjectIgnorer ignorer = new ObjectIgnorer(); Body tankBody = new Body(new PhysicsState(new ALVector2D(0, 0, 0)), shape, 300,//new MassInfo(40, Scalar.PositiveInfinity), new Coefficients(0, 1), avatarLifespan); result.Add(tankBody); tankBody.State.Position.Linear += position; tankBody.ApplyPosition(); tankBody.CollisionIgnorer = ignorer; BodyGraphic graphic = CreateGraphic(tankBody); graphic.ZOrder = 2; info.Scene.AddGraphic(graphic); Scalar wheelSize = 18; Scalar wheelSpacing = -9; Scalar lenghtPercent = .84f; Matrix2x3 ident = Matrix2x3.Identity; BoundingRectangle rect; shape.CalcBoundingRectangle(ref ident, out rect); Scalar y = (rect.Max.Y + 4); Body lastWheel = null; BoundingPolygon polygon = new BoundingPolygon(shape.Vertexes); Ray ray2 = new Ray(new Vector2D(rect.Max.X, y), -Vector2D.YAxis); Scalar y3 = y - polygon.Intersects(ray2); Vector2D avatarBarrelOffset = new Vector2D(rect.Max.X + 10, y3); CircleShape wheelShape = ShapeFactory.CreateColoredCircle(wheelSize, 30); Scalar force = 0; for (Scalar x = rect.Min.X + wheelSize; x < (rect.Max.X - wheelSize) * lenghtPercent; x += (wheelSize * 2 + wheelSpacing)) { Ray ray = new Ray(new Vector2D(x, y), -Vector2D.YAxis); Scalar y2 = y - polygon.Intersects(ray); Vector2D offset = new Vector2D(x, y2); Body wheel = new Body( new PhysicsState(new ALVector2D(0, offset + position)), wheelShape, 10, new Coefficients(0, 3),// coefficients.Duplicate(), avatarLifespan); result.Add(wheel); wheel.CollisionIgnorer = ignorer; wheel.AngularDamping = .9f; wheel.Updated += delegate(object sender, UpdatedEventArgs e) { wheel.State.ForceAccumulator.Angular += force; }; info.Scene.AddGraphic(CreateGraphic(wheel)); HingeJoint joint = new HingeJoint(tankBody, wheel, offset + position, avatarLifespan); joint.Softness = .1f; info.Scene.Engine.AddJoint(joint); if (lastWheel != null) { AngleJoint joint2 = new AngleJoint(lastWheel, wheel, avatarLifespan); info.Scene.Engine.AddJoint(joint2); } lastWheel = wheel; } CircleShape weaponShape = ShapeFactory.CreateColoredCircle(5, 8); //now begins the abuse of anominous delegates (BIG TIME) EventHandler <KeyboardEventArgs> keyDownHandler = delegate(object sender, KeyboardEventArgs e) { switch (e.Key) { case Key.LeftArrow: force = -1500000; break; case Key.RightArrow: force = 1500000; break; case Key.Space: Scalar velocity = 2000; Matrix2x3 toWorld = tankBody.Matrices.ToWorld; Matrix2x2 toWorldNormal = tankBody.Matrices.ToWorldNormal; // Matrix2D mat = avatarBodies[0].Matrices.ToWorld; Vector2D direction = toWorldNormal * Vector2D.XAxis; PhysicsState state = new PhysicsState(); state.Position.Linear = toWorld * (avatarBarrelOffset); state.Velocity.Linear = velocity * direction + tankBody.State.Velocity.Linear; Body weapon = new Body(state, weaponShape, 5, new Coefficients(1, 1), new Lifespan(10)); //weapon.CollisionIgnorer = tankBody.CollisionIgnorer; weapon.Collided += delegate(object sender2, CollisionEventArgs e2) { if (!weapon.Lifetime.IsExpired) { weapon.Lifetime.IsExpired = true; AddParticles(info, weapon.State.Position.Linear, weapon.State.Velocity.Linear * .5f, 50); } }; // weapon.Collided += weapon_Collided; tankBody.State.Velocity.Linear -= (velocity * weapon.Mass.Mass * tankBody.Mass.MassInv) * direction; info.Scene.AddGraphic(CreateGraphic(weapon)); break; } }; EventHandler <KeyboardEventArgs> keyUpHandler = delegate(object sender, KeyboardEventArgs e) { switch (e.Key) { case Key.LeftArrow: force = 0; break; case Key.RightArrow: force = 0; break; } }; Events.KeyboardDown += keyDownHandler; Events.KeyboardUp += keyUpHandler; return(delegate() { Events.KeyboardDown -= keyDownHandler; Events.KeyboardUp -= keyUpHandler; }); }