示例#1
0
        private void OpenRemoteGame(RemoteGame remoteGame)
        {
            var formGameWindow = new FormGameWindow();
            var gameWindowGui  = formGameWindow.GetGameWindowGui();

            gameWindowGui.SetGameData(remoteGame);
            remoteGame.SetGameView(gameWindowGui);

            formGameWindow.ShowDialog();
        }
        public StarlingGameSpriteBeta2()
        {
            var textures_beta = new_tex96(new BetaBanner());

            //var textures_map = new StarlingGameSpriteWithMapTextures(new_tex_crop);

            //var textures_ped = new StarlingGameSpriteWithPedTextures(this.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_tex_crop);
            //var textures_cannon = new StarlingGameSpriteWithCannonTextures(this.new_tex_crop);
            //var textures_bunker = new StarlingGameSpriteWithBunkerTextures(this.new_tex_crop);

            this.disablephysicsdiagnostics = true;
            this.disable_enter_and_space   = true;

            this.onbeforefirstframe += (stage, s) =>
            {
                #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 :ego
                var ego = this.current as PhysicalPed;

                ego.Identity = sessionid + ":ego";

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

                current = ego;
                #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);

                    if (u == ego)
                    {
                        // discard, only we are allowed to move
                        // ourselves for now
                        return;
                    }

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

                    #region u PhysicalPed
                    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;
                        }
                    }
                    #endregion

                    if (u == ego)
                    {
                        // discard, only we are allowed to move
                        // ourselves for now
                        return;
                    }

                    // 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



                this.units.WithEachIndex(
                    (u, i) =>
                {
                    if (u.Identity == null)
                    {
                        u.Identity = "#" + i;
                    }
                }
                    );



                #region beta
                var beta = new Image(textures_beta()).AttachTo(this);

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

                        cm.translate(
                            stage.stageWidth - 96,
                            0);

                        beta.transformationMatrix = cm;
                    }
                    #endregion
                };
                #endregion


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

                                    __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;

                                    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();
                                            if (ShopEnter != null)
                                            {
                                                ShopEnter(candidatedriver);
                                            }
                                        }
                                        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());

                                    if (current is PhysicalBunker)
                                    {
                                        if ((current as PhysicalBunker).IsShop)
                                        {
                                            if (ShopExit != null)
                                            {
                                                ShopExit();
                                            }
                                        }
                                    }

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

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

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

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

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

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

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



                            mode_changepending = false;
                        }
                    }
                    #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);
                };
            };
        }
        public StarlingGameSpriteWithJeepSync()
        {
            this.autorotate = false;



            var textures_jeep = new StarlingGameSpriteWithJeepTextures(new_tex_crop);

            this.onbeforefirstframe += (stage, s) =>
            {
                #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



                var ego = new PhysicalJeep(textures_jeep, this)
                {
                    Identity = sessionid + ":ego"
                };

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


                current = ego;

                new PhysicalJeep(textures_jeep, this);
                new PhysicalJeep(textures_jeep, this);



                #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_SetVelocityFromInput
                __at_SetVelocityFromInput +=
                    (
                        string __egoid,
                        string __identity,
                        string __KeySample,
                        string __fixup_x,
                        string __fixup_y,
                        string __fixup_angle

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



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

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


                    // set the input!


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

                        fixup = true,

                        x     = double.Parse(__fixup_x),
                        y     = double.Parse(__fixup_y),
                        angle = double.Parse(__fixup_angle)
                    }
                        );
                };
                #endregion


                onsyncframe += delegate
                {
                    current.SetVelocityFromInput(__keyDown);

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

                        );


                    // tell others this sync frame ended for us
                    __raise_sync("" + sessionid);
                };
            };
        }
        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);
                };
            };
        }
示例#5
0
        public StarlingGameSpriteWithHindSync()
        {
            var textures_hind = new StarlingGameSpriteWithHindTextures(this.new_tex_crop);


            this.onbeforefirstframe += (stage, s) =>
            {
                #region __keyDown
                var __keyDown = new KeySample();

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

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

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

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

                #endregion



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

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

                current = ego;
                #endregion



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

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

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

                            // this
                            __syncframeid = this.syncframeid
                        };

                        others.Add(already_known_other);
                    }


                    return(already_known_other);
                };
                #endregion


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

                    var o = other(__egoid);

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

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

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

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


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

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



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

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


                    // set the input!


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

                        fixup = true,

                        x     = double.Parse(__fixup_x),
                        y     = double.Parse(__fixup_y),
                        angle = double.Parse(__fixup_angle)
                    }
                        );
                };
                #endregion



                bool mode_changepending = false;

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

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

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

                            //    }
                            //);



                            mode_changepending = false;
                        }
                    }
                    #endregion


                    current.SetVelocityFromInput(__keyDown);



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

                        );


                    // tell others this sync frame ended for us
                    __raise_sync("" + sessionid);
                };
            };
        }
示例#6
0
 private void Model_ServerGameStarted(object sender, EventArgs e)
 {
     this.Model.ServerGameStarted -= Model_ServerGameStarted;
     Game game = new RemoteGame(App.Context);
     App.Context.CurrentGame = game;
     game.PlayGame();
     App.RootFrame.Navigate(typeof(GamePage));
     game.ExitingGame += game_ExitingGame;
 }
        public StarlingGameSpriteWithPedSync()
        {
            var textures_ped = new StarlingGameSpriteWithPedTextures(new_tex_crop, new_texsprite_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

                // 32x32 = 15FPS?
                // 24x24 35?

                #region others
                for (int ix = 2; ix < 4; ix++)
                {
                    for (int iy = 2; iy < 4; iy++)
                    {
                        var p = new PhysicalPed(textures_ped, this);

                        p.SetPositionAndAngle(
                            8 * ix, 8 * iy
                            );
                    }
                }
                #endregion


                #region KeySample
                var __keyDown = new KeySample();

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

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

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

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

                #endregion

                #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_SetVelocityFromInput
                __at_SetVelocityFromInput +=
                    (
                        string __egoid,
                        string __identity,
                        string __KeySample,
                        string __fixup_x,
                        string __fixup_y,
                        string __fixup_angle

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



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

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


                    // set the input!


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

                        fixup = true,

                        x     = double.Parse(__fixup_x),
                        y     = double.Parse(__fixup_y),
                        angle = double.Parse(__fixup_angle)
                    }
                        );
                };
                #endregion


                bool mode_changepending = false;
                onsyncframe += delegate
                {
                    // sync me!

                    // tell others in the session about our game
                    // a beacon


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

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

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

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

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

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


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


                            var fix = body.CreateFixture(fixDef);

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


                    #region mode
                    if (!__keyDown[Keys.Space])
                    {
                        // space is not down.
                        mode_changepending = true;
                    }
                    else
                    {
                        if (mode_changepending)
                        {
                            if (ego.visual.LayOnTheGround)
                            {
                                ego.visual.LayOnTheGround = false;
                            }
                            else
                            {
                                ego.visual.LayOnTheGround = true;
                            }

                            mode_changepending = false;
                        }
                    }
                    #endregion



                    ego.SetVelocityFromInput(__keyDown);

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

                        );


                    // tell others this sync frame ended for us
                    __raise_sync("" + sessionid);
                };
            };
        }
示例#8
0
 private void OnRemoteGameStarting(RemoteGame remoteGame)
 {
     RemoteGame     = remoteGame;
     OpenGameWindow = true;
     _view.CloseLobby();
 }