Example #1
0
        public override void OnLoad()
        {
            Paint += OnPaint;

            dd = new SKDrawDebug(HipsterEngine);

            HipsterEngine.Physics.Initialize(-1000, -1000, 1000, 1000, 0, 0f, true);
            HipsterEngine.Physics.GetWorld().SetDebugDraw(dd);

            MousePosition = new Vec2(0, 0);


            HipsterEngine.Surface.Canvas.Camera.SetScale(0.5f);

            HipsterEngine.Surface.Canvas.Camera.Y = Height / 2;
            HipsterEngine.Surface.Canvas.Camera.X = -Width / 2;

            HipsterEngine.Particles.AddParticleSystem(new ParticlesControllerFire(HipsterEngine));


            var        isMove     = false;
            var        mouse      = new Vec2();
            var        listMouses = new List <Vec2>();
            MouseJoint joint      = null;
            Body       body       = null;

            MouseDown += (o, e) =>
            {
                isMove = true;

                if (e.Button == MouseButton.Right)
                {
                    HipsterEngine.Physics.FactoryBody
                    .CreateRigidVertex()
                    .CreateBox(0.2f, 0.2f, 50, 50, 0.2f)
                    .CreateBodyDef(e.X, e.Y, 0, true, false)
                    .Build(1f);
                }
            };
            MouseMove += (o, e) =>
            {
                MousePosition = new Vec2(e.X, e.Y);

                var ps = (ParticlesControllerFire)HipsterEngine.Particles.GetSystem(typeof(ParticlesControllerFire));
                ps.AddBlood(MousePosition.X - HipsterEngine.Surface.Canvas.Camera.X, MousePosition.Y + HipsterEngine.Surface.Canvas.Camera.Y, new Vec2(), 5);

                if (isMove)
                {
                    mouse = new Vec2(e.X / PhysicsController.metric, e.Y / PhysicsController.metric);

                    if (listMouses.Count >= 10)
                    {
                        listMouses.RemoveAt(0);
                    }
                    listMouses.Add(mouse);

                    body = HipsterEngine.Physics.GetRayBody(e.X, e.Y);

                    if (body != null && joint == null)
                    {
                        joint = HipsterEngine.Physics.AddJointMouse(body, mouse);
                    }

                    joint?.SetTarget(mouse);
                }
            };
            MouseUp += (o, e) =>
            {
                if (joint != null)
                {
                    HipsterEngine.Physics.GetWorld().DestroyJoint(joint);
                    joint = null;
                    body  = null;
                }

                isMove = false;
                listMouses.Clear();
            };

            Trees = new List <Tree>();


            InitializeBall();

            //   Robots = new List<IRobot>();
            //   var robot = new Robot(HipsterEngine, Earth);
            //   robot.Initialize(new TwoWheels(), new Box2(), new Gun1())
            //       .Build(Width / 2+200, 120, 90, 20);

            //   var robot1 = new Robot(HipsterEngine, Earth);
            //   robot1.Initialize(new TwoWheels(), new Box2(), new Gun1())
            //       .Build(Width / 2-200, 120, 90, 20);
            //   Robots.Add(robot);
            //   Robots.Add(robot1);

            aControl = new AttackControl(HipsterEngine, 70);
            mControl = new MoveControl(HipsterEngine);
            mControl.Tracker.Move += (sender, vec2) =>
            {
                ValueX = vec2.X;
                //       Robots.First().Transmission.Move(-ValueX / 10);

                if (ValueX > 0)
                {
                    //         ((Gun1) Robots.First().Arms).SetAngleRad(90);
                }
                else if (ValueX < 0)
                {
                    //         ((Gun1) Robots.First().Arms).SetAngleRad(-90);
                }
                else if (ValueX == 0)
                {
                    //     ((Gun1) Robots.First().Arms).SetAngleRad(180);
                }
            };
            aControl.Click += (sender, args) =>
            {
                //       Robots.First().Arms.Attack();
            };

            Timer       = new TimeWatch();
            Timer.Tick += tick => { ((Gun1)Robots.First().Arms).SetAngleRad(tick); };
        }