!function(){function Asteroids(){function Vector(e,t){"Object"==typeof e?(this.x=e.x,this.y=e.y):(this.x=e,this.y=t)}function Line(e,t){this.p1=e,this.p2=t}window.ASTEROIDS||(window.ASTEROIDS={enemiesKilled:0}),Vector.prototype={cp:function(){return new Vector(this.x,this.y)},mul:function(e){return this.x*=e,this.y*=e,this},mulNew:function(e){return new Vector(this.x*e,this.y*e)},add:function(e){return this.x+=e.x,this.y+=e.y,this},addNew:function(e){return new Vector(this.x+e.x,this.y+e.y)},sub:function(e){return this.x-=e.x,this.y-=e.y,this},subNew:function(e){return new Vector(this.x-e.x,this.y-e.y)},rotate:function(e){var t=this.x,i=this.y;return this.x=t*Math.cos(e)-Math.sin(e)*i,this.y=t*Math.sin(e)+Math.cos(e)*i,this},rotateNew:function(e){return this.cp().rotate(e)},setAngle:function(e){var t=this.len();return this.x=Math.cos(e)*t,this.y=Math.sin(e)*t,this},setAngleNew:function(e){return this.cp().setAngle(e)},setLength:function(e){var t=this.len();return t?this.mul(e/t):this.x=this.y=e,this},setLengthNew:function(e){return this.cp().setLength(e)},normalize:function(){var e=this.len();return this.x/=e,this.y/=e,this},normalizeNew:function(){return this.cp().normalize()},angle:function(){return Math.atan2(this.y,this.x)},collidesWith:function(e){return this.x>e.x&&this.y>e.y&&this.x-.005?0:e},is:function(e){return"object"==typeof e&&this.x==e.x&&this.y==e.y},toString:function(){return"[Vector("+this.x+", "+this.y+") angle: "+this.angle()+", length: "+this.len()+"]"}},Line.prototype={shift:function(e){this.p1.add(e),this.p2.add(e)},intersectsWithRect:function(e){var t=new Vector(e.x,e.y+e.height),i=new Vector(e.x,e.y),s=new Vector(e.x+e.width,e.y+e.height),n=new Vector(e.x+e.width,e.y);return this.p1.x>t.x&&this.p1.xn.y&&this.p2.x>t.x&&this.p2.xn.y||!!this.intersectsLine(new Line(i,t))||!!this.intersectsLine(new Line(t,s))||!!this.intersectsLine(new Line(i,n))||!!this.intersectsLine(new Line(n,s))},intersectsLine:function(e){var t=this.p1,i=this.p2,s=e.p1,n=e.p2,a=(n.y-s.y)*(i.x-t.x)-(n.x-s.x)*(i.y-t.y),o=(n.x-s.x)*(t.y-s.y)-(n.y-s.y)*(t.x-s.x),h=(i.x-t.x)*(t.y-s.y)-(i.y-t.y)*(t.x-s.x);if(0==a)return!1;var r=o/a,l=h/a;return r>=0&&r<=1&&l>=0&&l<=1}};var that=this,isIE=!!window.ActiveXObject,isIEQuirks=isIE&&"BackCompat"==document.compatMode,w=document.documentElement.clientWidth,h=document.documentElement.clientHeight;isIEQuirks&&(w=document.body.clientWidth,h=document.body.clientHeight);var playerWidth=20,playerHeight=30,playerVerts=[[-1*playerHeight/2,-1*playerWidth/2],[-1*playerHeight/2,playerWidth/2],[playerHeight/2,0]],ignoredTypes=["HTML","HEAD","BODY","SCRIPT","TITLE","META","STYLE","LINK"];window.ActiveXObject&&(ignoredTypes=["HTML","HEAD","BODY","SCRIPT","TITLE","META","STYLE","LINK","SHAPE","LINE","GROUP","IMAGE","STROKE","FILL","SKEW","PATH","TEXTPATH","INS"]);var hiddenTypes=["BR","HR"],FPS=50,acc=300,maxSpeed=600,rotSpeed=360,bulletSpeed=700,particleSpeed=400,timeBetweenFire=150,timeBetweenBlink=250,timeBetweenEnemyUpdate=isIE?1e4:2e3,bulletRadius=2,maxParticles=isIE?20:40,maxBullets=isIE?10:20,createFlames,rWidth,rIncrease,yWidth,yIncrease,halfR,halfY,halfPlayerHeight;function updateEnemyIndex(){for(var e,t=0;e=that.enemies[t];t++)removeClass(e,"ASTEROIDSYEAHENEMY");var i,s=document.body.getElementsByTagName("*");for(that.enemies=[],t=0;i=s[t];t++)-1==indexOf(ignoredTypes,i.tagName.toUpperCase())&&"g_vml_"!=i.prefix&&hasOnlyTextualChildren(i)&&"ASTEROIDSYEAH"!=i.className&&i.offsetHeight>0&&(i.aSize=size(i),that.enemies.push(i),addClass(i,"ASTEROIDSYEAHENEMY"),i.aAdded||(i.aAdded=!0,that.totalEnemies++))}function radians(e){return.0174532925*e}function degrees(e){return 57.2957795*e}function random(e,t){return Math.floor(Math.random()*(t+1)+e)}function code(e){var t={up:38,down:40,left:37,right:39,esc:27};return t[e]?t[e]:e.charCodeAt(0)}function boundsCheck(e){e.x>w?e.x=0:e.x<0&&(e.x=w),e.y>h?e.y=0:e.y<0&&(e.y=h)}function size(e){var t=e,i=0,s=0;do{i+=t.offsetLeft||0,s+=t.offsetTop||0,t=t.offsetParent}while(t);return{x:i,y:s,width:e.offsetWidth||10,height:e.offsetHeight||10}}function addEvent(e,t,i){e.addEventListener?e.addEventListener(t,i,!1):e.attachEvent&&(e["e"+t+i]=i,e[t+i]=function(){e["e"+t+i](window.event)},e.attachEvent("on"+t,e[t+i]))}function removeEvent(e,t,i){e.removeEventListener?e.removeEventListener(t,i,!1):e.detachEvent&&(e.detachEvent("on"+t,e[t+i]),e[t+i]=null,e["e"+t+i]=null)}function arrayRemove(e,t,i){var s=e.slice((i||t)+1||e.length);return e.length=t<0?e.length+t:t,e.push.apply(e,s)}function applyVisibility(e){for(var t,i=0;t=window.ASTEROIDSPLAYERS[i];i++)t.gameContainer.style.visibility=e}function getElementFromPoint(e,t){applyVisibility("hidden");var i=document.elementFromPoint(e,t);return i?(3==i.nodeType&&(i=i.parentNode),applyVisibility("visible"),i):(applyVisibility("visible"),!1)}function addParticles(e){for(var t=(new Date).getTime(),i=maxParticles,s=0;s0&&e.offsetHeight>0)return!1;if(-1!=indexOf(hiddenTypes,e.tagName))return!0;if(0==e.offsetWidth&&0==e.offsetHeight)return!1;for(var t=0;t50&&(createFlames(),this.updated.flame=t),this.scrollPos.x=window.pageXOffset||document.documentElement.scrollLeft,this.scrollPos.y=window.pageYOffset||document.documentElement.scrollTop,this.keysPressed[code("up")]||this.keysPressed[code("W")]?(this.vel.add(this.dir.mulNew(acc*i)),s=!0):this.vel.mul(.96),(this.keysPressed[code("left")]||this.keysPressed[code("A")])&&(e=!0,this.dir.rotate(radians(rotSpeed*i*-1))),(this.keysPressed[code("right")]||this.keysPressed[code("D")])&&(e=!0,this.dir.rotate(radians(rotSpeed*i))),this.keysPressed[code(" ")]&&t-this.firedAt>timeBetweenFire&&(this.bullets.unshift({dir:this.dir.cp(),pos:this.pos.cp(),startVel:this.vel.cp(),cameAlive:t}),this.firedAt=t,this.bullets.length>maxBullets&&this.bullets.pop()),this.keysPressed[code("B")]?(this.updated.enemies||(updateEnemyIndex(),this.updated.enemies=!0),e=!0,this.updated.blink.time+=1e3*i,this.updated.blink.time>timeBetweenBlink&&(this.toggleBlinkStyle(),this.updated.blink.time=0)):this.updated.enemies=!1,this.keysPressed[code("esc")])destroy.apply(this);else{this.vel.len()>maxSpeed&&this.vel.setLength(maxSpeed),this.pos.add(this.vel.mulNew(i)),this.pos.x>w?(window.scrollTo(this.scrollPos.x+50,this.scrollPos.y),this.pos.x=0):this.pos.x<0&&(window.scrollTo(this.scrollPos.x-50,this.scrollPos.y),this.pos.x=w),this.pos.y>h?(window.scrollTo(this.scrollPos.x,this.scrollPos.y+.75*h),this.pos.y=0):this.pos.y<0&&(window.scrollTo(this.scrollPos.x,this.scrollPos.y-.75*h),this.pos.y=h);for(var n=this.bullets.length-1;n>=0;n--)if(t-this.bullets[n].cameAlive>2e3)this.bullets.splice(n,1),e=!0;else{var a=this.bullets[n].dir.setLengthNew(bulletSpeed*i).add(this.bullets[n].startVel.mulNew(i));this.bullets[n].pos.add(a),boundsCheck(this.bullets[n].pos);var o=getElementFromPoint(this.bullets[n].pos.x,this.bullets[n].pos.y);o&&o.tagName&&-1==indexOf(ignoredTypes,o.tagName.toUpperCase())&&hasOnlyTextualChildren(o)&&"ASTEROIDSYEAH"!=o.className&&(didKill=!0,addParticles(this.bullets[n].pos),this.dying.push(o),this.bullets.splice(n,1))}if(this.dying.length){for(n=this.dying.length-1;n>=0;n--)try{this.dying[n].parentNode&&window.ASTEROIDS.enemiesKilled++,this.dying[n].parentNode.removeChild(this.dying[n])}catch(e){}setScore(),this.dying=[]}for(n=this.particles.length-1;n>=0;n--)this.particles[n].pos.add(this.particles[n].dir.mulNew(particleSpeed*i*Math.random())),t-this.particles[n].cameAlive>1e3&&(this.particles.splice(n,1),e=!0);isIEQuirks&&(this.gameContainer.style.left=this.canvas.style.left=document.documentElement.scrollLeft+"px",this.gameContainer.style.top=this.canvas.style.top=document.documentElement.scrollTop+"px",this.navigation.style.right="10px",this.navigation.style.top=document.documentElement.scrollTop+document.body.clientHeight-this.navigation.clientHeight-10+"px"),(e||0!=this.bullets.length||0!=this.particles.length||!this.pos.is(this.lastPos)||this.vel.len()>0)&&(this.ctx.clear(),this.ctx.drawPlayer(),s&&this.ctx.drawFlames(that.flame),this.bullets.length&&this.ctx.drawBullets(this.bullets),this.particles.length&&this.ctx.drawParticles(this.particles)),this.lastPos=this.pos}};var updateFunc=function(){try{that.update.call(that)}catch(e){throw clearInterval(interval),e}},interval=setInterval(updateFunc,1e3/FPS);function destroy(){removeEvent(document,"keydown",eventKeydown),removeEvent(document,"keypress",eventKeypress),removeEvent(document,"keyup",eventKeyup),removeEvent(window,"resize",eventResize),isRunning=!1,removeStylesheet("ASTEROIDSYEAHSTYLES"),removeClass(document.body,"ASTEROIDSYEAH"),this.gameContainer.parentNode.removeChild(this.gameContainer)}}if(window.ASTEROIDSPLAYERS||(window.ASTEROIDSPLAYERS=[]),window.ActiveXObject&&!document.createElement("canvas").getContext){try{var xamlScript=document.createElement("script");xamlScript.setAttribute("type","text/xaml"),xamlScript.textContent='',document.getElementsByTagName("head")[0].appendChild(xamlScript)}catch(e){}var script=document.createElement("script");script.setAttribute("type","text/javascript"),script.onreadystatechange=function(){"loaded"!=script.readyState&&"complete"!=script.readyState||"undefined"!=typeof G_vmlCanvasManager&&(window.ASTEROIDSPLAYERS[window.ASTEROIDSPLAYERS.length]=new Asteroids)},script.src="http://erkie.github.com/excanvas.js",document.getElementsByTagName("head")[0].appendChild(script)}else window.ASTEROIDSPLAYERS[window.ASTEROIDSPLAYERS.length]=new Asteroids}();