TypoSnake Source

AS3

package 
{
	[SWF(width='800',height='500',backgroundColor='0xFFFFFF',frameRate='30')]
	import flash.display.*;
	import flash.events.*;
	import flash.geom.Rectangle;
	import flash.media.*;
	import flash.text.*;
	import flash.filters.*;
	import flash.utils.*;
	import classes.HitTest;
	// 06.07.2009
	public class Main extends Sprite 
	{
		private var stageWidthX:int = 800;
		private var stageHeightY:int = 500;
		[Embed(source = '/img/l.png')]
		private var l:Class;
		private var head:Bitmap = new l();
		private var overlay:Sprite = new Sprite;
		private var overlayWhite:Sprite = new Sprite;
		[Embed(source = '/img/info.png')]
		private var info:Class;
		private var infoG:Bitmap = new info();
		[Embed(source = '/img/gameover.png')]
		private var gameOverPng:Class;
		private var gameOverPngLost:Bitmap = new gameOverPng();		
		private var gameOverLabel:TextField = new TextField();
 
		[Embed(source='/img/bg01.jpg')]
		private var art1:Class;
		private var artBitmap1:Bitmap = new art1();
		private var artBitmap1Visible:Boolean = true;
		[Embed(source = '/img/bg02.jpg')]
		private var art2:Class;
		private var artBitmap2:Bitmap = new art2();
		private var artBitmap2Visible:Boolean = false;
		[Embed(source = '/img/bg03.jpg')]
		private var art3:Class;
		private var artBitmap3:Bitmap = new art3();		
		[Embed(source = '/img/bg04.jpg')]
		private var art4:Class;
		private var artBitmap4:Bitmap = new art4();
		private var artBitmap5:Bitmap = new art1();	
 
		[Embed(source = '/img/color.png')]
		private var color:Class;
		[Embed(source = '/img/mouse.png')]
		private var mouse:Class;
		[Embed(source = '/img/bold.png')]
		private var bold:Class;		
		[Embed(source = '/img/italic.png')]
		private var italic:Class;
		[Embed(source = '/img/yinyang.png')]
		private var yinyang:Class;
		private var yinyangFlag:Boolean = false;
		[Embed(source = '/img/less.png')]
		private var less:Class;
		[Embed(source = '/img/font.png')]
		private var font:Class;
 
		private var fontNameArray:Array	= new Array();
		[Embed(source='/fonts/Helvetica-Regular.otf', fontName = "Helvetica-Regular", mimeType="application/x-font-opentype")]
		private var helveticaR:Class;
		private var _1R:Font = new helveticaR();
		[Embed(source="/fonts/Helvetica-Italic.otf", fontFamily="Helvetica-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var helveticaI:Class;
		private var _1I:Font = new helveticaI();	
		[Embed(source = "/fonts/Helvetica-Bold.otf", fontFamily = "Helvetica-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var helveticaB:Class;
		private var _1B:Font = new helveticaB();		
 
		[Embed(source='/fonts/GaramondThreeLT-Regular.otf', fontName = "GaramondThreeLT-Regular", mimeType="application/x-font-opentype")]
		private var garamondThreeLTR:Class;
		private var _2R:Font = new garamondThreeLTR();
		[Embed(source="/fonts/GaramondThreeLT-Italic.otf", fontFamily="GaramondThreeLT-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var garamondThreeLTI:Class;
		private var _2I:Font = new garamondThreeLTI();	
		[Embed(source = "/fonts/GaramondThreeLT-Bold.otf", fontFamily = "GaramondThreeLT-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var garamondThreeLTB:Class;
		private var _2B:Font = new garamondThreeLTB();	
 
		[Embed(source='/fonts/FrutigerCE-Regular.otf', fontName = "FrutigerCE-Regular", mimeType="application/x-font-opentype")]
		private var frutigerR:Class;
		private var _3R:Font = new frutigerR();
		[Embed(source="/fonts/FrutigerCE-Italic.otf", fontFamily="FrutigerCE-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var frutigerI:Class;
		private var _3I:Font = new frutigerI();	
		[Embed(source = "/fonts/FrutigerCE-Bold.otf", fontFamily = "FrutigerCE-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var frutigerB:Class;
		private var _3B:Font = new frutigerB();				
 
		[Embed(source='/fonts/BodoniStd-Regular.otf', fontName = "BodoniStd-Regular", mimeType="application/x-font-opentype")]
		private var bodoniR:Class;
		private var _4R:Font = new bodoniR();
		[Embed(source="/fonts/BodoniStd-Italic.otf", fontFamily="BodoniStd-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var bodoniI:Class;
		private var _4I:Font = new bodoniI();	
		[Embed(source = "/fonts/BodoniStd-Bold.otf", fontFamily = "BodoniStd-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var bodoniB:Class;
		private var _4B:Font = new bodoniB();	
 
		[Embed(source='/fonts/FuturaStd-Regular.otf', fontName = "FuturaStd-Regular", mimeType="application/x-font-opentype")]
		private var futuraR:Class;
		private var _5R:Font = new futuraR();
		[Embed(source="/fonts/FuturaStd-Italic.otf", fontFamily="FuturaStd-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var futuraI:Class;
		private var _5I:Font = new futuraI();	
		[Embed(source = "/fonts/FuturaStd-Bold.otf", fontFamily = "FuturaStd-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var futuraB:Class;
		private var _5B:Font = new futuraB();
 
		[Embed(source='/fonts/Times-Regular.otf', fontName = "Times-Regular", mimeType="application/x-font-opentype")]
		private var timesR:Class;
		private var _6R:Font = new timesR();
		[Embed(source="/fonts/Times-Italic.otf", fontFamily="Times-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var timesI:Class;
		private var _6I:Font = new timesI();	
		[Embed(source = "/fonts/Times-Bold.otf", fontFamily = "Times-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var timesB:Class;
		private var _6B:Font = new timesB();
 
		[Embed(source='/fonts/OfficinaSansStd-Regular.otf', fontName = "OfficinaSansStd-Regular", mimeType="application/x-font-opentype")]
		private var officinaR:Class;
		private var _7R:Font = new officinaR();
		[Embed(source="/fonts/OfficinaSansStd-Italic.otf", fontFamily="OfficinaSansStd-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var officinaI:Class;
		private var _7I:Font = new officinaI();	
		[Embed(source = "/fonts/OfficinaSansStd-Bold.otf", fontFamily = "OfficinaSansStd-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var officinaB:Class;
		private var _7B:Font = new officinaB();
 
		[Embed(source='/fonts/GillSansStd-Regular.otf', fontName = "GillSansStd-Regular", mimeType="application/x-font-opentype")]
		private var gillSansStdR:Class;
		private var _8R:Font = new gillSansStdR();
		[Embed(source="/fonts/GillSansStd-Italic.otf", fontFamily="GillSansStd-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var gillSansStdI:Class;
		private var _8I:Font = new gillSansStdI();	
		[Embed(source = "/fonts/GillSansStd-Bold.otf", fontFamily = "GillSansStd-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var gillSansStdB:Class;
		private var _8B:Font = new gillSansStdB();
 
		[Embed(source='/fonts/UniversLTStd-Regular.otf', fontName = "UniversLTStd-Regular", mimeType="application/x-font-opentype")]
		private var universLTStdR:Class;
		private var _9R:Font = new universLTStdR();
		[Embed(source="/fonts/UniversLTStd-Italic.otf", fontFamily="UniversLTStd-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var universLTStdI:Class;
		private var _9I:Font = new universLTStdI();	
		[Embed(source = "/fonts/UniversLTStd-Bold.otf", fontFamily = "UniversLTStd-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var universLTStdB:Class;
		private var _9B:Font = new universLTStdB();
 
		[Embed(source='/fonts/BemboStd-Regular.otf', fontName = "BemboStd-Regular", mimeType="application/x-font-opentype")]
		private var bemboStdR:Class;
		private var _10R:Font = new bemboStdR();
		[Embed(source="/fonts/BemboStd-Italic.otf", fontFamily="BemboStd-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var bemboStdI:Class;
		private var _10I:Font = new bemboStdI();	
		[Embed(source = "/fonts/BemboStd-Bold.otf", fontFamily = "BemboStd-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var bemboStdB:Class;
		private var _10B:Font = new bemboStdB();
 
		[Embed(source='/fonts/RockwellStd-Regular.otf', fontName = "RockwellStd-Regular", mimeType="application/x-font-opentype")]
		private var rockwellStdR:Class;
		private var _11R:Font = new rockwellStdR();
		[Embed(source="/fonts/RockwellStd-Italic.otf", fontFamily="RockwellStd-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var rockwellStdI:Class;
		private var _11I:Font = new rockwellStdI();	
		[Embed(source = "/fonts/RockwellStd-Bold.otf", fontFamily = "RockwellStd-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var rockwellStdB:Class;
		private var _11B:Font = new rockwellStdB();
 
		[Embed(source='/fonts/MyriadPro-Regular.otf', fontName = "MyriadPro-Regular", mimeType="application/x-font-opentype")]
		private var myriadProR:Class;
		private var _12R:Font = new myriadProR();
		[Embed(source="/fonts/MyriadPro-Italic.otf", fontFamily="MyriadPro-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var myriadProI:Class;
		private var _12I:Font = new myriadProI();	
		[Embed(source = "/fonts/MyriadPro-Bold.otf", fontFamily = "MyriadPro-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var myriadProB:Class;
		private var _12B:Font = new myriadProB();
 
		[Embed(source='/fonts/DidotHTF-Regular.otf', fontName = "DidotHTF-Regular", mimeType="application/x-font-opentype")]
		private var didotHTFR:Class;
		private var _13R:Font = new didotHTFR();
		[Embed(source="/fonts/DidotHTF-Italic.otf", fontFamily="DidotHTF-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var didotHTFI:Class;
		private var _13I:Font = new didotHTFI();	
		[Embed(source = "/fonts/DidotHTF-Bold.otf", fontFamily = "DidotHTF-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var didotHTFB:Class;
		private var _13B:Font = new didotHTFB();
 
		[Embed(source='/fonts/LegacySansStd-Regular.otf', fontName = "LegacySansStd-Regular", mimeType="application/x-font-opentype")]
		private var legacySansStdR:Class;
		private var _14R:Font = new legacySansStdR();
		[Embed(source="/fonts/LegacySansStd-Italic.otf", fontFamily="LegacySansStd-Italic", fontStyle = "italic", mimeType="application/x-font-opentype")]
		private var legacySansStdI:Class;
		private var _14I:Font = new legacySansStdI();	
		[Embed(source = "/fonts/LegacySansStd-Bold.otf", fontFamily = "LegacySansStd-Bold", fontWeight= "bold", mimeType="application/x-font-opentype")]
		private var legacySansStdB:Class;
		private var _14B:Font = new legacySansStdB();
 
		[Embed(source = '/mp3/music.mp3')]
		private var music:Class;
		private var musicPlay:Sound = new music();
 
		[Embed(source = '/mp3/pick01.mp3')]
		private var pick01:Class;
		private var pick01s:Sound = new pick01();
 
		[Embed(source = '/mp3/pick02.mp3')]
		private var pick02:Class;
		private var pick02s:Sound = new pick02();
 
		[Embed(source = '/mp3/pick03.mp3')]
		private var pick03:Class;
		private var pick03s:Sound = new pick03();
 
		[Embed(source = '/mp3/pick04.mp3')]
		private var pick04:Class;
		private var pick04s:Sound = new pick04();
 
		[Embed(source = '/mp3/pick05.mp3')]
		private var pick05:Class;
		private var pick05s:Sound = new pick05();
 
		[Embed(source = '/mp3/crowd-cheer.mp3')]
		private var crowdCheer:Class;
		private var crowdCheerWin:Sound = new crowdCheer();
 
		[Embed(source = '/mp3/crowd-boo.mp3')]
		private var crowdBoo:Class;
		private var crowdBooLost:Sound = new crowdBoo();
 
		private var scoreDisplay:TextField = new TextField();		
		private var score:int = 5;
		private var snakeLengthCounterScore:int = 0;
		private var lengthBetweenNextLetter:Number = 0;
		private var startSnakeX:int = 10;
		private var startSnakeY:int = stageHeightY / 2;
		private var snakeX:int = startSnakeX;
		private var snakeY:int = startSnakeY;
		private var forceX:int = 5;
		private var forceY:int = 0;
		private var labelObjectArray:Array = new Array();
		private var textTail:String = "Schlangen-Beschwörung - Wenn auf dem Markt, sich wiegend, der Beschwörer die Kürbisflöte pfeift, die reizt und lullt, so kann es sein, dass er sich einen Hörer herüberlockt, der ganz aus dem Tumult  der Buden eintritt in den Kreis der Pfeife, die will und will und will und die erreicht, dass das Reptil in seinem Korb sich steife und die das steife schmeichlerisch erweicht,  abwechselnd immer schwindelnder und blinder mit dem, was schreckt und streckt, und dem, was löst -; und dann genügt ein Blick: so hat der Inder dir eine Fremde eingeflößt,  in der du stirbst. Es ist als überstürze glühender Himmel dich. Es geht ein Sprung durch dein Gesicht. Es legen sich Gewürze auf deine nordische Erinnerung,  die dir nichts hilft. Dich feien keine Kräfte, die Sonne gärt, das Fieber fällt und trifft; von böser Freude steilen sich die Schäfte, nd in den Schlangen glänzt das Gift. - Rainer Maria Rilke (1875-1926)";
		private var textTailCharPosition:int = 0;
		private var goodiesArray:Array = new Array();		
		private var miceFont:String = "Helvetica-Regular";
		private var startFontSize:int = 14;
		private var miceFontSize:int = startFontSize;
		private var miceBold:Boolean = false;
		private var miceItalic:Boolean = false;
		private var fontColor:String = "0xc4ffc4";
		private var diaTimer:Timer = new Timer(8500);
		private var frameCounter:Number = 0;
		private var changeDiaShowFlag:Boolean =  false;
		private var dropShadow:DropShadowFilter = new DropShadowFilter();
		private var scoreDisplayTextFormatter:TextFormat = new TextFormat();
 
		public function Main():void 
		{
			if (stage) init();
			else addEventListener(Event.ADDED_TO_STAGE, init);
		}
 
		private function run(e:Event):void {
			stage.removeEventListener(MouseEvent.CLICK, run);
			stage.removeChild(infoG);
			this.addChild(artBitmap1);
			artBitmap1.visible = true;
			artBitmap1.alpha = 1.0;
			this.addChild(artBitmap2);
			artBitmap2.visible = false;
			artBitmap2.alpha = 0.0;
			this.addChild(artBitmap3);
			artBitmap3.visible = false;
			artBitmap3.alpha = 0.0;
			this.addChild(artBitmap4);
			artBitmap4.visible = false;
			artBitmap4.alpha = 0.0;
			this.addChild(artBitmap5);
			artBitmap5.visible = false;
			artBitmap5.alpha = 0.0;
 
			overlay.graphics.beginFill(0x000000, 1.0);
			overlay.graphics.drawRect(0, 0, stageWidthX, stageHeightY);
			overlay.graphics.endFill();
			overlay.alpha = 0.3;
			stage.addChild(overlay);
			overlayWhite.graphics.beginFill(0xFFFFFF, 1.0);
			overlayWhite.graphics.drawRect(0, 0, stageWidthX, stageHeightY);
			overlayWhite.graphics.endFill();
			overlayWhite.alpha = 0.0;
			stage.addChild(overlayWhite);
			dropShadow.color = 0xFFFFF0;
			dropShadow.inner = false;
			dropShadow.alpha = 0.8;
			dropShadow.angle = 0;
			scoreDisplay.autoSize = TextFieldAutoSize.RIGHT;
			scoreDisplay.background = true;
			scoreDisplay.backgroundColor = 0x000000;
			scoreDisplayTextFormatter.bold = true;
			scoreDisplayTextFormatter.font = _1B.fontName;
			scoreDisplay.embedFonts = true;
			scoreDisplayTextFormatter.size = 10;
			scoreDisplay.alpha = 0.8;
			scoreDisplay.defaultTextFormat = scoreDisplayTextFormatter;
			scoreDisplay.htmlText = "<b>Score:</b> 0"  + " Font: " + miceFont;
			scoreDisplay.x = stageWidthX - 10 - scoreDisplay.width;
			scoreDisplay.y = stageHeightY - 10 - scoreDisplay.height;
			scoreDisplay.textColor = 0xFFFFFF;
			stage.addChild(scoreDisplay);
			head.x += 10;
			head.alpha = 0.9;
			stage.addChild(head);
			stage.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			stage.addEventListener(KeyboardEvent.KEY_UP, onKey);
			diaTimer.addEventListener (TimerEvent.TIMER, onDiaTimer);
			diaTimer.start();			
		}
 
		private function init(e:Event = null):void 
		{
			removeEventListener(Event.ADDED_TO_STAGE, init);
			musicPlay.play(0,int.MAX_VALUE);
			for (var numFonts:int = 1; numFonts < 13; numFonts++ ) {
				fontNameArray.push(this["_" + numFonts + "R"].fontName);
			}
			stage.addChild(infoG);
			infoG.x = stageWidthX / 2 - infoG.width / 2;
			infoG.y = stageHeightY / 2 - infoG.height / 2;
			stage.addEventListener(MouseEvent.CLICK, run);
		}
 
		public function onEnterFrame(event:Event):void 
		{
			frameCounter++;
			DiaShow(frameCounter);
			if (!(forceX == 0 && forceY == 0)) {
				if (labelObjectArray.length > score) {
					var displayObject:DisplayObject = stage.getChildByName(labelObjectArray[0].name);
					if (displayObject !== null && displayObject.name.charAt(0) !== 'G') {
						stage.removeChild(displayObject);
						labelObjectArray.shift();
					}
				}
				if (Math.abs(forceX) > Math.abs(forceY)) {
					lengthBetweenNextLetter -= Math.abs(forceX);
				} else {
					lengthBetweenNextLetter -= Math.abs(forceY);
				}
				if (lengthBetweenNextLetter <= 0) {
					lengthBetweenNextLetter = 0;
					var pushMe:TextField = new TextField();
					var pushMeFormatter:TextFormat = new TextFormat();			
					pushMeFormatter.size = miceFontSize;
					pushMeFormatter.bold = miceBold;
					pushMeFormatter.italic = miceItalic;
					pushMeFormatter.color = fontColor;
					pushMe.embedFonts = true;
					pushMeFormatter.font = miceFont;
					pushMe.defaultTextFormat = pushMeFormatter;
					if (textTailCharPosition >= textTail.length) {
							textTailCharPosition = 0;
					}
					pushMe.text = textTail.charAt(textTailCharPosition);
					if (forceX == 0) {
						pushMe.text = pushMe.text.toUpperCase();
						if (pushMe.text == " ") pushMe.text = "|";
					} else {
						if (pushMe.text == " ") pushMe.text = "-";
					}
					pushMe.name = "TextField " + (labelObjectArray.length + 1).toString();
					pushMe.autoSize = TextFieldAutoSize.LEFT;
					pushMe.wordWrap = false;
					if (forceX == 0) {
						lengthBetweenNextLetter = pushMe.textHeight - 2;
					} else if (forceY == 0) {
						// Laufweite / Tracking
						if (textTailCharPosition !== 0){
							var widthChar1:Number = pushMe.textWidth;
							if (textTail.charAt(textTailCharPosition) == "i") widthChar1 -= 1.2;
							pushMe.text = textTail.charAt(textTailCharPosition - 1);
							var widthChar2:Number = pushMe.textWidth;
							if (textTail.charAt(textTailCharPosition) == "i") widthChar2 -= 1.2;
							pushMe.text = textTail.charAt(textTailCharPosition) + textTail.charAt(textTailCharPosition - 1);
							var widthChar1And2:Number = pushMe.textWidth;
							pushMe.text = textTail.charAt(textTailCharPosition);					
							lengthBetweenNextLetter = Math.abs(widthChar1And2 - widthChar1 - widthChar2) + pushMe.textWidth;
						} else {
							lengthBetweenNextLetter = pushMe.textWidth - 1;	
						}
					}
					labelObjectArray.push(pushMe);
					stage.addChild(pushMe);
					snakeLengthCounterScore++;
					textTailCharPosition++;
					pushMe.x = snakeX - pushMe.width / 2;
					pushMe.y = snakeY - pushMe.height / 2;
					if (snakeX < 0 || snakeX > stageWidthX || snakeY < 0 || snakeY > stageHeightY) {
						gameOver();
					}
					if (labelObjectArray.length > 12){
						for (var j:int = 0; j < labelObjectArray.length - 8; j++) {
							var lastElementHead:TextField = labelObjectArray[labelObjectArray.length];
							if (labelObjectArray[j].name !== null) {
								var laufVar:TextField = labelObjectArray[j];
								var displayObjectHit:DisplayObject = stage.getChildByName(laufVar.name);
								var rect:Rectangle = classes.HitTest.hitTestObject(pushMe, displayObjectHit, false, 100);
								if (rect == null) {
									null;
								} else if (rect.height > (pushMe.textHeight / 3) + 3) {
									laufVar.background = true;
									laufVar.backgroundColor = 0x33ff00;
									gameOver();
								}
							} else {
								trace("HitTest: labelObjectArray[j].name !== null");
							}
						}
					}				
 
					var splitIndexOf:int = miceFont.indexOf("-");
					var visibleCounter:int = 0;
					for (var i:int = 0; i < goodiesArray.length; i++) {
						var tmpDisplayObject:DisplayObject = goodiesArray[i];
						var charPos:int = tmpDisplayObject.name.indexOf(":");
						if (charPos == -1){
							var tmpBitmap:Bitmap = goodiesArray[i];
							if (tmpBitmap.visible == true) visibleCounter++;
							if (tmpBitmap.hitTestObject(pushMe) == true && tmpBitmap.visible == true) {
								tmpBitmap.visible = false;
								if (tmpBitmap.name == "Goodie Mouse") {
									pick05s.play();
									miceFontSize += 4;
									trace ("Font++");
								} else if (tmpBitmap.name == "Goodie Bold") {
									pick03s.play();
									splitIndexOf = miceFont.indexOf("-");
									miceFont = miceFont.substring(0, splitIndexOf) + "-Bold";
									trace("Bold");
								} else if (tmpBitmap.name == "Goodie Italic") {
									pick03s.play();
									splitIndexOf = miceFont.indexOf("-");
									miceFont = miceFont.substring(0, splitIndexOf) + "-Italic";
									trace("Italic");
								} else if (tmpBitmap.name == "Goodie YinYang") {
									pick04s.play();
									if (yinyangFlag == true) {
										yinyangFlag = false;
										overlay.alpha = 0.3;
										overlayWhite.alpha = 0.0;
									} else {
										yinyangFlag = true;
										overlayWhite.alpha = 0.6;
										overlay.alpha = 0.0;
									}
									setRandomColor();
									for (var o:int = 0; o < labelObjectArray.length; o++) {
											labelObjectArray[o].textColor = fontColor;
									}
									splitIndexOf = miceFont.indexOf("-");
									miceFont = miceFont.substring(0, splitIndexOf) + "-Regular";
									trace("YinYang");
								} else if (tmpBitmap.name == "Goodie Less") {
									pick04s.play();
									if (miceFontSize > 9){
										miceFontSize -= 4;
									}
									trace("Less");
								} else if (tmpBitmap.name == "Goodie RandFont") {
									pick02s.play();
									var rndFontName:String = randomFontName();
									if (rndFontName == null) {
										miceFont = _1R.fontName;
									} else {
										miceFont = rndFontName;
									}									
									trace("Font");
								} else if (tmpBitmap.name == "Goodie Color") {
									setRandomColor();
								}
								score += 2;
								var splitIndexOfInt1:int = miceFont.indexOf("-");
								var miceFont2:String = miceFont.substring(0, splitIndexOfInt1) + "-Bold";
								scoreDisplayTextFormatter.font = miceFont2;
								scoreDisplay.defaultTextFormat = scoreDisplayTextFormatter;
								scoreDisplay.htmlText = "Score: " + score.toString() + " - Font: " + miceFont + " - Size: " + miceFontSize.toString() + " Pt";
								scoreDisplay.x = stageWidthX - 10 - scoreDisplay.width;
							}
						} else {
							if (tmpDisplayObject.visible == true) visibleCounter++;
							if (tmpDisplayObject.hitTestObject(pushMe) == true && tmpDisplayObject.visible == true) {
								tmpDisplayObject.visible = false;
								pick02s.play();
								miceFont = tmpDisplayObject.name.substring(charPos + 1, tmpDisplayObject.name.length);
								trace("Font");
								score += 2;
								var splitIndexOfInt:int = miceFont.indexOf("-");
								miceFont = miceFont.substring(0, splitIndexOfInt) + "-Bold";
								scoreDisplayTextFormatter.font = miceFont;
								scoreDisplay.defaultTextFormat = scoreDisplayTextFormatter;
								scoreDisplay.htmlText = "Score: " + score.toString() + " - Font: " + miceFont + " - Size: " + miceFontSize.toString() + " Pt";
								scoreDisplay.x = stageWidthX - 10 - scoreDisplay.width;
							}
						}
					}
 
					if (visibleCounter < 4) {
						// Set a goodie
						var type:int = randomNumber(0, 12);
						if (miceFontSize < 13) {
							type = 0;
						} else if (miceFontSize > 45) {
							type = 5;
						}
						if (type == 1 || type == 0) {
							var pushMeBitmap:Bitmap = new mouse();
							pushMeBitmap.name = "Goodie Mouse";
							pushMeBitmap.filters = [dropShadow];
							pushMeBitmap.x = randomNumber(100, stageWidthX - 100);
							pushMeBitmap.y = randomNumber(100, stageHeightY - 100);
							pushMeBitmap.height /= 5;
							pushMeBitmap.width /= 5;
							pushMeBitmap.width -= 11;
							goodiesArray.push(pushMeBitmap);
							stage.addChild(pushMeBitmap);
						} else if (type == 2) {
							var pushMeBitmap2:Bitmap = new bold();
							pushMeBitmap2.name = "Goodie Bold";
							pushMeBitmap2.filters = [dropShadow];
							pushMeBitmap2.x = randomNumber(100, stageWidthX - 100);
							pushMeBitmap2.y = randomNumber(100, stageHeightY - 100);
							pushMeBitmap2.height /= 2;
							pushMeBitmap2.width /= 2;
							goodiesArray.push(pushMeBitmap2);
							stage.addChild(pushMeBitmap2);					
						} else if (type == 3) {
							var pushMeBitmap3:Bitmap = new italic();
							pushMeBitmap3.filters = [dropShadow];
							pushMeBitmap3.name = "Goodie Italic";
							pushMeBitmap3.x = randomNumber(100, stageWidthX - 100);
							pushMeBitmap3.y = randomNumber(100, stageHeightY - 100);
								pushMeBitmap3.height /= 2;
							pushMeBitmap3.width /= 2;
							goodiesArray.push(pushMeBitmap3);
							stage.addChild(pushMeBitmap3);					
						} else if (type == 4) {
							var yinYangPng:Bitmap = new yinyang();
							yinYangPng.filters = [dropShadow];
							yinYangPng.name = "Goodie YinYang";
							yinYangPng.x = randomNumber(100, stageWidthX - 100);
							yinYangPng.y = randomNumber(100, stageHeightY - 100);
							yinYangPng.height /= 5;
							yinYangPng.width /= 5;
							goodiesArray.push(yinYangPng);
							stage.addChild(yinYangPng);					
						} else if (type == 5 || type == 6) {
							var pushMeBitmap5:Bitmap = new less();
							pushMeBitmap5.name = "Goodie Less";
							pushMeBitmap5.filters = [dropShadow];
							pushMeBitmap5.x = randomNumber(100, stageWidthX - 100);
							pushMeBitmap5.y = randomNumber(100, stageHeightY - 100);
							pushMeBitmap5.height /= 2;
							pushMeBitmap5.width /= 2;
							goodiesArray.push(pushMeBitmap5);
							stage.addChild(pushMeBitmap5);					
						} else if (type == 7) {
							var pushMeBitmap7:Bitmap = new font();
							pushMeBitmap7.name = "Goodie RandFont";
							pushMeBitmap7.x = randomNumber(100, stageWidthX - 100);
							pushMeBitmap7.y = randomNumber(100, stageHeightY - 100);
							pushMeBitmap7.height /= 4;
							pushMeBitmap7.width /= 4;
							goodiesArray.push(pushMeBitmap7);
							stage.addChild(pushMeBitmap7);					
						} else if (type == 10 || type == 11) {
							var pushMeBitmap0:Bitmap = new color();
							pushMeBitmap0.name = "Goodie Color";
							pushMeBitmap0.filters = [dropShadow];
							pushMeBitmap0.x = randomNumber(100, stageWidthX - 100);
							pushMeBitmap0.y = randomNumber(100, stageHeightY - 100);
							pushMeBitmap0.height /= 3;
							pushMeBitmap0.width /= 3;
							goodiesArray.push(pushMeBitmap0);
							stage.addChild(pushMeBitmap0);					
						} else if (type == 8 || type == 9 || type == 12) {
							var fontDemo:TextField = new TextField();
							var fontDemoFormatter:TextFormat = new TextFormat();
							var rndFont:String = randomFontName();
							if (rndFont == null) {
								fontDemo.name = "Goodie Font:" + _1R.fontName;
								fontDemoFormatter.font = _1R.fontName;
								fontDemo.text = "Aa";
							} else {
								fontDemo.name = "Goodie Font:" + rndFont;
								fontDemoFormatter.font = rndFont;
								if (rndFont !== null) {
									if (rndFont.length > 3){
										fontDemo.text = rndFont.substr(0, 2);
									} else {
										fontDemo.text = "Aa";
									}
								}
							}
							fontDemoFormatter.size = 35;
							fontDemo.setTextFormat(fontDemoFormatter);
							fontDemo.embedFonts = true;
							fontDemo.defaultTextFormat = fontDemoFormatter;
							fontDemo.autoSize = TextFieldAutoSize.LEFT;
							fontDemo.background = true;
							fontDemo.backgroundColor = 0xFFFFFF;
							fontDemo.filters = [dropShadow];
							fontDemo.x = randomNumber(100, stageWidthX - 100);
							fontDemo.y = randomNumber(100, stageHeightY - 100);
							goodiesArray.push(fontDemo);
							stage.addChild(fontDemo);					
						}
					}
				}
				snakeX += forceX;
				snakeY += forceY;
			}
		}		
 
		private function setRandomColor():void {
			pick01s.play();
			var randc:int = randomNumber(1, 9);
			if (yinyangFlag !== true) {
				if (randc == 1) {
				fontColor = "0xffd1d1";	
				} else if (randc == 2) {
					fontColor = "0xfad1ff";	
				} else if (randc == 3) {
					fontColor = "0xd1d1ff";	
				} else if (randc == 4) {
					fontColor = "0xd1feff";	
				} else if (randc == 5) {
					fontColor = "0xc4ffc4";	
				} else if (randc == 6) {
					fontColor = "0xc4ffc4";	
				} else if (randc == 7) {
					fontColor = "0xfffdc4";	
				} else if (randc == 8) {
					fontColor = "0xfff3c4";	
				} else if (randc == 9) {
					fontColor = "0xffffff";	
				}
			} else {
				// Dark colors please:
				if (randc == 1) {
					fontColor = "0xab0000";	
				} else if (randc == 2) {
					fontColor = "0x9e00b1";	
				} else if (randc == 3) {
					fontColor = "0x0000ae";	
				} else if (randc == 4) {
					fontColor = "0x009a9d";	
				} else if (randc == 5) {
					fontColor = "0x009a00";	
				} else if (randc == 6) {
					fontColor = "0x008d00";	
				} else if (randc == 7) {
					fontColor = "0x5b5800";	
				} else if (randc == 8) {
					fontColor = "0x937500";	
				} else if (randc == 9) {
					fontColor = "0x000000";	
				}
			}
			trace("Color");	
		}
 
		private function gameOver():void {
			SoundMixer.stopAll();
			overlay.alpha = 0.8;
			diaTimer.stop();
			trace("Game over");
			gameOverPngLost.x = stageWidthX / 2 - gameOverPngLost.width / 2;
			gameOverPngLost.y = stageHeightY / 2 - gameOverPngLost.height / 2;
			stage.addChild(gameOverPngLost);
			var gameOverFormatter:TextFormat = new TextFormat();
			gameOverFormatter.size = 40;
			gameOverLabel.autoSize = TextFieldAutoSize.LEFT;
			gameOverFormatter.bold = true;
			gameOverLabel.x = gameOverPngLost.x + 10;
			gameOverLabel.y = stageHeightY / 2 - gameOverLabel.height / 2 + gameOverPngLost.height;
			if (score > 100) {
				crowdCheerWin.play();
				gameOverFormatter.color = 0x18e10e;
			} else {
				crowdBooLost.play();
				gameOverFormatter.color = 0xff0000;
			}
			gameOverLabel.defaultTextFormat = gameOverFormatter;
			gameOverLabel.text = "Score: " + score.toString();
			stage.addChild(gameOverLabel);
			forceX = 0;
			forceY = 0;
			// Restart
			snakeLengthCounterScore = 0;
			lengthBetweenNextLetter = 0;
			snakeX = startSnakeX;
			snakeY = startSnakeY;
			textTailCharPosition = 0;
			miceFont = "Helvetica-Regular";
			miceFontSize = startFontSize;
			miceBold = false;
			miceItalic = false;
			fontColor = "0xc4ffc4";
			stage.addEventListener(MouseEvent.MOUSE_DOWN, onRestart);
		}
 
		private function onRestart(e:MouseEvent):void {
			stage.removeEventListener(MouseEvent.MOUSE_DOWN, onRestart);
			stage.removeChild(gameOverPngLost);
			stage.removeChild(gameOverLabel);		
			overlay.alpha = 0.3;
			overlayWhite.alpha = 0.0;
			yinyangFlag = false;		
			var displayObject:DisplayObject;
			var displayObjectLabel:DisplayObject;
			for (var k:int = 0; k < goodiesArray.length; k++) {
				goodiesArray[k].visible = false;
			}	
			for (var j:int = 0; j < labelObjectArray.length; j++) {
				var laufVar:TextField = labelObjectArray[j];
				displayObjectLabel = stage.getChildByName(laufVar.name);
				stage.removeChild(displayObjectLabel);
			}	
			labelObjectArray = new Array();
			goodiesArray = new Array();
			musicPlay.play(0,int.MAX_VALUE);
			artBitmap1.visible = true;
			artBitmap1.alpha = 1.0;
			artBitmap2.visible = false;
			artBitmap2.alpha = 0.0;
			artBitmap3.visible = false;
			artBitmap3.alpha = 0.0;
			artBitmap4.visible = false;
			artBitmap4.alpha = 0.0;
			artBitmap5.visible = false;
			artBitmap5.alpha = 0.0;
			scoreDisplay.htmlText = "Score: 0"  + " - Font: " + miceFont + " - Size: " + miceFontSize.toString() + " Pt";
			diaTimer.start();
			forceX = 5;
			forceY = 0;
			score = 5;
		}
 
		private function onKey(keyEvent:KeyboardEvent):void {
			var div:int = 220;
			trace(keyEvent.keyCode);
			var tmpForce:int;
			if (Math.abs(forceX) > Math.abs(forceY)) {	
				tmpForce = forceX
				switch (keyEvent.keyCode) {
					case 38: // Up
						forceY = -1 * (Math.abs(tmpForce) + score / div);
						forceX = 0;
						break;
					case 40: // Down
							forceY = (Math.abs(tmpForce) + score / div);
						forceX = 0;
						break;
					case 87: // W
						forceY = -1 * (Math.abs(tmpForce) + score / div);
						forceX = 0;
						break;	
					case 83: // S
							forceY = (Math.abs(tmpForce) + score / div);
						forceX = 0;
						break;
				}
			} else if (Math.abs(forceY) > Math.abs(forceX)) {	
				tmpForce = forceY;
				switch (keyEvent.keyCode) {
					case 37: // Left
						forceX = -1 * (Math.abs(tmpForce) + score / div);
						forceY = 0;
						break;
					case 39: // Right
						forceX = (Math.abs(tmpForce) + score / div);
						forceY = 0;
						break;
					case 65: // A
						forceX = -1 * (Math.abs(tmpForce) + score / div);
						forceY = 0;
						break;
					case 68: // D
						forceX = (Math.abs(tmpForce) + score / div);
						forceY = 0;
						break;
				}
			}			
		}
 
		private function onDiaTimer (event:TimerEvent):void {
			changeDiaShowFlag = true;
		}	
 
		private function DiaShow (frameCount:int):void {
			 if (changeDiaShowFlag) {				
				if (artBitmap1.visible) {
					artBitmap2.visible = true;
					artBitmap1.alpha -= 0.05;
					artBitmap2.alpha += 0.05;
					if (artBitmap2.alpha >= 1.0) {
						artBitmap1.visible = false;
						artBitmap1.alpha = 0.0;
						artBitmap3.visible = true;
						changeDiaShowFlag = false;
					}
				} else if (artBitmap2.visible) {
					artBitmap3.visible = true;
					artBitmap2.alpha -= 0.05;
					artBitmap3.alpha += 0.05;
					if (artBitmap3.alpha >= 1.0) {
						artBitmap2.visible = false;
						artBitmap2.alpha = 0.0;
						artBitmap4.visible = true;
						changeDiaShowFlag = false;
					}
				} else if (artBitmap3.visible) {
					artBitmap4.visible = true;
					artBitmap3.alpha -= 0.05;
					artBitmap4.alpha += 0.05;
					if (artBitmap4.alpha >= 1.0) {
						artBitmap3.visible = false;
						artBitmap3.alpha = 0.0;
						artBitmap5.visible = true;
						changeDiaShowFlag = false;
					}
				} else if (artBitmap4.visible) {
					artBitmap5.visible = true;
					artBitmap4.alpha -= 0.05;
					artBitmap5.alpha += 0.05;
					if (artBitmap5.alpha >= 1.0) {
						artBitmap4.visible = false;
						artBitmap4.alpha = 0.0;
						changeDiaShowFlag = false;
					}
				} else {
					artBitmap1.visible = true;
					artBitmap1.alpha = 1.0;
 
					artBitmap2.visible = false;
					artBitmap2.alpha = 0.0;
 
					artBitmap3.visible = false;
					artBitmap3.alpha = 0.0;
 
					artBitmap4.visible = false;
					artBitmap4.alpha = 0.0;
 
					artBitmap5.visible = false;
					artBitmap5.alpha = 0.0;
					changeDiaShowFlag = false;
				}
			}
		}
 
		private function randomFontName():String {
			return fontNameArray[randomNumber(0, fontNameArray.length)];
		}
 
		private function randomNumber(low:Number=NaN, high:Number=NaN):int
		{
			var low:Number = low;
			var high:Number = high;
			if(isNaN(low)) {
				throw new Error("low must be defined");
			}
			if(isNaN(high)) {
				throw new Error("high must be defined");
			}
			return Math.round(Math.random() * (high - low)) + low;
		}
	}
}


SourcecodeDownload SWF and Src.