public void InitializeMapOnce()
		{
			// this should be a ctor instead?

			this.Map =
				new FlashTreasureHunt
				{
					ReadyWithLoadingCurrentLevel =
						delegate
						{
							//this.Map.WriteLine("ready for multiplayer map");

							FirstMapLoader.ContinueWhenDone(
								this.Map.ReadyWithLoadingCurrentLevelDirect
							);

							// if we are the host, we will have the primary map
						}
				};

			#region FirstMapLoader
			this.FirstMapLoader.SignalMissed +=
				delegate
				{
					this.Map.WriteLine("FirstMapLoader.SignalMissed - Noone sent us a map");
				};

			this.FirstMapLoader.SignalNotExpected +=
				delegate
				{
					this.Map.WriteLine("FirstMapLoader.SignalNotExpected - Already got it or it is too late");
				};

			this.FirstMapLoader.SignalWaisted +=
				delegate
				{
					this.Map.WriteLine("FirstMapLoader.SignalWaisted - We were really slow loading that map...");
				};

			this.FirstMapLoader.SignalWasExpected +=
				delegate
				{
					this.Map.WriteLine("FirstMapLoader.SignalWasExpected - we got map in time");
				};
			#endregion


			this.Map.AttachTo(Element);


		}
        public void InitializeMapOnce()
        {
            // this should be a ctor instead?

            this.Map = new FlashTreasureHunt();
            this.Map.ReadyWithLoadingCurrentLevel = this.ReadyWithLoadingCurrentLevel;
            this.Map.ReadyForNextLevel            = this.ReadyForNextLevel;
            this.Map.VirtualGetScoreValues        = GetScoreValues;



            #region FirstMapLoader
            this.FirstMapLoader.SignalMissed +=
                delegate
            {
                this.Map.WriteLine("FirstMapLoader.SignalMissed - Noone sent us a map");
            };

            this.FirstMapLoader.SignalNotExpected +=
                delegate
            {
                this.Map.WriteLine("FirstMapLoader.SignalNotExpected - Already got it or it is too late");
            };

            this.FirstMapLoader.SignalWaisted +=
                delegate
            {
                this.Map.WriteLine("FirstMapLoader.SignalWaisted - We were really slow loading that map...");
            };

            this.FirstMapLoader.SignalWasExpected +=
                delegate
            {
                this.Map.WriteLine("FirstMapLoader.SignalWasExpected - we got map in time");
            };
            #endregion



            // pass sync events from singleplayer to server

            this.Map.Sync_TakeGold +=
                index =>
            {
                this.LocalCoPlayer.Score += FlashTreasureHunt.ScoreForGold;
                this.Messages.TakeGold(index);
            };

            this.Map.Sync_GuardKilled +=
                DamageOwner =>
            {
                this.CoPlayers.Where(k => k.WeaponIdentity == DamageOwner).ForEach(k => k.Kills++);
            };

            this.Map.Sync_TakeAmmo   += this.Messages.TakeAmmo;
            this.Map.Sync_FireWeapon += this.Messages.FireWeapon;

            this.Map.Sync_GuardLookAt    += this.Messages.GuardLookAt;
            this.Map.Sync_GuardWalkTo    += GuardWalkTo;
            this.Map.Sync_GuardAddDamage +=
                (index, damage, DamageOwner) =>
            {
                if (DamageOwner != Map.EgoWeaponIdentity)
                {
                    return;
                }

                if (DisableGuardAddDamage)
                {
                    return;
                }

                //this.Map.WriteLine("sent GuardAddDamage " + new { index, damage });

                this.Messages.GuardAddDamage(index, damage);
            };


            this.Map.Sync_PortalUsed +=
                delegate
            {
                this.LocalCoPlayer.Teleports++;
            };

            var LevelFPS = 0;

            this.MapInitializedAndLoaded.ContinueWhenDone(
                delegate
            {
                this.Map.EgoView.FramesPerSecondChanged +=
                    delegate
                {
                    LevelFPS = (LevelFPS + this.Map.EgoView.FramesPerSecond) / 2;
                };

                this.Map.AddAmmoToEgoAndSwitchWeapon();
            }
                );

            this.Map.Sync_EnterEndLevelMode +=
                delegate
            {
                this.CoPlayers.ForEach(k => this.Map.EgoView.Sprites.Remove(k.Guard));

                FirstMapLoader.Wait(TimeoutAction.LongOperation);

                var LScoreForLevelEnding = 0;

                if (!DisableEnterEndLevelMode)
                {
                    LScoreForLevelEnding = 1;

                    this.LocalCoPlayer.Score += FlashTreasureHunt.ScoreForEndLevel;

                    this.Map.WriteLine("send EnterEndLevelMode");

                    this.Messages.EnterEndLevelMode();

                    UseOurMapForNextLevel();
                }


                this.Messages.ReportScore(LScoreForLevelEnding,
                                          this.LocalCoPlayer.Score,
                                          this.LocalCoPlayer.Kills,
                                          this.LocalCoPlayer.Teleports,

                                          LevelFPS
                                          );
            };

            this.Map.Sync_ExitEndLevelMode +=
                delegate
            {
                LevelFPS = 0;

                this.CoPlayers.ForEach(
                    k =>
                {
                    k.Score     = 0;
                    k.Kills     = 0;
                    k.Teleports = 0;
                });
            };
            this.Map.AttachTo(Element);
        }
		public void InitializeMapOnce()
		{
			// this should be a ctor instead?

			this.Map = new FlashTreasureHunt();
			this.Map.ReadyWithLoadingCurrentLevel = this.ReadyWithLoadingCurrentLevel;
			this.Map.ReadyForNextLevel = this.ReadyForNextLevel;
			this.Map.VirtualGetScoreValues = GetScoreValues;



			#region FirstMapLoader
			this.FirstMapLoader.SignalMissed +=
				delegate
				{
					this.Map.WriteLine("FirstMapLoader.SignalMissed - Noone sent us a map");
				};

			this.FirstMapLoader.SignalNotExpected +=
				delegate
				{
					this.Map.WriteLine("FirstMapLoader.SignalNotExpected - Already got it or it is too late");
				};

			this.FirstMapLoader.SignalWaisted +=
				delegate
				{
					this.Map.WriteLine("FirstMapLoader.SignalWaisted - We were really slow loading that map...");
				};

			this.FirstMapLoader.SignalWasExpected +=
				delegate
				{
					this.Map.WriteLine("FirstMapLoader.SignalWasExpected - we got map in time");
				};
			#endregion




			// pass sync events from singleplayer to server

			this.Map.Sync_TakeGold +=
				index =>
				{
					this.LocalCoPlayer.Score += FlashTreasureHunt.ScoreForGold;
					this.Messages.TakeGold(index);
				};

			this.Map.Sync_GuardKilled +=
				DamageOwner =>
				{
					this.CoPlayers.Where(k => k.WeaponIdentity == DamageOwner).ForEach(k => k.Kills++);

				};

			this.Map.Sync_TakeAmmo += this.Messages.TakeAmmo;
			this.Map.Sync_FireWeapon += this.Messages.FireWeapon;

			this.Map.Sync_GuardLookAt += this.Messages.GuardLookAt;
			this.Map.Sync_GuardWalkTo += GuardWalkTo;
			this.Map.Sync_GuardAddDamage +=
				(index, damage, DamageOwner) =>
				{
					if (DamageOwner != Map.EgoWeaponIdentity)
						return;

					if (DisableGuardAddDamage)
						return;

					//this.Map.WriteLine("sent GuardAddDamage " + new { index, damage });

					this.Messages.GuardAddDamage(index, damage);
				};


			this.Map.Sync_PortalUsed +=
				delegate
				{
					this.LocalCoPlayer.Teleports++;
				};

			var LevelFPS = 0;

			this.MapInitializedAndLoaded.ContinueWhenDone(
				delegate
				{
					this.Map.EgoView.FramesPerSecondChanged +=
						delegate
						{
							LevelFPS = (LevelFPS + this.Map.EgoView.FramesPerSecond) / 2;
						};

					this.Map.AddAmmoToEgoAndSwitchWeapon();
				}
			);
		
			this.Map.Sync_EnterEndLevelMode +=
				delegate
				{
					this.CoPlayers.ForEach(k => this.Map.EgoView.Sprites.Remove(k.Guard));

					FirstMapLoader.Wait(TimeoutAction.LongOperation);

					var LScoreForLevelEnding = 0;

					if (!DisableEnterEndLevelMode)
					{
						LScoreForLevelEnding = 1;

						this.LocalCoPlayer.Score += FlashTreasureHunt.ScoreForEndLevel;

						this.Map.WriteLine("send EnterEndLevelMode");

						this.Messages.EnterEndLevelMode();

						UseOurMapForNextLevel();

					}


					this.Messages.ReportScore(LScoreForLevelEnding,
						this.LocalCoPlayer.Score ,
						this.LocalCoPlayer.Kills ,
						this.LocalCoPlayer.Teleports,
						
						LevelFPS
					);


				};

			this.Map.Sync_ExitEndLevelMode +=
				delegate
				{
					LevelFPS = 0;

					this.CoPlayers.ForEach(
						k =>
						{
							k.Score = 0;
							k.Kills = 0;
							k.Teleports = 0;
						});
				};
			this.Map.AttachTo(Element);


		}
Esempio n. 4
0
            public static void Invoke(FlashTreasureHunt that, Texture64[] Hit, Texture64[] Death, SpriteInfoExtended s, double DamageToBeTaken, object DamageOwner)
            {
                // we have nothing to do here if we are dead
                if (s.Health < 0)
                {
                    return;
                }

                s.Health -= DamageToBeTaken;

                if (s.Health > 0)
                {
                    Assets.Default.Sounds.hit.play();

                    #region just show being hurt for a short moment
                    s.AIEnabled = false;

                    var q = s.Frames;
                    s.Frames = Hit;

                    300.AtDelayDo(
                        delegate
                    {
                        s.Frames    = q;
                        s.AIEnabled = true;
                    }
                        );
                    #endregion

                    // remove old blood which is too near
                    that.EmitBloodUnderSprite(s);
                }
                else
                {
                    if (that.Sync_GuardKilled != null)
                    {
                        that.Sync_GuardKilled(DamageOwner);
                    }

                    that.RemoveBloodUnderSprite(s);

                    Assets.Default.Sounds.death.play();

                    // player wont be blocked by a corpse
                    s.Range = 0;

                    // animate death
                    FrameRate_DeathAnimation.AtInterval(
                        ttt =>
                    {
                        if (Death.Length == ttt.currentCount)
                        {
                            ttt.stop();
                            return;
                        }

                        s.Frames = new[] { Death[ttt.currentCount] };
                    }
                        );
                }

                if (s.TakeDamageDone != null)
                {
                    s.TakeDamageDone(DamageToBeTaken, DamageOwner);
                }
            }
            public static void Invoke(FlashTreasureHunt that, Texture64[] Hit, Texture64[] Death, SpriteInfoExtended s, double DamageToBeTaken, object DamageOwner)
            {
                // we have nothing to do here if we are dead 
                if (s.Health < 0)
                    return;

                s.Health -= DamageToBeTaken;

                if (s.Health > 0)
                {
                    Assets.Default.Sounds.hit.play();

                    #region just show being hurt for a short moment
                    s.AIEnabled = false;

                    var q = s.Frames;
                    s.Frames = Hit;

                    300.AtDelayDo(
                        delegate
                        {
                            s.Frames = q;
                            s.AIEnabled = true;
                        }
                    );
                    #endregion

                    // remove old blood which is too near
                    that.EmitBloodUnderSprite(s);
                }
                else
                {
                    if (that.Sync_GuardKilled != null)
                        that.Sync_GuardKilled(DamageOwner);

                    that.RemoveBloodUnderSprite(s);

                    Assets.Default.Sounds.death.play();

                    // player wont be blocked by a corpse
                    s.Range = 0;

                    // animate death
                    FrameRate_DeathAnimation.AtInterval(
                        ttt =>
                        {
                            if (Death.Length == ttt.currentCount)
                            {
                                ttt.stop();
                                return;
                            }

                            s.Frames = new[] { Death[ttt.currentCount] };
                        }
                    );
                }

                if (s.TakeDamageDone != null)
                    s.TakeDamageDone(DamageToBeTaken, DamageOwner);
            }