Пример #1
0
        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);
            });
        }