public StarlingGameSpriteWithTestGamePad()
        {
            var textures_ped = new StarlingGameSpriteWithPedTextures(new_tex_crop, this.new_texsprite_crop);
            var textures_tank = new StarlingGameSpriteWithTankTextures(this.new_texsprite_crop);
            var textures_hind = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);
            var textures_jeep = new StarlingGameSpriteWithJeepTextures(new_tex_crop);
            var textures_cannon = new StarlingGameSpriteWithCannonTextures(new_tex_crop);
            var textures_bunker = new StarlingGameSpriteWithBunkerTextures(new_tex_crop);

            disablephysicsdiagnostics = true;
            disable_movezoom_and_altitude_for_scale = true;

            internalscale = 1.7;
            internal_center_y = 0.5;

            this.onbeforefirstframe += (stage, s) =>
            {

                #region __keyDown

                stage.keyDown +=
                   e =>
                   {
                       // http://circlecube.com/2008/08/actionscript-key-listener-tutorial/
                       if (e.altKey)
                           __keyDown[Keys.Alt] = true;

                       __keyDown[(Keys)e.keyCode] = true;
                   };

                stage.keyUp +=
                 e =>
                 {
                     if (!e.altKey)
                         __keyDown[Keys.Alt] = false;

                     __keyDown[(Keys)e.keyCode] = false;
                 };

                #endregion


                var tank1 = new PhysicalTank(textures_tank, this);
                tank1.SetPositionAndAngle(random.NextDouble() * 4000, 100);

                // half speed!
                //tank1.AngularVelocityMultiplier = 0.5;
                //tank1.speed = 10;

                //tank1.SetPositionAndAngle(100, 100);



                var cannon1 = new PhysicalCannon(textures_cannon, this);
                cannon1.SetPositionAndAngle(random.NextDouble() * 4000, 100);

                var physical0 = new PhysicalPed(textures_ped, this);
                physical0.SetPositionAndAngle(random.NextDouble() * 4000, 100);

                current = physical0;

                var hind0 = new PhysicalHind(textures_hind, this);
                hind0.SetPositionAndAngle(random.NextDouble() * 4000, 100);

                var jeep = new PhysicalJeep(textures_jeep, this);
                jeep.SetPositionAndAngle(random.NextDouble() * 4000, 100);

                var bunker0 = new PhysicalBunker(textures_bunker, this);
                bunker0.SetPositionAndAngle(random.NextDouble() * 4000, 100);

                var silo0 = new PhysicalSilo(textures_bunker, this);

                __switchto +=
                    type =>
                    {
                        if (type == "ped")
                            current = physical0;

                        if (type == "tank")
                            current = tank1;

                        if (type == "hind")
                            current = hind0;

                        if (type == "jeep")
                            current = jeep;

                        if (type == "cannon")
                            current = cannon1;

                        if (type == "bunker")
                            current = bunker0;

                        if (type == "silo")
                            current = silo0;
                    };

                onsyncframe += delegate
                {

                    current.SetVelocityFromInput(__keyDown);


                    while (Content_layer0_tracks.numChildren > 5)
                    {
                        Content_layer0_tracks.removeChildAt(0);
                    }

                };
            };
        }
        public StarlingGameSpriteWithHindControl()
        {
            // how much bigger are units in flight altidude?

            var textures_hind = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);


            this.onbeforefirstframe += (stage, s) =>
            {


                var physical0 = new PhysicalHind(textures_hind, this);


                for (int ix = 0; ix < 32; ix++)
                {
                    var physical1 = new PhysicalHind(textures_hind, this);
                    var physical2 = new PhysicalHind(textures_hind, this);
                    var physical3 = new PhysicalHind(textures_hind, this);

                    physical1.SetPositionAndAngle(10 + 20 * ix, 20);

                    physical2.visual.Altitude = 1.0;

                    physical2.SetPositionAndAngle(20 + 20 * ix, 40);

                    physical3.visual.Altitude = 0.5;

                    physical3.SetPositionAndAngle(30 + 20 * ix, 60);
                }





                bool mode_changepending = false;
                //bool visual0_flightmode = false;


                #region __keyDown

                stage.keyDown +=
                   e =>
                   {
                       // http://circlecube.com/2008/08/actionscript-key-listener-tutorial/
                       if (e.altKey)
                           __keyDown[System.Windows.Forms.Keys.Alt] = true;

                       __keyDown[(System.Windows.Forms.Keys)e.keyCode] = true;
                   };

                stage.keyUp +=
                 e =>
                 {
                     if (!e.altKey)
                         __keyDown[System.Windows.Forms.Keys.Alt] = false;

                     __keyDown[(System.Windows.Forms.Keys)e.keyCode] = false;
                 };

                #endregion

                this.current = physical0;

                // http://doc.starling-framework.org/core/starling/filters/ColorMatrixFilter.html
                // create an inverted filter with 50% saturation and 180° hue rotation
                var filter = new ColorMatrixFilter();
                filter.adjustSaturation(-1.0);
                filter.invert();
                filter.adjustContrast(0.5);

                this.filter = filter;
                this.stage.color = 0x808080;

                onsyncframe +=
                    delegate
                    {
                        #region mode
                        if (!__keyDown[System.Windows.Forms.Keys.Space])
                        {
                            // space is not down.
                            mode_changepending = true;
                        }
                        else
                        {
                            if (mode_changepending)
                            {
                                (current as PhysicalHind).With(
                                    hind1 =>
                                    {
                                        if (hind1.visual.Altitude == 0)
                                            hind1.VerticalVelocity = 1.0;
                                        else
                                            hind1.VerticalVelocity = -0.4;

                                    }
                                );






                                mode_changepending = false;



                            }
                        }
                        #endregion


                        // for camera

                        current.SetVelocityFromInput(__keyDown);




                        #region simulate a weapone!
                        if (__keyDown[System.Windows.Forms.Keys.ControlKey])
                            if (frameid % 20 == 0)
                            {
                                var bodyDef = new b2BodyDef();

                                bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;

                                // stop moving if legs stop walking!
                                bodyDef.linearDamping = 0;
                                bodyDef.angularDamping = 0;
                                //bodyDef.angle = 1.57079633;
                                bodyDef.fixedRotation = true;

                                var body = physical0.body.GetWorld().CreateBody(bodyDef);
                                body.SetPosition(
                                    new b2Vec2(
                                        current.body.GetPosition().x + 2,
                                        current.body.GetPosition().y + 2
                                    )
                                );

                                body.SetLinearVelocity(
                                       new b2Vec2(
                                         100,
                                        100
                                    )
                                );

                                var fixDef = new Box2D.Dynamics.b2FixtureDef();
                                fixDef.density = 0.1;
                                fixDef.friction = 0.01;
                                fixDef.restitution = 0;


                                fixDef.shape = new Box2D.Collision.Shapes.b2CircleShape(1.0);


                                var fix = body.CreateFixture(fixDef);

                                //body.SetPosition(
                                //    new b2Vec2(0, -100 * 16)
                                //);
                            }
                        #endregion
                    };
            };
        }
        public StarlingGameSpriteWithHindSync()
        {
            var textures_hind = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);


            this.onbeforefirstframe += (stage, s) =>
            {




                #region __keyDown
                var __keyDown = new KeySample();

                stage.keyDown +=
                   e =>
                   {
                       // http://circlecube.com/2008/08/actionscript-key-listener-tutorial/
                       if (e.altKey)
                           __keyDown[System.Windows.Forms.Keys.Alt] = true;

                       __keyDown[(System.Windows.Forms.Keys)e.keyCode] = true;
                   };

                stage.keyUp +=
                 e =>
                 {
                     if (!e.altKey)
                         __keyDown[System.Windows.Forms.Keys.Alt] = false;

                     __keyDown[(System.Windows.Forms.Keys)e.keyCode] = false;
                 };

                #endregion



                #region ego
                var ego = new PhysicalHind(textures_hind, this)
                {
                    Identity = sessionid + ":ego"
                };

                ego.SetPositionAndAngle(
                   random.NextDouble() * -20 - 4,
                   random.NextDouble() * -20 - 4,
                   random.NextDouble() * Math.PI
               );

                current = ego;
                #endregion





                #region other
                Func<string, RemoteGame> other = __egoid =>
                {
                    // that other game has sent us a sync frame!

                    var already_known_other = others.FirstOrDefault(k => k.__egoid == __egoid);

                    if (already_known_other == null)
                    {
                        already_known_other = new RemoteGame
                        {
                            __egoid = __egoid,

                            // this
                            __syncframeid = this.syncframeid
                        };

                        others.Add(already_known_other);
                    }


                    return already_known_other;
                };
                #endregion


                #region __at_sync
                __at_sync += __egoid =>
                {
                    // that other game has sent us a sync frame!

                    var o = other(__egoid);

                    o.__syncframeid++;
                    // move on!
                };
                #endregion

                #region __at_SetVerticalVelocity
                __at_SetVerticalVelocity +=
                    (string __sessionid, string identity, string value) =>
                    {
                        var o = other(__sessionid);

                        var u = this.units.FirstOrDefault(k => k.Identity == identity);

                        (u as PhysicalHind).With(hind1 => hind1.VerticalVelocity = double.Parse(value));

                    };
                #endregion


                #region __at_SetVelocityFromInput
                __at_SetVelocityFromInput +=
                    (
                        string __egoid,
                        string __identity,
                        string __KeySample,
                        string __fixup_x,
                        string __fixup_y,
                        string __fixup_angle

                        ) =>
                    {
                        var o = other(__egoid);



                        if (o.ego == null)
                        {
                            o.ego = new PhysicalHind(textures_hind, this)
                            {
                                Identity = __identity,
                                RemoteGameReference = o
                            };

                            o.ego.SetPositionAndAngle(
                                double.Parse(__fixup_x),
                                double.Parse(__fixup_y),
                                double.Parse(__fixup_angle)
                            );
                        }


                        // set the input!


                        o.ego.SetVelocityFromInput(
                            new KeySample
                            {
                                value = int.Parse(__KeySample),

                                fixup = true,

                                x = double.Parse(__fixup_x),
                                y = double.Parse(__fixup_y),
                                angle = double.Parse(__fixup_angle)

                            }
                        );

                    };
                #endregion




                bool mode_changepending = false;

                onsyncframe += delegate
                {
                    #region mode
                    if (!__keyDown[System.Windows.Forms.Keys.Space])
                    {
                        // space is not down.
                        mode_changepending = true;
                    }
                    else
                    {
                        if (mode_changepending)
                        {
                            (current as PhysicalHind).With(
                                hind1 =>
                                {
                                    if (hind1.visual.Altitude == 0)
                                        hind1.VerticalVelocity = 1.0;
                                    else
                                        hind1.VerticalVelocity = -0.4;

                                    __raise_SetVerticalVelocity(
                                        "" + this.sessionid,
                                        hind1.Identity,
                                        "" + hind1.VerticalVelocity
                                    );
                                }
                            );

                            //   (current as PhysicalPed).With(
                            //    physical0 =>
                            //    {
                            //        if (physical0.visual.LayOnTheGround)
                            //            physical0.visual.LayOnTheGround = false;
                            //        else
                            //            physical0.visual.LayOnTheGround = true;

                            //    }
                            //);




                            mode_changepending = false;



                        }
                    }
                    #endregion


                    current.SetVelocityFromInput(__keyDown);




                    __raise_SetVelocityFromInput(
                         "" + sessionid,
                         current.Identity,
                         "" + current.CurrentInput.value,
                         "" + current.body.GetPosition().x,
                         "" + current.body.GetPosition().y,
                         "" + current.body.GetAngle()

                     );


                    // tell others this sync frame ended for us
                    __raise_sync("" + sessionid);
                };
            };
        }
        public StarlingGameSpriteWithHindControl()
        {
            // how much bigger are units in flight altidude?

            var textures_hind = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);


            this.onbeforefirstframe += (stage, s) =>
            {
                var physical0 = new PhysicalHind(textures_hind, this);


                for (int ix = 0; ix < 32; ix++)
                {
                    var physical1 = new PhysicalHind(textures_hind, this);
                    var physical2 = new PhysicalHind(textures_hind, this);
                    var physical3 = new PhysicalHind(textures_hind, this);

                    physical1.SetPositionAndAngle(10 + 20 * ix, 20);

                    physical2.visual.Altitude = 1.0;

                    physical2.SetPositionAndAngle(20 + 20 * ix, 40);

                    physical3.visual.Altitude = 0.5;

                    physical3.SetPositionAndAngle(30 + 20 * ix, 60);
                }



                bool mode_changepending = false;
                //bool visual0_flightmode = false;


                #region __keyDown

                stage.keyDown +=
                    e =>
                {
                    // http://circlecube.com/2008/08/actionscript-key-listener-tutorial/
                    if (e.altKey)
                    {
                        __keyDown[System.Windows.Forms.Keys.Alt] = true;
                    }

                    __keyDown[(System.Windows.Forms.Keys)e.keyCode] = true;
                };

                stage.keyUp +=
                    e =>
                {
                    if (!e.altKey)
                    {
                        __keyDown[System.Windows.Forms.Keys.Alt] = false;
                    }

                    __keyDown[(System.Windows.Forms.Keys)e.keyCode] = false;
                };

                #endregion

                this.current = physical0;

                // http://doc.starling-framework.org/core/starling/filters/ColorMatrixFilter.html
                // create an inverted filter with 50% saturation and 180° hue rotation
                var filter = new ColorMatrixFilter();
                filter.adjustSaturation(-1.0);
                filter.invert();
                filter.adjustContrast(0.5);

                this.filter      = filter;
                this.stage.color = 0x808080;

                onsyncframe +=
                    delegate
                {
                    #region mode
                    if (!__keyDown[System.Windows.Forms.Keys.Space])
                    {
                        // space is not down.
                        mode_changepending = true;
                    }
                    else
                    {
                        if (mode_changepending)
                        {
                            (current as PhysicalHind).With(
                                hind1 =>
                            {
                                if (hind1.visual.Altitude == 0)
                                {
                                    hind1.VerticalVelocity = 1.0;
                                }
                                else
                                {
                                    hind1.VerticalVelocity = -0.4;
                                }
                            }
                                );



                            mode_changepending = false;
                        }
                    }
                    #endregion


                    // for camera

                    current.SetVelocityFromInput(__keyDown);



                    #region simulate a weapone!
                    if (__keyDown[System.Windows.Forms.Keys.ControlKey])
                    {
                        if (frameid % 20 == 0)
                        {
                            var bodyDef = new b2BodyDef();

                            bodyDef.type = Box2D.Dynamics.b2Body.b2_dynamicBody;

                            // stop moving if legs stop walking!
                            bodyDef.linearDamping  = 0;
                            bodyDef.angularDamping = 0;
                            //bodyDef.angle = 1.57079633;
                            bodyDef.fixedRotation = true;

                            var body = physical0.body.GetWorld().CreateBody(bodyDef);
                            body.SetPosition(
                                new b2Vec2(
                                    current.body.GetPosition().x + 2,
                                    current.body.GetPosition().y + 2
                                    )
                                );

                            body.SetLinearVelocity(
                                new b2Vec2(
                                    100,
                                    100
                                    )
                                );

                            var fixDef = new Box2D.Dynamics.b2FixtureDef();
                            fixDef.density     = 0.1;
                            fixDef.friction    = 0.01;
                            fixDef.restitution = 0;


                            fixDef.shape = new Box2D.Collision.Shapes.b2CircleShape(1.0);


                            var fix = body.CreateFixture(fixDef);

                            //body.SetPosition(
                            //    new b2Vec2(0, -100 * 16)
                            //);
                        }
                    }
                    #endregion
                };
            };
        }