var frameRate=0,canvas,lastTime,isXperiaPlay=!0,isMoga=!1,useMultiFactor=0,keyBoardOut=!0,isTouchBase=!1,isFirefoxOS=!0,GameState,loopStart,loopEnd,loopPause,secondPassed=!1,upPressed,upLocked,downPressed,downLocked,rightPressed,rightLocked,leftPressed,leftLocked,actionButton1,actionButton1Locked,actionButton2,actionButton2Locked,pl2_upPressed,pl2_upLocked,pl2_downPressed,pl2_downLocked,pl2_rightPressed,pl2_rightLocked,pl2_leftPressed,pl2_leftLocked,pl2_actionButton1,pl2_actionButton1Locked,pl2_actionButton2,
pl2_actionButton2Locked,soundButton,soundButtonLocked,musicButton,musicButtonLocked,backPressed,backLocked=!1,worldTicks,mTouch=[],mTouchX=Array(25),mTouchY=Array(25),mTouchID=Array(25),touchX=-1,touchY=-1,touched=!1,touchReleased=!0,ctx;window.requestAnimFrame=function(){return window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){window.setTimeout(a,1E3/60)}}();var params={};
if(location.search)for(var parts=location.search.substring(1).split("&"),i=0;i<parts.length;i++){var nv=parts[i].split("=");nv[0]&&(params[nv[0]]=nv[1]||!0)}
function init(){canvas=document.getElementById("mycanvas");musicButtonLocked=musicButton=soundButtonLocked=soundButton=actionButton2Locked=actionButton2=actionButton1Locked=actionButton1=leftLocked=leftPressed=downLocked=downPressed=rightLocked=rightPressed=upLocked=upPressed=!1;worldTicks=0;if(canvas.getContext){ctx=canvas.getContext("2d");isFirefoxOS?(useMultiFactor=0,drawableResource=engineRoot+"drawable/"):params.big&&1==params.big?(useMultiFactor=2,drawableResource=engineRoot+"drawablex4/"):
(useMultiFactor=1,drawableResource=engineRoot+"drawablex2/");canvas.width=lowDisplayW<<useMultiFactor;canvas.height=lowDisplayH<<useMultiFactor;ctx=canvas.getContext("2d");initGameEngine();lastTime=(new Date).getTime();loopPause=(new Date).getTime();loopEnd=loopStart=(new Date).getTime();runThread();canvas.onmousemove=fw_mouseMove;canvas.onmousedown=fw_mouseDown;canvas.onmouseup=fw_mouseUp;touchY=touchX=-1;touched=!1;touchReleased=!0;for(var a=mTouchX.length;0<=--a;)mTouchX[a]=-1,mTouchY[a]=-1,mTouchID[a]=
-1;canvas.addEventListener("touchstart",function(a){a.preventDefault();mTouch=a.touches;for(var d,b=0;b<a.touches.length;b++)d=a.touches[b],0==b&&(touchX=d.pageX,touchY=d.pageY,touched=!0)},!1);canvas.addEventListener("touchmove",function(a){a.preventDefault();mTouch=a.touches;for(var d,b=0;b<a.touches.length;b++)d=a.touches[b],0==b&&(touchX=d.pageX,touchY=d.pageY,touched=!0)},!1);canvas.addEventListener("touchend",function(a){a.preventDefault();mTouch=a.touches;touchY=touchX=-1;touchReleased=!0},
!1)}else alert("You need HTML5 compatible browser to see this demo!.. try Google Chrome ")}function getRandom(a){return Math.floor(a*Math.random())}function convertToRadians(a){return a*(Math.PI/180)}
function runThread(){requestAnimFrame(runThread);loopEnd=(new Date).getTime();24>loopEnd-loopStart||(lastTime=(new Date).getTime(),loopStart=(new Date).getTime(),GameState==INGAME?GameLoop():LogicLoop(),worldTicks++,1E3<worldTicks&&(worldTicks-=1E3),1E3<loopEnd-loopPause&&(secondPassed=!0,loopPause=loopEnd))}var mouseX=0,mouseY=0,mouseButton;function fw_mouseMove(a){mouseX=a.clientX-canvas.offsetLeft;mouseY=a.clientY-canvas.offsetTop}
function fw_mouseDown(a){mouseX=a.clientX-canvas.offsetLeft;mouseY=a.clientY-canvas.offsetTop;touchX=mouseX>>useMultiFactor;touchY=mouseY>>useMultiFactor;switch(a.which){case 1:mouseButton|=1;break;case 2:mouseButton|=2;break;case 3:mouseButton|=4}}function fw_mouseUp(a){mouseX=a.clientX-canvas.offsetLeft;mouseY=a.clientY-canvas.offsetTop;touchY=touchX=-1;switch(a.which){case 1:mouseButton&=6;break;case 2:mouseButton&=5;break;case 3:mouseButton&=3}touchReleased=!0}
function onKeyDown(a){switch(a.keyCode){case 27:return backPressed=!0,a.preventDefault(),!1;case 32:return actionButton2=!0,a.preventDefault(),!1;case 38:return upPressed=!0,a.preventDefault(),!1;case 40:return downPressed=!0,a.preventDefault(),!1;case 37:return leftPressed=!0,a.preventDefault(),!1;case 39:return rightPressed=!0,a.preventDefault(),!1;case 77:return musicButton=!0,a.preventDefault(),!1;case 83:return soundButton=!0,a.preventDefault(),!1;case 88:return actionButton2=!0,a.preventDefault(),
!1;case 90:return actionButton2=!0,a.preventDefault(),!1}}
function onKeyUp(a){switch(a.keyCode){case 27:return backLocked=backPressed=!1,a.preventDefault(),!1;case 32:return actionButton2Locked=actionButton2=!1,a.preventDefault(),!1;case 38:return upLocked=upPressed=!1,a.preventDefault(),!1;case 40:return downLocked=downPressed=!1,a.preventDefault(),!1;case 37:return leftLocked=leftPressed=!1,a.preventDefault(),!1;case 39:return rightLocked=rightPressed=!1,a.preventDefault(),!1;case 77:return musicButtonLocked=musicButton=!1,a.preventDefault(),!1;case 83:return soundButtonLocked=
soundButton=!1,a.preventDefault(),!1;case 88:return actionButton2Locked=actionButton2=!1,a.preventDefault(),!1;case 90:return actionButton2Locked=actionButton2=!1,a.preventDefault(),!1}}function setAlpha(a){ctx.globalAlpha=1/255*a}function renderAtPoint(a,c,d){ctx.drawImage(a,c<<useMultiFactor,d<<useMultiFactor,a.width,a.height)}
function renderSubImageAtPoint(a,c,d,b,e,f,h){ctx.drawImage(a,b<<useMultiFactor,e<<useMultiFactor,f<<useMultiFactor,h<<useMultiFactor,c<<useMultiFactor,d<<useMultiFactor,f<<useMultiFactor,h<<useMultiFactor)}function drawRect(a,c,d,b,e){ctx.fillStyle=e;ctx.fillRect(a<<useMultiFactor,c<<useMultiFactor,d-a<<useMultiFactor,b-c<<useMultiFactor)}function makeRGBA(a,c,d,b){return"rgba("+a+","+c+","+d+","+1/255*b+")"}
function clipRect(a,c,d,b){ctx.save();ctx.beginPath();ctx.rect(a<<useMultiFactor,c<<useMultiFactor,d-a<<useMultiFactor,b-c<<useMultiFactor);ctx.clip()}function endClip(){ctx.restore();ctx.beginPath();ctx.rect(0,0,lowDisplayW<<useMultiFactor,lowDisplayH<<useMultiFactor);ctx.clip()}var renderToCanvas=function(a,c,d){var b=document.createElement("canvas");b.width=a;b.height=c;d(b.getContext("2d"));return b};
function setScale(a,c,d,b){ctx.save();ctx.translate(a<<useMultiFactor,c<<useMultiFactor);ctx.scale(d,b);ctx.translate(-(a<<useMultiFactor),-(c<<useMultiFactor))}function endScale(){ctx.restore()}function AssetManager(){this.errorCount=this.successCount=0;this.cache={};this.downloadQueue=[];this.resourceRoot=""}AssetManager.prototype.queueDownload=function(a){this.downloadQueue.push(a)};AssetManager.prototype.setRoot=function(a){this.resourceRoot=a};
AssetManager.prototype.downloadAll=function(a){0===this.downloadQueue.length&&a();for(var c=0;c<this.downloadQueue.length;c++){var d=this.downloadQueue[c],b=new Image,e=this;b.addEventListener("load",function(){e.successCount+=1;e.isDone()&&a()},!1);b.addEventListener("error",function(){e.errorCount+=1;e.isDone()&&a()},!1);b.src=this.resourceRoot+d;this.cache[d]=b}};AssetManager.prototype.getTotal=function(){return this.downloadQueue.length-1};
AssetManager.prototype.getDone=function(){return this.successCount+this.errorCount};AssetManager.prototype.isDone=function(){return this.downloadQueue.length<=this.successCount+this.errorCount};AssetManager.prototype.getAsset=function(a){return this.cache[a]};window.addEventListener("load",init,!1);window.addEventListener("keydown",onKeyDown,!1);window.addEventListener("keyup",onKeyUp,!1);
var INLOADER=9,INSPLASH=10,INMENU=11,INGAME=12,INITMAP=51,INPAUSE=52,INANIMATION=55,activePlayer=new PlayerProfile,DUDE_CASH=0,DUDE_SMOOTH=1,DUDE_ADVENTURER=2,DUDE_PIXMAN=3,DUDE_BURNIE=4,DUDE_CAVOR=5,DUDE_THOR=6,DUDE_DINO=7,DUDE_KNIGHT=8,DUDE_DEEPLOOT=9,COLLECT_GOLDENEGG=0,COLLECT_CASHACTIONFIGURE=1,COLLECT_GHOSTFIGURE=2,COLLECT_MEGANOID=3,COLLECT_CHRONOTOYBOT=4,COLLECT_MAXIMUM=5,MENU_STARTSCREEN=1,MENU_MAIN=2,MENU_SETTINGS=3,MENU_BUTTONS=4,MENU_OBJECTIVES=5,MENU_NAMEENTRY=6,MENU_NEWCOMPLETED=7,MENU_CHARACTERS=
8,MENU_UNLOCKCHAR=9,MENU_CREDITS=10,MENU_COLLECTABLES=11,MENU_CONTROLLER=12,MENU_PROMOTE=13,myLoadManager=new AssetManager,displayW=480,displayH=320,lowDisplayW=240,lowDisplayH=160,imgLogo,imgUI,imgStatus,myPlayer=new player,tileMapW=30,tileMapH=20,tileMap=Array(tileMapW*tileMapH),uiAlpha,uiAlphaTarget,uiY,uiYTarget,world,level,difficulty,worldOffsetX,worldOffsetY,worldCollectCount,worldCompleteCount,worldGameOver,worldAge,worldTime,worldTimeTick,worldWaterLevel,worldFruit,didAllWorlds,didFruit,didPerfect,
didPerfectRound1,didPerfectRound2,didPerfectRound3,didCollectDiamonds,didCollectItems=Array(8),newUnlockChars=Array(32),collectableInPlay=Array(32),didWorldCollectable=!1,didCollectItems=Array(8),newUnlockChars=Array(32),playerStartX,playerStartY,scoreboard=Array(6),timeboard=Array(2),digitsboard=Array(3),animScene,animState,animSpeech,animAvatar,animDelay,animMonster,animAllowSkip,animWords=[58,8,0,30,20,1,70,16,2],splash,splashicn,splashFrame,splashDone=!1,splashAlpha,splashYSpeed,splashY,sprites=
Array(32),menuMode,menuState,nextState,menuTiming,objectivesOnScreen,objectiveYOffset,objectiveYSpeed,menuSelected,startTouchY,challengeX1,challengeX2,challengeX3,challengeX1speed,challengeX2speed,challengeX3speed,challengeTarget,inNewChallenges=!1,statusBarY,statusBarTarget,nameEntryLetters=Array(3),nameEntryIDX,nameEntryDone=!1,fxList=Array(128),fxCount=0,monsterList=Array(64),monsterCount=0;
function initGameEngine(){initSounds();myLoadManager.setRoot(drawableResource);myLoadManager.queueDownload("spl1.png");myLoadManager.queueDownload("spl2.png");myLoadManager.queueDownload("fx.png");myLoadManager.queueDownload("joystick.png");myLoadManager.queueDownload("uigame.png");myLoadManager.queueDownload("m01.png");myLoadManager.queueDownload("m02.png");myLoadManager.queueDownload("uicaptions.png");myLoadManager.queueDownload("m03.png");myLoadManager.queueDownload("m00.png");myLoadManager.queueDownload("m05.png");
myLoadManager.queueDownload("m06.png");myLoadManager.queueDownload("m07.png");myLoadManager.queueDownload("m08.png");myLoadManager.queueDownload("m09.png");myLoadManager.queueDownload("m10.png");myLoadManager.queueDownload("uifont.png");myLoadManager.queueDownload("logo.png");myLoadManager.queueDownload("uiinterface.png");myLoadManager.queueDownload("water.png");myLoadManager.queueDownload("uiachieves.png");myLoadManager.queueDownload("uiachieves2.png");myLoadManager.queueDownload("m05.png");myLoadManager.queueDownload("larcade01.png");
myLoadManager.queueDownload("larcade02.png");myLoadManager.queueDownload("larcade03.png");myLoadManager.queueDownload("larcade04.png");myLoadManager.queueDownload("larcade05.png");myLoadManager.queueDownload("anim00.png");myLoadManager.queueDownload("anim01.png");myLoadManager.queueDownload("anim02.png");myLoadManager.queueDownload("anim03.png");myLoadManager.queueDownload("anim04.png");myLoadManager.queueDownload("anim05.png");myLoadManager.queueDownload("player.png");myLoadManager.queueDownload("pladventurer.png");
myLoadManager.queueDownload("plcavorite.png");myLoadManager.queueDownload("pldeeploot.png");myLoadManager.queueDownload("plknight.png");myLoadManager.queueDownload("plpastry.png");myLoadManager.queueDownload("plpixman.png");myLoadManager.queueDownload("plscorched.png");myLoadManager.queueDownload("plsmooth.png");myLoadManager.queueDownload("plthor.png");myLoadManager.queueDownload("uipromote.png");myLoadManager.queueDownload("uicredz.png");myLoadManager.queueDownload("uiunlock.png");myLoadManager.queueDownload("uifont.png");
myLoadManager.downloadAll(function(){});activePlayer=new PlayerProfile;activePlayer.loadSettings();lastHighScore=-1;for(var a=fxList.length-1;0<=a;a--)fxList[a]=new FX;for(a=monsterList.length-1;0<=a;a--)monsterList[a]=new Monster;GameState=INLOADER}function InitMenu(a){paused=!1;menuMode=MENU_STARTSCREEN;menuSelected=nextState=menuState=-1;uiAlpha=0;uiAlphaTarget=255;activePlayer.saveSettings();GameState=INMENU;menuTiming=0;paused=!1;getMusic();a&&playBackground()}
function LogicLoop(){touchY=touchX=-1;null!=mTouch[0]&&(0<=mTouch[0].pageX&&0<=mTouch[0].pageY)&&(touchY=lowDisplayH/100*100/displayH*mTouch[0].pageY,touchX=lowDisplayW/100*100/displayW*mTouch[0].pageX);switch(GameState){case INLOADER:if(myLoadManager.isDone())splashicn=myLoadManager.getAsset("spl1.png"),splash=myLoadManager.getAsset("spl2.png"),sprites[0]=myLoadManager.getAsset("player.png"),sprites[1]=myLoadManager.getAsset("fx.png"),sprites[4]=myLoadManager.getAsset("joystick.png"),sprites[5]=
myLoadManager.getAsset("uigame.png"),sprites[6]=myLoadManager.getAsset("m01.png"),sprites[7]=myLoadManager.getAsset("m02.png"),sprites[8]=myLoadManager.getAsset("uicaptions.png"),sprites[9]=myLoadManager.getAsset("m03.png"),sprites[11]=myLoadManager.getAsset("m00.png"),sprites[13]=myLoadManager.getAsset("m06.png"),sprites[24]=myLoadManager.getAsset("uicredz.png"),sprites[25]=myLoadManager.getAsset("uiunlock.png"),sprites[26]=myLoadManager.getAsset("uifont.png"),sprites[28]=11<3*(activePlayer.achievementLevel-
1)?myLoadManager.getAsset("uiachieves2.png"):myLoadManager.getAsset("uiachieves.png"),sprites[29]=myLoadManager.getAsset("logo.png"),sprites[30]=myLoadManager.getAsset("uiinterface.png"),sprites[27]=myLoadManager.getAsset("water.png"),sprites[31]=myLoadManager.getAsset("uipromote.png"),animAllowSkip=!1,myPlayer.gameReset(),splashFrame=0,splashDone=!1,splashY=splashAlpha=0,splashYSpeed=-8,GameState=INSPLASH,playSound("FX_SPLASH");else{ctx.fillStyle="#000000";ctx.fillRect(0,0,canvas.width,canvas.height);
ctx.fillStyle="#ffffff";tx=(lowDisplayW>>1)-64;ty=lowDisplayH>>1;drawRect(tx,ty,tx+130,ty+8,makeRGBA(255,255,255,255));tx++;ty++;drawRect(tx,ty,tx+128,ty+6,makeRGBA(0,0,0,255));var a=myLoadManager.getTotal()+mySoundPool.getTotal(),c=myLoadManager.getDone()+mySoundPool.getDone();drawRect(tx,ty,tx+100/a*c,ty+6,makeRGBA(255,255,255,255))}break;case INSPLASH:drawRect(0,0,displayW,displayH,makeRGBA(255,255,255,255));setAlpha(splashAlpha);if(!splashDone||255>splashAlpha)splashAlpha+=32,255<splashAlpha&&
(splashAlpha=255);splashDone||(splashFrame+=16,96==splashFrame&&(splashFrame=0,splashDone=!0));6>splashYSpeed&&splashYSpeed++;splashY+=splashYSpeed;0<=splashY&&(splashY=0,splashYSpeed=-(splashYSpeed>>1));tx=(lowDisplayW>>1)-32;ty=(lowDisplayH>>1)-48+splashY;renderSubImageAtPoint(splashicn,tx,ty,splashFrame<<2,0,64,64);tx=(lowDisplayW>>1)-61;ty=(lowDisplayH>>1)+30;renderSubImageAtPoint(splash,tx,ty,0,16,122,18);48<worldTicks&&splashDone&&(myPlayer.gameReset(),uiAlpha=0,uiAlphaTarget=255,InitMenu(!0));
break;case INMENU:if(uiAlpha<uiAlphaTarget)uiAlpha+=32,uiAlpha>=uiAlphaTarget&&(uiAlpha=uiAlphaTarget);else if(uiAlpha>uiAlphaTarget&&(uiAlpha-=32,uiAlpha<=uiAlphaTarget)){uiAlpha=0;switch(nextState){case MENU_STARTSCREEN:menuTiming=0;menuMode=nextState;uiAlphaTarget=255;break;case MENU_MAIN:menuTiming=0;menuMode=nextState;uiAlphaTarget=255;break;case MENU_SETTINGS:menuTiming=0;menuMode=nextState;menuSelected=-1;uiAlphaTarget=255;break;case MENU_BUTTONS:menuMode=nextState;menuSelected=-1;uiAlphaTarget=
255;break;case MENU_OBJECTIVES:menuTiming=0;menuMode=nextState;uiAlphaTarget=255;objectivesOnScreen=(lowDisplayH-62)/21;objectiveYSpeed=objectiveYOffset=0;startTouchY=-1;break;case MENU_NAMEENTRY:menuMode=MENU_NAMEENTRY;uiAlphaTarget=255;nameEntryIDX=0;for(a=nameEntryLetters.length-1;0<=a;a--)nameEntryLetters[a]=activePlayer.lastNameIDX[a],0<=nameEntryLetters[a]&&nameEntryIDX++;nameEntryDone=!1;menuSelected=-1;break;case MENU_NEWCOMPLETED:initNewChallenges();menuMode=MENU_NEWCOMPLETED;uiAlphaTarget=
255;break;case MENU_CHARACTERS:worldAge=0;menuSelected=activePlayer.currentCharacter;loadCharacter(menuSelected);menuMode=nextState;uiAlphaTarget=255;break;case MENU_UNLOCKCHAR:initNewCharacter();break;case MENU_CREDITS:menuMode=nextState;menuSelected=-1;uiAlphaTarget=255;break;case MENU_PROMOTE:menuTiming=0;menuMode=nextState;uiAlphaTarget=255;break;case INITMAP:stopBackground();worldFruit=1;didCollectDiamonds=0;resetUnlockCache();for(a=32;0<=--a;)newUnlockChars[a]=!1;for(a=32;0<=--a;)collectableInPlay[a]=
!1;didWorldCollectable=!1;myPlayer.gameReset();didAllWorlds=!1;for(a=8;0<=--a;)didCollectItems[a]=0;difficulty=level=1;didPerfectRound3=didPerfectRound2=didPerfectRound1=!1;GameState=INGAME;loadCharacter(activePlayer.currentCharacter);initAnimation();break;default:menuTiming=0,GameState=nextState}nextState=-1;return}drawRect(0,0,displayW,displayH,makeRGBA(0,0,0,255));switch(menuMode){case MENU_STARTSCREEN:setAlpha(uiAlpha);ty=0;tx=(lowDisplayW>>1)-142;renderAtPoint(sprites[29],tx,ty);setAlpha(uiAlpha>>
1);tx=(lowDisplayW>>1)-59;ty=lowDisplayH-16;renderSubImageAtPoint(sprites[5],tx,ty,0,27,118,12);setAlpha(uiAlpha);12>worldTicks%24&&(isTouchBase?(tx=(lowDisplayW>>1)-45,ty=lowDisplayH-38,renderSubImageAtPoint(sprites[5],tx,ty,0,39,90,8)):(tx=(lowDisplayW>>1)-30,ty=lowDisplayH-38,renderSubImageAtPoint(sprites[5],tx,ty,0,227,61,8)));tx=1;ty=lowDisplayH-7;isTouchBase||(renderSubImageAtPoint(sprites[5],tx,ty-1,79,57,7,7),tx+=8);renderSubImageAtPoint(sprites[5],tx,ty,0,47,27,5);setAlpha(uiAlpha);if(touchReleased&&
touchX>=tx&&touchY>=lowDisplayH-16&&touchX<=tx+32||leftPressed&&!leftLocked)leftPressed?leftLocked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_SETTINGS,uiAlphaTarget=0;tx=lowDisplayW-40;isTouchBase||(tx-=8);ty=lowDisplayH-7;renderSubImageAtPoint(sprites[5],tx,ty,46,47,39,5);tx+=40;isTouchBase||renderSubImageAtPoint(sprites[5],tx,ty-1,87,57,7,7);setAlpha(uiAlpha);if(touchReleased&&touchX>=tx&&touchY>=lowDisplayH-16&&touchX<=tx+32||rightPressed&&!rightLocked)rightPressed?rightLocked=!0:
touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_OBJECTIVES,uiAlphaTarget=0;menuTiming++;99<menuTiming&&(uiAlphaTarget=0,nextState=MENU_MAIN,menuTiming=0);setAlpha(255);if(touchReleased&&0<touchX&&32<touchY&&touchY<lowDisplayH-32||actionButton2&&!actionButton2Locked)actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),world=1,uiAlphaTarget=0,nextState=INITMAP;break;case MENU_MAIN:setAlpha(uiAlpha);tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],
tx,ty,0,0,lowDisplayW,lowDisplayH);tx=(lowDisplayW>>1)-30;ty=24;renderSubImageAtPoint(sprites[5],tx,ty,23,98,59,8);ty=42;for(c=0;5>c;c++){if(c!=lastHighScore||12>worldTicks%24){tx=(lowDisplayW>>1)-64;renderSubImageAtPoint(sprites[5],tx,ty,7*(c+1),65,7,8);tx+=8;0==c?(renderSubImageAtPoint(sprites[26],tx,ty,126,0,14,8),tx+=14):(1==c?(renderSubImageAtPoint(sprites[26],tx,ty,91,0,7,8),tx+=7,renderSubImageAtPoint(sprites[26],tx,ty,21,0,7,8)):2==c?(renderSubImageAtPoint(sprites[26],tx,ty,119,0,7,8),tx+=
7,renderSubImageAtPoint(sprites[26],tx,ty,21,0,7,8)):(renderSubImageAtPoint(sprites[26],tx,ty,133,0,7,8),tx+=7,renderSubImageAtPoint(sprites[26],tx,ty,49,0,7,8)),tx+=7);tx+=12;setDigits(activePlayer.highscore[c],scoreboard);for(a=0;6>a;a++)renderSubImageAtPoint(sprites[5],tx,ty,7*scoreboard[a],65,7,8),tx+=7;tx+=28;for(a=0;a<activePlayer.highname[c].length;a++)0<=activePlayer.highname[c].charCodeAt(a)&&renderSubImageAtPoint(sprites[26],tx,ty,7*(activePlayer.highname[c].charCodeAt(a)-65),0,7,8),tx+=
7}ty+=10}menuTiming++;165<menuTiming&&(uiAlphaTarget=0,nextState=MENU_STARTSCREEN);tx=lowDisplayW-24;ty=8;setAlpha(uiAlpha);if(touchReleased&&0<touchX&&32<touchY||actionButton2&&!actionButton2Locked)actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),uiAlphaTarget=0,nextState=MENU_STARTSCREEN;setAlpha(255);break;case MENU_SETTINGS:setAlpha(uiAlpha);leftPressed&&(!leftLocked&&0<menuSelected)&&(leftLocked=!0,menuSelected--,playSound("FX_PICKUP"));rightPressed&&(!rightLocked&&
2>menuSelected)&&(rightLocked=!0,menuSelected++,2<menuSelected&&(menuSelected=2),playSound("FX_PICKUP"));tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],tx,ty,0,0,lowDisplayW,lowDisplayH);tx=(lowDisplayW>>1)-25;ty=24;renderSubImageAtPoint(sprites[5],tx,ty,0,106,49,8);tx=keyBoardOut?(lowDisplayW>>1)-54:(lowDisplayW>>1)-72;ty=34;0==menuSelected?setAlpha(255):setAlpha(160);renderSubImageAtPoint(sprites[5],tx,ty,48,142,24,28);setAlpha(255);if(touchReleased&&touchX>=tx&&touchY>=
ty&&touchX<=tx+22&&touchY<=ty+28||0==menuSelected&&actionButton2&&!actionButton2Locked)actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),loadCharacter(activePlayer.currentCharacter),nextState=MENU_CHARACTERS,uiAlphaTarget=0;tx+=36;1==menuSelected?setAlpha(255):setAlpha(160);activePlayer.useMusic?renderSubImageAtPoint(sprites[5],tx,ty,0,114,24,28):activePlayer.useSFX?renderSubImageAtPoint(sprites[5],tx,ty,155,186,24,28):renderSubImageAtPoint(sprites[5],tx,ty,24,114,24,28);
setAlpha(255);if(touchReleased&&touchX>=tx&&touchY>=ty&&touchX<=tx+22&&touchY<=ty+28||1==menuSelected&&actionButton2&&!actionButton2Locked)playSound("FX_PICKUP"),actionButton2?actionButton2Locked=!0:touchReleased=!1,activePlayer.useMusic&&stopBackground(),activePlayer.useMusic?activePlayer.useMusic=!1:activePlayer.useSFX?activePlayer.useSFX=!1:(activePlayer.useSFX=!0,activePlayer.useMusic=!0),activePlayer.useMusic&&playBackground();if(!keyBoardOut&&(tx+=36,2==menuSelected?setAlpha(255):setAlpha(160),
renderSubImageAtPoint(sprites[5],tx,ty,24,142,24,28),setAlpha(255),touchReleased&&touchX>=tx&&touchY>=ty&&touchX<=tx+22&&touchY<=ty+28||2==menuSelected&&actionButton2&&!actionButton2Locked))actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_BUTTONS,uiAlphaTarget=0;tx+=36;!keyBoardOut&&3==menuSelected||keyBoardOut&&2==menuSelected?setAlpha(255):setAlpha(160);renderSubImageAtPoint(sprites[5],tx,ty,132,186,22,30);setAlpha(255);if(touchReleased&&touchX>=tx&&touchY>=
ty&&touchX<=tx+22&&touchY<=ty+28||actionButton2&&!actionButton2Locked&&(!keyBoardOut&&3==menuSelected||keyBoardOut&&2==menuSelected))actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_CREDITS,uiAlphaTarget=0;isTouchBase?(tx=(lowDisplayW>>1)-33,ty+=32,renderSubImageAtPoint(sprites[5],tx,ty,0,170,66,5),tx=(lowDisplayW>>1)-41,ty+=8,renderSubImageAtPoint(sprites[5],tx,ty,80,0,38,8),touchReleased&&(touchX>=tx&&touchY>=ty&&touchX<=tx+40&&touchY<=ty+28)&&(touchReleased=
!1,playSound("FX_PICKUP")),tx+=41,renderSubImageAtPoint(sprites[5],tx,ty,80,8,41,8),touchReleased&&(touchX>=tx&&touchY>=ty&&touchX<=tx+40&&touchY<=ty+28)&&(touchReleased=!1,playSound("FX_PICKUP"))):(tx=(lowDisplayW>>1)-35,ty+=64,renderSubImageAtPoint(sprites[5],tx,ty,55,222,71,5));tx=lowDisplayW-16;ty=lowDisplayH-6;isTouchBase||(tx-=14,renderSubImageAtPoint(sprites[5],tx,ty,100,54,13,5),tx+=14);renderSubImageAtPoint(sprites[5],tx,ty,29,47,15,5);if(backPressed&&!backLocked||actionButton1&&!actionButton1Locked||
actionButton2&&!actionButton2Locked||touchReleased&&touchX>=lowDisplayW-32&&touchY>=lowDisplayH-24)backPressed?backLocked=!0:actionButton1?actionButton1Locked=!0:actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_STARTSCREEN,menuTiming=uiAlphaTarget=0;break;case MENU_BUTTONS:setAlpha(uiAlpha);tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],tx,ty,0,0,lowDisplayW,lowDisplayH);tx=(lowDisplayW>>1)-46;ty=24;renderSubImageAtPoint(sprites[5],
tx,ty,50,106,92,8);tx=(lowDisplayW>>1)-33;ty=(lowDisplayH>>1)-11;56<activePlayer.buttonDistance&&setAlpha(128);renderSubImageAtPoint(sprites[5],tx,ty,72,114,23,28);setAlpha(255);if(touchReleased&&touchX>=tx&&touchY>=ty&&touchX<=tx+22&&touchY<=ty+28||0==menuSelected&&actionButton2&&!actionButton2Locked)actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),64>activePlayer.buttonDistance&&(activePlayer.buttonDistance+=8);tx+=36;0==activePlayer.buttonDistance&&setAlpha(128);renderSubImageAtPoint(sprites[5],
tx,ty,72,142,24,28);setAlpha(255);if(touchReleased&&touchX>=tx&&touchY>=ty&&touchX<=tx+22&&touchY<=ty+28||1==menuSelected&&actionButton2&&!actionButton2Locked)actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),0<activePlayer.buttonDistance&&(activePlayer.buttonDistance-=8),0>activePlayer.buttonDistance&&(activePlayer.buttonDistance=0);tx=4;ty=lowDisplayH-34;renderSubImageAtPoint(sprites[4],tx,ty,0,0,30,30);tx=32+activePlayer.buttonDistance;renderSubImageAtPoint(sprites[4],
tx,ty,30,0,30,30);tx=lowDisplayW-16;ty=lowDisplayH-6;isTouchBase||(tx-=14,renderSubImageAtPoint(sprites[5],tx,ty,100,54,13,5),tx+=14);renderSubImageAtPoint(sprites[5],tx,ty,29,47,15,5);if(backPressed&&!backLocked||touchReleased&&touchX>=lowDisplayW-32&&touchY>=lowDisplayH-24)backPressed?backLocked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_SETTINGS,menuTiming=uiAlphaTarget=0;break;case MENU_OBJECTIVES:setAlpha(uiAlpha);tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],
tx,ty,0,0,lowDisplayW,lowDisplayH);tx=(lowDisplayW>>1)-35;ty=24;renderSubImageAtPoint(sprites[5],tx,ty,0,178,70,8);tx=(lowDisplayW>>1)+40;renderSubImageAtPoint(sprites[5],tx,ty,87,57,7,7);if(touchReleased&&touchX>=tx-8&&touchY>=ty-24&&touchX<=tx+64&&touchY<=ty+8||rightPressed&&!rightLocked)rightPressed?rightLocked=!0:touchReleased=!1,playSound("FX_PICKUP"),menuMode=MENU_COLLECTABLES,menuSelected=-1;tx=(lowDisplayW>>1)-63;ty=42;objectiveYOffset=3*(activePlayer.achievementLevel-1);for(a=0;3>a;a++)objectiveYOffset+
a<PlayerProfile.A_MAXACHIEVEMENTS&&(activePlayer.isUnlocked(objectiveYOffset+a)?renderSubImageAtPoint(sprites[5],tx,ty,51,82,16,16):renderSubImageAtPoint(sprites[5],tx,ty,35,82,16,16),activePlayer.isUnlocked(objectiveYOffset+a)||setAlpha(128),renderSubImageAtPoint(sprites[28],tx+20,ty+2,0,11*activePlayer.getAchievementIDX(objectiveYOffset+a),108,11),setAlpha(255),ty+=21);tx=(lowDisplayW>>1)-35;tx=9<activePlayer.achievementLevel?tx-8:tx-4;ty=105;renderSubImageAtPoint(sprites[5],tx,ty,71,170,71,8);
tx+=72;setDigits(activePlayer.achievementLevel,scoreboard);foundFirst=!1;for(a=scoreboard.length;0<=--a;)if(foundFirst||0!=scoreboard[a])renderSubImageAtPoint(sprites[5],tx,ty,7*scoreboard[a],208,7,8),tx+=8;tx=lowDisplayW-16;ty=lowDisplayH-6;setAlpha(uiAlpha);isTouchBase||(tx-=14,renderSubImageAtPoint(sprites[5],tx,ty,100,54,13,5),tx+=14);renderSubImageAtPoint(sprites[5],tx,ty,29,47,15,5);if(touchReleased&&touchX>=tx&&touchY>=lowDisplayH-48&&touchX<=tx+32||actionButton1&&!actionButton1Locked||backPressed&&
!backLocked)backPressed?backLocked=!0:actionButton1?actionButton1Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_STARTSCREEN,uiAlphaTarget=0;break;case MENU_NAMEENTRY:setAlpha(uiAlpha);tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],tx,ty,0,0,lowDisplayW,lowDisplayH);setAlpha(255);leftPressed&&!leftLocked&&(leftLocked=!0,menuSelected--,0>menuSelected&&(menuSelected=0));rightPressed&&!rightLocked&&(rightLocked=!0,menuSelected++,28<menuSelected&&(menuSelected=
28));upPressed&&!upLocked&&(upLocked=!0,28==menuSelected?menuSelected--:menuSelected-=8,0>menuSelected&&(menuSelected=0));downPressed&&!downLocked&&(downLocked=!0,menuSelected=0>menuSelected?0:menuSelected+8,27<menuSelected&&(menuSelected=27));if(12>worldTicks%24){setDigits(myPlayer.score,scoreboard);tx=(lowDisplayW>>1)-24;ty=8+myPlayer.scoreY;for(a=0;6>a;a++)renderSubImageAtPoint(sprites[5],tx,ty,7*scoreboard[a],65,7,8),tx+=7}tx=(lowDisplayW>>1)-38;ty=24;renderSubImageAtPoint(sprites[5],tx,ty,0,
98,75,8);tx=(lowDisplayW>>1)-12;ty+=15;for(a=0;3>a;a++)0<=nameEntryLetters[a]?renderSubImageAtPoint(sprites[26],tx,ty,7*nameEntryLetters[a],0,7,8):renderSubImageAtPoint(sprites[5],tx+2,ty+6,116,6,3,2),tx+=8;tx=(lowDisplayW>>1)-80;ty+=12;for(a=0;28>a;a++)actionButton2&&(!actionButton2Locked&&a==menuSelected)&&(actionButton2Locked=!0,26==a?0<nameEntryIDX&&(nameEntryIDX--,nameEntryLetters[nameEntryIDX]=-1,playSound("FX_PICKUP")):27==a?nameEntryDone=!0:nameEntryIDX<nameEntryLetters.length&&(nameEntryLetters[nameEntryIDX]=
a,nameEntryIDX++,playSound("FX_PICKUP"))),touchReleased&&(touchX>=tx&&touchY>=ty&&touchX<=tx+20&&touchY<=ty+20)&&(touchReleased=!1,26==a?0<nameEntryIDX&&(nameEntryIDX--,nameEntryLetters[nameEntryIDX]=-1,playSound("FX_PICKUP")):27==a?nameEntryDone=!0:nameEntryIDX<nameEntryLetters.length&&(nameEntryLetters[nameEntryIDX]=a,nameEntryIDX++,playSound("FX_PICKUP"))),renderSubImageAtPoint(sprites[26],tx+7,ty+6,7*a,0,7,8),menuSelected==a&&(renderSubImageAtPoint(sprites[5],tx,ty,123,0,3,3),renderSubImageAtPoint(sprites[5],
tx+19,ty,127,0,3,3),renderSubImageAtPoint(sprites[5],tx,ty+19,123,5,3,3),renderSubImageAtPoint(sprites[5],tx+19,ty+19,127,5,3,3)),tx+=20,tx>(lowDisplayW>>1)+63&&(tx=(lowDisplayW>>1)-80,ty+=20);keyBoardOut||(tx=lowDisplayW-20,ty=lowDisplayH-7,renderSubImageAtPoint(sprites[5],tx,ty,100,60,15,5));if(0<nameEntryIDX&&(nameEntryDone||!keyBoardOut&&touchReleased&&touchX>=tx-10&&touchY>=ty-16&&touchX<=tx+76&&touchY<=ty+16))nameEntryDone||(touchReleased=!1),playSound("FX_PICKUP"),nameEntryDone=!1,didUnlockCurrent()?
(nextState=MENU_NEWCOMPLETED,uiAlphaTarget=0):didUnlockCharacter()?(nextState=MENU_UNLOCKCHAR,uiAlphaTarget=0):(nextState=MENU_MAIN,uiAlphaTarget=0,playBackground()),setHighScoreName();break;case MENU_NEWCOMPLETED:setAlpha(uiAlpha);tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],0,0,0,0,lowDisplayW,lowDisplayH);setAlpha(255);inNewChallenges?(tx=(lowDisplayW>>1)-46,ty=24,renderSubImageAtPoint(sprites[5],tx,ty,0,98,21,8),tx+=23):(tx=(lowDisplayW>>1)-35,ty=24);renderSubImageAtPoint(sprites[5],
tx,ty,0,178,70,8);tx=(lowDisplayW>>1)-63;ty=42;nameEntryIDX=3*(activePlayer.achievementLevel-1);for(a=0;3>a;a++)a+nameEntryIDX<PlayerProfile.A_MAXACHIEVEMENTS&&(0==a?tx=challengeX1:1==a?tx=challengeX2:2==a&&(tx=challengeX3),worldAge==12+24*a&&(unlockCache[nameEntryIDX+a]?playSound("FX_DIAMOND"):worldAge+=24),worldAge>=12+24*a&&unlockCache[nameEntryIDX+a]||activePlayer.isUnlocked(nameEntryIDX+a)&&!unlockCache[nameEntryIDX+a]?(renderSubImageAtPoint(sprites[5],tx,ty,51,82,16,16),setAlpha(255)):(renderSubImageAtPoint(sprites[5],
tx,ty,35,82,16,16),setAlpha(128)),renderSubImageAtPoint(sprites[28],tx+20,ty+2,0,11*activePlayer.getAchievementIDX(nameEntryIDX+a),108,11),setAlpha(255)),ty+=22;tx=(lowDisplayW>>1)-35;tx=9<activePlayer.achievementLevel?tx-8:tx-4;renderSubImageAtPoint(sprites[5],tx,ty,71,170,71,8);tx+=72;setDigits(activePlayer.achievementLevel,scoreboard);foundFirst=!1;for(a=scoreboard.length;0<=--a;)if(foundFirst||0!=scoreboard[a])renderSubImageAtPoint(sprites[5],tx,ty,7*scoreboard[a],208,7,8),tx+=8;0<challengeTarget&&
(challengeX1>challengeTarget&&(challengeX1speed=challengeX1-challengeTarget>>1,32<challengeX1speed&&(challengeX1speed=32),challengeX1-=challengeX1speed,challengeX1<=challengeTarget+4&&(challengeX1=challengeTarget)),challengeX2>challengeTarget&&(challengeX2speed=challengeX2-challengeTarget>>1,32<challengeX2speed&&(challengeX2speed=32),challengeX2-=challengeX2speed,challengeX2<=challengeTarget+4&&(challengeX2=challengeTarget)),challengeX3>challengeTarget&&(challengeX3speed=challengeX3-challengeTarget>>
1,32<challengeX3speed&&(challengeX3speed=32),challengeX3-=challengeX3speed,challengeX3<=challengeTarget+4&&(challengeX3=challengeTarget)));challengeX1==challengeTarget&&(challengeX2==challengeTarget&&challengeX3==challengeTarget)&&worldAge++;if(96<worldAge)if(0>challengeTarget)challengeX1speed+=challengeX1speed,8<challengeX1speed&&(1==challengeX2speed&&playSound("FX_SLIDE"),challengeX2speed+=challengeX2speed),8<challengeX2speed&&(1==challengeX3speed&&playSound("FX_SLIDE"),challengeX3speed+=challengeX3speed),
challengeX1-=challengeX1speed,challengeX2-=challengeX2speed,challengeX3-=challengeX3speed,challengeX1<=challengeTarget&&(challengeX1=challengeTarget),challengeX2<=challengeTarget&&(challengeX2=challengeTarget),challengeX3<=challengeTarget&&(challengeX3=challengeTarget,activePlayer.getLevel(),initNewChallenges(),inNewChallenges=!0,sprites[28]=11<3*(activePlayer.achievementLevel-1)?myLoadManager.getAsset("uiachieves2.png"):myLoadManager.getAsset("uiachieves.png"));else if(activePlayer.checkLevel())challengeTarget=
-200,challengeX3speed=challengeX2speed=challengeX1speed=1,playSound("FX_SLIDE");else if(worldAge=128,tx=lowDisplayW-16,ty=lowDisplayH-6,renderSubImageAtPoint(sprites[5],tx,ty,100,60,15,5),touchReleased&&touchX>lowDisplayW-32&&touchY>lowDisplayH-20||actionButton2&&!actionButton2Locked||backPressed&&!backLocked)backPressed?backLocked=!0:actionButton1?actionButton1Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),uiAlphaTarget=0,didUnlockCharacter()?nextState=MENU_UNLOCKCHAR:(nextState=MENU_STARTSCREEN,
playBackground());break;case MENU_CHARACTERS:setAlpha(uiAlpha);leftPressed&&(!leftLocked&&0<menuSelected)&&(leftLocked=!0,playSound("FX_PICKUP"),menuSelected--,activePlayer.charUnlocks[menuSelected]&&(activePlayer.currentCharacter=menuSelected),loadCharacter(menuSelected));rightPressed&&(!rightLocked&&8>menuSelected)&&(rightLocked=!0,playSound("FX_PICKUP"),menuSelected++,activePlayer.charUnlocks[menuSelected]&&(activePlayer.currentCharacter=menuSelected),loadCharacter(menuSelected));upPressed&&!upLocked&&
(upLocked=!0,playSound("FX_PICKUP"),menuSelected-=4,0>menuSelected&&(menuSelected=0),activePlayer.charUnlocks[menuSelected]&&(activePlayer.currentCharacter=menuSelected),loadCharacter(menuSelected));downPressed&&!downLocked&&(downLocked=!0,playSound("FX_PICKUP"),menuSelected+=4,8<menuSelected&&(menuSelected=8),activePlayer.charUnlocks[menuSelected]&&(activePlayer.currentCharacter=menuSelected),loadCharacter(menuSelected));tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],
0,0,0,0,lowDisplayW,lowDisplayH);tx=(lowDisplayW>>1)-30;ty=24;renderSubImageAtPoint(sprites[5],tx,ty,82,98,61,8);tx=(lowDisplayW>>1)-60;ty=32;activePlayer.useArcadeMode&&(ty+=8);worldAge++;for(a=0;9>a;a++)activePlayer.charUnlocks[a]?a==menuSelected?(0<myPlayer.FrameDelay&&160>myPlayer.xOffset?myPlayer.FrameDelay--:(myPlayer.FrameDelay=2,myPlayer.xOffset+=16,128==myPlayer.xOffset&&4!=getRandom(8)&&(myPlayer.xOffset=32),160<myPlayer.xOffset&&(myPlayer.xOffset=0)),renderSubImageAtPoint(sprites[0],tx+
4,ty+4,myPlayer.xOffset,0,16,16)):renderSubImageAtPoint(sprites[25],tx+4,ty+4,a<<4,0,16,16):renderSubImageAtPoint(sprites[25],tx+4,ty+4,a<<4,16,16,16),touchReleased&&(touchX>=tx&&touchY>=ty&&touchX<=tx+24&&touchY<=ty+24)&&(touchReleased=!1,activePlayer.charUnlocks[a]&&(activePlayer.currentCharacter=a),loadCharacter(a),playSound("FX_PICKUP"),menuSelected=a),a==menuSelected&&(renderSubImageAtPoint(sprites[5],tx,ty,123,0,3,3),renderSubImageAtPoint(sprites[5],tx+21,ty,127,0,3,3),renderSubImageAtPoint(sprites[5],
tx,ty+21,123,5,3,3),renderSubImageAtPoint(sprites[5],tx+21,ty+21,127,5,3,3)),tx+=24,tx>(lowDisplayW>>1)+48&&(tx=(lowDisplayW>>1)-60,ty+=24);tx=(lowDisplayW>>1)-66;ty=104;activePlayer.useArcadeMode&&(ty+=8);setAlpha(120);renderSubImageAtPoint(sprites[5],tx,ty,0,186,132,22);setAlpha(255);if(0<=menuSelected&&!activePlayer.charUnlocks[menuSelected])switch(tx=(lowDisplayW>>1)-21,ty+=3,renderSubImageAtPoint(sprites[5],tx,ty,70,208,42,8),ty+=12,menuSelected){case 1:tx=(lowDisplayW>>1)-29;renderSubImageAtPoint(sprites[25],
tx,ty,0,72,58,5);break;case 2:tx=(lowDisplayW>>1)-29;renderSubImageAtPoint(sprites[25],tx,ty,0,77,58,5);break;case 3:tx=(lowDisplayW>>1)-19;renderSubImageAtPoint(sprites[25],tx,ty,58,77,37,5);break;case 4:tx=(lowDisplayW>>1)-29;renderSubImageAtPoint(sprites[25],tx,ty,0,82,58,5);break;case 5:tx=(lowDisplayW>>1)-12;renderSubImageAtPoint(sprites[25],tx,ty,59,72,23,5);break;case 6:tx=(lowDisplayW>>1)-12;renderSubImageAtPoint(sprites[25],tx,ty,59,72,23,5);break;case 7:tx=(lowDisplayW>>1)-26;renderSubImageAtPoint(sprites[25],
tx,ty,59,82,53,5);break;case 8:tx=(lowDisplayW>>1)-26,renderSubImageAtPoint(sprites[25],tx,ty,84,72,58,5)}else switch(ty+=3,menuSelected){case 0:tx=(lowDisplayW>>1)-14;renderSubImageAtPoint(sprites[25],tx,ty,0,32,28,8);break;case 1:tx=(lowDisplayW>>1)-49;renderSubImageAtPoint(sprites[25],tx,ty,0,40,98,8);break;case 2:tx=(lowDisplayW>>1)-35;renderSubImageAtPoint(sprites[25],tx,ty,28,32,70,8);break;case 3:tx=(lowDisplayW>>1)-54;renderSubImageAtPoint(sprites[25],tx,ty,0,48,108,8);break;case 4:tx=(lowDisplayW>>
1)-21;renderSubImageAtPoint(sprites[25],tx,ty,0,56,42,8);break;case 5:tx=(lowDisplayW>>1)-25;renderSubImageAtPoint(sprites[25],tx,ty,42,56,51,8);break;case 6:tx=(lowDisplayW>>1)-14;renderSubImageAtPoint(sprites[25],tx,ty,56,64,28,8);break;case 7:tx=(lowDisplayW>>1)-14;renderSubImageAtPoint(sprites[25],tx,ty,99,32,28,8);break;case 8:tx=(lowDisplayW>>1)-32;renderSubImageAtPoint(sprites[25],tx,ty,84,64,65,8);break;case 9:tx=(lowDisplayW>>1)-28,renderSubImageAtPoint(sprites[25],tx,ty,0,64,51,8)}tx=lowDisplayW-
16;ty=lowDisplayH-6;isTouchBase||(tx-=14,renderSubImageAtPoint(sprites[5],tx,ty,100,54,13,5),tx+=14);renderSubImageAtPoint(sprites[5],tx,ty,29,47,15,5);if(backPressed&&!backLocked||actionButton1&&!actionButton1Locked||touchReleased&&touchX>=lowDisplayW-32&&touchY>=lowDisplayH-24)backPressed?backLocked=!0:actionButton1?actionButton1Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_SETTINGS,menuTiming=uiAlphaTarget=0;break;case MENU_CREDITS:setAlpha(uiAlpha);leftPressed&&(!leftLocked&&
0<menuSelected)&&(leftLocked=!0,menuSelected--,playSound("FX_PICKUP"));rightPressed&&(!rightLocked&&3>menuSelected)&&(rightLocked=!0,menuSelected++,playSound("FX_PICKUP"));tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],0,0,0,0,lowDisplayW,lowDisplayH);tx=(lowDisplayW>>1)-24;ty=24;renderSubImageAtPoint(sprites[5],tx,ty,107,90,47,8);tx=(lowDisplayW>>1)-59;ty=(lowDisplayH>>1)-43;renderAtPoint(sprites[24],tx,ty);tx=lowDisplayW-16;ty=lowDisplayH-6;isTouchBase||(tx-=14,renderSubImageAtPoint(sprites[5],
tx,ty,100,54,13,5),tx+=14);renderSubImageAtPoint(sprites[5],tx,ty,29,47,15,5);if(backPressed&&!backLocked||actionButton1&&!actionButton1Locked||touchReleased&&touchX>=lowDisplayW-32&&touchY>=lowDisplayH-24)backPressed?backLocked=!0:actionButton1?actionButton1Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_SETTINGS,menuTiming=uiAlphaTarget=0;break;case MENU_COLLECTABLES:setAlpha(uiAlpha);tx=142-(lowDisplayW>>1);0>tx&&(tx=0);ty=0;renderSubImageAtPoint(sprites[30],0,0,0,0,lowDisplayW,
lowDisplayH);tx=(lowDisplayW>>1)-42;ty=24;renderSubImageAtPoint(sprites[5],tx,ty,118,29,84,8);tx=(lowDisplayW>>1)-54;renderSubImageAtPoint(sprites[5],tx,ty,79,57,7,7);if(touchReleased&&touchX>=tx-64&&touchY>=ty-24&&touchX<=tx+8&&touchY<=ty+8||leftPressed&&!leftLocked)leftPressed?leftLocked=!0:touchReleased=!1,playSound("FX_PICKUP"),menuMode=MENU_OBJECTIVES;tx=(lowDisplayW>>1)-63;tx=(lowDisplayW>>1)-48;ty=42;activePlayer.useArcadeMode&&(ty+=8);for(a=0;a<COLLECT_MAXIMUM-1;a++)activePlayer.collectables[a]&&
renderSubImageAtPoint(sprites[11],tx,ty,12*a,12,12,12),renderSubImageAtPoint(sprites[5],tx-3,ty-5,165,0,18,24),touchReleased&&(touchX>=tx-4&&touchY>=ty-5&&touchX<=tx+24&&touchY<=ty+19)&&(touchReleased=!1,playSound("FX_PICKUP"),menuSelected=a),tx+=24,tx>(lowDisplayW>>1)+48&&(tx=(lowDisplayW>>1)-48,ty+=24);tx=(lowDisplayW>>1)-66;ty=114;activePlayer.useArcadeMode&&(ty+=8);setAlpha(120);renderSubImageAtPoint(sprites[5],tx,ty,0,186,132,22);setAlpha(255);if(0<=menuSelected&&activePlayer.collectables[menuSelected])switch(ty+=
3,menuSelected){case COLLECT_GOLDENEGG:tx=(lowDisplayW>>1)-28;renderSubImageAtPoint(sprites[7],tx,ty,0,0,57,8);break;case COLLECT_CASHACTIONFIGURE:tx=(lowDisplayW>>1)-57;renderSubImageAtPoint(sprites[7],tx,ty,0,8,114,8);break;case COLLECT_GHOSTFIGURE:tx=(lowDisplayW>>1)-30;renderSubImageAtPoint(sprites[7],tx,ty,50,0,59,8);break;case COLLECT_MEGANOID:tx=(lowDisplayW>>1)-50,renderSubImageAtPoint(sprites[7],tx,ty,0,16,100,8)}tx=lowDisplayW-16;ty=lowDisplayH-6;setAlpha(uiAlpha);isTouchBase||(tx-=14,renderSubImageAtPoint(sprites[5],
tx,ty,100,54,13,5),tx+=14);renderSubImageAtPoint(sprites[5],tx,ty,29,47,15,5);if(touchReleased&&touchX>=tx&&touchY>=lowDisplayH-48&&touchX<=tx+32||actionButton1&&!actionButton1Locked||backPressed&&!backLocked)backPressed?backLocked=!0:actionButton1?actionButton1Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),nextState=MENU_STARTSCREEN,uiAlphaTarget=0;break;case MENU_PROMOTE:setAlpha(uiAlpha),tx=(lowDisplayW>>1)-142,ty=0,renderAtPoint(sprites[28],tx,ty),menuTiming++,165<menuTiming&&(uiAlphaTarget=
0,nextState=MENU_STARTSCREEN),mouseButton&1&&window.open("http://orangepixel.net/chronocash","Chrono&Cash braggin",""),actionButton2&&!actionButton2Locked&&(actionButton2Locked=!0,playSound("FX_PICKUP"),uiAlphaTarget=0,nextState=MENU_STARTSCREEN),setAlpha(255)}break;case INITMAP:paused=!1;loadWorld();lastHighScore=-1;worldCompleteCount=0;worldOffsetX=-(lowDisplayW-240>>1);worldOffsetY=0;worldTime=100;worldAge=worldTimeTick=0;worldGameOver=-1;didFruit=!1;didPerfect=!0;GameState=INGAME;worldWaterLevel=
lowDisplayH;fxAdd(myPlayer.x,myPlayer.y,FX.fAPPEAR,0);break;case INPAUSE:paused=!0;renderScene();leftPressed&&!leftLocked&&(leftLocked=!0,menuSelected--,0>menuSelected&&(menuSelected=0));rightPressed&&!rightLocked&&(rightLocked=!0,-1==menuSelected?menuSelected=1:menuSelected++,1<menuSelected&&(menuSelected=1));uiAlpha<uiAlphaTarget?(uiAlpha+=16,uiAlpha>uiAlphaTarget&&(uiAlpha=uiAlphaTarget)):uiAlpha>uiAlphaTarget&&(uiAlpha-=16,uiAlpha<uiAlphaTarget&&(uiAlpha=uiAlphaTarget));100>menuMode&&menuMode++;
0!=uiAlpha&&(uiAlphaTarget=16>menuMode?255:0,setAlpha(uiAlpha),ty=(lowDisplayH>>1)-16,ctx.save(),ctx.translate(lowDisplayW>>1<<useMultiFactor,ty<<useMultiFactor),16>menuMode?ctx.scale(1/48*(menuMode<<2),1/48*(menuMode<<2)):ctx.scale(1/48*(32-menuMode<<2),1/48*(32-menuMode<<2)),ctx.translate(-(lowDisplayW>>1)<<useMultiFactor,-ty<<useMultiFactor),tx=(lowDisplayW>>1)-75,ty=(lowDisplayH>>1)-35,renderSubImageAtPoint(sprites[8],tx,ty,0,69,149,36),ctx.restore());setAlpha(255);ty=(lowDisplayH>>1)-4+uiY;drawRect(0,
ty,lowDisplayW,ty+30,makeRGBA(255,255,255,128));tx=activePlayer.useArcadeMode?(lowDisplayW>>1)-71:(lowDisplayW>>1)-64;ty=(lowDisplayH>>1)+uiY+6;0==menuSelected?setScale(tx+15,ty+11,2.2,2.2):setScale(tx+15,ty+11,2,2);renderSubImageAtPoint(sprites[5],tx,ty,27,16,31,11);endScale();if(touchReleased&&touchX>=tx&&touchY>=ty&&touchX<=tx+62&&touchY<=ty+22||actionButton2&&!actionButton2Locked&&0==menuSelected)actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),paused=!1,GameState=
INGAME;tx=activePlayer.useArcadeMode?(lowDisplayW>>1)+5:(lowDisplayW>>1)+15;ty=(lowDisplayH>>1)+uiY+6;1==menuSelected?(setScale(tx+14,ty+11,2.2,2.2),renderSubImageAtPoint(sprites[5],tx-2,ty-2,30,54,27,11)):(setScale(tx+14,ty+11,2,2),renderSubImageAtPoint(sprites[5],tx,ty,30,54,27,11));endScale();if(touchReleased&&touchX>=tx&&touchY>=ty&&touchX<=tx+62&&touchY<=ty+22||actionButton2&&!actionButton2Locked&&1==menuSelected)actionButton2?actionButton2Locked=!0:touchReleased=!1,playSound("FX_PICKUP"),paused=
!1,InitMenu(!0);backPressed&&!backLocked&&(backLocked=!0,paused=!1,InitMenu(!0));break;case INANIMATION:myPlayer.leftPressed=!1;myPlayer.rightPressed=!1;myPlayer.jumpPressed=!1;drawRect(0,0,displayW,displayH,makeRGBA(0,0,0,255));tx=(lowDisplayW>>1)-70;ty=(lowDisplayH>>1)-56>>3<<3;renderSubImageAtPoint(sprites[31],tx,ty,0,0,140,80);switch(world){case 1:ty=((lowDisplayH>>1)-56>>3<<3)+86;didAllWorlds?(tx=(lowDisplayW>>1)-68,renderSubImageAtPoint(sprites[31],tx,ty,0,80,136,17)):(tx=(lowDisplayW>>1)-60,
renderSubImageAtPoint(sprites[31],tx,ty,0,80,121,17));break;case 2:ty=((lowDisplayH>>1)-56>>3<<3)+86;didAllWorlds?(tx=(lowDisplayW>>1)-55,renderSubImageAtPoint(sprites[31],tx,ty,0,80,110,17)):(tx=(lowDisplayW>>1)-47,renderSubImageAtPoint(sprites[31],tx,ty,0,80,94,17));break;case 3:ty=((lowDisplayH>>1)-34>>3<<3)+86;didAllWorlds?(tx=(lowDisplayW>>1)-45,renderSubImageAtPoint(sprites[31],tx,ty,0,80,90,17)):(tx=(lowDisplayW>>1)-38,renderSubImageAtPoint(sprites[31],tx,ty,0,80,76,17));break;case 4:ty=((lowDisplayH>>
1)-34>>3<<3)+86;didAllWorlds?(tx=(lowDisplayW>>1)-60,renderSubImageAtPoint(sprites[31],tx,ty,0,80,120,17)):(tx=(lowDisplayW>>1)-52,renderSubImageAtPoint(sprites[31],tx,ty,0,80,103,17));break;case 5:ty=((lowDisplayH>>1)-34>>3<<3)+86;didAllWorlds?(tx=(lowDisplayW>>1)-52,renderSubImageAtPoint(sprites[31],tx,ty,0,80,104,17)):(tx=(lowDisplayW>>1)-45,renderSubImageAtPoint(sprites[31],tx,ty,0,80,90,17));break;case 99:tx=(lowDisplayW>>1)-41,ty=((lowDisplayH>>1)-34>>3<<3)+86,renderSubImageAtPoint(sprites[31],
tx,ty,0,80,82,17)}tx=(lowDisplayW>>1)-70;ty=(lowDisplayH>>1)-56>>3<<3;switch(animScene){case 1:switch(animState){case 0:myPlayer.x<tx+140?myPlayer.rightPressed=!0:(animState=1,animDelay=24,myPlayer.rightPressed=!1);break;case 1:0<animDelay?animDelay--:(myPlayer.maxSpeed=6,animState=monsterAdd(Monster.mMOBMINI,myPlayer.x>>3,(myPlayer.y>>3)+1,0,0),monsterList[animState].maxSpeed=4,animState=monsterAdd(Monster.mMOBMINI,(myPlayer.x>>3)+1,(myPlayer.y>>3)+1,1,0),monsterList[animState].maxSpeed=4,animState=
monsterAdd(Monster.mMOBMINI,(myPlayer.x>>3)+2,(myPlayer.y>>3)+1,2,0),monsterList[animState].maxSpeed=4,animState=2);break;case 2:myPlayer.x>tx-32?myPlayer.leftPressed=!0:(animState=3,animDelay=64);break;case 3:if(0<animDelay)animDelay--;else{GameState=INITMAP;return}}break;case 2:switch(animState){case 0:myPlayer.x<tx+140?myPlayer.rightPressed=!0:(animState=1,animDelay=24);myPlayer.jumpPressed=!1;myPlayer.x>tx+22&&myPlayer.x<tx+40&&myPlayer.onGround?myPlayer.jumpPressed=!0:myPlayer.x>tx+48&&myPlayer.x<
tx+80&&(myPlayer.jumpPressed=!0);break;case 1:0<animDelay?animDelay--:animState=2;break;case 2:myPlayer.x>tx-16?myPlayer.leftPressed=!0:(animState=3,animDelay=40);break;case 3:if(0<animDelay)animDelay--;else{GameState=INITMAP;return}}break;case 3:switch(animState){case 0:myPlayer.x<tx+32?myPlayer.rightPressed=!0:(myPlayer.rightPressed=!1,animState=1,animDelay=24);break;case 1:0<animDelay?animDelay--:(animState=2,myPlayer.jumpPressed=!0);break;case 2:myPlayer.x<tx+140?myPlayer.rightPressed=!0:(animState=
3,animDelay=40);myPlayer.jumpPressed=!1;myPlayer.x>tx+48&&(myPlayer.x<tx+64&&myPlayer.onGround)&&(myPlayer.jumpPressed=!0);break;case 3:if(0<animDelay)animDelay--;else{GameState=INITMAP;return}}break;case 4:switch(animState){case 0:myPlayer.x<tx+140?myPlayer.rightPressed=!0:(animState=1,animDelay=24),28<myPlayer.x&&38>myPlayer.x&&(myPlayer.jumpPressed=!0),79<myPlayer.x&&92>myPlayer.x&&(myPlayer.jumpPressed=!0)}if(worldWaterLevel>ty+8)worldWaterLevel--;else{GameState=INITMAP;return}break;case 5:switch(animState){case 0:myPlayer.x<
tx+84?myPlayer.rightPressed=!0:(animState=1,animDelay=24);break;case 1:0<animDelay?(animDelay--,0==animDelay%8&&(0<myPlayer.myDirection?myPlayer.leftPressed=!0:myPlayer.rightPressed=!0)):(animState=2,myPlayer.initFlash(),animDelay=44);break;case 2:if(0<animDelay)animDelay--;else{GameState=INITMAP;return}}break;case 99:switch(animState){case 0:0<animDelay?animDelay--:animState=1;break;case 1:myPlayer.x>tx+50?myPlayer.leftPressed=!0:(animState=2,animDelay=48,myPlayer.jumpPressed=!0);break;case 2:0<
animDelay?animDelay--:animState=3;break;case 3:if(myPlayer.x<tx+140)myPlayer.rightPressed=!0;else{InitMenu(!0);menuMode=MENU_CHARACTERS;menuSelected=activePlayer.currentCharacter;loadCharacter(menuSelected);return}}}myPlayer.update(tileMap,tileMapW,tileMapH,!0);monsterUpdate();fxUpdate();ty=(lowDisplayH>>1)-56>>3<<3;clipRect(tx,ty,tx+140,ty+80);monsterRender(0);myPlayer.Paint(sprites[0],worldOffsetX,worldOffsetY);monsterRender(1);monsterRender(2);fxRender();4==animScene&&(tx=(lowDisplayW>>1)-70,ty=
(lowDisplayH>>1)-56>>3<<3,setAlpha(116),renderSubImageAtPoint(sprites[27],tx,worldWaterLevel,tx,worldWaterLevel,140,80),setAlpha(255),renderSubImageAtPoint(sprites[31],tx,ty+75,127,82,5,5),renderSubImageAtPoint(sprites[31],tx+135,ty+75,135,82,5,5),renderSubImageAtPoint(sprites[31],tx,ty,127,87,5,5),renderSubImageAtPoint(sprites[31],tx+135,ty,135,87,5,5));endClip();if(animAllowSkip&&(animAllowSkip=!1,tx=lowDisplayW-47,ty=lowDisplayH-7,renderSubImageAtPoint(sprites[5],tx,ty,98,74,45,5),actionButton2&&
!actionButton2Locked)){actionButton2Locked=!1;currentJingleIDX=0;GameState=INITMAP;return}}renderAchievements()}function tweetScore(){if(0<myPlayer.score){var a="I scored "+myPlayer.score+" points in ",a=unescape(encodeURIComponent(a)),c=unescape(encodeURIComponent("http://arcade.orangepixel.net/chronocash"));window.open("https://twitter.com/intent/tweet?hashtags=chronocash,html5&related=orangepixel&url="+c+"&text="+a,"Chrono&Cash braggin","width=480,height=240")}hideTweet()}
function GameLoop(){24<=worldAge&&doControlls();3==world&&(0==(worldAge-24)%200&&24<worldAge)&&monsterAdd(Monster.mROCK,3+getRandom(tileMapW-6),-22,12,0);4==world&&(myPlayer.died&&worldWaterLevel<lowDisplayH?worldWaterLevel++:116<worldAge&&(0==worldAge%2&&8<worldWaterLevel)&&worldWaterLevel--,myPlayer.y+2>=worldWaterLevel&&myPlayer.hit(myPlayer.myDirection));paused||myPlayer.update(tileMap,tileMapW,tileMapH,!1);!didFruit&&128<worldAge&&(addFruit(),playSound("FX_FLASH"));playPlayerSounds();monsterUpdate();
fxUpdate();renderScene();if(myPlayer.died&&0==myPlayer.diedCounter&&(myPlayer.lives--,0<myPlayer.lives)){myPlayer.levelInit(playerStartX,playerStartY);worldCompleteCount=0;worldTime=100;worldAge=worldTimeTick=0;worldWaterLevel=lowDisplayH;fxAdd(myPlayer.x,myPlayer.y,FX.fAPPEAR,0);for(var a=0;a<monsterList.length;a++)monsterList[a]&&!monsterList[a].deleted&&monsterList[a].reset()}myPlayer.died&&(1==myPlayer.lives&&0>worldGameOver)&&(worldGameOver=0);if(0<=worldGameOver&&(myPlayer.died=!0,myPlayer.blockPlayerMovement=
!0,worldGameOver++,96<worldGameOver)){1==world&&(animAllowSkip=!0);5E3<=myPlayer.score&&unlockAchievement(PlayerProfile.A_ROOKIEROBBER);8E3<=myPlayer.score&&!activePlayer.charUnlocks[DUDE_PIXMAN]&&(newUnlockChars[DUDE_PIXMAN]=!0);1E4<=myPlayer.score&&unlockAchievement(PlayerProfile.A_REALTHIEF);15E3<=myPlayer.score&&unlockAchievement(PlayerProfile.A_MASTERTHIEF);20<=didCollectItems[2]&&unlockAchievement(PlayerProfile.A_NEWBIECOLLECTOR);32<=didCollectItems[3]&&unlockAchievement(PlayerProfile.A_EGGAHOLIC);
InitMenu(!1);if(!uploadHighscores()){if(didUnlockCurrent()){menuMode=MENU_NEWCOMPLETED;inNewChallenges=!1;initNewChallenges();return}if(didUnlockCharacter()){initNewCharacter();return}playBackground()}return}0<worldTimeTick?worldTimeTick--:(worldTimeTick=16,worldTime--);if(0==worldCollectCount&&(myPlayer.blockPlayerMovement=!0,0==worldCompleteCount&&(uiAlphaTarget=255,myPlayer.initFlash()),worldCompleteCount++,32<worldCompleteCount&&!didPerfect||didPerfect&&96<worldCompleteCount))3==myPlayer.lives&&
unlockAchievement(PlayerProfile.A_EASYTAKINGS),didPerfect&&(myPlayer.addScore(perfectBonusScore),8E3>perfectBonusScore&&(perfectBonusScore<<=1),1==level&&(didPerfectRound1=!0),3==world&&1==level&&unlockAchievement(PlayerProfile.A_DINKY),2==level&&(didPerfectRound2=!0),3==level&&(didPerfectRound3=!0,didPerfectRound1&&(didPerfectRound2&&1==world)&&unlockAchievement(PlayerProfile.A_HAWKEYE),didPerfectRound1&&(didPerfectRound2&&3==world)&&(activePlayer.charUnlocks[DUDE_DINO]||(newUnlockChars[DUDE_DINO]=
!0)),didPerfectRound1&&(didPerfectRound2&&2==world)&&unlockAchievement(PlayerProfile.A_LARACROFTY)),1==world&&1==level&&unlockAchievement(PlayerProfile.A_GOODEYE),2==world&&1==level&&unlockAchievement(PlayerProfile.A_CROFTY),4==world&&1<level&&(tx=0,didPerfectRound1&&tx++,didPerfectRound2&&tx++,didPerfectRound3&&tx++,2<=tx&&unlockAchievement(PlayerProfile.A_ARRRR)),didPerfect=!1),GameState=INITMAP,5==world&&unlockAchievement(PlayerProfile.A_SPIRITED),level++,4E4<=myPlayer.score&&addCollectable(COLLECT_CASHACTIONFIGURE),
3<level&&(level=1,1==world&&(unlockAchievement(PlayerProfile.A_SMALLTHIEF),activePlayer.charUnlocks[DUDE_SMOOTH]||(newUnlockChars[DUDE_SMOOTH]=!0),myPlayer.hasLostALife||unlockAchievement(PlayerProfile.A_NOCEMENT),didAllWorlds&&addCollectable(COLLECT_MEGANOID)),2==world&&(unlockAchievement(PlayerProfile.A_TEMPLERAIDER),activePlayer.charUnlocks[DUDE_ADVENTURER]||(newUnlockChars[DUDE_ADVENTURER]=!0)),3==world&&(activePlayer.charUnlocks[DUDE_BURNIE]||(newUnlockChars[DUDE_BURNIE]=!0),addCollectable(COLLECT_GOLDENEGG)),
4==world&&(activePlayer.charUnlocks[DUDE_THOR]||(newUnlockChars[DUDE_THOR]=!0)),5==world&&addCollectable(COLLECT_GHOSTFIGURE),world>activePlayer.worldUnlocked&&(activePlayer.worldUnlocked=world),world++,5<world&&!activePlayer.charUnlocks[DUDE_KNIGHT]&&(newUnlockChars[DUDE_KNIGHT]=!0),5<world&&(world=1,didAllWorlds=!0,didPerfectRound3=didPerfectRound2=didPerfectRound1=!1),initAnimation());uiAlpha<uiAlphaTarget?(uiAlpha+=16,uiAlpha>uiAlphaTarget&&(uiAlpha=uiAlphaTarget)):uiAlpha>uiAlphaTarget&&(uiAlpha-=
16,uiAlpha<uiAlphaTarget&&(uiAlpha=uiAlphaTarget));if(0==worldCollectCount&&(32>worldCompleteCount&&(uiAlphaTarget=16>worldCompleteCount?255:0,setAlpha(uiAlpha),ty=lowDisplayH>>1,ctx.save(),ctx.translate(lowDisplayW>>1<<useMultiFactor,ty<<useMultiFactor),16>worldCompleteCount?ctx.scale(1/48*(worldCompleteCount<<2),1/48*(worldCompleteCount<<2)):ctx.scale(1/48*(32-worldCompleteCount<<2),1/48*(32-worldCompleteCount<<2)),ctx.translate(-(lowDisplayW>>1)<<useMultiFactor,-ty<<useMultiFactor),tx=(lowDisplayW>>
1)-71,ty=(lowDisplayH>>1)-35,renderSubImageAtPoint(sprites[8],tx,ty,0,35,142,35),ctx.restore(),setAlpha(255)),didPerfect&&(20<worldCompleteCount&&(21==worldCompleteCount&&playSound("FX_DIAMOND"),tx=(lowDisplayW>>1)-24,ty=(lowDisplayH>>1)+8,renderSubImageAtPoint(sprites[5],tx,ty,67,82,48,8)),ty+=16,28<worldCompleteCount&&(29==worldCompleteCount&&playSound("FX_DIAMOND"),tx=lowDisplayW>>1,tx=500<perfectBonusScore?tx-38:tx-34,renderSubImageAtPoint(sprites[5],tx,ty,67,90,35,8)),36<worldCompleteCount))){37==
worldCompleteCount&&playSound("FX_DIAMOND");setDigits(perfectBonusScore,scoreboard);tx+=43;foundFirst=!1;for(a=0;6>a;a++)if(0!=scoreboard[a]||foundFirst)foundFirst=!0,renderSubImageAtPoint(sprites[5],tx,ty,7*scoreboard[a],65,7,8),tx+=7}24>worldAge&&(tx=(lowDisplayW>>1)-22,9<level&&(tx-=4),ty=(lowDisplayH>>1)+24,renderSubImageAtPoint(sprites[5],tx,ty,0,82,34,16),setDigits(level,timeboard),tx+=44,9<level&&(renderSubImageAtPoint(sprites[5],tx,ty,timeboard[0]<<3,0,8,16),tx+=8),renderSubImageAtPoint(sprites[5],
tx,ty,timeboard[1]<<3,0,8,16));24<worldAge&&56>worldAge&&(worldAge++,uiAlphaTarget=16>worldAge-24?255:0,ty=lowDisplayH>>1,ctx.save(),ctx.translate(lowDisplayW>>1<<useMultiFactor,ty<<useMultiFactor),16>worldAge-24?ctx.scale(1/48*(worldAge-24<<2),1/48*(worldAge-24<<2)):0<56-worldAge&&ctx.scale(1/48*(56-worldAge<<2),1/48*(56-worldAge<<2)),ctx.translate(-(lowDisplayW>>1)<<useMultiFactor,-ty<<useMultiFactor),tx=(lowDisplayW>>1)-45,ty=(lowDisplayH>>1)-35,renderSubImageAtPoint(sprites[8],tx,ty,0,0,89,35),
ctx.restore());0<worldGameOver&&(uiAlphaTarget=16>worldGameOver?255:0,0<uiAlpha&&(setAlpha(uiAlpha),ty=lowDisplayH>>1,ctx.save(),ctx.translate(lowDisplayW>>1<<useMultiFactor,ty<<useMultiFactor),16>worldGameOver?ctx.scale(1/48*(worldGameOver<<2),1/48*(worldGameOver<<2)):ctx.scale(1/48*(32-worldGameOver<<2),1/48*(32-worldGameOver<<2)),ctx.translate(-(lowDisplayW>>1)<<useMultiFactor,-ty<<useMultiFactor),tx=(lowDisplayW>>1)-64,ty=(lowDisplayH>>1)-48,renderSubImageAtPoint(sprites[8],tx,ty,0,105,128,64),
ctx.restore()));setAlpha(255);worldAge++}function renderScene(){tx=(lowDisplayW>>1)-142;renderSubImageAtPoint(sprites[2],0,0,22,0,240,160);monsterRender(0);myPlayer.Paint(sprites[0],worldOffsetX,worldOffsetY);monsterRender(1);monsterRender(2);fxRender();4==world&&(setAlpha(116),renderSubImageAtPoint(sprites[27],0,worldWaterLevel,0,worldWaterLevel,lowDisplayW,lowDisplayH-worldWaterLevel),setAlpha(255));renderStatusBar();renderAchievements()}
function renderStatusBar(){setAlpha(128);tx=2;ty=17;for(var a=myPlayer.lives-1;0<=--a;)renderSubImageAtPoint(sprites[5],tx,ty,95,130,8,8),tx+=9;tx=2;ty=1;renderSubImageAtPoint(sprites[5],tx,ty,85,74,12,6);setDigits(myPlayer.score,scoreboard);tx=2;ty=8+myPlayer.scoreY;for(a=0;6>a;a++)renderSubImageAtPoint(sprites[5],tx,ty,7*scoreboard[a],65,7,8),tx+=7;tx=(lowDisplayW>>1)-16;ty=1;renderSubImageAtPoint(sprites[5],tx,ty,52,74,31,6);myPlayer.score<activePlayer.highscore[0]&&setDigits(activePlayer.highscore[0],
scoreboard);tx=(lowDisplayW>>1)-24;ty=8;for(a=0;6>a;a++)renderSubImageAtPoint(sprites[5],tx,ty,7*scoreboard[a],65,7,8),tx+=7;setAlpha(255);keyBoardOut||(setAlpha(120),tx=4,ty=lowDisplayH-34,renderSubImageAtPoint(sprites[4],tx,ty,0,0,30,30),tx=32+activePlayer.buttonDistance,renderSubImageAtPoint(sprites[4],tx,ty,30,0,30,30),tx=lowDisplayW-36,ty=lowDisplayH-36,renderSubImageAtPoint(sprites[4],tx,ty,60,0,30,30),tx=lowDisplayW-24,ty=4,renderSubImageAtPoint(sprites[4],tx,ty,90,0,16,16),setAlpha(255))}
function renderAchievements(){popAchievementY<popAchievementYTarget?(popAchievementY+=popAchievementYTarget-popAchievementY>>1,popAchievementY>popAchievementYTarget-2&&(0<popAchievementDelay?popAchievementDelay--:popAchievementYTarget=-32)):popAchievementY>popAchievementYTarget&&(popAchievementY-=popAchievementY-popAchievementYTarget>>1,popAchievementY<popAchievementYTarget+2&&(popAchievementY=popAchievementYTarget));popAchievementY!=popAchievementYTarget&&(tx=0,ty=popAchievementY,setAlpha(120),renderSubImageAtPoint(sprites[5],
tx,ty-3,0,186,132,16),setAlpha(255),-1==popAchievementID?(renderSubImageAtPoint(sprites[5],tx,ty,183,0,16,16),renderSubImageAtPoint(sprites[5],tx+20,ty+2,0,216,78,11)):(renderSubImageAtPoint(sprites[5],tx,ty,51,82,16,16),renderSubImageAtPoint(sprites[28],tx+20,ty+2,0,11*activePlayer.getAchievementIDX(popAchievementID),108,11)))}function setDigits(a,c){for(var d=a,b=2,b=0;b<c.length;b++)c[b]=0;for(b=c.length-1;0<=b;)c[b]=d%10,d=d/10>>0,0==d?b=-1:b--}
function destroyMap(){for(var a=tileMapW*tileMapH;0<=a;a--)tileMap[a]=0;for(a=fxList.length-1;0<=a;a--)fxList[a]&&(fxList[a].deleted=!0);for(a=monsterList.length-1;0<=a;a--)monsterList[a]&&(monsterList[a].deleted=!0)}function monsterAdd(a,c,d,b,e){for(var f=0;monsterList[f]&&!monsterList[f].deleted&&f<monsterCount&&f<monsterList.length;)f++;return f<monsterList.length?(monsterList[f]||(monsterList[f]=new Monster),monsterList[f].init(a,c,d,b,e),f==monsterCount&&monsterCount++,f):null}
function monsterUpdate(){var a=0,c=!1;for(worldCollectCount=0;a<monsterCount;){if(!monsterList[a].deleted){if(!paused){monsterList[a].update(tileMap,tileMapW,tileMapH,myPlayer,lowDisplayW,lowDisplayH,GameState==INANIMATION,world);monsterList[a].doFallSound&&(monsterList[a].doFallSound=!1,(monsterList[a].myType==Monster.mMOBMINI||monsterList[a].myType==Monster.mMOBMINIEASY)&&playSound("FX_SMALLTHUMB"),monsterList[a].myType==Monster.mCOLLECT&&".mp3"==!mySoundPool.extension&&playSound("FX_BAGLAND"));
monsterList[a].doHitSound&&(monsterList[a].doHitSound=!1);if(monsterList[a].doMoveSound)switch(monsterList[a].doMoveSound=!1,monsterList[a].myType){case Monster.mMOBMINI:playSound("FX_JUMPM");break;case Monster.mROCK:playSound("FX_DROP");break;case Monster.mMOBMINIEASY:playSound("FX_JUMPM");break;default:playSound("FX_ALERT")}monsterList[a].doExplodeSound&&(monsterList[a].doExplodeSound=!1,(monsterList[a].myType==Monster.mMOBMINI||monsterList[a].myType==Monster.mMOBMINIEASY)&&playSound("FX_ALERT"));
if(monsterList[a].doShoot)switch(monsterList[a].doShoot=!1,monsterList[a].myType){case Monster.mWALLSPIKE:playSound("FX_WALLSPIKE");break;default:playSound("FX_SHOOT");fxAdd(myPlayer.x+getRandom(16),myPlayer.y+getRandom(16),FX.fBIGPARTICLE,0);for(var d=4;0<=--d;)fxAdd(myPlayer.x+getRandom(16),myPlayer.y+getRandom(16),FX.fPICKUP,0)}}monsterList[a].died?(monsterList[a].deleted=!0,monsterList[a].myType==Monster.mCOLLECT&&(monsterList[a].myType==Monster.mCOLLECT&&!c&&(monsterList[a].aiState=2),2==monsterList[a].aiState?
(fxAdd(monsterList[a].x+getRandom(16),monsterList[a].y+getRandom(16)-8,FX.fPICKUP,0),fxAdd(monsterList[a].x+8,monsterList[a].y-2,FX.fPLUSONE,10*activePlayer.achievementLevel),GameState==INGAME&&myPlayer.addScore(10*activePlayer.achievementLevel)):(fxAdd(monsterList[a].x+8,monsterList[a].y-2,FX.fPLUSONE,1*activePlayer.achievementLevel),GameState==INGAME&&myPlayer.addScore(1*activePlayer.achievementLevel),didPerfect=!1),GameState!=INANIMATION&&didCollectItems[world]++,playSound("FX_PICKUP")),monsterList[a].myType==
Monster.mFRUIT&&1==monsterList[a].aiState&&(playSound("FX_DIAMOND"),worldFruit++,4<worldFruit&&(worldFruit=1),fxAdd(monsterList[a].x+getRandom(16),monsterList[a].y+getRandom(16)-8,FX.fPICKUP,0),0>monsterList[a].subType?(collectableInPlay[-(monsterList[a].subType-1)]=!1,activePlayer.collectables[0-(monsterList[a].subType-1)]=!0,unlockCollectable()):fxAdd(monsterList[a].x+8,monsterList[a].y-2,FX.fBONUSPTS,monsterList[a].subType),didCollectDiamonds++,3==didCollectDiamonds&&unlockAchievement(PlayerProfile.A_DIMEITUP),
6==didCollectDiamonds&&!activePlayer.charUnlocks[DUDE_CAVOR]&&(newUnlockChars[DUDE_CAVOR]=!0),9==didCollectDiamonds&&unlockAchievement(PlayerProfile.A_DIAMONDDEALER))):(monsterList[a].myType==Monster.mCOLLECT&&!c&&(c=!0,monsterList[a].aiState=2),monsterList[a].myType==Monster.mCOLLECT&&worldCollectCount++)}a++}}
function monsterRender(a){for(var c=0,d,b;c<monsterCount;)!monsterList[c].deleted&&(monsterList[c].visible&&monsterList[c].renderPass==a)&&(d=monsterList[c].x-worldOffsetX,b=monsterList[c].y-worldOffsetY,setAlpha(monsterList[c].alpha),0!=monsterList[c].rotation&&(ctx.save(),ctx.translate(d+(monsterList[c].w>>1)<<useMultiFactor,b+(monsterList[c].h>>1)<<useMultiFactor),ctx.rotate(convertToRadians(monsterList[c].rotation)),ctx.translate(-(d+(monsterList[c].w>>1))<<useMultiFactor,-(b+(monsterList[c].h>>
1))<<useMultiFactor)),renderSubImageAtPoint(sprites[monsterList[c].SpriteSet],d,b,monsterList[c].xOffset,monsterList[c].yOffset,monsterList[c].w,monsterList[c].h),0!=monsterList[c].rotation&&ctx.restore()),c++}function fxAdd(a,c,d,b){for(var e=0;fxList[e]&&!fxList[e].deleted&&e<fxCount;)e++;fxList[e]||(fxList[e]=new FX);fxList[e].init(a,c,d,b);e==fxCount&&512>fxCount&&fxCount++}
function fxUpdate(){for(var a=0;a<fxCount;)fxList[a].deleted||(fxList[a].update(),fxList[a].died&&(fxList[a].deleted=!0)),a++;setAlpha(255)}
function fxRender(){for(var a,c,d=0;d<fxCount;){if(!fxList[d].deleted&&(a=fxList[d].x-worldOffsetX,c=fxList[d].y-worldOffsetY,-24<=c&&(c<displayH&&-24<a&&a<displayW)&&(setAlpha(fxList[d].alpha),renderSubImageAtPoint(sprites[fxList[d].spriteSet],a,c,fxList[d].animFrame,fxList[d].aOffset,fxList[d].w,fxList[d].h),fxList[d].fType==FX.fPLUSONE&&0!=fxList[d].SubType)))if(1>=fxList[d].SubType){a+=5;c-=1;foundFirst=!1;setDigits(fxList[d].SubType,digitsboard);for(var b=0;3>b;b++)if(foundFirst||0!=digitsboard[b])foundFirst=
!0,renderSubImageAtPoint(sprites[1],a,c,7*digitsboard[b],30,7,8),a+=6}else{a+=5;c-=6;foundFirst=!1;setDigits(fxList[d].SubType,digitsboard);for(b=0;3>b;b++)if(foundFirst||0!=digitsboard[b])foundFirst=!0,renderSubImageAtPoint(sprites[1],a,c,9*digitsboard[b],38,9,18),a+=8}d++}setAlpha(255)}
function initAnimation(){GameState=INANIMATION;destroyMap();paused=!1;worldOffsetY=worldOffsetX=0;perfectBonusScore=500;switch(world){case 1:sprites[12]=myLoadManager.getAsset("m05.png");sprites[31]=myLoadManager.getAsset("anim01.png");animScene=1;animSpeech=animDelay=animState=0;tx=(lowDisplayW>>1)-70>>3;ty=(lowDisplayH>>1)-56>>3;playerStartY=ty+7;playerStartX=tx-1;addLedge(0,playerStartY+1,tileMapW);addBags(tx+6,ty+7,3,!1);myPlayer.levelInit(playerStartX,playerStartY-1);myPlayer.maxSpeed=4;currentJingleIDX=
playSound("FX_JINGLE1");break;case 2:sprites[31]=myLoadManager.getAsset("anim02.png");sprites[12]=myLoadManager.getAsset("m07.png");animScene=2;animSpeech=animDelay=animState=0;tx=(lowDisplayW>>1)-70>>3;playerStartY=ty=(lowDisplayH>>1)-56>>3;playerStartX=tx-1;addLedge(tx-5,ty+3,10);addLedge(tx+11,ty+3,6);addLedge(0,ty+8,30);addBags(tx+6,ty+7,3,!0);addWallSpikes(tx+6,ty+2,4,1);myPlayer.levelInit(playerStartX,playerStartY-1);myPlayer.maxSpeed=4;currentJingleIDX=playSound("FX_JINGLE2");break;case 3:sprites[31]=
myLoadManager.getAsset("anim03.png");sprites[12]=myLoadManager.getAsset("m08.png");animScene=3;animSpeech=animDelay=animState=0;tx=(lowDisplayW>>1)-70>>3;playerStartY=ty=(lowDisplayH>>1)-56>>3;playerStartX=tx-1;addLedge(tx,ty+4,3);addLedge(tx+12,ty+3,6);addLedge(0,ty+8,30);addBags(tx+11,ty+7,3,!1);myPlayer.levelInit(playerStartX,playerStartY-1);myPlayer.maxSpeed=4;monsterAdd(Monster.mROCK,tx+13,(ty<<3)-22,12,0);currentJingleIDX=playSound("FX_JINGLE3");break;case 4:sprites[31]=myLoadManager.getAsset("anim04.png");
sprites[12]=myLoadManager.getAsset("m09.png");animScene=4;animSpeech=animDelay=animState=0;tx=(lowDisplayW>>1)-70>>3;ty=(lowDisplayH>>1)-56>>3;playerStartY=ty+7;playerStartX=tx-1;worldWaterLevel=ty+9<<3;addLedge(tx,ty+4,3);addLedge(tx+6,ty+4,6);addLedge(tx+15,ty+4,3);addLedge(tx+11,ty-1,9);addLedge(0,ty+8,30);addBags(tx+6,ty+3,3,!1);myPlayer.levelInit(playerStartX,playerStartY-1);myPlayer.maxSpeed=4;currentJingleIDX=playSound("FX_JINGLE4");break;case 5:sprites[31]=myLoadManager.getAsset("anim05.png");
sprites[12]=myLoadManager.getAsset("m10.png");animScene=5;tx=(lowDisplayW>>1)-70>>3;ty=(lowDisplayH>>1)-56>>3;playerStartY=ty+7;playerStartX=tx-1;animState=monsterAdd(Monster.mGHOSTEASY,tx,ty,0,0);monsterList[animState].aiCountDown=2;animState=monsterAdd(Monster.mGHOSTEASY,tx+15,ty+1,1,0);monsterList[animState].aiCountDown=2;animState=monsterAdd(Monster.mGHOSTEASY,tx,ty+4,2,0);monsterList[animState].aiCountDown=2;animSpeech=animDelay=animState=0;addLedge(0,ty+8,30);addBags(tx+6,ty+7,3,!1);myPlayer.levelInit(playerStartX,
playerStartY-1);myPlayer.maxSpeed=4;currentJingleIDX=playSound("FX_JINGLE5");break;case 99:sprites[31]=myLoadManager.getAsset("anim00.png"),sprites[12]=myLoadManager.getAsset("m05.png"),animScene=99,animState=0,animDelay=16,animSpeech=0,tx=(lowDisplayW>>1)-70>>3,ty=(lowDisplayH>>1)-56>>3,playerStartY=ty+7,playerStartX=tx+20,addLedge(0,playerStartY+1,tileMapW),myPlayer.levelInit(playerStartX,playerStartY-1),myPlayer.maxSpeed=4,currentJingleIDX=playSound("FX_JINGLECHAR")}}
function initPauseMenu(){GameState=INPAUSE;nextState=-1;menuMode=0;menuSelected=-1;uiAlphaTarget=255;uiYTarget=uiY=0;stopBackground()}var unlockCache=Array(100),popAchievementID,popAchievementY,popAchievementYTarget,popAchievementDelay=0;function resetUnlockCache(){for(var a=unlockCache.length;0<=--a;)unlockCache[a]=!1;popAchievementYTarget=popAchievementY=-22}
function uploadHighscores(){for(var a=0;5>a&&myPlayer.score<activePlayer.highscore[a];)a++;if(5>a){for(var c=5;--c>a;)activePlayer.highscore[c]=activePlayer.highscore[c-1],activePlayer.highname[c]=activePlayer.highname[c-1];activePlayer.highscore[a]=myPlayer.score;lastHighScore=a;menuMode=MENU_NAMEENTRY;nameEntryIDX=0;for(a=nameEntryLetters.length-1;0<=a;a--)nameEntryLetters[a]=activePlayer.lastNameIDX[a],0<=nameEntryLetters[a]&&nameEntryIDX++;return!0}return!1}
function updateAchievement(a,c){c>activePlayer.achievements[a]&&(activePlayer.achievements[a]=c)}function unlockAchievement(a){var c=3*(activePlayer.achievementLevel-1);if(a==c||a==c+1||a==c+2)100>activePlayer.achievements[a]&&(unlockCache[a]=!0,0>popAchievementYTarget&&popAchievementY==popAchievementYTarget&&(popAchievementID=a,popAchievementYTarget=2,popAchievementDelay=64,playSound("FX_ACHIEVE"))),activePlayer.achievements[a]=100}
function addCollectable(a){activePlayer.collectables[a]||(collectableInPlay[a]=!0)}function unlockCollectable(){0>popAchievementYTarget&&popAchievementY==popAchievementYTarget&&(popAchievementID=-1,popAchievementYTarget=2,popAchievementDelay=64,playSound("FX_ACHIEVE"))}function didUnlockCurrent(){var a=3*(activePlayer.achievementLevel-1);return unlockCache[a]||unlockCache[a+1]||unlockCache[a+2]?!0:!1}
function initNewChallenges(){challengeTarget=(lowDisplayW>>1)-63;challengeX1=lowDisplayW;challengeX2=lowDisplayW+(lowDisplayW>>1);challengeX3=lowDisplayW<<1;inNewChallenges=!1;worldAge=0}function didUnlockCharacter(){for(var a=!1,c=32;0<=--c;)newUnlockChars[c]&&(a=!0);return a}
function initNewCharacter(){for(menuSelected=0;!newUnlockChars[menuSelected]&&menuSelected<newUnlockChars.length;)menuSelected++;for(var a=32;0<=--a;)newUnlockChars[a]&&(activePlayer.charUnlocks[a]=!0);loadCharacter(menuSelected);world=99;initAnimation()}
function setHighScoreName(){for(var a=new String,c=0;c<nameEntryLetters.length;c++)0<=nameEntryLetters[c]&&(a+=String.fromCharCode(65+nameEntryLetters[c])),activePlayer.lastNameIDX[c]=nameEntryLetters[c];activePlayer.highname[lastHighScore]=a.toString();activePlayer.saveSettings();menuMode=MENU_NAMEENTRY}
function doControlls(){if(!myPlayer.blockPlayerMovement){var a,c;myPlayer.leftPressed=!1;myPlayer.rightPressed=!1;myPlayer.jumpPressed=!1;myPlayer.actionPressed=!1;if(!keyBoardOut&&touched){for(var d=mTouch.length;0<=--d;)a=lowDisplayH/100*100/displayH*mTouch[d].pageY,c=lowDisplayW/100*100/displayW*mTouch[d].pageX,c>(lowDisplayW>>1)+16&&0<a&&(myPlayer.jumpPressed=!0),a>lowDisplayH-128&&(0<=c&&c<32+activePlayer.buttonDistance&&(myPlayer.leftPressed=!0),c>32+activePlayer.buttonDistance&&c<lowDisplayW>>
1&&(myPlayer.rightPressed=!0));tx=lowDisplayW-24;ty=4;for(d=mTouch.length;0<=--d;)a=lowDisplayH/100*100/displayH*mTouch[d].pageY,c=lowDisplayW/100*100/displayW*mTouch[d].pageX,c>=tx&&(0<a&&a<ty+20)&&(paused=paused?!1:!0,initPauseMenu())}backPressed&&!backLocked&&(backPressed?backLocked=!0:menuLocked=!0,paused=paused?!1:!0,initPauseMenu());leftPressed&&(leftLocked=myPlayer.leftPressed=!0);rightPressed&&(rightLocked=myPlayer.rightPressed=!0);if(upPressed||actionButton2)myPlayer.jumpPressed=!0,actionButton2?
actionButton2Locked=!0:upPressed&&(upLocked=!0);actionButton1&&!actionButton1Locked&&(actionButton1Locked=!0,myPlayer.actionPressed=!0)}}
function loadCharacter(a){switch(a){case 0:sprites[0]=myLoadManager.getAsset("player.png");break;case 1:sprites[0]=myLoadManager.getAsset("plsmooth.png");break;case 2:sprites[0]=myLoadManager.getAsset("pladventurer.png");break;case 3:sprites[0]=myLoadManager.getAsset("plpixman.png");break;case 4:sprites[0]=myLoadManager.getAsset("plscorched.png");break;case 5:sprites[0]=myLoadManager.getAsset("plcavorite.png");break;case 6:sprites[0]=myLoadManager.getAsset("plthor.png");break;case 7:sprites[0]=myLoadManager.getAsset("plpastry.png");
break;case 8:sprites[0]=myLoadManager.getAsset("plknight.png")}}
function loadWorld(){destroyMap();playerStartX=13;playerStartY=16;addLedge(0,19,30);switch(world){case 1:sprites[12]=myLoadManager.getAsset("m05.png");sprites[2]=myLoadManager.getAsset("larcade01.png");addLedge(8,15,5);addLedge(16,15,6);addLedge(12,8,6);addLedge(0,10,8);addLedge(22,10,8);addLedge(4,4,6);addLedge(20,4,6);addBags(8,14,2,!0);addBags(16,14,3,!1);addBags(22,9,4,!1);addBags(0,9,4,!0);addBags(12,7,3,!1);addBags(20,3,3,!1);addBags(4,3,3,!0);monsterAdd(Monster.mDOOR,6,3,13,0);monsterAdd(Monster.mDOOR,
22,3,13,0);if(didAllWorlds){if(monsterAdd(Monster.mMOBMINI,6,3,0,0),monsterAdd(Monster.mMOBMINI,22,3,1,1),(1<level||didAllWorlds)&&monsterAdd(Monster.mMOBMINI,6,3,2,1),2<level||didAllWorlds)monsterAdd(Monster.mDOOR,14,7,13,0),monsterAdd(Monster.mMOBMINI,22,3,0,0),monsterAdd(Monster.mMOBMINI,14,7,3,2)}else monsterAdd(Monster.mMOBMINIEASY,6,3,0,0),monsterAdd(Monster.mMOBMINIEASY,22,3,1,1),1<level&&monsterAdd(Monster.mMOBMINIEASY,6,3,2,1),2<level&&(monsterAdd(Monster.mDOOR,14,7,13,0),monsterAdd(Monster.mMOBMINIEASY,
22,3,0,0),monsterAdd(Monster.mMOBMINIEASY,14,7,3,2));break;case 2:sprites[12]=myLoadManager.getAsset("m07.png");sprites[2]=myLoadManager.getAsset("larcade02.png");addLedge(4,14,8);addLedge(18,14,8);addLedge(0,9,8);addLedge(22,9,8);addLedge(12,6,6);addLedge(2,3,5);addLedge(23,3,5);addBags(2,18,4,!0);addBags(4,13,4,!1);addBags(0,8,4,!0);addBags(12,5,3,!1);addBags(20,18,4,!1);addBags(18,13,4,!1);addBags(22,8,4,!1);addBags(3,2,1,!0);addBags(25,2,1,!0);addWallSpikes(12,11,5,2);monsterAdd(Monster.mDOOR,
4,2,13,1);monsterAdd(Monster.mDOOR,14,5,13,1);didAllWorlds?(monsterAdd(Monster.mMOBMINI,4,2,0,3),monsterAdd(Monster.mMOBMINI,14,5,2,1),1<level&&(monsterAdd(Monster.mDOOR,26,2,13,1),monsterAdd(Monster.mMOBMINI,26,2,1,2)),2<level&&(monsterAdd(Monster.mDOOR,22,13,13,1),monsterAdd(Monster.mMOBMINI,22,13,3,0))):(monsterAdd(Monster.mMOBMINIEASY,4,2,0,3),monsterAdd(Monster.mMOBMINIEASY,14,5,2,1),1<level&&(monsterAdd(Monster.mDOOR,26,2,13,1),monsterAdd(Monster.mMOBMINIEASY,26,2,1,2)),2<level&&(monsterAdd(Monster.mDOOR,
22,13,13,1),monsterAdd(Monster.mMOBMINIEASY,22,13,3,0)));break;case 3:sprites[12]=myLoadManager.getAsset("m08.png");sprites[2]=myLoadManager.getAsset("larcade03.png");addLedge(0,2,3);addLedge(5,5,5);addLedge(14,5,4);addLedge(22,5,5);addLedge(27,2,3);addLedge(0,10,6);addLedge(15,10,11);addLedge(2,15,11);addLedge(22,14,6);addBags(3,14,4,!1);addBags(16,9,4,!1);addBags(23,13,2,!0);addBags(16,18,4,!0);addBags(1,9,2,!0);addBags(6,4,1,!1);addBags(0,1,1,!1);addBags(16,4,1,!1);addBags(22,4,2,!1);addBags(28,
1,1,!1);monsterAdd(Monster.mDOOR,6,4,13,2);monsterAdd(Monster.mDOOR,2,9,13,2);monsterAdd(Monster.mDOOR,15,4,13,2);monsterAdd(Monster.mDOOR,22,9,13,2);didAllWorlds?(monsterAdd(Monster.mMOBMINI,6,4,0,2),monsterAdd(Monster.mMOBMINI,2,9,1,3),monsterAdd(Monster.mMOBMINI,15,4,2,1),monsterAdd(Monster.mMOBMINI,22,9,3,0)):(monsterAdd(Monster.mMOBMINIEASY,6,4,0,2),monsterAdd(Monster.mMOBMINIEASY,2,9,1,3),monsterAdd(Monster.mMOBMINIEASY,15,4,2,1),monsterAdd(Monster.mMOBMINIEASY,22,9,3,0));break;case 4:sprites[12]=
myLoadManager.getAsset("m09.png");sprites[2]=myLoadManager.getAsset("larcade04.png");addLedge(12,2,6);addLedge(2,5,6);addLedge(22,5,6);addLedge(7,10,6);addLedge(17,10,6);addLedge(3,15,6);addLedge(12,15,6);addLedge(21,15,6);addBags(1,18,5,!0);addBags(12,14,3,!1);addBags(21,14,3,!1);addBags(17,9,3,!0);addBags(7,9,3,!0);addBags(22,4,3,!1);addBags(2,4,3,!0);monsterAdd(Monster.mDOOR,3,4,13,3);monsterAdd(Monster.mDOOR,23,4,13,3);monsterAdd(Monster.mDOOR,8,9,13,3);monsterAdd(Monster.mDOOR,13,14,13,3);didAllWorlds?
(monsterAdd(Monster.mMOBMINI,3,4,0,2),monsterAdd(Monster.mMOBMINI,23,4,1,3),monsterAdd(Monster.mMOBMINI,8,9,2,1),monsterAdd(Monster.mMOBMINI,13,14,3,0)):(monsterAdd(Monster.mMOBMINIEASY,3,4,0,2),monsterAdd(Monster.mMOBMINIEASY,23,4,1,3),monsterAdd(Monster.mMOBMINIEASY,8,9,2,1),monsterAdd(Monster.mMOBMINIEASY,13,14,3,0));break;case 5:sprites[12]=myLoadManager.getAsset("m10.png"),sprites[2]=myLoadManager.getAsset("larcade05.png"),addLedge(3,14,5),addLedge(8,10,5),addLedge(2,5,5),addLedge(14,3,2),addLedge(18,
10,5),addLedge(22,14,5),addLedge(23,5,5),addBags(21,18,4,!1),addBags(18,9,2,!0),addBags(2,18,4,!0),addBags(3,13,2,!1),addBags(8,9,2,!1),addBags(23,4,2,!1),addBags(14,2,1,!1),addBags(2,4,2,!0),monsterAdd(Monster.mGHOSTEASY,3,2,0,2),monsterAdd(Monster.mGHOSTEASY,23,11,3,0),1<level&&monsterAdd(Monster.mGHOSTEASY,24,2,1,3),2<level&&monsterAdd(Monster.mGHOSTEASY,4,11,2,1)}myPlayer.levelInit(playerStartX,playerStartY)}
function addBags(a,c,d,b){if(b)for(var e=d-1;0<=e;e--)b=monsterAdd(Monster.mCOLLECT,a+(e<<1),c,6,world-1),monsterList[b].aiCountDown=e<<2;else for(e=0;e<d;e++)b=monsterAdd(Monster.mCOLLECT,a+(e<<1),c,6,world-1),monsterList[b].aiCountDown=e<<2}function addLedge(a,c,d){for(var b=a;b<a+d;b++)tileMap[b+c*tileMapW]=1}function addLedgeV(a,c,d){for(var b=c;b<c+d;b++)tileMap[a+b*tileMapW]=1}
function addWallSpikes(a,c,d,b){for(var e=0;e<d;e++)for(var f=0;f<b;f++)monsterAdd(Monster.mWALLSPIKE,a+e,c+f,9,0)}
function addFruit(){for(var a=!1,c,d=256;!a&&0<d;){tx=getRandom(tileMapW-1);ty=getRandom(tileMapH-1);if(0==tileMap[tx+ty*tileMapW]&&0<tileMap[tx+(ty+1)*tileMapW]){a=!0;for(c=0;c<monsterList.length;)monsterList[c]&&!monsterList[c].deleted&&monsterList[c].myType==Monster.mCOLLECT&&monsterList[c].x+12>=tx<<3&&(monsterList[c].x<=(tx<<3)+12&&monsterList[c].y+12>=ty<<3&&monsterList[c].y<=(ty<<3)+12)&&(a=!1),c++;myPlayer.x+12>=tx<<3&&(myPlayer.x<=(tx<<3)+12&&myPlayer.y+12>=ty<<3&&myPlayer.y<=(ty<<3)+12)&&
(a=!1)}d--}a&&(didFruit=!0,monsterAdd(Monster.mFRUIT,tx,ty,11,worldFruit),fxAdd(tx<<3,ty<<3,FX.fAPPEAR,0))}var mySoundPool=new SoundPool(18),myGameMusic=-1;
function initSounds(){"localhost"==document.location.hostname||params.noaudio&&1==params.noaudio?(activePlayer.useMusic=!1,activePlayer.useSFX=!1):(mySoundPool.load(soundRoot+"audio/fxsplash","FX_SPLASH"),mySoundPool.load(soundRoot+"audio/fx1up","FX_ONEUP"),mySoundPool.load(soundRoot+"audio/fxarrow","FX_ARROW"),mySoundPool.load(soundRoot+"audio/fxbagland","FX_BAGLAND"),mySoundPool.load(soundRoot+"audio/fxdiamond","FX_DIAMOND"),mySoundPool.load(soundRoot+"audio/fxdie","FX_DIE"),mySoundPool.load(soundRoot+
"audio/fxdrop","FX_DROP"),mySoundPool.load(soundRoot+"audio/fxexplode","FX_EXPLODE"),mySoundPool.load(soundRoot+"audio/fxflash","FX_FLASH"),mySoundPool.load(soundRoot+"audio/fxjingle1","FX_JINGLE1"),mySoundPool.load(soundRoot+"audio/fxjingle2","FX_JINGLE2"),mySoundPool.load(soundRoot+"audio/fxjingle3","FX_JINGLE3"),mySoundPool.load(soundRoot+"audio/fxjingle4","FX_JINGLE4"),mySoundPool.load(soundRoot+"audio/fxjingle5","FX_JINGLE5"),mySoundPool.load(soundRoot+"audio/fxjumpa","FX_JUMP1"),mySoundPool.load(soundRoot+
"audio/fxjumpb","FX_JUMP2"),mySoundPool.load(soundRoot+"audio/fxjumpm","FX_JUMP3"),mySoundPool.load(soundRoot+"audio/fxland","FX_LAND"),mySoundPool.load(soundRoot+"audio/fxmobalert","FX_ALERT"),mySoundPool.load(soundRoot+"audio/fxpickup","FX_PICKUP"),mySoundPool.load(soundRoot+"audio/fxshoot","FX_SHOOT"),mySoundPool.load(soundRoot+"audio/fxslide","FX_SLIDE"),mySoundPool.load(soundRoot+"audio/fxsmallthumb","FX_SMALLTHUMB"),mySoundPool.load(soundRoot+"audio/fxspike","FX_SPIKE"),mySoundPool.load(soundRoot+
"audio/fxthrow","FX_THROW"),mySoundPool.load(soundRoot+"audio/fxwallspike","FX_WALLSPIKE"),mySoundPool.load(soundRoot+"audio/tune1","tune1"),mySoundPool.load(soundRoot+"audio/fxjinglechar","FX_JINGLECHAR"),mySoundPool.load(soundRoot+"audio/fxachieve","FX_ACHIEVE"),mySoundPool.load(soundRoot+"audio/fxslide","FX_SLIDE"),mySoundPool.load(soundRoot+"audio/fxbagland","FX_BAGLAND"))}function playSound(a){activePlayer.useSFX&&mySoundPool.playSound(a,!1)}
function playPlayerSounds(){myPlayer.doMoveSound&&(myPlayer.doMoveSound=!1,playSound("FX_SLIDE"));myPlayer.doJumpSoundMain&&(myPlayer.doJumpSoundMain=!1,playSound("FX_JUMP1"));myPlayer.doJumpSoundSecond&&(myPlayer.doJumpSoundSecond=!1,playSound("FX_JUMP2"));myPlayer.doLandSound&&(myPlayer.doLandSound=!1,playSound("FX_LAND"));myPlayer.doHitSound&&(myPlayer.doHitSound=!1,playSound("FX_DIE"));myPlayer.doFlashSound&&(myPlayer.doFlashSound=!1,playSound("FX_FLASH"));myPlayer.doLifeSound&&(myPlayer.doLifeSound=
!1,playSound("FX_ONEUP"))}function playBackground(){activePlayer.useMusic&&(myGameMusic=mySoundPool.playSound("tune1",!0))}function stopBackground(){activePlayer.useMusic&&-1!=myGameMusic&&mySoundPool.stopSound(myGameMusic)}function getMusic(){}function freeMusic(){myGameMusic=-1}
function FX(){FX.fALERT=1;FX.fPLUSONE=2;FX.fAPPEAR=3;FX.fSPARK=4;FX.fEXPLODE=5;FX.fSPEECH=6;FX.fBONUSPTS=7;FX.fDIZZY=8;FX.fLITTLEPUFF=9;FX.fPARTICLE=10;FX.fPICKUP=11;FX.fBIGPARTICLE=12;FX.fJUMPSMOKE=13;FX.animWords=[0,80,109,0,85,36,38,85,87];this.aOffset=this.animFrameA=this.animFrame=this.animSpeed=this.animDelay=this.h=this.w=this.ySpeed=this.xSpeed=this.y=this.x=this.ty=this.tx=0;this.died=!1;this.rotation=this.SubType=this.fType=this.spriteSet=this.aiCountDown=this.aiState=this.yIncrease=this.xIncrease=
0;this.alpha=255;this.visible=!0;this.deleted=!1;this.init=function(a,c,d,b){this.deleted=!1;this.spriteSet=1;this.x=a;this.y=c;this.fType=d;this.SubType=b;this.xSpeed=this.ySpeed=0;this.animSpeed=2;this.animFrameA=0;this.alpha=255;this.visible=!0;switch(this.fType){case FX.fALERT:this.w=6;this.h=12;this.aOffset=this.animFrame=0;this.animSpeed=8;break;case FX.fPLUSONE:this.ySpeed=-4;switch(this.SubType){case 0:this.w=25;this.h=18;this.y-=8;this.animFrame=68;this.aOffset=12;this.ySpeed=2;this.aiCountDown=
16;break;default:this.w=5,this.animFrame=this.h=6,this.aOffset=5}this.x-=this.w>>1;this.alpha=255;this.animSpeed=999;break;case FX.fAPPEAR:this.h=this.w=16;this.animFrame=0;this.animFrameA=16;this.aOffset=32;this.animSpeed=1;this.spriteSet=0;this.ySpeed=1;break;case FX.fSPARK:this.h=this.w=4;this.animFrame=14;this.animSpeed=this.aOffset=2;break;case FX.fEXPLODE:this.h=this.w=24;this.animFrame=0;this.aOffset=32;this.animFrameA=24;this.animSpeed=2;break;case FX.fSPEECH:this.h=5;this.spriteSet=31;this.xIncrease=
1;this.alpha=0;this.aiCountDown=24;this.aiState=0;this.animSpeed=999;this.animFrame=FX.animWords[3*SubType];this.aOffset=FX.animWords[3*SubType+1];this.w=FX.animWords[3*SubType+2];this.ySpeed=-4;break;case FX.fBONUSPTS:this.w=11;this.h=5;this.animFrame=21+12*(this.SubType-1);this.aOffset=12;this.x-=this.w>>1;this.ySpeed=-4;this.alpha=255;this.animSpeed=999;break;case FX.fDIZZY:this.w=16;this.h=8;this.animFrame=0;this.animFrameA=16;this.aOffset=64;this.animSpeed=2;break;case FX.fLITTLEPUFF:this.h=
this.w=8;this.animFrame=21;this.aOffset=17;this.animSpeed=2;this.animFrameA=8;this.xSpeed=this.SubType;break;case FX.fPARTICLE:this.h=this.w=8;this.animFrame=0;this.aOffset=56;this.animFrameA=8;this.animSpeed=1;break;case FX.fPICKUP:this.h=this.w=8;this.animFrame=0==getRandom(2)?0:48;this.aOffset=64;this.animFrameA=8;this.animSpeed=1;break;case FX.fBIGPARTICLE:this.h=this.w=16;this.animFrame=0;this.aOffset=72;this.animFrameA=16;this.animSpeed=1;break;case FX.fJUMPSMOKE:this.h=this.w=8,this.animFrame=
0,this.aOffset=88,this.animFrameA=8,this.animSpeed=2}this.animDelay=this.animSpeed;this.died=!1};this.update=function(){this.animDelay--;if(0==this.animDelay)switch(this.animDelay=this.animSpeed,this.animFrame+=this.animFrameA,this.fType){default:this.died=!0;break;case FX.fEXPLODE:96<this.animFrame&&(this.died=!0);break;case FX.fAPPEAR:112<this.animFrame&&(this.died=!0);break;case FX.fDIZZY:32<this.animFrame&&(this.died=!0);break;case FX.fLITTLEPUFF:54<this.animFrame&&(this.died=!0);break;case FX.fPARTICLE:56<
this.animFrame&&(this.died=!0);break;case FX.fPICKUP:if(48==this.animFrame||96==this.animFrame)this.died=!0;break;case FX.fBIGPARTICLE:64<this.animFrame&&(this.died=!0);break;case FX.fJUMPSMOKE:32<this.animFrame&&(this.died=!0)}switch(this.fType){case FX.fPLUSONE:this.y+=this.ySpeed;0==this.SubType?(0<this.aiCountDown&&this.aiCountDown--,-3<this.ySpeed?this.ySpeed--:0==this.aiCountDown&&(this.died=!0)):1>this.ySpeed?this.ySpeed++:this.died=!0;break;case FX.fAPPEAR:this.y+=this.ySpeed;-4<this.ySpeed&&
this.ySpeed--;break;case FX.fSPEECH:this.xIncrease=1-this.xIncrease;1==this.xIncrease&&this.x--;0==this.aiState?(this.alpha+=32,255<this.alpha&&(this.alpha=255,this.aiState=1)):1==this.aiState?0<this.aiCountDown?this.aiCountDown--:this.aiState=2:(this.alpha-=8,0>=this.alpha&&(this.alpha=0,this.died=!0));this.animDelay=999;break;case FX.fBONUSPTS:this.y+=this.ySpeed;1>this.ySpeed?this.ySpeed++:this.died=!0;break;case FX.fLITTLEPUFF:this.x+=this.xSpeed}}}
function Monster(){Monster.mCOLLECT=1;Monster.mBULLET=3;Monster.mWALLSPIKE=4;Monster.mSIDESHOOTER=5;Monster.mSIDEARROW=6;Monster.mRUNNER=7;Monster.mCHRONO=8;Monster.mFRUIT=9;Monster.mMOBMINI=10;Monster.mDOOR=11;Monster.mROCK=12;Monster.mMOBMINIEASY=13;Monster.mGHOSTEASY=14;this.rotation=this.startY=this.startX=this.targetY=this.targetX=this.y=this.x=this.h=this.w=0;this.allowJump=this.inJump=this.onGround=!1;this.animSpeed=this.animIncrease=this.animDelay=this.xOffsetAdd=this.yOffset=this.xOffset=
this.SpriteSet=this.fireDelay=this.myDirection=this.yIncrease=this.xIncrease=this.xSpeed=this.ySpeed=0;this.visible=!0;this.aiCountDown=this.aiState=this.maxEnergy=this.energy=this.subType=this.myType=this.alpha=this.renderPass=0;this.doFallSound=this.doExplodeSound=this.doMoveSound=this.doHitSound=this.doShoot=this.hasPlayer=this.died=!1;this.deleted=!0;this.init=function(a,c,d,b,e){this.deleted=!1;this.renderPass=1;this.myType=a;this.subType=e;this.x=c<<3;this.y=d<<3;this.startX=this.x;this.startY=
this.y;this.targetX=this.x;this.targetY=this.y;this.rotation=0;this.SpriteSet=b;this.visible=!0;this.alpha=255;this.aiState=0;this.doFallSound=this.doExplodeSound=this.doMoveSound=this.doShoot=this.doHitsound=this.hasPlayer=this.died=!1;this.fireDelay=this.maxEnergy=this.energy=0;switch(this.myType){case Monster.mCOLLECT:this.h=this.w=12;this.xOffset=0;this.yOffset=12*this.subType;this.x+=2;this.targetY=this.y+8-this.h;this.aiState=0;this.ySpeed=-2;this.renderPass=2;this.yIncrease=-2;break;case Monster.mBULLET:this.w=
8;this.h=4;this.xOffset=6;this.yOffset=0;this.xSpeed=this.subType<<2;this.aiCountDown=12;this.x=c;this.y=d;break;case Monster.mWALLSPIKE:this.h=this.w=16;this.aiState=this.yOffset=this.xOffset=0;this.aiCountDown=16;this.renderPass=0;break;case Monster.mSIDESHOOTER:this.visible=!1;this.aiState=0;this.aiCountDown=this.subType<<4;this.myDirection=80>this.x?1:-1;break;case Monster.mSIDEARROW:this.x=c;this.y=d;this.w=12;this.h=5;this.yOffset=16;80>this.x?(this.xSpeed=8,this.xOffset=12):(this.xSpeed=-8,
this.xOffset=0);break;case Monster.mRUNNER:this.w=16;this.h=20;this.y-=4;this.aiState=0;this.myDirection=getRandom(8);4>this.myDirection?(this.myDirection=-1,this.yOffset=this.h):(this.myDirection=1,this.yOffset=0);this.aiCountDown=1+getRandom(3);this.yOffset=this.xOffset=0;break;case Monster.mCHRONO:this.h=this.w=10;this.xOffset=192;this.yOffset=32;this.ySpeed=this.aiState=0;this.yIncrease=-1;break;case Monster.mFRUIT:this.renderPass=2;this.h=this.w=12;this.xOffset=12*(this.subType-1);this.yOffset=
0;this.aiCountDown=184;this.x+=2;this.targetY=this.y+8-this.h;this.aiState=0;this.yIncrease=this.ySpeed=-2;break;case Monster.mMOBMINI:this.h=this.w=16;this.startY=this.y-=8;this.startX=this.x;this.xOffsetAdd=this.SpriteSet;this.SpriteSet=12;this.reset();break;case Monster.mDOOR:this.renderPass=0;this.w=21;this.h=24;this.xOffset=21*this.subType;this.yOffset=0;this.x-=2;this.y-=16;break;case Monster.mROCK:this.h=this.w=20;this.y=d;this.xOffset=112;fireDelay=myDirection=aiState=xSpeed=rotation=this.yOffset=
0;break;case Monster.mMOBMINIEASY:this.h=this.w=16;this.startY=this.y-=8;this.startX=this.x;this.xOffsetAdd=this.SpriteSet;this.SpriteSet=12;this.reset();break;case Monster.mGHOSTEASY:this.h=this.w=16,this.startY=this.y-=8,this.startX=this.x,this.xOffsetAdd=this.SpriteSet,this.SpriteSet=12,this.reset()}this.animDelay=this.animSpeed};this.reset=function(){switch(this.myType){case Monster.mMOBMINI:this.x=this.startX;this.y=this.startY;this.aiState=this.ySpeed=this.xSpeed=this.xOffset=0;this.aiCountDown=
24+80*this.subType;this.visible=!1;3==this.subType&&(this.aiCountDown=24);this.maxSpeed=2;this.inJump=!1;this.allowJump=!0;break;case Monster.mMOBMINIEASY:this.x=this.startX;this.y=this.startY;this.aiState=this.ySpeed=this.xSpeed=this.xOffset=0;this.aiCountDown=24+(this.subType<<5);this.visible=!1;this.maxSpeed=2;this.inJump=!1;this.allowJump=!0;break;case Monster.mGHOSTEASY:this.x=this.startX,this.y=this.startY,this.aiState=this.ySpeed=this.xSpeed=this.xOffset=0,this.aiCountDown=24+(this.subType<<
5),this.visible=!1,this.maxSpeed=2,this.inJump=!1,this.allowJump=!0}};this.update=function(a,c,d,b,e,f,h,g){switch(this.myType){case Monster.mCOLLECT:0<this.aiCountDown?(this.aiCountDown--,this.visible=!1):(this.visible=!0,this.xOffset=2==this.aiState?12:0,this.y+=this.ySpeed,8>this.ySpeed&&this.ySpeed++,this.y>=this.targetY&&(this.y=this.targetY,1<this.ySpeed&&(this.doFallSound=!0),this.ySpeed=this.yIncrease,0>this.yIncrease&&this.yIncrease++),this.hitPlayer(b.x,b.y)&&!b.died&&(this.died=!0));break;
case Monster.mBULLET:0<this.aiCountDown?this.aiCountDown--:this.died=!0;this.x+=this.xSpeed>>1;this.hitPlayer(b.x,b.y)&&(b.hit(this.xSpeed),this.died=!0);this.x+=this.xSpeed>>1;this.hitPlayer(b.x,b.y)&&(b.hit(this.xSpeed),this.died=!0);break;case Monster.mWALLSPIKE:switch(this.aiState){case 0:0<this.aiCountDown?this.aiCountDown--:this.animDelay=this.aiState=1;break;case 1:0<this.animDelay?this.animDelay--:(this.animDelay=1,this.xOffset+=16,48<=this.xOffset&&(this.xOffset=48,this.aiState=2,this.aiCountDown=
32,this.doShoot=!0));break;case 2:0<this.aiCountDown?this.aiCountDown--:(this.aiState=3,this.animDelay=1);b.x+16>=this.x+5&&(b.x<=this.x+11&&b.y+16>=this.y+5&&b.y<=this.y+11)&&b.hit(1);break;case 3:0<this.animDelay?this.animDelay--:(this.animDelay=2,this.xOffset-=16,0>=this.xOffset&&(this.aiState=this.xOffset=0,this.aiCountDown=64)),32<=this.xOffset&&(b.x+16>=this.x+5&&b.x<=this.x+11&&b.y+16>=this.y+5&&b.y<=this.y+11)&&b.hit(1)}break;case Monster.mSIDESHOOTER:0<this.aiCountDown?this.aiCountDown--:
(this.doShoot=!0,this.aiCountDown=80);break;case Monster.mSIDEARROW:this.x+=this.xSpeed;this.x>e-16&&0<this.xSpeed?this.died=!0:16>this.x&&0>this.xSpeed&&(this.died=!0);e=this.x+8>>4;f=this.y>>4;1==a[e+f*c]&&(this.died=!0);this.hitPlayer(b.x,b.y)&&b.hit(this.xSpeed);break;case Monster.mRUNNER:this.checkPlayerNearBy(b);2>this.aiState&&(b.y+16>this.y-12&&b.y<this.y+this.h)&&(0>this.myDirection&&b.x<this.x&&b.x+16>this.x-80?(this.aiState=2,this.aiCountDown=3,this.xSpeed=-2,this.fireDelay=6,this.targetX=
b.x+24,targetX>this.x-8&&(targetX=this.x-8),fxAdd(this.x,this.y-14,FX.fALERT,0),this.doMoveSound=!0):0<this.myDirection&&(b.x>this.x+this.w&&b.x<this.x+80)&&(this.aiState=2,this.aiCountDown=3,this.xSpeed=2,this.fireDelay=6,this.targetX=b.x-24,this.targetX<this.x+8&&(this.targetX=this.x+8),fxAdd(this.x,this.y-14,FX.fALERT,0),this.doMoveSound=!0));switch(this.aiState){case 0:0<this.animDelay?this.animDelay--:(this.animDelay=6,this.xOffset+=this.w,2>this.aiCountDown?(this.yOffset=0,this.myDirection=
1):(this.yOffset=this.h,this.myDirection=-1),this.xOffset==this.w<<2&&(this.xOffset=0,this.aiCountDown--,0>=this.aiCountDown&&(this.aiState=1,this.aiCountDown=80,this.xSpeed=0<this.myDirection?1:-1)));break;case 1:if(0>this.xSpeed)this.yOffset=this.h,this.myDirection=-1,this.x+=this.xSpeed,e=this.x>>4,f=this.y+this.h-4>>4,1!=a[e+(f+1)*c]&&(this.xSpeed=1),1==a[e+f*c]&&(this.x=(e<<4)+16,this.xSpeed=1);else{this.yOffset=0;this.myDirection=1;this.x+=this.xSpeed;e=this.x+this.w-1>>4;f=this.y+this.h-4>>
4;if(x>c-1||1!=a[e+(f+1)*c])this.xSpeed=-1;if(0>e||1==a[e+f*c])this.x=(e<<4)-this.w,this.xSpeed=-1}0<this.animDelay?this.animDelay--:(this.animDelay=2,this.xOffset+=this.w,this.xOffset>=this.w<<3&&(this.xOffset=this.w<<2));0<this.aiCountDown?this.aiCountDown--:(this.aiState=0,this.aiCountDown=2,this.animDelay=6,this.xOffset=0);break;case 2:0<this.fireDelay?this.fireDelay--:(this.doShoot=!0,this.fireDelay=12,0<this.aiCountDown?this.aiCountDown--:(this.aiState=3,this.aiCountDown=2,this.xOffset=0,this.animDelay=
2));break;case 3:0<this.animDelay?this.animDelay--:(this.animDelay=6,this.xOffset+=this.w,this.xOffset==this.w<<2&&(this.xOffset=0,this.aiCountDown--,0>=this.aiCountDown&&(this.aiState=1,this.aiCountDown=80,this.xSpeed=0<this.myDirection?1:-1)))}this.hitPlayer(b.x,b.y)&&b.hit(this.xSpeed);break;case Monster.mCHRONO:0<this.animDelay?this.animDelay--:(this.animDelay=1,this.y+=this.ySpeed,this.ySpeed+=this.yIncrease,-1>this.ySpeed?this.yIncrease=1:1<this.ySpeed&&(this.yIncrease=-1),this.yOffset=0>this.myDirection?
42:32);break;case Monster.mFRUIT:this.y+=this.ySpeed;8>this.ySpeed&&this.ySpeed++;this.y>=this.targetY&&(this.y=this.targetY,this.ySpeed=this.yIncrease,0>this.yIncrease&&this.yIncrease++);this.hitPlayer(b.x,b.y)&&!b.died&&(this.died=!0,this.aiState=1,this.inAnimation||b.addScore(100*this.subType));this.visible=16<this.aiCountDown||2>this.aiCountDown%4?!0:!1;0<this.aiCountDown?this.aiCountDown--:this.died=!0;break;case Monster.mMOBMINI:switch(this.aiState){case 0:this.visible=!1;if(0<this.aiCountDown)this.aiCountDown--,
16==this.aiCountDown&&(fxAdd(this.x,this.y-14,FX.fALERT,0),this.doExplodeSound=!0);else{switch(this.subType){case 0:this.myDirection=b.x>this.x?-1:1;break;case 1:this.myDirection=b.x<this.x?-1:1;break;case 2:this.myDirection=b.x<this.x?-1:1;b.y>this.y+48&&(this.myDirection=-this.myDirection);break;case 3:this.myDirection=b.x>this.x?-1:1,b.y>this.y+48&&(this.myDirection=-this.myDirection)}this.inAnimation&&(this.myDirection=b.x<this.x?-1:1);this.aiState=1;this.alpha=0;this.visible=!0}break;case 1:this.alpha+=
16;255<this.alpha&&(this.alpha=255,this.aiState=2);break;case 2:0<this.animDelay?this.animDelay--:(this.animDelay=2,this.xOffset+=16,80<=this.xOffset&&(this.xOffset=16));if(this.inJump||this.onGround)this.x+=this.xSpeed;this.y+=this.ySpeed;this.onGround=!1;8>this.ySpeed&&this.ySpeed++;0<this.ySpeed&&(e=this.x+8>>3,0>this.xSpeed?e=this.x+14>>3:0<this.xSpeed&&(e=this.x+2>>3),f=this.y+16>>3,0<=e&&(0<=f&&e<c&&f<d&&1==a[e+f*c])&&(this.y=(f<<3)-16,this.inJump=!1,this.onGround=!0,2<this.ySpeed&&(fxAdd(this.x+
4,this.y+8,FX.fPARTICLE,this.myDirection),this.doFallSound=!0),this.ySpeed=0),f>d&&(this.y=(d-1<<3)-16,this.inJump=!1,this.onGround=!0,this.ySpeed=0));this.x>=(c<<3)-16&&(this.y<(d-1<<3)-16&&!this.inAnimation)&&(this.x=(c<<3)-16,0<this.xSpeed&&(this.xSpeed=-this.xSpeed),0==this.subType&&(this.allowJump=!0));0>=this.x&&(this.y<(d-1<<3)-16&&!this.inAnimation)&&(this.x=0,0>this.xSpeed&&(this.xSpeed=-this.xSpeed),0==this.subType&&(this.allowJump=!0));if(0>this.x||this.x>(c<<3)-16&&this.onGround){this.aiState=
3;return}this.onGround&&0==this.xSpeed&&(this.xSpeed=0>this.myDirection?-this.maxSpeed:this.maxSpeed);if(this.onGround){if(0<this.xSpeed){if(f=this.y+18>>3,e=this.x>>3,e++,b.y<this.y+8&&b.y>this.y-64&&0<=e&&e<c&&0<=f&&f<d&&0==a[e+f*c])switch(this.subType){case 0:this.allowJump&&(this.ySpeed=-4,this.doMoveSound=this.inJump=!0);break;case 1:this.ySpeed=-4;this.doMoveSound=this.inJump=!0;break;case 2:b.x<this.x+32&&b.y<this.y-16&&(this.ySpeed=-4,this.doMoveSound=this.inJump=!0);break;case 3:b.x>this.x&&
(this.ySpeed=-4,this.doMoveSound=this.inJump=!0)}}else if(f=this.y+18>>3,e=this.x+16>>3,e--,b.y<this.y+8&&b.y>this.y-64&&0<=e&&e<c&&0<=f&&f<d&&0==a[e+f*c])switch(this.subType){case 0:this.allowJump&&(this.ySpeed=-4,this.doMoveSound=this.inJump=!0);break;case 1:this.ySpeed=-4;this.doMoveSound=this.inJump=!0;break;case 2:b.x>this.x-32&&b.y<this.y-16&&(this.ySpeed=-4,this.doMoveSound=this.inJump=!0);break;case 3:b.x<this.x&&(this.ySpeed=-4,this.doMoveSound=this.inJump=!0)}f=this.y>>3;e=this.x>>3;f-=
3;e=0>this.xSpeed?e-2:e+2;switch(this.subType){case 0:if(this.allowJump&&0==this.aiCountDown&&0<=b.ySpeed){if(0<=f&&f<d&&0<=e&&e<c&&(1==a[e+f*c]||1==a[e+(f+1)*c])&&b.y+16<this.y)this.ySpeed=-9,this.doMoveSound=this.inJump=!0,this.allowJump=!1,this.aiCountDown=24}else-5>=b.ySpeed&&(this.allowJump=!0);break;case 1:if(this.allowJump&&b.y<this.y-16&&2==b.onGroundCountdown&&0<=f&&f<d&&0<=e&&e<c&&(1==a[e+f*c]||1==a[e+(f+1)*c])&&3<f&&0==a[e+(f-4)*c])this.ySpeed=-9,this.doMoveSound=this.inJump=!0,this.allowJump=
!1,this.aiCountDown=64;break;case 2:if(this.allowJump&&64<b.xOffset&&0<=f&&0<=e&&e<c&&f<d&&(1==a[e+f*c]||1==a[e+(f+1)*c])&&3<f&&0==a[e+(f-4)*c])this.ySpeed=-9,this.doMoveSound=this.inJump=!0,this.allowJump=!1,this.aiCountDown=64;break;case 3:if(b.y<this.y&&(b.x<this.x&&0>this.myDirection||b.x>this.x&&0<this.myDirection))if(0<=f&&f<d&&0<=e&&e<c&&(1==a[e+f*c]||1==a[e+(f+1)*c])&&b.y+16<this.y)this.ySpeed=-9,this.doMoveSound=this.inJump=!0,this.allowJump=!1,this.aiCountDown=64}}1==this.subType&&(b.x>
this.x-32&&b.x<this.x+32)&&(this.allowJump=!0);2==this.subType&&(b.onGround&&b.y>this.y+16)&&(this.allowJump=!0);3==this.subType&&(this.allowJump=!0);0<this.aiCountDown?this.aiCountDown--:2==this.subType&&(this.allowJump=!0);0>this.xSpeed?this.myDirection=-1:0<this.xSpeed&&(this.myDirection=1);this.yOffset=0<this.myDirection?0+(this.xOffsetAdd<<5):16+(this.xOffsetAdd<<5);if(0>this.myDirection){if(b.x+16>=this.x&&b.x<=this.x+(this.w>>1)&&b.y+16>=this.y&&b.y<=this.y+this.h){b.hit(this.xSpeed);this.myDirection=
b.x<this.x?-1:1;this.aiState=4;this.aiCountDown=2;this.xOffset=96;this.xSpeed=0;this.targetY=this.y;this.animDelay=6;switch(g){case 3:this.ySpeed=-3}this.doShoot=!0}}else if(b.x+16>=this.x+(this.w>>1)&&b.x<=this.x+this.w&&b.y+16>=this.y&&b.y<=this.y+this.h){b.hit(this.xSpeed);this.myDirection=b.x<this.x?-1:1;this.aiState=4;this.aiCountDown=2;this.xOffset=96;this.xSpeed=0;this.targetY=this.y;this.animDelay=6;switch(g){case 3:this.ySpeed=-3}this.doShoot=!0}break;case 3:this.x+=this.xSpeed;this.y+=this.ySpeed;
this.y>(d-1<<3)-16&&(this.y=(d-1<<3)-16,this.onGround=!0,this.ySpeed=0);if(-48>this.x||this.x>(c<<3)+48){this.reset();this.aiCountDown=16;fxAdd(this.x,this.y-14,FX.fALERT,0);this.doExplodeSound=!0;return}break;case 4:this.yOffset=0<this.myDirection?0+(this.xOffsetAdd<<5):16+(this.xOffsetAdd<<5),this.y+=this.ySpeed,this.onGround=!1,8>this.ySpeed&&this.ySpeed++,0<this.ySpeed&&(e=this.x+8>>3,f=this.y+16>>3,0<=e&&(0<=f&&e<c&&f<d&&1==a[e+f*c])&&(this.y=(f<<3)-16,this.inJump=!1,this.onGround=!0,2<this.ySpeed&&
(0<this.myDirection?fxAdd(this.x+4,this.y+8,FX.fLITTLEPUFF,-2):fxAdd(this.x+8,this.y+8,FX.fLITTLEPUFF,2),this.doFallSound=!0),2==this.subType&&(this.myDirection=-this.myDirection),this.ySpeed=0),f>d&&(this.y=(d-1<<3)-16,this.inJump=!1,this.onGround=!0,this.ySpeed=0)),0<this.animDelay?this.animDelay--:this.aiState=2}break;case Monster.mROCK:switch(this.aiState){case 0:b.died&&(this.fireDelay=1);if(0>this.x||this.x>(c<<3)-16&&this.onGround){this.aiState=2;return}this.onGround=!1;this.y+=this.ySpeed;
8>this.ySpeed&&this.ySpeed++;e=this.x+10>>3;f=this.y+20>>3;0<=e&&(0<=f&&e<c&&f<d)&&0!=a[e+f*c]&&(this.y=(f<<3)-20,this.onGround=!0,0==this.myDirection&&(this.myDirection=b.x<this.x?-1:1),2<this.ySpeed&&(fxAdd(this.x,this.y+this.h,FX.fLITTLEPUFF,-2),fxAdd(this.x+this.w-8,this.y+this.h,FX.fLITTLEPUFF,2)),4<this.ySpeed?(this.ySpeed=-2,this.doMoveSound=!0):this.ySpeed=0,this.xSpeed=0<this.myDirection?2:-2,this.aiCountDown=4);this.onGround&&(this.x+=this.xSpeed);f=this.y+16>>3;0>this.xSpeed?(this.rotation-=
2<<-this.xSpeed,0>this.rotation&&(this.rotation+=360),e=this.x>>3,0<=e&&(0<=f&&e<c&&f<d)&&0!=a[e+f*c]&&(this.x=e<<3,this.xSpeed=-this.xSpeed)):(this.rotation+=2<<this.xSpeed,359<this.rotation&&(this.rotation-=360),e=this.x+20>>3,0<=e&&(0<=f&&e<c&&f<d)&&0!=a[e+f*c]&&(this.x=(e<<3)-20,this.xSpeed=-this.xSpeed));break;case 2:if(this.x=0>this.myDirection?this.x-2:this.x+2,-64>this.x||this.x>(c<<3)+64)this.died=!0}0==this.x%8&&this.onGround&&fxAdd(this.x+4,this.y+12,FX.fPARTICLE,this.myDirection);0==this.fireDelay&&
(b.x+16>=this.x+4&&b.x<=this.x+(this.w>>1)-4&&b.y+16>=this.y&&b.y<=this.y+this.h)&&b.hit(this.xSpeed);break;case Monster.mMOBMINIEASY:switch(this.aiState){case 0:this.visible=!1;if(0<this.aiCountDown)this.aiCountDown--,16==this.aiCountDown&&(fxAdd(this.x,this.y-14,FX.fALERT,0),this.doExplodeSound=!0);else{switch(this.subType){case 0:this.myDirection=b.x>this.x?-1:1;break;case 1:this.myDirection=b.x<this.x?-1:1;break;case 2:this.myDirection=b.x<this.x?-1:1;b.y>this.y+48&&(this.myDirection=-this.myDirection);
break;case 3:this.myDirection=b.x>this.x?-1:1,b.y>this.y+48&&(this.myDirection=-this.myDirection)}this.inAnimation&&(this.myDirection=b.x<this.x?-1:1);this.aiState=1;this.alpha=0;this.visible=!0}break;case 1:this.alpha+=16;255<this.alpha&&(this.alpha=255,this.aiState=2);break;case 2:0<this.animDelay?this.animDelay--:(this.animDelay=2,this.xOffset+=16,80<=this.xOffset&&(this.xOffset=16));if(this.inJump||this.onGround)this.x+=this.xSpeed;this.y+=this.ySpeed;this.onGround=!1;8>this.ySpeed&&this.ySpeed++;
0<this.ySpeed&&(e=this.x+8>>3,0>this.xSpeed?e=this.x+14>>3:0<this.xSpeed&&(e=this.x+2>>3),f=this.y+16>>3,0<=e&&(0<=f&&e<c&&f<d&&1==a[e+f*c])&&(this.y=(f<<3)-16,this.inJump=!1,this.onGround=!0,2<this.ySpeed&&(fxAdd(this.x+4,this.y+8,FX.fPARTICLE,this.myDirection),this.doFallSound=!0),this.ySpeed=0),f>d&&(this.y=(d-1<<3)-16,this.inJump=!1,this.onGround=!0,this.ySpeed=0));this.x>=(c<<3)-16&&(this.y<(d-1<<3)-16&&!this.inAnimation)&&(this.x=(c<<3)-16,0<this.xSpeed&&(this.xSpeed=-this.xSpeed));0>=this.x&&
(this.y<(d-1<<3)-16&&!this.inAnimation)&&(this.x=0,0>this.xSpeed&&(this.xSpeed=-this.xSpeed));if(0>this.x||this.x>(c<<3)-16&&this.onGround){this.aiState=3;return}this.onGround&&0==this.xSpeed&&(this.xSpeed=0>this.myDirection?-this.maxSpeed:this.maxSpeed);0>this.xSpeed?this.myDirection=-1:0<this.xSpeed&&(this.myDirection=1);this.yOffset=0<this.myDirection?0+(this.xOffsetAdd<<5):16+(this.xOffsetAdd<<5);if(0>this.myDirection){if(b.x+16>=this.x&&b.x<=this.x+(this.w>>1)&&b.y+16>=this.y&&b.y<=this.y+this.h){b.hit(this.xSpeed);
this.myDirection=b.x<this.x?-1:1;this.aiState=4;this.aiCountDown=2;this.xOffset=96;this.xSpeed=0;this.targetY=this.y;this.animDelay=6;switch(g){case 3:this.ySpeed=-3}this.doShoot=!0}}else if(b.x+16>=this.x+(this.w>>1)&&b.x<=this.x+this.w&&b.y+16>=this.y&&b.y<=this.y+this.h){b.hit(this.xSpeed);this.myDirection=b.x<this.x?-1:1;this.aiState=4;this.aiCountDown=2;this.xOffset=96;this.xSpeed=0;this.targetY=this.y;this.animDelay=6;switch(g){case 3:this.ySpeed=-3}this.doShoot=!0}break;case 3:this.x+=this.xSpeed;
this.y+=this.ySpeed;this.y>(d-1<<3)-16&&(this.y=(d-1<<3)-16,this.onGround=!0,this.ySpeed=0);if(-48>this.x||this.x>(c<<3)+48){this.reset();this.aiCountDown=16;fxAdd(this.x,this.y-14,FX.fALERT,0);this.doExplodeSound=!0;return}break;case 4:this.yOffset=0<this.myDirection?0+(this.xOffsetAdd<<5):16+(this.xOffsetAdd<<5),this.y+=this.ySpeed,this.onGround=!1,8>this.ySpeed&&this.ySpeed++,0<this.ySpeed&&(e=this.x+8>>3,f=this.y+16>>3,0<=e&&(0<=f&&e<c&&f<d&&1==a[e+f*c])&&(this.y=(f<<3)-16,this.inJump=!1,this.onGround=
!0,2<this.ySpeed&&(0<this.myDirection?fxAdd(this.x+4,this.y+8,FX.fLITTLEPUFF,-2):fxAdd(this.x+8,this.y+8,FX.fLITTLEPUFF,2),this.doFallSound=!0),2==this.subType&&(this.myDirection=-this.myDirection),this.ySpeed=0),f>d&&(this.y=(d-1<<3)-16,this.inJump=!1,this.onGround=!0,this.ySpeed=0)),0<this.animDelay?this.animDelay--:this.aiState=2}break;case Monster.mGHOSTEASY:switch(this.aiState){case 0:this.visible=!1;if(0<this.aiCountDown)this.aiCountDown--,16==this.aiCountDown&&(fxAdd(this.x,this.y-14,FX.fALERT,
0),this.doExplodeSound=!0);else{switch(this.subType){case 0:this.myDirection=b.x>this.x?-1:1;this.ySpeed=b.y>this.y?1:-1;break;case 1:this.myDirection=b.x<this.x?-1:1;this.ySpeed=b.y>this.y?-1:1;break;case 2:this.myDirection=b.x<this.x?-1:1;b.y>this.y+48&&(this.myDirection=-this.myDirection);this.ySpeed=b.y>d<<2?1:-1;break;case 3:this.myDirection=b.x>this.x?-1:1,b.y>this.y+48&&(this.myDirection=-this.myDirection),this.ySpeed=b.y>d<<2?-1:1}this.inAnimation&&(this.myDirection=b.x<this.x?-1:1);this.aiState=
1;this.alpha=0;this.visible=!0}break;case 1:this.alpha+=16;180<this.alpha&&(this.alpha=180,this.aiState=2);break;case 2:0<this.animDelay?this.animDelay--:(this.animDelay=2,this.xOffset+=16,80<=this.xOffset&&(this.xOffset=16));b.y>=this.y-6?b.x<this.x&&0>b.myDirection?-1<this.xSpeed&&this.xSpeed--:b.x>this.x&&0<b.myDirection?1>this.xSpeed&&this.xSpeed++:this.ySpeed=this.xSpeed=0:this.xSpeed=0<this.myDirection?2:-2;0>this.xSpeed?this.myDirection=-1:0<this.xSpeed&&(this.myDirection=1);this.yOffset=0<
this.myDirection?0+(this.xOffsetAdd<<5):16+(this.xOffsetAdd<<5);if(this.inJump||this.onGround)this.x+=this.xSpeed;b.y<this.y&&b.y>this.y-24&&!b.died?-1<this.ySpeed&&this.ySpeed--:2>this.ySpeed&&this.ySpeed++;this.y+=this.ySpeed;this.onGround=!1;0<this.ySpeed&&(e=this.x+8>>3,0>this.xSpeed?e=this.x+14>>3:0<this.xSpeed&&(e=this.x+2>>3),f=this.y+16>>3,0<=e&&(0<=f&&e<c&&f<d&&1==a[e+f*c])&&(this.y=(f<<3)-16,this.inJump=!1,this.onGround=!0,this.xSpeed=b.y>this.y-6?b.x<this.x?-1:1:0<this.myDirection?1:-1,
this.ySpeed=0),f>d&&(this.y=(d-1<<3)-16,this.inJump=!1,this.onGround=!0,this.ySpeed=0));this.x>=(c<<3)-16&&(this.y<(d-1<<3)-16&&!this.inAnimation)&&(this.x=(c<<3)-16,this.xSpeed=-this.xSpeed);0>=this.x&&(0>this.xSpeed&&this.y<(d-1<<3)-16&&!this.inAnimation)&&(this.x=0,this.xSpeed=-this.xSpeed);if(0>this.x||this.x>(c<<3)-16&&this.onGround){this.aiState=3;break}this.onGround&&0==this.xSpeed&&(this.xSpeed=0>this.myDirection?-this.maxSpeed:this.maxSpeed);0>this.xSpeed?this.myDirection=-1:0<this.xSpeed&&
(this.myDirection=1);this.yOffset=0<this.myDirection?0+(this.xOffsetAdd<<5):16+(this.xOffsetAdd<<5);0>this.myDirection?b.x+16>=this.x&&(b.x<=this.x+(this.w>>1)&&b.y+16>=this.y&&b.y<=this.y+this.h)&&(b.hit(this.xSpeed),this.myDirection=b.x<this.x?-1:1,this.aiState=4,this.aiCountDown=2,this.xOffset=96,this.xSpeed=0,this.targetY=this.y,this.animDelay=6,this.doShoot=!0):b.x+16>=this.x+(this.w>>1)&&(b.x<=this.x+this.w&&b.y+16>=this.y&&b.y<=this.y+this.h)&&(b.hit(this.xSpeed),this.myDirection=b.x<this.x?
-1:1,this.aiState=4,this.aiCountDown=2,this.xOffset=96,this.xSpeed=0,this.targetY=this.y,this.animDelay=6,this.doShoot=!0);break;case 3:this.x+=this.xSpeed;this.y+=this.ySpeed;this.y>(d-1<<3)-16&&(this.y=(d-1<<3)-16,this.onGround=!0,this.ySpeed=0);if(-48>this.x||this.x>(c<<3)+48){this.reset();this.aiCountDown=16;fxAdd(this.x,this.y-14,FX.fALERT,0);this.doExplodeSound=!0;break}break;case 4:this.yOffset=0<this.myDirection?0+(this.xOffsetAdd<<5):16+(this.xOffsetAdd<<5),this.y+=this.ySpeed,this.onGround=
!1,8>this.ySpeed&&this.ySpeed++,0<this.ySpeed&&(e=this.x+8>>3,f=this.y+16>>3,0<=e&&(0<=f&&e<c&&f<d&&1==a[e+f*c])&&(this.y=(f<<3)-16,this.inJump=!1,this.onGround=!0,2<this.ySpeed&&(0<this.myDirection?fxAdd(this.x+4,this.y+8,FX.fLITTLEPUFF,-2):fxAdd(this.x+8,this.y+8,FX.fLITTLEPUFF,2),this.doFallSound=!0),2==this.subType&&(this.myDirection=-this.myDirection),this.ySpeed=0),f>d&&(this.y=(d-1<<3)-16,this.inJump=!1,this.onGround=!0,this.ySpeed=0)),0<this.animDelay?this.animDelay--:this.aiState=2}}};this.checkPlayerNearBy=
function(a){var c=a.y+8,d=this.y+(this.h>>1),b=a.x+8,e=this.x+(this.w>>1),f=1;c>=d-16&&c<=d+16&&(f=5,b>e-32&&b<e+32?f=20:b>e-64&&b<e+64&&(f=10));f>a.nearByValue&&(a.nearByValue=f)};this.hitPlayer=function(a,c){return a+16>=this.x&&a<=this.x+this.w&&c+16>=this.y&&c<=this.y+this.h?!0:!1}}
function player(){this.maxSpeed=this.ySpeed=this.xSpeed=this.y=this.x=0;this.myDirection=1;this.FrameDelay=this.xOffset=this.yOffset=this.scoreYSpeed=this.scoreY=this.score=this.nearByValue=this.blinkCountDown=this.diedCounter=this.energy=this.lives=0;this.onGround=!1;this.jumpCount=this.onGroundCountdown=0;this.hasLostALife=this.died=this.doMoveSound=this.doLifeSound=this.doFlashSound=this.doLandSound=this.doHitSound=this.doJumpSoundSecond=this.doJumpSoundMain=this.flashOut=this.blockPlayerMovement=
this.actionReleased=this.actionPressed=this.jumpReleased=this.jumpPressed=this.rightPressed=this.leftPressed=this.headBump=!1;this.gameReset=function(){this.lives=3;this.energy=8;this.scoreYSpeed=this.scoreY=this.score=0;this.hasLostALife=!1};this.levelInit=function(a,c){this.x=a<<3;this.y=c<<3;this.ySpeed=this.xSpeed=this.yOffset=this.xOffset=0;this.myDirection=1;this.diedCounter=this.FrameDelay=0;this.jumpPressed=this.rightPressed=this.leftPressed=this.doMoveSound=this.doLifeSound=this.doFlashSound=
this.doLandSound=this.doJumpSoundSecond=this.doJumpSoundMain=this.doHitSound=this.died=!1;this.jumpReleased=!0;this.actionPressed=!1;this.actionReleased=!0;this.blockPlayerMovement=!1;this.onGroundCountdown=0;this.onGround=!0;this.jumpCount=2;this.flashOut=!1;this.maxSpeed=3;this.headBump=!1;this.blinkCountDown=0};this.addScore=function(a){this.score+=a;this.scoreYSpeed=-2;if((1E4>this.prescore&&1E4<=this.score||2E4>this.prescore&&2E4<=this.score||3E4>this.prescore&&3E4<=this.score||4E4>this.prescore&&
4E4<=this.score)&&4>this.lives)this.lives++,fxAdd(this.x+8,this.y-2,FX.fPLUSONE,0),this.doLifeSound=!0};this.hit=function(){!this.died&&!this.flashOut&&(this.diedCounter=48,this.doHitSound=this.died=!0,this.yOffset=0<this.myDirection?32:48,this.xOffset=128,this.ySpeed=this.FrameDelay=2)};this.initFlash=function(){this.flashOut=!0;this.xOffset=0;this.yOffset=0>this.myDirection?48:32;this.FrameDelay=2;this.blockPlayerMovement=!0;this.ySpeed=2;this.doFlashSound=!0};this.update=function(a,c,d,b){var e;
this.headBump=!1;0<this.blinkCountDown?this.blinkCountDown--:8>getRandom(48)&&(this.blinkCountDown=16);this.scoreY+=this.scoreYSpeed;0<this.scoreY&&(this.scoreYSpeed=this.scoreY=0);4>this.scoreYSpeed&&this.scoreYSpeed++;if(this.flashOut)0<this.FrameDelay?this.FrameDelay--:(this.FrameDelay=1,this.xOffset+=16,112<this.xOffset&&(this.xOffset=112,this.y=this.x=-256)),this.y+=this.ySpeed,-8<this.ySpeed&&this.ySpeed--;else if(0<this.diedCounter)b||(this.hasLostALife=!0),this.diedCounter--,0<this.FrameDelay?
this.FrameDelay--:(this.FrameDelay=2,this.xOffset+=16,176<this.xOffset&&(this.xOffset=176,this.y=this.x=-256)),this.y-=1;else if(!this.died){if(!this.blockPlayerMovement)if(this.leftPressed?(0<this.myDirection&&(this.doMoveSound=!0),this.myDirection=-1,this.yOffset=16,this.xSpeed=-this.maxSpeed):this.rightPressed?(0>this.myDirection&&(this.doMoveSound=!0),this.myDirection=1,this.yOffset=0,this.xSpeed=this.maxSpeed):this.xSpeed=0,this.jumpPressed&&this.jumpReleased){if(0<this.onGroundCountdown||this.onGround||
0<this.jumpCount)this.jumpReleased=!1,this.jumpCount--,fxAdd(this.x+4,this.y+8,FX.fJUMPSMOKE,0),1==this.jumpCount?(this.ySpeed=-7,this.doJumpSoundMain=!0):(this.ySpeed=-5,this.doJumpSoundSecond=!0),this.onGroundCountdown=0,this.onGround=!1}else this.jumpPressed||(this.jumpReleased=!0);this.blockPlayerMovement=!1;if(this.onGround)if(0==this.xSpeed){if(6<this.FrameDelay||32<this.xOffset)this.FrameDelay=6,this.xOffset=0;0<this.FrameDelay?this.FrameDelay--:(this.xOffset+=16,32<this.xOffset&&(this.xOffset=
0),this.FrameDelay=3)}else 48>this.xOffset&&(this.FrameDelay=0,this.xOffset=48),0<this.FrameDelay?this.FrameDelay--:(this.xOffset+=16,112<this.xOffset&&(this.xOffset=48),this.FrameDelay=1);else 0==this.jumpCount?(128>this.xOffset&&(this.xOffset=128,this.FrameDelay=3),0<this.FrameDelay?this.FrameDelay--:(this.xOffset+=16,160<this.xOffset&&(this.xOffset=128),this.FrameDelay=3)):this.xOffset=80;this.yOffset=0<this.myDirection?0:16;this.x+=this.xSpeed;this.y+=this.ySpeed;b||(0>=this.x&&(this.x=0),this.x>=
(c<<3)-16&&(this.x=(c<<3)-16));0<this.onGroundCountdown&&this.onGroundCountdown--;8>this.ySpeed&&this.ySpeed++;this.y>(d<<3)-8&&(this.y=(d<<3)-8);var f;0<=this.ySpeed&&(b=this.x+2>>3,f=this.x+12>>3,e=this.y+16>>3,0<=e&&e<d&&0<=b&&b<c?0!=a[b+e*c]||0!=a[f+e*c]?(this.y=(e<<3)-16,4<this.ySpeed&&(this.doLandSound=!0,fxAdd(this.x+4,this.y+8,FX.fPARTICLE,this.myDirection)),this.ySpeed=0,this.onGround=!0,this.onGroundCountdown=4,this.jumpCount=2):this.onGround=!1:this.onGround=!1);this.nearByValue=1}};this.Paint=
function(a,c,d){c=this.x-c;d=this.y-d;0>d&&(d=0);renderSubImageAtPoint(a,c,d,this.xOffset,this.yOffset,16,16,0,1)}}
function PlayerProfile(){this.useSFX=this.useMusic=!0;this.useArcadeMode=!1;this.controlScheme=this.lastWhatsNew=0;this.highscore=Array(5);this.highname=Array(5);this.defscore=[500,400,300,200,100];this.defnames=["PAS","GHS","ALI","SUF","NIK"];this.charUnlocks=Array(32);this.currentCharacter=0;this.shareAwesome;this.buttonDistance;this.worldUnlocked;this.achievements=[100];this.achievementLevel;this.lastNameIDX=Array(3);this.collectables=Array(32);PlayerProfile.A_EASYTAKINGS=0;PlayerProfile.A_SMALLTHIEF=
1;PlayerProfile.A_GOODEYE=2;PlayerProfile.A_DIMEITUP=3;PlayerProfile.A_ROOKIEROBBER=4;PlayerProfile.A_NEWBIECOLLECTOR=5;PlayerProfile.A_HAWKEYE=6;PlayerProfile.A_REALTHIEF=7;PlayerProfile.A_CROFTY=8;PlayerProfile.A_TEMPLERAIDER=9;PlayerProfile.A_MASTERTHIEF=10;PlayerProfile.A_EGGAHOLIC=11;PlayerProfile.A_NOCEMENT=12;PlayerProfile.A_DIAMONDDEALER=13;PlayerProfile.A_LARACROFTY=14;PlayerProfile.A_DINKY=15;PlayerProfile.A_ARRRR=16;PlayerProfile.A_SPIRITED=17;PlayerProfile.A_MAXEDOUT=18;PlayerProfile.A_MAXACHIEVEMENTS=
19;this.aINDICES=[0,1,2,3,4,5,6,7,8,9,10,11,0,1,2,3,4,5,12];for(var a=this.highscore.length;0<=--a;)this.highscore[a]=this.defscore[a],this.highname[a]=this.defnames[a];for(a=this.achievements.length;100>a;a++)this.achievements[a]=0;for(a=this.charUnlocks.length;0<=--a;)this.charUnlocks[a]=!1;for(a=this.collectables.length;0<=--a;)this.collectables[a]=!1;for(a=this.lastNameIDX.length;0<=--a;)this.lastNameIDX[a]=-1;this.shareAwesome=!1;this.currentCharacter=this.buttonDistance=0;this.setAchievement=
function(a,d){this.achievements[a]=d};this.getAchievement=function(a){return this.achievements[a]};this.isUnlocked=function(a){return 100==this.achievements[a]?!0:!1};this.getAchievementIDX=function(a){return this.aINDICES[a]};this.loadSettings=function(){if(null!=localStorage.chronocash){var a=JSON.parse(localStorage.chronocash);this.useMusic=a.usemusic;this.useSFX=a.usesfx;this.useArcadeMode=a.useArcadeMode;this.lastWhatsNew=a.lastWhatsNew;this.shareAwesome=a.shareAwesome;this.buttonDistance=a.buttonDistance;
this.currentCharacter=a.currentCharacter;this.worldUnlocked=a.worldUnlocked}null!=localStorage.highscore&&(this.highscore=JSON.parse(localStorage.highscore));null!=localStorage.highname&&(this.highname=JSON.parse(localStorage.highname));null!=localStorage.achievement&&(this.achievements=JSON.parse(localStorage.achievement));null!=localStorage.charunlocks&&(this.charUnlocks=JSON.parse(localStorage.charunlocks));null!=localStorage.collectables&&(this.collectables=JSON.parse(localStorage.collectables));
null!=localStorage.lastnameidx&&(this.lastNameIDX=JSON.parse(localStorage.lastnameidx));this.charUnlocks[0]=!0;this.getLevel()};this.checkLevel=function(){var a=this.achievementLevel,d=3*(a-1);100==this.achievements[d]&&(100==this.achievements[d+1]&&100==this.achievements[d+2])&&a++;return a>this.achievementLevel?!0:!1};this.getLevel=function(){this.achievementLevel=1;for(var a=0;a<=PlayerProfile.A_MAXACHIEVEMENTS/3;a++)0<this.achievements[3*a]&&(0<this.achievements[3*a+1]&&0<this.achievements[3*
a+2])&&this.achievementLevel++};this.saveSettings=function(){localStorage.chronocash=JSON.stringify({usemusic:this.useMusic,usesfx:this.useSFX,useArcadeMode:this.useArcadeMode,lastWhatsNew:this.lastWhatsNew,shareAwesome:this.shareAwesome,buttonDistance:this.buttonDistance,currentCharacter:this.currentCharacter,worldUnlocked:this.worldUnlocked});localStorage.highscore=JSON.stringify(this.highscore);localStorage.highname=JSON.stringify(this.highname);localStorage.achievement=JSON.stringify(this.achievements);
localStorage.charunlocks=JSON.stringify(this.charUnlocks);localStorage.collectables=JSON.stringify(this.collectables);localStorage.lastnameidx=JSON.stringify(this.lastNameIDX)};this.resetSettings=function(){localStorage.removeItem("chronocash");localStorage.removeItem("highscore");localStorage.removeItem("highname");localStorage.removeItem("achievement");localStorage.removeItem("charunlocks");localStorage.removeItem("collectables");localStorage.removeItem("lastnameidx")}}
function SoundPool(a){this.useSound=!1;this.extension=".ogg";this.channelCount=a;this.errorCount=this.successCount=this.soundCount=0;this.soundList={};this.useAudioContext=!0;this.extension=".ogg";if(!document.createElement("audio").canPlayType("audio/ogg")&&(this.extension=".mp3",!document.createElement("audio").canPlayType("audio/mpeg")))return;try{this.audioContext=new AudioContext}catch(c){try{this.audioContext=new webkitAudioContext}catch(d){if(document.createElement("audio").canPlayType){this.useAudioContext=
!1;this.audiochannels=[];for(i=0;i<a;i++)this.audiochannels[i]=[],this.audiochannels[i].channel=new Audio,this.audiochannels[i].finished=-1;this.currentChannel=-1}else return}}this.useSound=!0}
SoundPool.prototype.load=function(a,c){if(this.useSound)if(this.soundCount++,a+=this.extension,this.useAudioContext){var d=this,b=new XMLHttpRequest;b.open("GET",a,!0);b.responseType="arraybuffer";b.onload=function(){d.soundList[c]=d.audioContext.createBuffer(b.response,!1);d.successCount++};b.onerror=function(){d.errorCount++};b.send()}else{var e=new Audio,d=this;e.addEventListener("canplaythrough",function(){d.successCount+=1},!1);e.addEventListener("error",function(){d.errorCount+=1},!1);e.src=
a;this.soundList[c]=e}};SoundPool.prototype.getTotal=function(){return this.soundCount-1};SoundPool.prototype.getDone=function(){return this.successCount+this.errorCount};SoundPool.prototype.isDone=function(){return this.soundCount<=this.successCount+this.errorCount};
SoundPool.prototype.playSound=function(a,c){if(this.useSound&&this.soundList[a]){if(this.useAudioContext)return source=this.audioContext.createBufferSource(),source.connect(this.audioContext.destination),source.buffer=this.soundList[a],c&&(source.loop="loop"),source.noteOn(0),source;var d=!1;for(this.currentChannel=0;!d&&this.currentChannel<this.audiochannels.length;)this.audiochannels[this.currentChannel].channel?this.audiochannels[this.currentChannel].channel.src&&!this.audiochannels[this.currentChannel].channel.ended?
this.currentChannel++:d=!0:d=!0;return d?(this.audiochannels[this.currentChannel].channel.src=this.soundList[a].src,this.audiochannels[this.currentChannel].channel.load(),this.audiochannels[this.currentChannel].channel.play(),c&&this.audiochannels[this.currentChannel].channel.addEventListener("ended",function(){this.currentTime=0;this.play()},!1),this.currentChannel):null}};
SoundPool.prototype.stopSound=function(a){this.useSound&&a&&(alert(a),this.useAudioContext?a.noteOff(0):(this.audiochannels[a].channel.removeEventListener("ended",null),this.audiochannels[a].channel.pause(),this.audiochannels[a].channel=new Audio))};
