public PhysicalHindWeaponized(
            StarlingGameSpriteWithHindTextures textures_hind,
            StarlingGameSpriteWithRocketTextures textures_rocket,
            StarlingGameSpriteWithPhysics __Context,


            Image Explosion1 = null
            )
            : base(textures_hind, __Context)
        {
            var RocketsMax = 12;
            var Rockets    = new Queue <PhysicalRocket>();

            var Context = __Context;
            var rocket0 = new PhysicalRocket(textures_rocket, Context, Explosion1: Explosion1);

            rocket0.body.SetActive(false);
            rocket0.SetPositionAndAngle(-0.5, 2);


            var rocket1 = new PhysicalRocket(textures_rocket, Context, Explosion1: Explosion1);

            rocket1.body.SetActive(false);
            rocket1.SetPositionAndAngle(-0.5, -2);

            #region z fixup
            rocket0.visual.parent.setChildIndex(
                rocket0.visual,

                this.visual.visualnowings.parent.getChildIndex(
                    this.visual.visualnowings
                    )
                );
            #endregion

            #region z fixup
            rocket1.visual.parent.setChildIndex(
                rocket1.visual,

                this.visual.visualnowings.parent.getChildIndex(
                    this.visual.visualnowings
                    )
                );
            #endregion

            var hind0 = this;

            #region ShowPositionAndAngleForSlaves
            hind0.ShowPositionAndAngleForSlaves = delegate
            {
                // we are faking 3d here!
                var sc = 1 + hind0.visual.airzoom * hind0.visual.Altitude;


                if (rocket0 != null)
                {
                    rocket0.body.SetActive(false);
                    rocket0.Altitude = hind0.visual.Altitude;
                    rocket0.SetPositionAndAngle(


                        hind0.body.GetPosition().x + Math.Cos(hind0.body.GetAngle() - Math.PI * 0.5 - hind0.CameraRotation) * 2.2 * sc,
                        hind0.body.GetPosition().y + Math.Sin(hind0.body.GetAngle() - Math.PI * 0.5 - hind0.CameraRotation) * 2.2 * sc,

                        hind0.body.GetAngle() - hind0.CameraRotation
                        );
                    rocket0.ShowPositionAndAngle();
                }

                if (rocket1 != null)
                {
                    rocket1.body.SetActive(false);
                    rocket1.Altitude = hind0.visual.Altitude;
                    rocket1.SetPositionAndAngle(


                        hind0.body.GetPosition().x + Math.Cos(hind0.body.GetAngle() + Math.PI * 0.5 - hind0.CameraRotation) * 2.2 * sc,
                        hind0.body.GetPosition().y + Math.Sin(hind0.body.GetAngle() + Math.PI * 0.5 - hind0.CameraRotation) * 2.2 * sc,

                        hind0.body.GetAngle() - hind0.CameraRotation
                        );
                    rocket1.ShowPositionAndAngle();
                }
            };
            #endregion

            #region FireRocket
            FireRocket = delegate
            {
                if (rocket0 != null)
                {
                    var sc = 1 + hind0.visual.airzoom * hind0.visual.Altitude;

                    rocket0.SetPositionAndAngle(


                        hind0.body.GetPosition().x + Math.Cos(hind0.body.GetAngle() - Math.PI * 0.5 - hind0.CameraRotation) * 3.5 * sc,
                        hind0.body.GetPosition().y + Math.Sin(hind0.body.GetAngle() - Math.PI * 0.5 - hind0.CameraRotation) * 3.5 * sc,

                        hind0.body.GetAngle() - hind0.CameraRotation
                        );
                    rocket0.ShowPositionAndAngle();
                    rocket0.body.SetActive(true);

                    rocket0.CreateSmoke();
                    {
                        var up = new KeySample();
                        up[Keys.Up]   = true;
                        rocket0.speed = 60 + this.body.GetLinearVelocity().Length();
                        rocket0.SetVelocityFromInput(up);
                    }
                    Rockets.Enqueue(rocket0);
                    rocket0 = null;


                    if (rocket1 == null)
                    {
                        if (Rockets.Count > RocketsMax)
                        {
                            rocket1 = Rockets.Dequeue();
                            rocket1.SetVelocityFromInput(new KeySample());
                            rocket1.visual.visible = true;
                        }
                        else
                        {
                            rocket1 = new PhysicalRocket(textures_rocket, Context, Explosion1: Explosion1);
                            rocket1.body.SetActive(false);

                            #region z fixup
                            rocket1.visual.parent.setChildIndex(
                                rocket1.visual,

                                this.visual.visualnowings.parent.getChildIndex(
                                    this.visual.visualnowings
                                    )
                                );
                            #endregion
                        }
                    }
                }
                else if (rocket1 != null)
                {
                    var sc = 1 + hind0.visual.airzoom * hind0.visual.Altitude;

                    rocket1.SetPositionAndAngle(


                        hind0.body.GetPosition().x + Math.Cos(hind0.body.GetAngle() + Math.PI * 0.5 - hind0.CameraRotation) * 3.5 * sc,
                        hind0.body.GetPosition().y + Math.Sin(hind0.body.GetAngle() + Math.PI * 0.5 - hind0.CameraRotation) * 3.5 * sc,

                        hind0.body.GetAngle() - hind0.CameraRotation
                        );
                    rocket1.ShowPositionAndAngle();
                    rocket1.body.SetActive(true);

                    rocket1.CreateSmoke();
                    {
                        var up = new KeySample();
                        up[Keys.Up]   = true;
                        rocket1.speed = 60 + this.body.GetLinearVelocity().Length();
                        rocket1.SetVelocityFromInput(up);
                    }
                    Rockets.Enqueue(rocket1);
                    rocket1 = null;

                    if (rocket0 == null)
                    {
                        if (Rockets.Count > RocketsMax)
                        {
                            rocket0 = Rockets.Dequeue();
                            rocket0.SetVelocityFromInput(new KeySample());
                            rocket0.visual.visible = true;
                        }
                        else
                        {
                            rocket0 = new PhysicalRocket(textures_rocket, Context, Explosion1: Explosion1);
                            rocket0.body.SetActive(false);

                            #region z fixup
                            rocket0.visual.parent.setChildIndex(
                                rocket0.visual,

                                this.visual.visualnowings.parent.getChildIndex(
                                    this.visual.visualnowings
                                    )
                                );
                            #endregion
                        }
                    }
                }
            };
            #endregion
        }
Example #2
0
        public StarlingGameSpriteWithHindWeaponized()
        {
            var textures_ped = new StarlingGameSpriteWithPedTextures(
                this.new_tex_crop,
                this.new_texsprite_crop
                );


            var textures_hind       = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);
            var textures_rocket     = new StarlingGameSpriteWithRocketTextures(this.new_tex_crop);
            var textures_map        = new StarlingGameSpriteWithMapTextures(new_tex_crop);
            var textures_bunker     = new StarlingGameSpriteWithBunkerTextures(new_tex_crop);
            var textures_explosions = new StarlingGameSpriteWithMapExplosionsTextures(new_tex96);

            //this.internalscale = 1.0;
            this.disablephysicsdiagnostics = true;

            this.onbeforefirstframe += (stage, s) =>
            {
                stage.color = 0x75C64F;

                // hind is looking right
                var explosins = new List <ExplosionInfo>();

                for (int i = -12; i < 12; i++)
                {
                    new Image(textures_map.road0()).AttachTo(Content).x = 256 * i;

                    var bunker0 = new PhysicalBunker(textures_bunker, this);
                    bunker0.SetPositionAndAngle(-12 * i, 24);

                    var z = new PhysicalPed(textures_ped, this);

                    z.SetPositionAndAngle(16 * i, 0);
                    z.BehaveLikeZombie();

                    //var exp = new Image(textures_explosions.explosions[0]()).AttachTo(Content);
                    //explosins.Add(exp);
                    //exp.scaleX = 2.0;
                    //exp.scaleY = 2.0;

                    //exp.x = 256 * i;
                }

                #region other units
                for (int i = 3; i < 9; i++)
                {
                    var hind2 = new PhysicalHindWeaponized(textures_hind, textures_rocket, this)
                    {
                        AutomaticTakeoff = true
                    };

                    hind2.SetPositionAndAngle(
                        i * 16, 8, random.NextDouble()
                        );
                }
                #endregion


                #region CreateExplosion
                this.CreateExplosion = (x, y) =>
                {
                    var size = 0.2 + 0.2 * random.NextDouble();

                    sb.snd_explosion.play(
                        sndTransform: new ScriptCoreLib.ActionScript.flash.media.SoundTransform(size)
                        );

                    var exp = new Image(textures_explosions.explosions[0]()).AttachTo(Content);
                    var cm  = new Matrix();

                    cm.translate(-32, -32);
                    cm.scale(5 * size, 5 * size);
                    cm.translate(16 * x, 16 * y);

                    exp.transformationMatrix = cm;

                    explosins.Add(
                        new ExplosionInfo {
                        visual = exp
                    }
                        );
                };
                #endregion


                var hind0 = new PhysicalHindWeaponized(
                    textures_hind, textures_rocket, this
                    );


                current = hind0;


                #region __keyDown

                stage.keyDown +=
                    e =>
                {
                    e.preventDefault();
                    // 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 =>
                {
                    e.preventDefault();

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

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

                #endregion

                bool mode_changepending = false;

                var dx_stop = false;
                var dy_stop = false;
                var dx      = 0.0;
                var dy      = 0.0;

                //              Error: Error #3707: Property can not be set in non full screen mode.
                //at flash.display::Stage/set mouseLock()

                // http://inflagrantedelicto.memoryspiral.com/2012/07/as3-quickie-mouse-lock-and-relative-mouse-coordinates/
                stage.fullScreen +=
                    delegate
                {
                    if (stage.displayState == StageDisplayState.NORMAL)
                    {
                        return;
                    }

                    // http://helpx.adobe.com/flash-player/release-note/fp_114_air_34_release_notes.html
                    // · Mouse Lock feature disabled after entering Full Screen Interactive mode(3174344)
                    //stage.mouseLock = true;
                };



                stage.mouseDown +=
                    e =>
                {
                    if (stage.displayState == StageDisplayState.NORMAL)
                    {
                        return;
                    }

                    __keyDown[Keys.ControlKey] = true;
                };

                stage.doubleClickEnabled = true;
                stage.doubleClick       += delegate
                {
                    if (stage.displayState == StageDisplayState.NORMAL)
                    {
                        stage.displayState = ScriptCoreLib.ActionScript.flash.display.StageDisplayState.FULL_SCREEN;
                        stage.displayState = ScriptCoreLib.ActionScript.flash.display.StageDisplayState.FULL_SCREEN_INTERACTIVE;
                        return;
                    }
                };

                stage.mouseUp +=
                    e =>
                {
                    if (stage.displayState == StageDisplayState.NORMAL)
                    {
                        return;
                    }

                    __keyDown[Keys.ControlKey] = false;
                };

                stage.mouseMove +=
                    e =>
                {
                    if (stage.displayState == StageDisplayState.NORMAL)
                    {
                        dx = 0;
                        dy = 0;
                        return;
                    }

                    //dynamic ee = e;

                    //// ReferenceError: Erroe.r #1069: Property movementX not found on flash.events.MouseEvent and there is no default value.
                    //double movementX = ee.me.ovementX;
                    //double movementY = ee.movementY;

                    // http://www.levelxgames.com/2012/11/how-to-overlay-abode-air-sdk-over-flex-sdk/
                    //dx += e.movementX;
                    //dy += e.movementY;
                };

                onsyncframe +=
                    delegate
                {
                    this.Text = new { dx }.ToString();

                    foreach (var item in explosins.ToArray())
                    {
                        item.index++;

                        if (item.index == textures_explosions.explosions.Length)
                        {
                            item.visual.Orphanize();
                            explosins.Remove(item);
                        }
                        else
                        {
                            item.visual.texture = textures_explosions.explosions[item.index]();
                        }
                    }

                    #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

                    if (dx < 0)
                    {
                        __keyDown[Keys.Left]  = true;
                        __keyDown[Keys.Right] = false;
                        __keyDown.forcex      = (Math.Abs(dx) / 100.0).Min(1.0);
                        dx      = 0;
                        dx_stop = true;
                    }
                    else if (dx > 0)
                    {
                        __keyDown[Keys.Right] = true;
                        __keyDown[Keys.Left]  = false;
                        __keyDown.forcex      = (Math.Abs(dx) / 100.0).Min(1.0);
                        dx      = 0;
                        dx_stop = true;
                    }
                    else
                    {
                        if (dx_stop)
                        {
                            __keyDown[Keys.Left]  = false;
                            __keyDown[Keys.Right] = false;
                        }
                        dx_stop = false;

                        __keyDown.forcex = 1.0;
                    }

                    if (dy < 0)
                    {
                        __keyDown[Keys.Up]   = true;
                        __keyDown[Keys.Down] = false;
                        __keyDown.forcey     = (Math.Abs(dy) / 200.0).Min(1.0);
                        dy_stop = true;
                    }
                    else if (dy > 0)
                    {
                        __keyDown[Keys.Up]   = false;
                        __keyDown[Keys.Down] = true;
                        __keyDown.forcey     = (Math.Abs(dy) / 200.0).Min(1.0);
                        dy_stop = true;
                    }
                    else
                    {
                        if (dy_stop)
                        {
                            __keyDown[Keys.Up]   = false;
                            __keyDown[Keys.Down] = false;
                        }
                        dy_stop = false;

                        __keyDown.forcey = 1.0;
                    }

                    current.SetVelocityFromInput(__keyDown);



                    #region simulate a weapone!
                    if (__keyDown[System.Windows.Forms.Keys.ControlKey])
                    {
                        if (syncframeid % 3 == 0)
                        {
                            sb.snd_missleLaunch.play();
                            hind0.FireRocket();
                        }
                    }
                    #endregion
                };
            };
        }
        public StarlingGameSpriteWithTestDriversSync()
        {
            var textures_map = new StarlingGameSpriteWithMapTextures(new_tex_crop);

            var textures_ped    = new StarlingGameSpriteWithPedTextures(this.new_tex_crop, this.new_texsprite_crop);
            var textures_jeep   = new StarlingGameSpriteWithJeepTextures(this.new_tex_crop);
            var textures_tank   = new StarlingGameSpriteWithTankTextures(new_texsprite_crop);
            var textures_hind   = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);
            var textures_rocket = new StarlingGameSpriteWithRocketTextures(this.new_tex_crop);

            var textures_bunker = new StarlingGameSpriteWithBunkerTextures(this.new_tex_crop);

            this.onbeforefirstframe += (stage, s) =>
            {
                #region :ego
                var ego = new PhysicalPed(textures_ped, this)
                {
                    Identity = sessionid + ":ego"
                };

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

                current = ego;
                #endregion


                #region KeySample
                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

                new PhysicalBunker(textures_bunker, this)
                {
                    Identity = "bunker:0"
                }.SetPositionAndAngle(0, -24);

                var hind0 = new PhysicalHindWeaponized(textures_hind, textures_rocket, this)
                {
                    Identity = ":1",

                    AutomaticTakeoff   = true,
                    AutomaticTouchdown = true
                };

                hind0.SetPositionAndAngle(-12, -12);

                new Image(textures_map.touchdown()).AttachTo(Content).y = 256;

                new PhysicalJeep(textures_jeep, this)
                {
                    Identity = ":2"
                }.SetPositionAndAngle(0, -12);
                new PhysicalTank(textures_tank, this)
                {
                    Identity = ":3"
                }.SetPositionAndAngle(12, -12);



                #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));

                    (u as PhysicalPed).With(
                        physical0 =>
                    {
                        //                                  BCL needs another method, please define it.
                        //Cannot call type without script attribute :
                        //System.Convert for Boolean ToBoolean(Double) used at

                        var LayOnTheGround = double.Parse(value);

                        if (LayOnTheGround == 1)
                        {
                            physical0.visual.LayOnTheGround = true;
                        }
                        else
                        {
                            physical0.visual.LayOnTheGround = false;
                        }
                    }
                        );
                };
                #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);

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

                    if (u == null)
                    {
                        if (o.ego == null)
                        {
                            // the only object we can be creating implicitly is
                            // the remote ego

                            u = new PhysicalPed(textures_ped, this)
                            {
                                Identity            = __identity,
                                RemoteGameReference = o
                            };

                            u.SetPositionAndAngle(
                                double.Parse(__fixup_x),
                                double.Parse(__fixup_y),
                                double.Parse(__fixup_angle)
                                );

                            o.ego = u;
                        }
                    }


                    // set the input!


                    u.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


                #region __at_enterorexit
                __at_enterorexit += (__egoid, __from, __to) =>
                {
                    var o = other(__egoid);

                    var ufrom = this.units.FirstOrDefault(k => k.Identity == __from);
                    var uto   = this.units.FirstOrDefault(k => k.Identity == __to);

                    (ufrom as PhysicalPed).With(
                        candidatedriver =>
                    {
                        if (uto != null)
                        {
                            if (uto.driverseat != null)
                            {
                                if (uto.driverseat.driver == null)
                                {
                                    // and the devil enters
                                    uto.RemoteGameReference = o;

                                    candidatedriver.body.SetActive(false);

                                    uto.driverseat.driver         = candidatedriver;
                                    candidatedriver.seatedvehicle = uto;
                                }
                            }
                        }
                    }
                        );

                    (uto as PhysicalPed).With(
                        driver =>
                    {
                        if (ufrom != null)
                        {
                            if (ufrom.driverseat != null)
                            {
                                if (ufrom.driverseat.driver == driver)
                                {
                                    // relinguish that vehicle. no longer posessed :)
                                    ufrom.RemoteGameReference = null;

                                    // stop the vehicle
                                    ufrom.SetVelocityFromInput(new KeySample());

                                    // get out of the lift..
                                    ufrom.driverseat.driver = null;

                                    driver.seatedvehicle = null;
                                    driver.body.SetActive(true);
                                }
                            }
                        }
                    }
                        );
                };
                #endregion



                bool entermode_changepending = false;
                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;
                                }


                                //                                     BCL needs another method, please define it.
                                //Cannot call type without script attribute :
                                //System.Convert for Double ToDouble(Boolean) used at

                                var value = 0;
                                if (physical0.visual.LayOnTheGround)
                                {
                                    value = 1;
                                }

                                __raise_SetVerticalVelocity(
                                    "" + this.sessionid,
                                    physical0.Identity,
                                    "" + value
                                    );
                            }
                                );



                            mode_changepending = false;
                        }
                    }
                    #endregion



                    #region entermode_changepending
                    if (!__keyDown[System.Windows.Forms.Keys.Enter])
                    {
                        // space is not down.
                        entermode_changepending = true;
                    }
                    else
                    {
                        if (entermode_changepending)
                        {
                            entermode_changepending = false;

                            // enter another vehicle?

                            var candidatedriver = current as PhysicalPed;
                            if (candidatedriver != null)
                            {
                                var target =
                                    from candidatevehicle in units
                                    where candidatevehicle.driverseat != null

                                    // can enter if the seat is full.
                                    // unless we kick them out before ofcourse
                                    where candidatevehicle.driverseat.driver == null

                                    let distance = new __vec2(
                                        (float)(candidatedriver.body.GetPosition().x - candidatevehicle.body.GetPosition().x),
                                        (float)(candidatedriver.body.GetPosition().y - candidatevehicle.body.GetPosition().y)
                                        ).GetLength()

                                                   where distance < 6

                                                   orderby distance ascending
                                                   select new { candidatevehicle, distance };

                                target.FirstOrDefault().With(
                                    x =>
                                {
                                    Console.WriteLine(new { x.distance });

                                    __raise_enterorexit(
                                        "" + this.sessionid,
                                        candidatedriver.Identity,
                                        x.candidatevehicle.Identity
                                        );

                                    //current.loc.visible = false;
                                    current.body.SetActive(false);

                                    x.candidatevehicle.driverseat.driver = candidatedriver;
                                    candidatedriver.seatedvehicle        = x.candidatevehicle;

                                    move_zoom = 1;
                                    current   = x.candidatevehicle;



                                    //if (current.body.GetType() == Box2D.Dynamics.b2Body.b2_dynamicBody)
                                    //{
                                    //    hud.texture = textures_ped.hud_look_goggles();
                                    //}
                                    //else
                                    //{
                                    //    hud.texture = textures_ped.hud_look_building();
                                    //}

                                    //switchto(x.x);

                                    // fast start
                                    //(current as PhysicalHind).With(
                                    //    hind => hind.VerticalVelocity = 1
                                    //);
                                }
                                    );
                            }
                            else
                            {
                                (current.driverseat.driver as PhysicalPed).With(
                                    driver =>
                                {
                                    // stop the vehicle
                                    current.SetVelocityFromInput(new KeySample());

                                    // get out of the lift..
                                    current.driverseat.driver = null;

                                    driver.seatedvehicle = null;
                                    driver.body.SetActive(true);


                                    // crashland?
                                    //(current as PhysicalHind).With(
                                    //    hind => hind.VerticalVelocity = -1
                                    //);

                                    __raise_enterorexit(
                                        "" + this.sessionid,
                                        current.Identity,
                                        driver.Identity
                                        );

                                    current = driver;
                                    //hud.texture = textures_ped.hud_look();
                                    move_zoom = 1;
                                }
                                    );
                            }
                        }
                    }
                    #endregion



                    current.SetVelocityFromInput(__keyDown);

                    #region simulate a weapone!
                    if (__keyDown[System.Windows.Forms.Keys.ControlKey])
                    {
                        if (syncframeid % 3 == 0)
                        {
                            (this.current as PhysicalHindWeaponized).With(
                                h =>
                            {
                                //sb.snd_missleLaunch.play();

                                h.FireRocket();
                            }
                                );
                        }
                    }
                    #endregion

                    __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);
                };
            };
        }
Example #4
0
        public StarlingGameSpriteWithTestDrivers()
        {
            var textures_ped = new StarlingGameSpriteWithPedTextures(this.new_tex_crop, this.new_texsprite_crop);
            // ??
            //<Reference Include="FlashHeatZeeker.UnitHindControl">
            //  <HintPath>..\packages\FlashHeatZeeker.UnitHindControl.1.0.0.0\lib\FlashHeatZeeker.UnitHindControl.dll</HintPath>
            //</Reference>
            // "X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\packages\FlashHeatZeeker.UnitHindControl.1.0.0.0\lib\FlashHeatZeeker.UnitHindControl.dll"
            // "X:\jsc.svn\examples\actionscript\svg\FlashHeatZeeker\packages\FlashHeatZeeker.UnitHind.1.0.0.0\lib\FlashHeatZeeker.UnitHind.dll"
            var textures_hind   = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);
            var textures_jeep   = new StarlingGameSpriteWithJeepTextures(this.new_tex_crop);
            var textures_tank   = new StarlingGameSpriteWithTankTextures(this.new_texsprite_crop);
            var textures_cannon = new StarlingGameSpriteWithCannonTextures(this.new_tex_crop);
            var textures_bunker = new StarlingGameSpriteWithBunkerTextures(this.new_tex_crop);
            var textures_map    = new StarlingGameSpriteWithMapTextures(new_tex_crop);
            var textures_rocket = new StarlingGameSpriteWithRocketTextures(this.new_tex_crop);

            this.disablephysicsdiagnostics = true;

            this.onbeforefirstframe += (stage, s) =>
            {
                var hud = new Image(textures_ped.hud_look()).AttachTo(this);


                for (int i = 0; i < 32; i++)
                {
                    new Image(textures_map.hill1()).AttachTo(Content).With(
                        hill =>
                    {
                        hill.x = 2048.Random();
                        hill.y = 2048.Random();
                    }
                        );

                    new Image(textures_map.hole1()).AttachTo(Content).With(
                        hill =>
                    {
                        hill.x = 2048.Random();
                        hill.y = 2048.Random();
                    }
                        );

                    new Image(textures_map.grass1()).AttachTo(Content).With(
                        hill =>
                    {
                        hill.x = 2048.Random();

                        var y  = -2048.Random() - 512 - 256;
                        hill.y = y;
                    }
                        );
                }

                for (int i = 0; i < 128; i++)
                {
                    var x = 2048.Random();
                    var y = -2048.Random() - 512 - 256;

                    new Image(textures_map.tree0_shadow()).AttachTo(Content).MoveTo(x + 16, y + 16);
                    new Image(textures_map.tree0()).AttachTo(Content).MoveTo(x, y);
                }
                for (int i = -12; i < 12; i++)
                {
                    new Image(textures_map.road0()).AttachTo(Content).x = 256 * i;
                }

                new Image(textures_map.touchdown()).AttachTo(Content).MoveTo(256, -256);
                new Image(textures_map.touchdown()).AttachTo(Content).y = 256;

                new PhysicalHindWeaponized(textures_hind, textures_rocket, this)
                {
                    AutomaticTakeoff = true
                }.SetPositionAndAngle((128 + 256) / 16, -128 * 1.5 / 16);
                new PhysicalTank(textures_tank, this).SetPositionAndAngle(128 / 16, 128 * 3 / 16);

                new Image(textures_map.tree0_shadow()).AttachTo(Content).y = 128 + 16;
                new Image(textures_map.tree0()).AttachTo(Content).y        = 128;

                // can I have
                // new ped, hind, jeep, tank
                current = new PhysicalPed(textures_ped, this);


                // 12 = 34FPS
                #region other units
                for (int i = 3; i < 9; i++)
                {
                    var cannon2 = new PhysicalCannon(textures_cannon, this);

                    cannon2.SetPositionAndAngle(
                        i * 16, -32, random.NextDouble()
                        );



                    if (i % 3 == 0)
                    {
                        new PhysicalBunker(textures_bunker, this).SetPositionAndAngle(
                            i * 16, -16, random.NextDouble()
                            );
                    }
                    else if (i % 3 == 1)
                    {
                        new PhysicalWatertower(textures_bunker, this).SetPositionAndAngle(
                            i * 16, -16, random.NextDouble()
                            );
                    }
                    else
                    {
                        new PhysicalSilo(textures_bunker, this).SetPositionAndAngle(
                            i * 16, -16, random.NextDouble()
                            );
                    }

                    var hind2 = new PhysicalHindWeaponized(textures_hind, textures_rocket, this)
                    {
                        AutomaticTakeoff = true
                    };

                    hind2.SetPositionAndAngle(
                        i * 16, 8, random.NextDouble()
                        );


                    var jeep2 = new PhysicalJeep(textures_jeep, this);


                    jeep2.SetPositionAndAngle(
                        i * 16, 16, random.NextDouble()
                        );



                    var tank2 = new PhysicalTank(textures_tank, this);

                    tank2.SetPositionAndAngle(
                        i * 16, 24, random.NextDouble()
                        );


                    var ped2 = new PhysicalPed(textures_ped, this);

                    ped2.SetPositionAndAngle(
                        i * 16, 32, random.NextDouble()
                        );
                }
                #endregion



                #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

                bool entermode_changepending = false;
                bool mode_changepending      = false;

                onframe +=
                    delegate
                {
                    #region hud
                    {
                        var cm = new Matrix();

                        cm.scale(0.5, 0.5);
                        cm.translate(16, stage.stageHeight - 64 - 24);

                        hud.transformationMatrix = cm;
                    }
                    #endregion
                };

                onsyncframe +=
                    delegate
                {
                    #region entermode_changepending
                    if (!__keyDown[System.Windows.Forms.Keys.Enter])
                    {
                        // space is not down.
                        entermode_changepending = true;
                    }
                    else
                    {
                        if (entermode_changepending)
                        {
                            entermode_changepending = false;

                            // enter another vehicle?

                            var candidatedriver = current as PhysicalPed;
                            if (candidatedriver != null)
                            {
                                var target =
                                    from candidatevehicle in units
                                    where candidatevehicle.driverseat != null

                                    // can enter if the seat is full.
                                    // unless we kick them out before ofcourse
                                    where candidatevehicle.driverseat.driver == null

                                    let distance = new __vec2(
                                        (float)(candidatedriver.body.GetPosition().x - candidatevehicle.body.GetPosition().x),
                                        (float)(candidatedriver.body.GetPosition().y - candidatevehicle.body.GetPosition().y)
                                        ).GetLength()

                                                   where distance < 6

                                                   orderby distance ascending
                                                   select new { candidatevehicle, distance };

                                target.FirstOrDefault().With(
                                    x =>
                                {
                                    Console.WriteLine(new { x.distance });

                                    //current.loc.visible = false;
                                    current.body.SetActive(false);


                                    x.candidatevehicle.driverseat.driver = candidatedriver;
                                    candidatedriver.seatedvehicle        = x.candidatevehicle;

                                    current = x.candidatevehicle;

                                    if (current.body.GetType() == Box2D.Dynamics.b2Body.b2_dynamicBody)
                                    {
                                        hud.texture = textures_ped.hud_look_goggles();
                                    }
                                    else
                                    {
                                        hud.texture = textures_ped.hud_look_building();
                                    }

                                    //switchto(x.x);
                                }
                                    );
                            }
                            else
                            {
                                (current.driverseat.driver as PhysicalPed).With(
                                    driver =>
                                {
                                    current.driverseat.driver = null;
                                    driver.seatedvehicle      = null;
                                    current.SetVelocityFromInput(new KeySample());

                                    // crashland?
                                    (current as PhysicalHind).With(
                                        hind => hind.VerticalVelocity = -1
                                        );


                                    current = driver;
                                    current.body.SetActive(true);
                                    hud.texture = textures_ped.hud_look();
                                }
                                    );
                            }
                        }
                    }
                    #endregion



                    #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;
                                }
                            }
                                );

                            (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);



                    #region simulate a weapone!
                    if (__keyDown[System.Windows.Forms.Keys.ControlKey])
                    {
                        if (syncframeid % 3 == 0)
                        {
                            (this.current as PhysicalHindWeaponized).With(
                                h =>
                            {
                                //sb.snd_missleLaunch.play();

                                h.FireRocket();
                            }
                                );
                        }
                    }
                    #endregion
                };
            };
        }
        public StarlingGameSpriteWithTestDriversWithAudio()
        {
            // http://www.mochigames.com/game/gunship_v838523/

            textures_ped = new StarlingGameSpriteWithPedTextures(this.new_tex_crop, this.new_texsprite_crop);


            var textures_map = new StarlingGameSpriteWithMapTextures(new_tex_crop);

            var textures_jeep = new StarlingGameSpriteWithJeepTextures(this.new_tex_crop);

            var textures_hind       = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);
            var textures_tank       = new StarlingGameSpriteWithTankTextures(this.new_texsprite_crop);
            var textures_cannon     = new StarlingGameSpriteWithCannonTextures(this.new_tex_crop);
            var textures_bunker     = new StarlingGameSpriteWithBunkerTextures(this.new_tex_crop);
            var textures_rocket     = new StarlingGameSpriteWithRocketTextures(this.new_tex_crop);
            var textures_explosions = new StarlingGameSpriteWithMapExplosionsTextures(new_tex96);

            this.disablephysicsdiagnostics = true;

            this.onbeforefirstframe += (stage, s) =>
            {
                var explosins = new List <ExplosionInfo>();

                s.stage.color = 0xB27D51;

                // error JSC1000: ActionScript : failure at starling.display.Stage.add_keyUp : Object reference not set to an instance of an object.

                #region F2
                stage.keyUp +=
                    e =>
                {
                    if (e.keyCode == (uint)System.Windows.Forms.Keys.F2)
                    {
                        this.Content_layer2_shadows.visible =
                            !this.Content_layer2_shadows.visible;
                    }
                };
                #endregion

                #region F3
                stage.keyUp +=
                    e =>
                {
                    if (e.keyCode == (uint)System.Windows.Forms.Keys.F3)
                    {
                        this.Content_layer0_tracks.visible =
                            !this.Content_layer0_tracks.visible;
                    }
                };
                #endregion

                #region F1
                stage.keyUp +=
                    e =>
                {
                    if (e.keyCode == (uint)System.Windows.Forms.Keys.F1)
                    {
                        if (this.internalscale == 0.3)
                        {
                            this.internalscale = 0.05;
                        }
                        else
                        {
                            this.internalscale = 0.3;
                        }
                    }
                };
                #endregion

                var hud = new Image(textures_ped.hud_look()).AttachTo(this);

                #region hill1
                for (int i = 0; i < 32; i++)
                {
                    new Image(textures_map.hill1()).AttachTo(Content_layer0_ground).With(
                        hill =>
                    {
                        hill.x = 2048.Random();
                        hill.y = 2048.Random() - 1024;
                    }
                        );

                    new Image(textures_map.hole1()).AttachTo(Content_layer0_ground).With(
                        hill =>
                    {
                        hill.x = 2048.Random();
                        hill.y = 2048.Random() - 1024;
                    }
                        );

                    new Image(textures_map.grass1()).AttachTo(Content_layer0_ground).With(
                        hill =>
                    {
                        hill.x = 2048.Random();

                        var y  = -2048.Random() - 512 - 256;
                        hill.y = y;
                    }
                        );
                }
                #endregion

                for (int i = -12; i < 12; i++)
                {
                    new Image(textures_map.road0()).AttachTo(Content_layer0_ground).x = 256 * i;

                    if (i % 3 == 0)
                    {
                        var z = new PhysicalPed(textures_ped, this);

                        z.SetPositionAndAngle(16 * i, 0, random.NextDouble() * Math.PI);
                        z.BehaveLikeZombie();
                    }
                }

                var needdshop = true;

                #region other units
                for (int i = 3; i < 7; i++)
                {
                    {
                        new PhysicalCannon(textures_cannon, this).SetPositionAndAngle(
                            i * 16, -20, -random.NextDouble()
                            );

                        new PhysicalCannon(textures_cannon, this).SetPositionAndAngle(
                            i * 16, 36, random.NextDouble()
                            );
                    }


                    if (i % 3 == 0)
                    {
                        new PhysicalBunker(textures_bunker, this, IsShop: needdshop).SetPositionAndAngle(
                            i * 16, -8, random.NextDouble()
                            );
                        needdshop = false;

                        new PhysicalBunker(textures_bunker, this).SetPositionAndAngle(
                            i * 16, 24, random.NextDouble()
                            );


                        var ibunker = new PhysicalBunker(textures_bunker, this);

                        ibunker.SetPositionAndAngle(
                            i * 16, 64, random.NextDouble()
                            );

                        ibunker.visualshadow.Orphanize(); //.AttachTo(this.Content_layer10_hiddenforgoggles);
                        ibunker.visual.Orphanize().AttachTo(this.Content_layer10_hiddenforgoggles);
                    }
                    else if (i % 3 == 1)
                    {
                        new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(i * 16, -4 - 3);
                        new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(i * 16 + 2, -4);
                        new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(i * 16, -4 + 3);

                        new PhysicalWatertower(textures_bunker, this).SetPositionAndAngle(
                            i * 16, 16, random.NextDouble()
                            );

                        new PhysicalWatertower(textures_bunker, this).SetPositionAndAngle(
                            i * 16 - 4, 16 + 4, random.NextDouble()
                            );

                        new PhysicalWatertower(textures_bunker, this).SetPositionAndAngle(
                            i * 16 + 4, 16 + 4, random.NextDouble()
                            );
                    }
                    else
                    {
                        new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(i * 16, 24 - 3);
                        new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(i * 16 + 2, 24);
                        new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(i * 16, 24 + 3);

                        new PhysicalSilo(textures_bunker, this).SetPositionAndAngle(
                            i * 16, -4, random.NextDouble()
                            );
                    }
                }
                #endregion



                new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(12, 0);
                new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(12, -4);
                new PhysicalBarrel(textures_bunker, this).SetPositionAndAngle(12, -8);



                new Image(textures_map.touchdown()).AttachTo(Content_layer0_ground).MoveTo(256, -256);
                new Image(textures_map.touchdown()).AttachTo(Content_layer0_ground).y = 256;

                new PhysicalTank(textures_tank, this).SetPositionAndAngle(128 / 16, 128 * 3 / 16);

                new Image(textures_map.tree0_shadow()).AttachTo(Content).y = 128 + 16;
                new Image(textures_map.tree0()).AttachTo(Content).y        = 128;

                // can I have
                // new ped, hind, jeep, tank

                var egoped = new PhysicalPed(textures_ped, this)
                {
                    AttractZombies = true,
                };

                egoped.visual.StandWithVisibleGun = true;

                current = egoped;

                current.SetPositionAndAngle(
                    16.Random(),
                    16.Random(),

                    360.Random().DegreesToRadians()
                    );

                var jeep2 = new PhysicalJeep(textures_jeep, this);

                jeep2.SetPositionAndAngle(
                    16, 16, random.NextDouble()
                    );

                var jeep3 = new PhysicalJeep(textures_jeep, this);


                jeep3.visual0.shadow.Orphanize(); //.AttachTo(this.Content_layer10_hiddenforgoggles);
                jeep3.visual0.currentvisual.Orphanize().AttachTo(this.Content_layer10_hiddenforgoggles);

                jeep3.SetPositionAndAngle(
                    -16, 16, random.NextDouble()
                    );



                #region tree0
                for (int i = 0; i < 128; i++)
                {
                    {
                        var x = 2048.Random();
                        var y = -2048.Random() - 512 - 256;

                        new Image(textures_map.tree0_shadow()).AttachTo(Content_layer2_shadows).MoveTo(x + 16, y + 16);
                        new Image(textures_map.tree0()).AttachTo(Content).MoveTo(x, y);
                    }

                    {
                        var x = 2048.Random();
                        var y = 2048.Random() + 512 + 128;

                        new Image(textures_map.tree0_shadow()).AttachTo(Content_layer2_shadows).MoveTo(x + 16, y + 16);
                        new Image(textures_map.tree0()).AttachTo(Content).MoveTo(x, y);
                    }
                }
                #endregion

                // 12 = 34FPS

                //new PhysicalHind(textures_hind, this)
                new PhysicalHindWeaponized(textures_hind, textures_rocket, this)
                {
                    AutomaticTakeoff = true
                }.SetPositionAndAngle((128 + 256) / 16, -128 / 16);

                #region mouseWheel
                stage.mouseWheel += e =>
                {
                    e.preventDefault();

                    if (e.delta < 0)
                    {
                        this.internalscale -= 0.05;
                    }
                    if (e.delta > 0)
                    {
                        this.internalscale += 0.05;
                    }
                };
                #endregion


                #region __keyDown

                stage.keyDown +=
                    e =>
                {
                    e.preventDefault();

                    __keyDown.forcex = 1.0;
                    __keyDown.forcey = 1.0;

                    // 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 =>
                {
                    e.preventDefault();

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

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

                #endregion

                #region CreateExplosion
                this.CreateExplosion = (x, y) =>
                {
                    var size = 0.2 + 0.2 * random.NextDouble();

                    sb.snd_explosion_small.play(
                        sndTransform: new ScriptCoreLib.ActionScript.flash.media.SoundTransform(size)
                        );

                    var exp = new Image(textures_explosions.explosions[0]()).AttachTo(Content);
                    var cm  = new Matrix();

                    cm.translate(-32, -32);
                    cm.scale(10 * size, 10 * size);
                    cm.rotate(random.NextDouble() * Math.PI);

                    cm.translate(16 * x, 16 * y);

                    exp.transformationMatrix = cm;

                    explosins.Add(
                        new ExplosionInfo {
                        visual = exp
                    }
                        );
                };
                #endregion


                bool nightvision_changepending = false;
                bool entermode_changepending   = false;
                bool mode_changepending        = false;

                onframe +=
                    delegate
                {
                    //var v = current.body.GetLinearVelocity();

                    //Text = new { move_zoom, v.x, v.y }.ToString();

                    #region hud
                    {
                        var cm = new Matrix();

                        cm.scale(0.5, 0.5);
                        cm.translate(
                            16 + HudPadding,
                            stage.stageHeight - 64 - 24);

                        hud.transformationMatrix = cm;
                    }
                    #endregion
                };

                // ego + local environment
                #region Soundboard
                // http://www.nasa.gov/vision/universe/features/halloween_sounds.html

                sb.loopsand_run.MasterVolume = 0;
                sb.loopsand_run.Sound.play();

                sb.loophelicopter1.MasterVolume = 0;
                sb.loophelicopter1.Sound.play();

                sb.loopjeepengine.MasterVolume = 0;
                sb.loopjeepengine.Sound.play();

                sb.loopdiesel2.MasterVolume = 0;
                sb.loopdiesel2.Sound.play();

                sb.loopcrickets.MasterVolume = 0;
                sb.loopcrickets.Sound.play();

                sb.loopstrange1.MasterVolume = 0;
                sb.loopstrange1.Sound.play();

                sb.loop_GallinagoDelicata.MasterVolume = 0;
                sb.loop_GallinagoDelicata.Sound.play();

                var jeep_forceA      = 0.0;
                var ped_forceA       = 0.0;
                var pedzombie_forceA = 0.0;
                var barrel_forceA    = 0.0;

                var hardmetal_forceA = 0.0;

                this.oncollision +=
                    (u, force) =>
                {
                    if (u is PhysicalTank)
                    {
                        hardmetal_forceA = hardmetal_forceA.Max(force);
                    }
                    if (u is PhysicalSilo)
                    {
                        hardmetal_forceA = hardmetal_forceA.Max(force);
                    }
                    if (u is PhysicalBunker)
                    {
                        hardmetal_forceA = hardmetal_forceA.Max(force);
                    }
                    if (u is PhysicalWatertower)
                    {
                        hardmetal_forceA = hardmetal_forceA.Max(force);
                    }
                    if (u is PhysicalCannon)
                    {
                        hardmetal_forceA = hardmetal_forceA.Max(force);
                    }
                };

                PhysicalJeep.oncollision +=
                    (u, value) =>
                {
                    jeep_forceA = jeep_forceA.Max(value);
                };

                PhysicalPed.oncollision +=
                    (u, value) =>
                {
                    if (u.visual.WalkLikeZombie)
                    {
                        pedzombie_forceA = pedzombie_forceA.Max(value);
                    }
                    else
                    {
                        ped_forceA = ped_forceA.Max(value);
                    }
                };

                PhysicalBarrel.oncollision +=
                    (u, value) =>
                {
                    barrel_forceA = barrel_forceA.Max(value);
                };
                #endregion

                var nightvision_filter     = new ColorMatrixFilter();
                var nightvision_filter_age = new Stopwatch();
                nightvision_filter_age.Start();
                Action nighvision_handler = null;

                bool nightvision_mode = false;

                #region hud_update
                hud_update = delegate
                {
                    if (nightvision_mode)
                    {
                        hud.texture = textures_ped.hud_look_goggles();
                        return;
                    }

                    if (current is PhysicalPed)
                    {
                        hud.texture = textures_ped.hud_look();
                    }
                    else if (current == jeep3)
                    {
                        hud.texture = textures_ped.hud_look_onlygoggles();
                    }
                    else
                    {
                        if (current.body.GetType() == Box2D.Dynamics.b2Body.b2_dynamicBody)
                        {
                            hud.texture = textures_ped.hud_look_goggles();
                        }
                        else
                        {
                            hud.texture = textures_ped.hud_look_building();
                        }
                    }
                };
                #endregion



                #region nightvision_mode
                #region nightvision_on
                nightvision_on = delegate
                {
                    if (nightvision_mode)
                    {
                        return;
                    }

                    nightvision_mode = true;
                    hud_update();
                    nightvision_filter_age.Restart();
                    this.Content_layer10_hiddenforgoggles.visible = true;

                    sb.snd_nightvision.play(
                        sndTransform: new SoundTransform(
                            0.5
                            )
                        );


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

                        var a = (nightvision_filter_age.ElapsedMilliseconds / 1100.0).Min(1);

                        nightvision_filter.adjustContrast(

                            16 - 14 * a
                            );



                        //           V:\web\FlashHeatZeeker\TestDriversWithAudio\Library\StarlingGameSpriteWithTestDriversWithAudio___c__DisplayClass29___c__DisplayClass30.as(266): col: 28 Error: Implicit coercion of a value of type __AS3__.vec:Vector.<Object> to an unrelated type __AS3__.vec:Vector.<Number>.

                        //filter3.concat(vector_14);
                        //               ^

                        //  public function concat(matrix:Vector.<Number>):void
                        // public override void concat(Vector<object> matrix);

                        // X:\jsc.svn\examples\actionscript\test\TestVectorOfNumber\TestVectorOfNumber\ApplicationSprite.cs

#if FNGHTVISION
                        nightvision_filter.concat(
                            new double[] {
                            //new object[] {

                            0, 0, 0, 0, 0,
                            0, 1, 0, 0, 0,
                            0, 0, 0, 0, 0,
                            0, 0, 0, 1, 0
                        }
                            );
#endif



                        this.filter      = nightvision_filter;
                        this.stage.color = 0x006E00;

                        if (a == 1)
                        {
                            nighvision_handler = null;
                        }
                    };
                };
                #endregion

                #region nightvision_off
                nightvision_off = delegate
                {
                    if (!nightvision_mode)
                    {
                        return;
                    }

                    nightvision_mode = false;
                    hud_update();

                    this.Content_layer10_hiddenforgoggles.visible = false;

                    sb.snd_SelectWeapon.play(
                        sndTransform: new SoundTransform(
                            0.3
                            )
                        );

                    nightvision_filter_age.Restart();

                    nighvision_handler = delegate
                    {
                        nightvision_filter = new ColorMatrixFilter();



                        // nightvision_filter.adjustBrightness(

                        //    1 - (nightvision_filter_age.ElapsedMilliseconds / 200.0).Min(1)
                        //);

                        var a = (nightvision_filter_age.ElapsedMilliseconds / 500.0).Min(1);

                        nightvision_filter.adjustBrightness(

                            0.5 - 0.5 * a
                            );


                        this.filter      = nightvision_filter;
                        this.stage.color = 0xB27D51;

                        if (a == 1)
                        {
                            nighvision_handler = null;
                        }
                    };
                };
                #endregion


                onframe +=
                    delegate
                {
                    if (nighvision_handler != null)
                    {
                        nighvision_handler();
                    }
                };
                #endregion

                //(units.FirstOrDefault(k => k is PhysicalBunker) as PhysicalBunker).With(
                //    shop =>
                //    {
                //        shop.IsShop = true;
                //    }
                //);
                var mode_gun = false;

                onsyncframe +=
                    delegate
                {
                    while (Content_layer0_tracks.numChildren > 128)
                    {
                        Content_layer0_tracks.removeChildAt(0);
                    }

                    #region textures_explosions
                    foreach (var item in explosins.ToArray())
                    {
                        item.index++;

                        if (item.index == textures_explosions.explosions.Length)
                        {
                            item.visual.Orphanize();
                            explosins.Remove(item);
                        }
                        else
                        {
                            item.visual.texture = textures_explosions.explosions[item.index]();
                        }
                    }
                    #endregion

                    #region Soundboard
                    if (barrel_forceA > 0)
                    {
                        sb.snd_woodsmash.play(
                            sndTransform: new SoundTransform(
                                Math.Min(1.0, barrel_forceA / 30.0) * (0.15 + 0.15 * random.NextDouble())
                                )
                            );

                        barrel_forceA = 0;
                    }
                    else if (hardmetal_forceA > 0)
                    {
                        sb.snd_hardmetalsmash.play(
                            sndTransform: new SoundTransform(
                                Math.Min(1.0, hardmetal_forceA / 30.0) * (0.2 + 0.2 * random.NextDouble())
                                )
                            );

                        hardmetal_forceA = 0;
                    }
                    else if (jeep_forceA > 0)
                    {
                        sb.snd_metalsmash.play(
                            sndTransform: new SoundTransform(
                                Math.Min(1.0, jeep_forceA / 30.0) * (0.2 + 0.2 * random.NextDouble())
                                )
                            );

                        jeep_forceA = 0;
                    }
                    else if (ped_forceA > 0)
                    {
                        sb.snd_ped_hit.play(
                            sndTransform: new SoundTransform(
                                Math.Min(1.0, ped_forceA / 30.0) * (0.15 + 0.15 * random.NextDouble())
                                )
                            );

                        ped_forceA = 0;
                    }
                    else if (pedzombie_forceA > 0)
                    {
                        sb.snd_Argh.play(
                            sndTransform: new SoundTransform(
                                Math.Min(1.0, pedzombie_forceA / 30.0) * (0.15 + 0.15 * random.NextDouble())
                                )
                            );

                        pedzombie_forceA = 0;
                    }

                    if (this.syncframeid == 200)
                    {
                        sb.snd_whatsthatsound.play();
                    }

                    if (this.syncframeid == 400)
                    {
                        sb.snd_needweapon.play();
                    }

                    if (this.syncframeid == 800)
                    {
                        sb.snd_didyouhearthat.play();
                    }


                    if (this.syncframeid == 1200)
                    {
                        sb.snd_whatsthatsound.play();
                    }

                    sb.loopcrickets.MasterVolume           = (1 - move_zoom) * 0.09;
                    sb.loop_GallinagoDelicata.MasterVolume = (1 - move_zoom) * 0.3;

                    sb.loopstrange1.MasterVolume = (1 - move_zoom) * 0.04;

                    sb.loophelicopter1.MasterVolume = 0.0;
                    sb.loopjeepengine.MasterVolume  = 0.0;
                    sb.loopdiesel2.MasterVolume     = 0.0;
                    sb.loopsand_run.MasterVolume    = 0.0;


                    if (current is PhysicalPed)
                    {
                        sb.loopsand_run.MasterVolume = 0.5;
                        sb.loopsand_run.LeftVolume   = 0.0 + move_zoom * 0.9;
                        sb.loopsand_run.RightVolume  = 0.0 + move_zoom * 0.9;
                        sb.loopsand_run.Rate         = 0.9 + move_zoom * 0.1;
                    }
                    else if (current is PhysicalHind)
                    {
                        sb.loopcrickets.MasterVolume = 0;

                        sb.loophelicopter1.MasterVolume = 0.3 + (current as PhysicalHind).visual.Altitude * 0.2;
                        sb.loophelicopter1.LeftVolume   = 0.7 + move_zoom * 0.1;
                        sb.loophelicopter1.RightVolume  = 0.8;
                        sb.loophelicopter1.Rate         = 0.7 + (current as PhysicalHind).visual.Altitude * 0.25 + move_zoom * 0.05;
                    }
                    else if (current is PhysicalJeep)
                    {
                        sb.loopjeepengine.MasterVolume = 0.5;
                        sb.loopjeepengine.LeftVolume   = 0.4 + move_zoom * 0.7;
                        sb.loopjeepengine.RightVolume  = 1;
                        sb.loopjeepengine.Rate         = 0.9 + move_zoom * 0.5;
                    }
                    else if (current is PhysicalTank)
                    {
                        sb.loopcrickets.MasterVolume = 0;

                        sb.loopdiesel2.MasterVolume = 0.5;
                        sb.loopdiesel2.LeftVolume   = 0.3 + move_zoom * 0.7;
                        sb.loopdiesel2.RightVolume  = 1;
                        sb.loopdiesel2.Rate         = 0.9 + move_zoom;
                    }
                    else
                    {
                        sb.loopcrickets.MasterVolume           = 0.2;
                        sb.loop_GallinagoDelicata.MasterVolume = 0.2;
                    }

                    // stereoeffect // siren
                    sb.loopstrange1.LeftVolume  = 0.2 * (1 + Math.Cos(this.gametime.ElapsedMilliseconds * 0.00001)) / 2.0;
                    sb.loopstrange1.RightVolume = 0.4 * (1 + Math.Cos(this.gametime.ElapsedMilliseconds * 0.00001)) / 2.0;

                    sb.loopcrickets.LeftVolume = (1 + Math.Sin(
                                                      this.gametime.ElapsedMilliseconds * 0.0001
                                                      + this.current.CameraRotation
                                                      + this.current.body.GetAngle()
                                                      )) / 2.0;
                    sb.loopcrickets.RightVolume = (3 + Math.Cos(this.gametime.ElapsedMilliseconds * 0.001
                                                                + this.current.CameraRotation
                                                                + this.current.body.GetAngle()
                                                                )) / 4.0;

                    sb.loop_GallinagoDelicata.LeftVolume  = sb.loopcrickets.RightVolume;
                    sb.loop_GallinagoDelicata.RightVolume = sb.loopcrickets.LeftVolume;

                    #endregion

                    if (disable_enter_and_space)
                    {
                        // implemented elsewhere
                    }
                    else
                    {
                        #region Enter
                        if (!__keyDown[System.Windows.Forms.Keys.Enter])
                        {
                            // space is not down.
                            entermode_changepending = true;
                        }
                        else
                        {
                            if (entermode_changepending)
                            {
                                entermode_changepending = false;

                                // enter another vehicle?

                                var candidatedriver = current as PhysicalPed;
                                if (candidatedriver != null)
                                {
                                    var target =
                                        from candidatevehicle in units
                                        where candidatevehicle.driverseat != null

                                        // can enter if the seat is full.
                                        // unless we kick them out before ofcourse
                                        where candidatevehicle.driverseat.driver == null

                                        let distance = new __vec2(
                                            (float)(candidatedriver.body.GetPosition().x - candidatevehicle.body.GetPosition().x),
                                            (float)(candidatedriver.body.GetPosition().y - candidatevehicle.body.GetPosition().y)
                                            ).GetLength()

                                                       where distance < 6

                                                       orderby distance ascending
                                                       select new { candidatevehicle, distance };

                                    target.FirstOrDefault().With(
                                        x =>
                                    {
                                        Console.WriteLine(new { x.distance });

                                        //current.loc.visible = false;
                                        current.body.SetActive(false);


                                        x.candidatevehicle.driverseat.driver = candidatedriver;
                                        candidatedriver.seatedvehicle        = x.candidatevehicle;

                                        current = x.candidatevehicle;

                                        if (current is PhysicalJeep)
                                        {
                                            sb.snd_jeepengine_start.play();
                                        }

                                        else if (current is PhysicalBunker)
                                        {
                                            if ((current as PhysicalBunker).visual_shopoverlay.visible)
                                            {
                                                sb.snd_its_a_shop.play();
                                            }
                                            else
                                            {
                                                if (random.NextDouble() > 0.8)
                                                {
                                                    sb.haarp.play();
                                                }
                                                else
                                                {
                                                    if (random.NextDouble() > 0.5)
                                                    {
                                                        sb.snd_itsempty.play();
                                                    }
                                                    else
                                                    {
                                                        sb.snd_nothinghere.play();
                                                    }
                                                }
                                            }
                                        }
                                        else
                                        {
                                            sb.snd_dooropen.play(
                                                sndTransform: new SoundTransform(
                                                    0.3
                                                    )
                                                );
                                        }

                                        //if (current is PhysicalHind)
                                        //{
                                        //    nightvision_on();
                                        //}

                                        hud_update();


                                        //switchto(x.x);
                                        move_zoom = 1;

                                        // fast start
                                        //(current as PhysicalHind).With(
                                        //    hind => hind.VerticalVelocity = 1
                                        //);
                                    }
                                        );
                                }
                                else
                                {
                                    (current.driverseat.driver as PhysicalPed).With(
                                        driver =>
                                    {
                                        // get out of the lift..

                                        //nightvision_off();

                                        current.driverseat.driver = null;
                                        driver.seatedvehicle      = null;
                                        current.SetVelocityFromInput(new KeySample());

                                        // crashland?
                                        (current as PhysicalHind).With(
                                            hind =>
                                        {
                                            if (hind.visual.Altitude > 0)
                                            {
                                                hind.VerticalVelocity = -1;
                                                sb.snd_touchdown.play();
                                            }
                                        }

                                            );

                                        sb.snd_dooropen.play(
                                            sndTransform: new SoundTransform(
                                                0.3
                                                )
                                            );
                                        //if (current.body.GetType() != Box2D.Dynamics.b2Body.b2_dynamicBody)
                                        //{
                                        //    sb.snd_letsgo.play();
                                        //}

                                        current = driver;
                                        driver.body.SetActive(true);
                                        driver.body.SetAngularVelocity(-11);

                                        hud_update();
                                        move_zoom = 1;
                                    }
                                        );
                                }
                            }
                        }
                        #endregion


                        #region Space
                        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)
                                    {
                                        //nightvision_on();
                                        hind1.VerticalVelocity = 1.0;
                                    }
                                    else
                                    {
                                        //nightvision_off();

                                        hind1.VerticalVelocity = -0.4;

                                        sb.snd_touchdown.play();
                                    }
                                }
                                    );

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

                                        sb.snd_letsgo.play(
                                            sndTransform: new SoundTransform(
                                                0.3 * (0.15 + 0.15 * random.NextDouble())
                                                )
                                            );
                                    }
                                    else
                                    {
                                        physical0.visual.LayOnTheGround = true;

                                        sb.snd_ped_hit.play(
                                            sndTransform: new SoundTransform(
                                                0.3 * (0.15 + 0.15 * random.NextDouble())
                                                )
                                            );
                                    }
                                }
                                    );



                                mode_changepending = false;
                            }
                        }
                        #endregion
                    }


                    #region N
                    if (!__keyDown[System.Windows.Forms.Keys.N])
                    {
                        // space is not down.
                        nightvision_changepending = true;
                    }
                    else
                    {
                        if (nightvision_changepending)
                        {
                            if (nightvision_mode)
                            {
                                nightvision_off();
                            }
                            else
                            {
                                nightvision_on();
                            }



                            nightvision_changepending = false;
                        }
                    }
                    #endregion



                    current.SetVelocityFromInput(__keyDown);



                    #region simulate a weapone!
                    if (__keyDown[System.Windows.Forms.Keys.ControlKey])
                    {
                        if (syncframeid % 3 == 0)
                        {
                            (this.current as PhysicalHindWeaponized).With(
                                h =>
                            {
                                sb.snd_missleLaunch.play(
                                    sndTransform: new SoundTransform(0.5)
                                    );

                                h.FireRocket();
                            }
                                );
                        }
                    }
                    #endregion

                    #region simulate a weapone!
                    if (__keyDown[System.Windows.Forms.Keys.ControlKey])
                    {
                        mode_gun = true;
                    }
                    else
                    {
                        if (mode_gun)
                        {
                            mode_gun = false;

                            (this.current as PhysicalPed).With(
                                h =>
                            {
                                h.visual.StandWithVisibleGunFire.Restart();


                                sb.snd_shotgun3.play();

                                #region CreateBullet
                                Action <double> CreateBullet =
                                    a =>
                                {
                                    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 dx = Math.Cos(current.body.GetAngle() + current.CameraRotation + a);
                                    var dy = Math.Sin(current.body.GetAngle() + current.CameraRotation + a);

                                    var body = damage_b2world.CreateBody(bodyDef);
                                    body.SetPosition(
                                        new b2Vec2(
                                            current.body.GetPosition().x + dx * 0.3,
                                            current.body.GetPosition().y + dy * 0.3
                                            )
                                        );

                                    body.SetLinearVelocity(
                                        new b2Vec2(
                                            dx * 100,
                                            dy * 100
                                            )
                                        );

                                    var fixDef         = new Box2D.Dynamics.b2FixtureDef();
                                    fixDef.density     = 20;
                                    fixDef.friction    = 0.0;
                                    fixDef.restitution = 0;


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


                                    var fix = body.CreateFixture(fixDef);
                                };
                                #endregion

                                CreateBullet(-6.DegreesToRadians());
                                CreateBullet(-2.DegreesToRadians());
                                CreateBullet(2.DegreesToRadians());
                                CreateBullet(6.DegreesToRadians());
                            }
                                );
                        }
                    }
                    #endregion
                };
            };
        }