public static void ToBitmapArray(this ZIPFile zip, Action<int, int> progress, Bitmap[] cache, Action<Bitmap[]> h)
		{
			if (cache == null)
				zip.ToBitmapArray(progress, h);
			else
				h(cache);
		}
		public static void ToBitmapArray(this ZIPFile zip, Bitmap[] cache, Action<Bitmap[]> h)
		{
			if (cache == null)
				zip.ToBitmapArray(h);
			else
				h(cache);
		}
		/// <summary>
		/// Default constructor
		/// </summary>
		public FlashPlasma()
		{

			this.InvokeWhenStageIsReady(
				delegate
				{
					Buffer = new BitmapData(DefaultWidth, DefaultHeight, false);
					var bitmap = new Bitmap(Buffer);
					addChild(bitmap);

					generatePlasma();

					RenderMode = 0;

					stage.click +=
						delegate
						{
							RenderMode++;
						};

					stage.enterFrame +=
						delegate
						{
							enterFrame2();
						};

					KnownEmbeddedResources.Default[KnownAssets.Path.Assets + "/jsc.png"].ToBitmapAsset().AttachTo(this).MoveTo(DefaultWidth - 128, DefaultHeight - 128);



				}
			);
		}
		public static void ToImages(this IEnumerable<MemoryStream> m, Action<int, int> progress, Action<Bitmap[]> h)
		{
			var a = m.ToArray();

			var n = new Bitmap[a.Length];

			var Next = default(Action<int>);

			Next =
				k => a[k].ToByteArray().LoadBytes<Bitmap>(
					u =>
					{
						n[k] = u;

						if (progress != null)
							progress(k, a.Length);

						if (k == 0)
							h(n);
						else
							Next(k - 1);
					}
				);

			Next(a.Length - 1);
		}
Exemplo n.º 5
0
        public static Texture32 Of(Bitmap bd, bool alpha)
        {
            var t = new Texture32
            {
                Bitmap = bd,
            };

            t.alpha = alpha;
            t.Update();

            return t;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Default constructor
        /// </summary>
        public RayCaster2()
        {
            stage.keyDown +=
                e =>
                {
                    var key = e.keyCode;

                    fKeyUp.ProcessKeyDown(key);
                    fKeyDown.ProcessKeyDown(key);
                    fKeyLeft.ProcessKeyDown(key);
                    fKeyRight.ProcessKeyDown(key);
                };

            stage.keyUp +=
                e =>
                {
                    var key = e.keyCode;

                    fKeyUp.ProcessKeyUp(key);
                    fKeyDown.ProcessKeyUp(key);
                    fKeyLeft.ProcessKeyUp(key);
                    fKeyRight.ProcessKeyUp(key);
                };


            createTables();

            var data = new BitmapData(DefaultWidth, DefaultHeight, false);
            var bitmap = new Bitmap(data);

            bitmap.scaleX = DefaultScale;
            bitmap.scaleY = DefaultScale;


            fOffscreenGraphics = data;
            bitmap.AttachTo(this);





            stage.enterFrame += e => run();
        }
        public ApplicationSprite()
        {
            // see also: http://zproxy.wordpress.com/2009/05/29/using-flint-particle-system-from-jsc/

            
            bitmap = new ActionScript.Images._184098();

            renderer = new DisplayObjectRenderer();
            renderer.camera.dolly(-400);
            renderer.camera.projectionDistance = 400;
            //renderer.y = 175;
            renderer.y = 0;
            renderer.x = 250;
            addChild(renderer);

            emitter = new Emitter3D();
            emitter.addAction(new Move());
            emitter.addAction(new DeathZone(new FrustrumZone(renderer.camera, new ScriptCoreLib.ActionScript.flash.geom.Rectangle(-2900, -2150, 5800, 4300)), true));
            emitter.position = new Vector3D(0, 0, 0, 1);

            var __JSC_should_detect_element_type_for_Vector_of_Particle = default(Particle);

            var particles = Particle3DUtils.createRectangleParticlesFromBitmapData(
                bitmap.bitmapData, 
                20, 
                emitter.particleFactory, 
                new Vector3D(-192, 127, 0)
            );

            emitter.addParticles(particles, false);

            renderer.addEmitter(emitter);
            emitter.start();

            stage.click += explode;

            var txt = new TextField();
            txt.text = "Click on the image";
            addChild(txt);

        }
		/// <summary>
		/// Default constructor
		/// </summary>
		public MandelbrotFlash()
		{
			this.InvokeWhenStageIsReady(
				delegate
				{
					var Buffer = new BitmapData(MandelbrotProvider.DefaultWidth, MandelbrotProvider.DefaultHeight, false);
					var bitmap = new Bitmap(Buffer);
					addChild(bitmap);

					MandelbrotProxy.InitializeMandelbrotProvider();

					var shift = 0;

					stage.enterFrame +=
						delegate
						{
							var ptr = MandelbrotProxy.DrawMandelbrotSet(shift);
							Buffer.@lock();

							MandelbrotProxy.Memory.position = ptr;
							Buffer.setPixels(Buffer.rect, MandelbrotProxy.Memory);
							Buffer.unlock();
							shift++;
						};

			
					
					//KnownEmbeddedResources.Default[KnownAssets.Path.Assets + "/jsc.png"].ToBitmapAsset().AttachTo(this).MoveTo(
					//    MandelbrotProvider.DefaultWidth - 128,
					//    MandelbrotProvider.DefaultHeight - 128);



				}
			);
		}
Exemplo n.º 9
0
		private void Initialize()
		{
			txtMain = new TextField
			{
				defaultTextFormat = new TextFormat
				{
					font = "Verdana",
					align = TextFormatAlign.LEFT,
					size = 10,
					color = 0xffffff
				},
				autoSize = TextFieldAutoSize.LEFT,
				text = "0"
			};

			AddFullscreenMenu();





			EgoView = new ViewEngineBase(DefaultWidth, DefaultHeight)
			{
				FloorAndCeilingVisible = false,

				ViewPosition = new Point { x = 4, y = 22 },
				ViewDirection = 90.DegreesToRadians(),

			};

			var Portals = new List<PortalInfo>();

			EgoView.ViewDirectionChanged += () => Portals.ForEach(Portal => Portal.View.ViewDirection = EgoView.ViewDirection);

			#region create a dual portal
			var PortalA = new PortalInfo
			{
				Color = 0xFF6A00,
				ViewVector = new Vector { Direction = EgoView.ViewDirection, Position = new Point { x = 4.5, y = 14 } },
				SpriteVector = new Vector { Direction = EgoView.ViewDirection, Position = new Point { x = 3.5, y = 20 } },
			}.AddTo(Portals);


			EgoView.Sprites.Add(PortalA.Sprite);


			var PortalB = new PortalInfo
			{
				Color = 0xff00,
				ViewVector = PortalA.SpriteVector,
				SpriteVector = PortalA.ViewVector,
			}.AddTo(Portals);


			EgoView.Sprites.Add(PortalB.Sprite);
			#endregion



			var Ego = default(SpriteInfo);


			EgoView.ViewPositionChanged +=
				delegate
				{
					foreach (var Portal in Portals)
					{
						var p = EgoView.SpritesFromPointOfView.SingleOrDefault(i => i.Sprite == Portal.Sprite);

						if (p != null)
						{
							if (p.Distance < Portal.Sprite.Range)
							{
								// we are going thro the portal, show it

								new Bitmap(EgoView.Buffer.clone())
								{
									scaleX = DefaultScale,
									scaleY = DefaultScale
								}.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);

								Assets.SoundFiles.teleport.ToSoundAsset().play();

								// fixme: should use Ego.MovementDirection instead
								// currently stepping backwards into the portal will behave recursivly
								EgoView.ViewPosition = Portal.View.ViewPosition.MoveToArc(EgoView.ViewDirection, Portal.Sprite.Range + p.Distance);

								break;
							}
						}
					}

				};

			var CameraView = new ViewEngineBase(64, 48)
			{
			};


			EgoView.RenderOverlay += DrawMinimap;
			EgoView.FramesPerSecondChanged += () => txtMain.text = EgoView.FramesPerSecond + " fps " + new { EgoView.ViewPositionX, EgoView.ViewPositionY };

			EgoView.Image.AttachTo(this);

			txtMain.AttachTo(this);



			EgoView.Image.scaleX = DefaultScale;
			EgoView.Image.scaleY = DefaultScale;
			//this.filters = new[] { new BlurFilter() };


			KeyboardButton fKeyTurnLeft = new uint[] { Keyboard.LEFT, 'j', 'J', };
			KeyboardButton fKeyTurnRight = new uint[] { Keyboard.RIGHT, 'l', 'L', };

			KeyboardButton fKeyStrafeLeft = new uint[] { 'a', 'A' };
			KeyboardButton fKeyStrafeRight = new uint[] { 'd', 'D' };

			KeyboardButton fKeyUp = new uint[] { Keyboard.UP, 'i', 'I', 'w', 'W' };
			KeyboardButton fKeyDown = new uint[] { Keyboard.DOWN, 'k', 'K', 's', 'S' };


			stage.keyDown +=
				e =>
				{
					var key = e.keyCode;

					fKeyStrafeLeft.ProcessKeyDown(key);
					fKeyStrafeRight.ProcessKeyDown(key);
					fKeyTurnLeft.ProcessKeyDown(key);
					fKeyTurnRight.ProcessKeyDown(key);

					fKeyUp.ProcessKeyDown(key);
					fKeyDown.ProcessKeyDown(key);


				};

			stage.keyUp +=
				e =>
				{
					var key = e.keyCode;


					fKeyStrafeLeft.ProcessKeyUp(key);
					fKeyStrafeRight.ProcessKeyUp(key);

					fKeyTurnLeft.ProcessKeyUp(key);
					fKeyTurnRight.ProcessKeyUp(key);

					fKeyUp.ProcessKeyUp(key);
					fKeyDown.ProcessKeyUp(key);

				};


			Action UpdateEgoPosition =
				delegate
				{
					if (Ego != null)
					{
						Ego.Position = EgoView.ViewPosition;
						Ego.Direction = EgoView.ViewDirection;
					}
				};

			EgoView.ViewPositionChanged +=
				delegate
				{
					UpdateEgoPosition();
				};

			(1000 / 30).AtInterval(
					delegate
					{
						if (fKeyTurnRight.IsPressed)
							EgoView.ViewDirection += 10.DegreesToRadians();
						else if (fKeyTurnLeft.IsPressed)
							EgoView.ViewDirection -= 10.DegreesToRadians();

						if (fKeyUp.IsPressed || fKeyStrafeLeft.IsPressed || fKeyStrafeRight.IsPressed)
						{
							var d = EgoView.ViewDirection;



							if (fKeyStrafeLeft.IsPressed)
								d -= 90.DegreesToRadians();
							else if (fKeyStrafeRight.IsPressed)
								d += 90.DegreesToRadians();


							EgoView.MoveTo(
									EgoView.ViewPositionX + Math.Cos(d) * 0.2,
									EgoView.ViewPositionY + Math.Sin(d) * 0.2
							);
						}
						else if (fKeyDown.IsPressed)
							EgoView.MoveTo(
								 EgoView.ViewPositionX + Math.Cos(EgoView.ViewDirection) * -0.2,
								 EgoView.ViewPositionY + Math.Sin(EgoView.ViewDirection) * -0.2
						 );


					}
			);

			var UpdatePortals = true;

			stage.keyUp +=
				   e =>
				   {
					   if (e.keyCode == Keyboard.V)
					   {
						   UpdatePortals = !UpdatePortals;
					   }

					   if (e.keyCode == Keyboard.N)
					   {
						   EgoView.RenderLowQualityWalls = !EgoView.RenderLowQualityWalls;
					   }

					   if (e.keyCode == Keyboard.M)
					   {
						   DrawMinimapEnabled = !DrawMinimapEnabled;
					   }

					   if (e.keyCode == Keyboard.B)
					   {
						   EgoView.SpritesVisible = !EgoView.SpritesVisible;
					   }

					   if (e.keyCode == Keyboard.F)
					   {
						   EgoView.FloorAndCeilingVisible = !EgoView.FloorAndCeilingVisible;
					   }

					   if (e.keyCode == Keyboard.DELETE)
					   {
						   EgoView.Sprites.RemoveAll(p => p != Ego);
					   }
				   };


			Action<Bitmap[]> BitmapsLoadedAction =
				Bitmaps =>
				{
					if (Bitmaps == null)
						throw new Exception("No bitmaps");

					Func<Texture64[], Texture64[]> Reorder8 =
						p =>
							Enumerable.ToArray(
								from i in Enumerable.Range(0, 8)
								select p[(i + 6) % 8]
							);

					var BitmapStream = Bitmaps.Select(i => (Texture64)i).GetEnumerator();

					Func<Texture64[]> Next8 =
						delegate
						{
							// keeping compiler happy with full delegate form

							if (BitmapStream == null)
								throw new Exception("BitmapStream is null");

							return Reorder8(BitmapStream.Take(8));
						};


					var Stand = Next8();
					var Spawn = default(Func<SpriteInfo>);

					if (Bitmaps.Length == 8)
					{
						Spawn = () => CreateWalkingDummy(Stand);
					}
					else
					{
						var Walk = new[]
                        {
                            Next8(),
                            Next8(),
                            Next8(),
                            Next8(),
                        };



						Spawn = () => CreateWalkingDummy(Stand, Walk);
					}

					Ego = Spawn();


					UpdateEgoPosition();



					stage.keyUp +=
						  e =>
						  {
							  if (e.keyCode == Keyboard.SPACE)
							  {
								  var s = Spawn();

								  //s.Direction += 180.DegreesToRadians();

								  CameraView.ViewPosition = s.Position;
								  CameraView.ViewDirection = s.Direction;
							  }

							  if (e.keyCode == Keyboard.INSERT)
							  {
								  var s = Spawn();

								  s.Direction += 180.DegreesToRadians();
								  s.Position = Ego.Position.MoveToArc(Ego.Direction, 0.5);
							  }

							  if (e.keyCode == Keyboard.ENTER)
							  {
								  EgoView.ViewPosition = new Point { x = 4, y = 22 };
								  EgoView.ViewDirection = 270.DegreesToRadians();


							  }



							  if (e.keyCode == Keyboard.BACKSPACE)
							  {

								  (1000 / 30).AtInterval(
									  t =>
									  {
										  EgoView.ViewDirection += 18.DegreesToRadians();

										  if (t.currentCount == 10)
											  t.stop();
									  }
								  );
							  }
						  };
				};


			Assets.ZipFiles.MyZipFile
				.ToFiles()
				.Where(f => f.FileName.EndsWith(".png"))
				.ToBitmapArray(BitmapsLoadedAction);



			Assets.ZipFiles.MyStuff.ToFiles().ToBitmapDictionary(
					f =>
					{
						// ! important
						// ----------------------------------------------------
						// ! loading png via bytes affects pixel values
						// ! this is why map is in gif format

						EgoView.Map.WorldMap = Texture32.Of(f["Map1.gif"], false);

						Action<IEnumerator<Texture64.Entry>, Texture64, Action<SpriteInfo>> AddSpriteByTexture =
								  (SpaceForStuff, tex, handler) => SpaceForStuff.Take().Do(p => CreateDummy(tex).Do(handler).Position.To(p.XIndex + 0.5, p.YIndex + 0.5));

						var FreeSpaceForStuff = EgoView.Map.WorldMap.Entries.Where(i => i.Value == 0).Randomize().GetEnumerator();

						Action<Bitmap> AddSprite =
							e => AddSpriteByTexture(FreeSpaceForStuff, e, null);

						Assets.ZipFiles.MySprites.ToFiles().ToBitmapArray(
						   sprites =>
						   {
							   foreach (var s in sprites)
							   {
								   for (int i = 0; i < 3; i++)
								   {
									   AddSprite(s);
								   }
							   }
						   }
						);
						#region gold

						Assets.ZipFiles.MyGold.ToFiles().ToBitmapArray(
						   sprites =>
						   {
							   var GoldSprites = new List<SpriteInfo>();

							   foreach (var s in sprites)
							   {
								   for (int i = 0; i < 20; i++)
								   {
									   // compiler bug: get a delegate to BCL class
									   //AddSpriteByTexture(FreeSpaceForStuff, s, GoldSprites.Add);

									   AddSpriteByTexture(FreeSpaceForStuff, s,
										   k =>
										   {
											   k.Range = 0.5;
											   GoldSprites.Add(k);
										   }
									   );

								   }
							   }

							   var LastPosition = new Point();

							   EgoView.ViewPositionChanged +=
								   delegate
								   {
									   // only check for items each 0.5 distance travelled
									   if ((EgoView.ViewPosition - LastPosition).length < 0.5)
										   return;

									   Action Later = delegate { };


									   foreach (var Item in EgoView.SpritesFromPointOfView)
									   {
										   var Item_Sprite = Item.Sprite;

										   if (Item.Distance < Item_Sprite.Range)
										   {
											   if (GoldSprites.Contains(Item_Sprite))
											   {
												   // ding-ding-ding!

												   new Bitmap(new BitmapData(DefaultWidth, DefaultHeight, false, 0xffff00))
												   {
													   scaleX = DefaultScale,
													   scaleY = DefaultScale
												   }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);

												   InternalGotGold();
												   Later += () => EgoView.Sprites.Remove(Item_Sprite);
											   }
										   }
									   }

									   Later();

									   LastPosition = EgoView.ViewPosition;
								   };


						   }
						);
						#endregion

						#region ammo

						Assets.ZipFiles.ammo.ToFiles().ToBitmapArray(
						   sprites =>
						   {
							   var AmmoSprites = new List<SpriteInfo>();

							   foreach (var s in sprites)
							   {
								   for (int i = 0; i < 20; i++)
								   {
									   // compiler bug: get a delegate to BCL class
									   //AddSpriteByTexture(FreeSpaceForStuff, s, GoldSprites.Add);

									   AddSpriteByTexture(FreeSpaceForStuff, s,
										   k =>
										   {
											   k.Range = 0.5;
											   AmmoSprites.Add(k);
										   }
									   );

								   }
							   }

							   var LastPosition = new Point();

							   EgoView.ViewPositionChanged +=
								   delegate
								   {
									   // only check for items each 0.5 distance travelled
									   if ((EgoView.ViewPosition - LastPosition).length < 0.5)
										   return;

									   Action Later = delegate { };


									   foreach (var Item in EgoView.SpritesFromPointOfView)
									   {
										   var Item_Sprite = Item.Sprite;

										   if (Item.Distance < Item_Sprite.Range)
										   {
											   if (AmmoSprites.Contains(Item_Sprite))
											   {
												   // ding-ding-ding!

												   new Bitmap(new BitmapData(DefaultWidth, DefaultHeight, false, 0x8080ff))
												   {
													   scaleX = DefaultScale,
													   scaleY = DefaultScale
												   }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);


												   InternalGotAmmo();
												   

												   Later += () => EgoView.Sprites.Remove(Item_Sprite);
											   }
										   }
									   }

									   Later();

									   LastPosition = EgoView.ViewPosition;
								   };


						   }
						);
						#endregion

						Func<string, Texture64> t =
							texname => f[texname + ".png"];

						EgoView.FloorTexture = t("floor");
						EgoView.CeilingTexture = t("roof");



						var DynamicTextureBitmap = new Bitmap(new BitmapData(Texture64.SizeConstant, Texture64.SizeConstant, false, 0));
						Texture64 DynamicTexture = DynamicTextureBitmap;
						uint DynamicTextureKey = 0xffffff;

						EgoView.Map.WorldMap[2, 22] = DynamicTextureKey;
						EgoView.Map.WorldMap[3, 15] = DynamicTextureKey;


						EgoView.Map.Textures = new Dictionary<uint, Texture64>
                        {
                            {0xff0000, t("graywall")},
                            {0x0000ff, t("bluewall")},
                            {0x00ff00, t("greenwall")},
                            {0x7F3300, t("woodwall")},

                            {DynamicTextureKey, DynamicTexture}
                        };


						if (EgoView.CurrentTile != 0)
							throw new Exception("bad start position: " + new { EgoView.ViewPositionX, EgoView.ViewPositionY, EgoView.CurrentTile }.ToString());



						CameraView.Map.WorldMap = EgoView.Map.WorldMap;
						CameraView.Map.Textures = EgoView.Map.Textures;
						CameraView.Sprites = EgoView.Sprites;
						CameraView.ViewPosition = EgoView.ViewPosition;

						foreach (var Portal in Portals)
						{
							Portal.View.Map.WorldMap = EgoView.Map.WorldMap;
							Portal.View.Map.Textures = EgoView.Map.Textures;
							Portal.View.Sprites = EgoView.Sprites;
							Portal.AlphaMask = f["portalmask.png"];
						}


						EgoView.RenderScene();


						var MirrorFrame = f["mirror.png"];
						var counter = 0;

						stage.enterFrame += e =>
						{
							counter++;

							if (UpdatePortals)
							{
								// updateing it too often causes framerate to drop

								foreach (var Portal in Portals)
								{
									Portal.Update();
								}

								DynamicTextureBitmap.bitmapData.fillRect(DynamicTextureBitmap.bitmapData.rect, (uint)(counter * 8 % 256));
								var m = new Matrix();

								// to center
								m.translate(0, 10);
								// m.scale(0.3, 0.3);

								CameraView.RenderScene();

								DynamicTextureBitmap.bitmapData.draw(CameraView.Image.bitmapData, m);
								DynamicTextureBitmap.bitmapData.draw(MirrorFrame.bitmapData);

								DynamicTexture.Update();
							}

							EgoView.RenderScene();
						};






					}
				);

			AttachMovementInput(EgoView);
		}
		private void LoadGuardTextures(Bitmap[] Bitmaps)
		{
			// wont load twice
			if (CachedGuardTextures != null)
				return;

			CachedGuardTextures = Bitmaps;

			var Spawn = default(Func<SpriteInfoExtended>);

			#region figure out
			if (Bitmaps == null)
				throw new Exception("No bitmaps");

			Func<Texture64[], Texture64[]> Reorder8 =
				p =>
					Enumerable.ToArray(
						from i in Enumerable.Range(0, 8)
						select p[(i + 6) % 8]
					);

			var BitmapStream = Bitmaps.Select(i => (Texture64)i).GetEnumerator();

			Func<Texture64[]> Next8 =
				delegate
				{
					// keeping compiler happy with full delegate form

					if (BitmapStream == null)
						throw new Exception("BitmapStream is null");

					return Reorder8(BitmapStream.Take(8));
				};


			var Stand = Next8();


			var Walk = new[]
							{
								Next8(),
								Next8(),
								Next8(),
								Next8(),
							};

			var Death = new List<Texture64>
							{
								BitmapStream.Take(),
								BitmapStream.Take(),
								BitmapStream.Take(),
								BitmapStream.Take(),
								BitmapStream.Take()
							};


			var Hit = new[] { BitmapStream.Take() };

			// funny ordering huh?
			Death.Add(BitmapStream.Take());


			var Shooting = new List<Texture64>
							{
								BitmapStream.Take(),
								BitmapStream.Take(),
								BitmapStream.Take()
							};

			Spawn = () => CreateWalkingDummy(Stand, Walk, Hit, Death.ToArray(), Shooting.ToArray());


			#endregion

			CreateGuard = Spawn;


			this.WriteLine("init: dude5");


			InitializeMap();
		}
		private void Initialize()
		{
			this.stage.fullScreenSourceRect = new Rectangle
			{
				width = DefaultControlWidth,
				height = DefaultControlHeight
			};

			#region fullscreen support
			bool NextFullscreenMode = true;

			this.stage.fullScreen +=
				e =>
				{
					NextFullscreenMode = !e.fullScreen;

					// hide chat while fullscreen zoom
					this.GetStageChild().Siblings().ForEach(k => k.visible = !e.fullScreen);
				};
			
		
			this.contextMenu = new ContextMenuEx
			{
				{ "Fullscreen", 
					delegate
					{
						this.stage.SetFullscreen(NextFullscreenMode);
					}
				}
			};
			#endregion



			this.music = Assets.Default.Music.music.play(0, 9999, new SoundTransform(0.5));




			EgoView = new ViewEngine(DefaultWidth, DefaultHeight)
			{
				FloorAndCeilingVisible = false,
				RenderLowQualityWalls = false,
				ViewDirection = 0,
				ViewPosition = new Point(0, 0)
			};

			EgoView.Image.scaleX = DefaultScale;
			EgoView.Image.scaleY = DefaultScale;
			EgoView.Image.alpha = 0;
			EgoView.Image.AttachTo(this);

			EgoView.ViewPositionChanged +=
				delegate
				{
					this.NextViewPosition = EgoView.ViewPosition;
				};

			EgoView.ViewDirectionChanged +=
				delegate
				{
					this.NextViewDirection = EgoView.ViewDirection;
				};
		
			EgoView.FramesPerSecondChanged +=
				delegate
				{
					if (EgoView.FramesPerSecond < 14)
						if (!EgoView.RenderLowQualityWalls)
							EgoView.RenderLowQualityWalls = true;

					if (EgoView.FramesPerSecond > 20)
						if (EgoView.RenderLowQualityWalls)
							EgoView.RenderLowQualityWalls = false;
				};


			this.HudContainer = new Sprite().AttachTo(this);
			this.HudContainer.alpha = 0;

			getpsyched = Assets.Default.getpsyched.AttachTo(this);

			getpsyched.scaleX = 2;
			getpsyched.scaleY = 2;
			getpsyched.MoveTo((DefaultControlWidth - getpsyched.width) / 2, (DefaultControlHeight - getpsyched.height) / 2);
			getpsyched.alpha = 0;

			InitializeWriteLine();

			this.WriteLine("init: getpsyched");

			//WriteLine("with minimap");


			getpsyched.FadeIn(
				delegate
				{
					Assets.Default.Sounds.gutentag.play();

					this.WriteLine("init: gutentag");

					var TryLoad = default(Action);

					TryLoad =
						delegate
						{
							Assets.Default.dude5.ToBitmapArray(
								CachedGuardTextures,
								Bitmaps =>
								{
									TryLoad = null;
									LoadGuardTextures(Bitmaps);
								}
							);
						};


					10000.AtDelayDo(
						delegate
						{
							if (TryLoad != null)
								TryLoad();
						}
					);

					TryLoad();

				}
			);

		}
		//bool DrawMinimapEnabled = true;


		private void DrawMinimap()
		{
			//if (!DrawMinimapEnabled)
			//    return;

			var EgoView = this;

			var _WallMap = EgoView.Map.WallMap;
			var posX = EgoView.ViewPositionX;
			var posY = EgoView.ViewPositionY;
			var rayDirLeft = EgoView.ViewDirectionLeftBorder;
			var rayDirRight = EgoView.ViewDirectionRightBorder;


			int isize = 3;

			var minimap = new BitmapData(isize * (_WallMap.Size + 2), isize * (_WallMap.Size + 2), true, 0x0);
			var minimap_bmp = new Bitmap(minimap);


			for (int ix = 0; ix < _WallMap.Size; ix++)
				for (int iy = 0; iy < _WallMap.Size; iy++)
				{
					if (_WallMap[ix, iy] == 0)
						minimap.fillRect(new Rectangle((ix + 1) * isize, (iy + 1) * isize, isize, isize), 0x4f00ff00);

				}

			//minimap.applyFilter(minimap, minimap.rect, new Point(), new GlowFilter(0x00ff00));


			minimap.drawLine(0xffffffff,
					(posX + 1) * isize,
					(posY + 1) * isize,
					(posX + 1 + Math.Cos(rayDirLeft) * isize) * isize,
					(posY + 1 + Math.Sin(rayDirLeft) * isize) * isize
					);

			minimap.drawLine(0xffffffff,
				(posX + 1) * isize,
				(posY + 1) * isize,
				(posX + 1 + Math.Cos(rayDirRight) * isize) * isize,
				(posY + 1 + Math.Sin(rayDirRight) * isize) * isize
				);

			//Console.WriteLine("left: " + rayDirLeft);
			//Console.WriteLine("right: " + rayDirLeft);

			foreach (var ss in EgoView.SpritesFromPointOfView)
			{
				uint color = 0xff00ff00;



				if (!ss.ViewInfo.IsInView)
					color = 0x9f008000;


				minimap.fillRect(new Rectangle(
						(ss.Sprite.Position.x + 0.5) * isize,
						(ss.Sprite.Position.y + 0.5) * isize,
						isize,
						isize), color);

				var _x = (ss.Sprite.Position.x + 1) * isize;
				var _y = (ss.Sprite.Position.y + 1) * isize;


				if (ss.Sprite.Frames.Length > 1)
					minimap.drawLine(
							0xffffffff,
							_x,
							_y,
							_x + Math.Cos(ss.Sprite.Direction) * isize,
							_y + Math.Sin(ss.Sprite.Direction) * isize
					);

			}

			minimap.fillRect(new Rectangle((posX + 0.5) * isize, (posY + 0.5) * isize, isize, isize), 0xffff0000);



			EgoView.Buffer.draw(minimap);
		}
		private void Initialize()
		{
			this.music = Assets.Default.Sounds.music.play(0, 9999);




			EgoView = new ViewEngine(DefaultWidth, DefaultHeight)
			{
				FloorAndCeilingVisible = false,
				RenderLowQualityWalls = false,
				ViewDirection = 0,
				ViewPosition = new Point()
			};

			EgoView.Image.scaleX = DefaultScale;
			EgoView.Image.scaleY = DefaultScale;
			EgoView.Image.alpha = 0;
			EgoView.Image.AttachTo(this);

			// show fps
			new TextField { textColor = 0xff0000, x = DefaultControlWidth / 2 }.AttachTo(this).Do(t => EgoView.FramesPerSecondChanged += () => t.text = "fps: " + EgoView.FramesPerSecond);

			EgoView.FramesPerSecondChanged +=
				delegate
				{
					if (EgoView.FramesPerSecond < 14)
						if (!EgoView.RenderLowQualityWalls)
							EgoView.RenderLowQualityWalls = true;

					if (EgoView.FramesPerSecond > 22)
						if (EgoView.RenderLowQualityWalls)
							EgoView.RenderLowQualityWalls = false;
				};


			this.HudContainer = new Sprite().AttachTo(this);
			this.HudContainer.alpha = 0;

			getpsyched = Assets.Default.getpsyched.AttachTo(this);

			getpsyched.scaleX = 2;
			getpsyched.scaleY = 2;
			getpsyched.MoveTo((DefaultControlWidth - getpsyched.width) / 2, (DefaultControlHeight - getpsyched.height) / 2);
			getpsyched.alpha = 0;

			InitializeWriteLine();

			getpsyched.FadeIn(
				delegate
				{
					Assets.Default.Sounds.gutentag.play();


					Assets.Default.dude5.ToBitmapArray(
						Bitmaps =>
						{
							var Spawn = default(Func<SpriteInfoExtended>);

							#region figure out
							if (Bitmaps == null)
								throw new Exception("No bitmaps");

							Func<Texture64[], Texture64[]> Reorder8 =
								p =>
									Enumerable.ToArray(
										from i in Enumerable.Range(0, 8)
										select p[(i + 6) % 8]
									);

							var BitmapStream = Bitmaps.Select(i => (Texture64)i).GetEnumerator();

							Func<Texture64[]> Next8 =
								delegate
								{
									// keeping compiler happy with full delegate form

									if (BitmapStream == null)
										throw new Exception("BitmapStream is null");

									return Reorder8(BitmapStream.Take(8));
								};


							var Stand = Next8();


							//if (Bitmaps.Length == 8)
							//{
							//    Spawn = () => CreateWalkingDummy(Stand);
							//}
							//else
							//{
							var Walk = new[]
							{
								Next8(),
								Next8(),
								Next8(),
								Next8(),
							};

							var Death = new List<Texture64>
							{
								BitmapStream.Take(),
								BitmapStream.Take(),
								BitmapStream.Take(),
								BitmapStream.Take(),
								BitmapStream.Take()
							};


							var Hit = new[] { BitmapStream.Take() };

							// funny ordering huh?
							Death.Add(BitmapStream.Take());

							Spawn = () => CreateWalkingDummy(Stand, Walk, Hit, Death.ToArray());

							//}

							#endregion

							CreateGuard = Spawn;




							InitializeMap();


						}
					);
				}
			);

		}
		private void InitializeMap()
		{
			#region fill map
			Assets.Default.stuff.ToBitmapDictionary(
				f =>
				{
					this.WriteLine("init: stuff");

					StuffDictionary = f;


					CreateMapFromMaze();




					Func<string, Texture64> t =
						texname => f[texname + ".png"];

					Func<string, string, Texture64> mix =
						(a, b) =>
						{
							var ia = f[a + ".png"];
							var ib = f[b + ".png"];

							var u = new Bitmap(ia.bitmapData.clone());



							u.bitmapData.draw(ib);
							return u;
						};



					#region game goal
					TheGoldStack = CreateDummy(f["life.png"]);

					TheGoldStack.RemoveFrom(EgoView.Sprites);

					WaitForCollectingHalfTheTreasureToRevealEndGoal();

					TheGoldStack.Position.To(maze.Width - 1.25, maze.Height - 1.25);
					TheGoldStack.Range = 0.6;
					TheGoldStack.ItemTaken +=
						delegate
						{
							if (EndLevelMode)
								return;

							if (HalfOfTheTreasureCollected != null)
							{
								throw new Exception("should not reach here");
							}

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


							// show stats
							this.WriteLine("TheGoldStack -> EnterEndLevelMode");
							EnterEndLevelMode();
						};
					GoldSprites.Add(TheGoldStack);


					#endregion


					EgoView.Map.Textures = new Dictionary<uint, Texture64>
                        {
                            {graywall_achtung, mix("graywall", "achtung")},
                            {graywall_verboten, mix("graywall", "verboten")},
                            {graywall, t("graywall")},


							{woodwall_achtung, mix("woodwall", "achtung")},
                            {woodwall_verboten, mix("woodwall", "verboten")},
                            {woodwall, t("woodwall")},
                            {woodwall_books, t("woodwall_books")},


                            {bluewall, t("bluewall")},
                            {greenwall, t("greenwall")},
                        };

					// EgoView.RenderScene();

					InitializeWeaponOverlay(f);

					#region heads

					Assets.Default.head.Items.OrderBy(k => k.FileName).Select(k => k.Data).ToImages(
						heads =>
						{
							var head = default(Bitmap);

							1000.AtInterval(
								tt =>
								{
									if (head != null)
										head.Orphanize();

									if (heads.Length > 0)
									{
										if (GoldTakenCounter > 0)
										{
											GoldTakenCounter--;
											head = heads.Last();
										}
										else
											head = heads.AtModulus(tt.currentCount % 3);

										head.filters = new[] { new DropShadowFilter() };
										head.scaleX = 2;
										head.scaleY = 2;
										head.MoveTo(4, DefaultControlHeight - head.height - 4).AttachTo(HudContainer);
									}
								}
							);
						}
					);


					#endregion

					InitializeCompass();
					InitializeKeyboard();



					AttachMovementInput(EgoView, true, false);

					#region focus logic
					this.focusIn +=
						e =>
						{
							this.MovementEnabled_IsFocused = true;
							//WriteLine("focusIn");

							//if (this.MovementEnabled_IsAlive)
							//    this.filters = null;

						};

					this.focusOut +=
						delegate
						{
							this.MovementEnabled_IsFocused = false;

							//if (this.MovementEnabled_IsAlive)
							//    this.filters = new[] { Filters.GrayScaleFilter };
							//WriteLine("focusOut");
						};


					this.focusRect = null;
					this.mouseChildren = false;
					this.tabEnabled = true;
					#endregion

					//this.stage.focus = this;

					ResetEgoPosition();

					AddPortals();

					AddIngameEntities(
						delegate
						{
							this.WriteLine("init: AddIngameEntities done");


							stage.enterFrame +=
								e =>
								{
									ApplyNextViewVector();

									if (EgoView.Image.alpha > 0)
										EgoView.RenderScene();
								};

							this.WriteLine("init: AddIngameEntities + ReadyWithLoadingCurrentLevel");

							this.ReadyWithLoadingCurrentLevel();
						}
					);
				}
			);
			#endregion
		}
		private void InitializeMap()
		{
			#region fill map
			Assets.Default.stuff.ToBitmapDictionary(
				f =>
				{
					StuffDictionary = f;


					CreateMapFromMaze();


					

					Func<string, Texture64> t =
						texname => f[texname + ".png"];

					Func<string, string, Texture64> mix =
						(a, b) =>
						{
							var ia = f[a + ".png"];
							var ib = f[b + ".png"];

							var u = new Bitmap(ia.bitmapData.clone());



							u.bitmapData.draw(ib);
							return u;
						};



					#region game goal
					TheGoldStack = CreateDummy(f["life.png"]);
					
					TheGoldStack.RemoveFrom(EgoView.Sprites);

					WaitForCollectingHalfTheTreasureToRevealEndGoal();

					TheGoldStack.Position.To(maze.Width - 1.5, maze.Height - 1.5);
					TheGoldStack.Range = 0.5;
					TheGoldStack.ItemTaken +=
						delegate
						{
							if (EndLevelMode)
								return;

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


							// show stats

							EnterEndLevelMode();
						};
					GoldSprites.Add(TheGoldStack);


					#endregion


					EgoView.Map.Textures = new Dictionary<uint, Texture64>
                        {
                            {graywall_achtung, mix("graywall", "achtung")},
                            {graywall_verboten, mix("graywall", "verboten")},
                            {graywall, t("graywall")},


							{woodwall_achtung, mix("woodwall", "achtung")},
                            {woodwall_verboten, mix("woodwall", "verboten")},
                            {woodwall, t("woodwall")},
                            {woodwall_books, t("woodwall_books")},


                            {bluewall, t("bluewall")},
                            {greenwall, t("greenwall")},
                        };

					// EgoView.RenderScene();

					InitializeWeaponOverlay(f);

					#region heads

					Assets.Default.head.Items.OrderBy(k => k.FileName).Select(k => k.Data).ToImages(
						heads =>
						{
							var head = default(Bitmap);

							1000.AtInterval(
								tt =>
								{
									if (head != null)
										head.Orphanize();

									if (heads.Length > 0)
									{
										if (GoldTakenCounter > 0)
										{
											GoldTakenCounter--;
											head = heads.Last();
										}
										else
											head = heads.AtModulus(tt.currentCount % 3);

										head.filters = new[] { new DropShadowFilter() };
										head.scaleX = 2;
										head.scaleY = 2;
										head.MoveTo(4, DefaultControlHeight - head.height - 4).AttachTo(HudContainer);
									}
								}
							);
						}
					);


					#endregion

					InitializeCompass();
					InitializeKeyboard();
					
					AddIngameEntities();

					AttachMovementInput(EgoView, true, false);


					ResetEgoPosition();

					AddPortals();

				

					getpsyched.FadeOut(
						delegate
						{
							stage.enterFrame +=
								e =>
								{
							
									EgoView.RenderScene();
								};

							this.EgoView.Image.FadeIn(
								delegate
								{
									1500.AtDelayDo(
										delegate
										{
											this.HudContainer.FadeIn();
										}
									);
								}
							);

						}

					);

				
				}
			);
			#endregion
		}
Exemplo n.º 16
0
        public Actor(Bitmap[] frames, Bitmap corpse, Bitmap blood, Sound death)
        {
            this._frames = frames;
            this._corpse = corpse;
            this._blood = blood;

            this.mouseEnabled = false;

            PlayDeathSound = death.ToAction();




            Kill = delegate
            {

                IsAlive = false;
                PlayDeathSound();

                foreach (var v in frames)
                    v.Orphanize();

                #region corpse
                if (corpse != null)
                {
                    corpse.MoveToCenter().AttachTo(this);

                    (10000 + 10000.FixedRandom()).AtDelay(
                        delegate
                        {
                            if (IsAlive)
                                return;

                            corpse.Orphanize();


                            blood.x = -blood.width / 2;
                            blood.y = -blood.height / 2;
                            blood.AttachTo(this);


                            ((20000 + 10000.FixedRandom())).AtDelay(
                               delegate
                               {
                                   if (IsAlive)
                                       return;

                                   blood.Orphanize();

                                   IsCorpseAndBloodGone = true;

                                   if (CorpseAndBloodGone != null)
                                       CorpseAndBloodGone();

                               }
                           );

                            IsCorpseGone = true;

                            if (CorpseGone != null)
                                CorpseGone();
                        }
                    );
                }
                #endregion



                if (Die != null)
                    Die();
            };

            //this.Moved +=
            //    delegate
            //    {



            RunAnimationTimer = (1000 / 15).AtInterval(
                 t =>
                 {
                     if (!IsAlive)
                     {
                         t.stop();
                         return;
                     }

                     if (!RunAnimation)
                         return;


                     ShowFrame(t.currentCount);
                 }
             );

            ShowFrame(0);

       
        }
		//bool DrawMinimapEnabled = true;


		private void DrawMinimap()
		{
			//if (!DrawMinimapEnabled)
			//    return;

			var EgoView = this;

			var _WallMap = EgoView.Map.WallMap;
			var posX = EgoView.ViewPositionX;
			var posY = EgoView.ViewPositionY;
			var rayDirLeft = EgoView.ViewDirectionLeftBorder;
			var rayDirRight = EgoView.ViewDirectionRightBorder;


			int isize = 3;

			var minimap = new BitmapData(isize * (_WallMap.Size + 2), isize * (_WallMap.Size + 2), true, 0x0);
			var minimap_bmp = new Bitmap(minimap);


			for (int ix = 0; ix < _WallMap.Size; ix++)
				for (int iy = 0; iy < _WallMap.Size; iy++)
				{
					if (_WallMap[ix, iy] == 0)
						minimap.fillRect(new Rectangle((ix + 1) * isize, (iy + 1) * isize, isize, isize), 0x4f00ff00);

				}

			//minimap.applyFilter(minimap, minimap.rect, new Point(), new GlowFilter(0x00ff00));

			//Console.WriteLine("left: " + rayDirLeft);
			//Console.WriteLine("right: " + rayDirLeft);

			Func<SpriteInfoFromPOV, int> Predicate =
				p =>
				{
					var extended = p.Sprite as SpriteInfoExtended;

					if (extended == null)
						return SpriteInfoExtended.MinimapZIndex_Default;

					return extended.MinimapZIndex;
				};

			foreach (var _ss in EgoView.SpritesFromPointOfView.OrderBy(Predicate))
			{
				var ss = _ss;

				uint color = 0x9f008000;



				var extended = _ss.Sprite as SpriteInfoExtended;

				if (extended != null)
				{
					color = extended.MinimapInactiveColor;

					if (ss.LastRenderedClip != null)
						if (ss.LastRenderedClip.width > 0)
							color = extended.MinimapColor;
				}


				minimap.fillRect(new Rectangle(
						(ss.Sprite.Position.x + 0.5) * isize,
						(ss.Sprite.Position.y + 0.5) * isize,
						isize,
						isize), color);

				var _x = (ss.Sprite.Position.x + 1) * isize;
				var _y = (ss.Sprite.Position.y + 1) * isize;



			}

			minimap.drawLine(0xffffffff,
				(posX + 1) * isize,
				(posY + 1) * isize,
				(posX + 1 + Math.Cos(rayDirLeft) * isize) * isize,
				(posY + 1 + Math.Sin(rayDirLeft) * isize) * isize
				);

			minimap.drawLine(0xffffffff,
				(posX + 1) * isize,
				(posY + 1) * isize,
				(posX + 1 + Math.Cos(rayDirRight) * isize) * isize,
				(posY + 1 + Math.Sin(rayDirRight) * isize) * isize
				);


			minimap.fillRect(new Rectangle((posX + 0.5) * isize, (posY + 0.5) * isize, isize, isize), 0xffff0000);



			EgoView.Buffer.draw(minimap);
		}
Exemplo n.º 18
0
        protected void prepare()
        {
            stage.align = StageAlign.TOP_LEFT;
            //stage.quality 	= StageQuality.LOW;

            txtMain = new TextField();
            tfNormal = new TextFormat();
            tfNormal.font = "Verdana";
            tfNormal.align = TextFormatAlign.LEFT;
            tfNormal.size = 10;
            tfNormal.color = 0xffffff;
            txtMain.defaultTextFormat = tfNormal;
            txtMain.autoSize = "left";
            txtMain.appendText("0");

            moveSpeed = 0.2;
            rotSpeed = 0.12;
            texWidth = 256;
            texHeight = 256;
            posX = 22;
            posY = 11.5;
            dirX = -1;
            dirY = 0;
            planeX = 0;
            planeY = 0.66;
            w = 320;
            h = 240;
            time = getTimer();
            setWorldMap();

            //floorVals = new[] {
            //    80,40,26.6666666666667,20,16,13.3333333333333,11.4285714285714,10,8.88888888888889,8,7.27272727272727,6.66666666666667,6.15384615384615,5.71428571428571,5.33333333333333,5,4.70588235294118,4.44444444444444,4.21052631578947,4,3.80952380952381,3.63636363636364,3.47826086956522,3.33333333333333,3.2,3.07692307692308,2.96296296296296,2.85714285714286,2.75862068965517,2.66666666666667,2.58064516129032,2.5,2.42424242424242,2.35294117647059,2.28571428571429,2.22222222222222,2.16216216216216,2.10526315789474,2.05128205128205,2,
            //1.95121951219512,1.9047619047619,1.86046511627907,1.81818181818182,1.77777777777778,1.73913043478261,1.70212765957447,1.66666666666667,1.63265306122449,1.6,1.56862745098039,1.53846153846154,1.50943396226415,1.48148148148148,1.45454545454545,1.42857142857143,1.40350877192982,1.37931034482759,1.35593220338983,1.33333333333333,1.31147540983607,1.29032258064516,1.26984126984127,1.25,1.23076923076923,1.21212121212121,1.19402985074627,1.17647058823529,1.15942028985507,1.14285714285714,1.12676056338028,1.11111111111111,1.0958904109589,1.08108108108108,1.06666666666667,1.05263157894737,1.03896103896104,1.02564102564103,1.0126582278481 };

            time = getTimer();
            counter = 0;

            ZBuffer = new double[0];

            screen = new BitmapData(w, h, false, 0x0);
            screenImage = new Bitmap();
            screenImage.bitmapData = screen;

            addChild(screenImage);
            addChild(txtMain);

            this.enterFrame += render;

            //addEventListener(Event.ENTER_FRAME, render);

        }
		private void InitializeMap()
		{
			#region fill map
			Assets.Default.stuff.ToBitmapDictionary(
				f =>
				{
					const uint graywall = 0xff0000;
					const uint graywall_achtung = 0xff0001;
					const uint graywall_verboten = 0xff0002;

					const uint woodwall = 0x7F3300;
					const uint woodwall_books = 0x7F33F0;
					const uint woodwall_achtung = 0x7F3301;
					const uint woodwall_verboten = 0x7F3302;


					const uint bluewall = 0x0000ff;
					const uint greenwall = 0x00ff00;

					var Map = new Texture32();


					#region safe map
					for (int i = 0; i < 32; i++)
						for (int j = 0; j < 32; j++)
						{
							Map[i, j] = bluewall;
						}
					#endregion

					maze = new BlockMaze(new MazeGenerator(MazeSize, MazeSize, null));

					#region write walls to map
					var wall_counter = 0;

					for (int x = 1; x < maze.Width - 1; x++)
						for (int y = 1; y < maze.Height - 1; y++)
						{
							if (maze.Walls[x][y])
							{
								wall_counter++;

								var variant = graywall;

								if (y > maze.Height / 2)
								{
									variant = woodwall;

									if (wall_counter % 7 == 0)
										variant = woodwall_books;
									if (wall_counter % 11 == 0)
										variant = woodwall_achtung;
									else if (wall_counter % 13 == 0)
										variant = woodwall_verboten;
								}
								else
								{
									variant = graywall;

									if (wall_counter % 8 == 0)
										variant = graywall_achtung;
									else if (wall_counter % 9 == 0)
										variant = graywall_verboten;

								}

								Map[x, y] = variant;

							}
							else
								Map[x, y] = 0;
						}
					#endregion


					#region maze is smaller than 31
					for (int x = 1; x < maze.Width - 1; x++)
					{
						Map[x, maze.Height - 1] = greenwall;
					}

					for (int y = 1; y < maze.Height - 1; y++)
					{
						Map[maze.Width - 1, y] = greenwall;
					}
					#endregion


					EgoView.Map.WorldMap = Map;


					Action<IEnumerator<Texture64.Entry>, Texture64, Action<SpriteInfoExtended>> AddSpriteByTexture =
							  (SpaceForStuff, tex, handler) =>
							  {
								  var p = SpaceForStuff.TakeOrDefault();

								  if (p == null)
									  return;

								  CreateDummy(tex).Do(handler).Position.To(p.XIndex + 0.5, p.YIndex + 0.5);

							  };



					var FreeSpaceForStuff = EgoView.Map.WorldMap.Entries.Where(i => i.Value == 0).Randomize().GetEnumerator();

					CreateGuards(FreeSpaceForStuff);


					var GoldTakenCounter = 0;

					#region gold

					var GoldSprites = new List<SpriteInfo>();

					#region nonblock
					Action AddNonBlockingItems =
						delegate
						{



							Assets.Default.nonblock.ToBitmapArray(
								sprites =>
								{
									for (int i = 0; i < 7; i++)
										foreach (var s in sprites)
										{
											// compiler bug: get a delegate to BCL class
											//AddSpriteByTexture(FreeSpaceForStuff, s, GoldSprites.Add);

											AddSpriteByTexture(FreeSpaceForStuff, s,
												k =>
												{
													k.Range = 0.5;
													//GoldSprites.Add(k);
												}
											);

										}
								}
							);


						};
					#endregion

					Assets.Default.gold.ToBitmapArray(
					   sprites =>
					   {

						   for (int i = 0; i < 6; i++)
							   foreach (var _s in sprites)
							   {
								   var s = _s;

								   // compiler bug: get a delegate to BCL class
								   //AddSpriteByTexture(FreeSpaceForStuff, s, GoldSprites.Add);

								   AddSpriteByTexture(FreeSpaceForStuff, s,
									   k =>
									   {
										   k.Range = 0.5;
										   k.ItemTaken +=
											   delegate
											   {
												   Assets.Default.treasure.play();
											   };

										   GoldSprites.Add(k);
									   }
								   );

							   }

						   var LastPosition = new Point();

						   EgoView.ViewPositionChanged +=
							   delegate
							   {
								   // only check for items each 0.5 distance travelled
								   if ((EgoView.ViewPosition - LastPosition).length < 0.5)
									   return;

								   Action Later = null;
								   Action ItemTaken = null;


								   foreach (var Item in EgoView.SpritesFromPointOfView)
								   {
									   var Item_Sprite = Item.Sprite as SpriteInfoExtended;

									   if (Item_Sprite != null)
										   if (!Item_Sprite.IsTaken)
											   if (Item.Distance < Item_Sprite.Range)
											   {
												   if (GoldSprites.Contains(Item_Sprite))
												   {
													   // ding-ding-ding!
													   Item_Sprite.IsTaken = true;

													   new Bitmap(new BitmapData(DefaultWidth, DefaultHeight, false, 0xffff00))
													   {
														   scaleX = DefaultScale,
														   scaleY = DefaultScale
													   }.AttachTo(this).FadeOutAndOrphanize(1000 / 24, 0.2);



													   if (Item_Sprite != null)
														   if (Item_Sprite.ItemTaken != null)
															   ItemTaken += () => Item_Sprite.ItemTaken();

													   GoldTakenCounter = (GoldTakenCounter + 1).Min(1);

													   Later +=
														   delegate
														   {
															   EgoView.Sprites.Remove(Item_Sprite);
															   GoldSprites.Remove(Item_Sprite);
														   };
												   }
											   }
								   }

								   if (Later != null)
									   Later();

								   LastPosition = EgoView.ViewPosition;

								   if (ItemTaken != null)
									   ItemTaken();
							   };

						   AddNonBlockingItems();

					   }
					);
					#endregion

					Func<string, Texture64> t =
						texname => f[texname + ".png"];

					Func<string, string, Texture64> mix =
						(a, b) =>
						{
							var ia = f[a + ".png"];
							var ib = f[b + ".png"];

							var u = new Bitmap(ia.bitmapData.clone());



							u.bitmapData.draw(ib);
							return u;
						};



					#region game goal
					TheGoldStack = CreateDummy(f["life.png"]);
					TheGoldStack.Position.To(maze.Width - 1.5, maze.Height - 1.5);
					TheGoldStack.Range = 0.5;
					TheGoldStack.ItemTaken +=
						delegate
						{
							if (EndLevelMode)
								return;


							// show stats

							EnterEndLevelMode();
						};
					GoldSprites.Add(TheGoldStack);


					#endregion


					EgoView.Map.Textures = new Dictionary<uint, Texture64>
                        {
                            {graywall_achtung, mix("graywall", "achtung")},
                            {graywall_verboten, mix("graywall", "verboten")},
                            {graywall, t("graywall")},


							{woodwall_achtung, mix("woodwall", "achtung")},
                            {woodwall_verboten, mix("woodwall", "verboten")},
                            {woodwall, t("woodwall")},
                            {woodwall_books, t("woodwall_books")},


                            {bluewall, t("bluewall")},
                            {greenwall, t("greenwall")},
                        };

					// EgoView.RenderScene();

					#region hand
					var hand = f["hand.png"];
					const int handsize = 4;

					var hand_x = (DefaultControlWidth - hand.width * handsize) / 2;
					var hand_y = DefaultControlHeight - hand.height * handsize;
					hand.x = hand_x;
					hand.y = hand_y;
					hand.scaleX = handsize;
					hand.scaleY = handsize;
					hand.AttachTo(HudContainer);

					(1000 / 24).AtInterval(
						tt =>
						{
							hand.x = hand_x + Math.Cos(tt.currentCount * 0.2) * 6;
							hand.y = hand_y + Math.Abs(Math.Sin(tt.currentCount * 0.2)) * 4;
						}
					);
					#endregion

					#region heads

					Assets.Default.head.Items.OrderBy(k => k.FileName).Select(k => k.Data).ToImages(
						heads =>
						{
							var head = default(Bitmap);

							1000.AtInterval(
								tt =>
								{
									if (head != null)
										head.Orphanize();

									if (heads.Length > 0)
									{
										if (GoldTakenCounter > 0)
										{
											GoldTakenCounter--;
											head = heads.Last();
										}
										else
											head = heads.AtModulus(tt.currentCount % 3);

										head.filters = new[] { new DropShadowFilter() };
										head.scaleX = 2;
										head.scaleY = 2;
										head.MoveTo(4, DefaultControlHeight - head.height - 4).AttachTo(HudContainer);
									}
								}
							);
						}
					);


					#endregion

					InitializeCompass();
					InitializeKeyboard();

					AttachMovementInput(EgoView, true, false);


					ResetEgoPosition();

					stage.enterFrame +=
						e =>
						{
							//if (EndLevelMode)
							//    return;

							EgoView.RenderScene();
						};

					//getpsyched.FadeOutAndOrphanize(1000 / 15, 0.1);

					this.EgoView.Image.FadeIn(
						delegate
						{
							//1500.AtDelayDo(
							//    delegate
							//    {
							//        this.HudContainer.FadeIn();
							//    }
							//);
						}
					);
				}
			);
			#endregion
		}
		private void ShowScoreTable(Sprite ScoreContainer, Bitmap scroll)
		{

			var ContainerForEntries = new Sprite { x = scroll.x, y = scroll.y }.AttachTo(ScoreContainer);

			var Entries = new Queue<Sprite>();

			Action RemoveFirst =
				delegate
				{
					Entries.Dequeue().FadeOut();

					var Steps = DelayBetweenEntries / FrameRate_HideEntry;

					(FrameRate_HideEntry / 2).AtInterval(
						t =>
						{
							if (t.currentCount == Steps)
							{
								t.stop();

								return;
							}

							ContainerForEntries.y -= Spacing / Steps;
						}
					);
				};

			Action ConditionalRemoveFirst =
				delegate
				{
					if (Entries.Count > 4)
						RemoveFirst();
				};

			#region chain
			DelayBetweenEntries.Chain(
				delegate
				{
					Assets.Default.Sounds.gunshot.play();

					new TextField
					{
						defaultTextFormat = new TextFormat
						{
							size = 33,
						},
						text = "Level " + CurrentLevel + " Complete",

						textColor = 0xFFC526,
						autoSize = TextFieldAutoSize.LEFT,
						filters = new[] { new GlowFilter(0xC1931D) }
					}.AttachTo(ScoreContainer).MoveTo(scroll.x + 40, scroll.y + 64);

				}
			).Chain(
				GetScoreValues().Select<ScoreTag, Action>(
					(k, i) => delegate
					{
						Entries.Enqueue(ShowScoreTable_Entry(ContainerForEntries, k.Name, k.Score, k.Kills, i + 1));
						ConditionalRemoveFirst();
					}
				)
			).Do();
			#endregion
		}