From 08d88e2b54f208247cf4660df2f2bf4f393f52a1 Mon Sep 17 00:00:00 2001 From: Sky Date: Tue, 23 May 2023 15:12:38 -0400 Subject: [PATCH] adding death run and cell machine --- js/asteroids.js | 66 ++++++++++++ js/kickass.js | 263 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 329 insertions(+) create mode 100644 js/asteroids.js create mode 100644 js/kickass.js diff --git a/js/asteroids.js b/js/asteroids.js new file mode 100644 index 00000000..8862c903 --- /dev/null +++ b/js/asteroids.js @@ -0,0 +1,66 @@ + +(function(){function Asteroids(){if(!window.ASTEROIDS) + window.ASTEROIDS={enemiesKilled:0};function Vector(x,y){if(typeof x=='Object'){this.x=x.x;this.y=x.y;}else{this.x=x;this.y=y;}};Vector.prototype={cp:function(){return new Vector(this.x,this.y);},mul:function(factor){this.x*=factor;this.y*=factor;return this;},mulNew:function(factor){return new Vector(this.x*factor,this.y*factor);},add:function(vec){this.x+=vec.x;this.y+=vec.y;return this;},addNew:function(vec){return new Vector(this.x+vec.x,this.y+vec.y);},sub:function(vec){this.x-=vec.x;this.y-=vec.y;return this;},subNew:function(vec){return new Vector(this.x-vec.x,this.y-vec.y);},rotate:function(angle){var x=this.x,y=this.y;this.x=x*Math.cos(angle)-Math.sin(angle)*y;this.y=x*Math.sin(angle)+Math.cos(angle)*y;return this;},rotateNew:function(angle){return this.cp().rotate(angle);},setAngle:function(angle){var l=this.len();this.x=Math.cos(angle)*l;this.y=Math.sin(angle)*l;return this;},setAngleNew:function(angle){return this.cp().setAngle(angle);},setLength:function(length){var l=this.len();if(l)this.mul(length/l);else this.x=this.y=length;return this;},setLengthNew:function(length){return this.cp().setLength(length);},normalize:function(){var l=this.len();this.x/=l;this.y/=l;return this;},normalizeNew:function(){return this.cp().normalize();},angle:function(){return Math.atan2(this.y,this.x);},collidesWith:function(rect){return this.x>rect.x&&this.y>rect.y&&this.x-0.005)return 0;return l;},is:function(test){return typeof test=='object'&&this.x==test.x&&this.y==test.y;},toString:function(){return'[Vector('+this.x+', '+this.y+') angle: '+this.angle()+', length: '+this.len()+']';}};function Line(p1,p2){this.p1=p1;this.p2=p2;};Line.prototype={shift:function(pos){this.p1.add(pos);this.p2.add(pos);},intersectsWithRect:function(rect){var LL=new Vector(rect.x,rect.y+rect.height);var UL=new Vector(rect.x,rect.y);var LR=new Vector(rect.x+rect.width,rect.y+rect.height);var UR=new Vector(rect.x+rect.width,rect.y);if(this.p1.x>LL.x&&this.p1.xUR.y&&this.p2.x>LL.x&&this.p2.xUR.y)return true;if(this.intersectsLine(new Line(UL,LL)))return true;if(this.intersectsLine(new Line(LL,LR)))return true;if(this.intersectsLine(new Line(UL,UR)))return true;if(this.intersectsLine(new Line(UR,LR)))return true;return false;},intersectsLine:function(line2){var v1=this.p1,v2=this.p2;var v3=line2.p1,v4=line2.p2;var denom=((v4.y-v3.y)*(v2.x-v1.x))-((v4.x-v3.x)*(v2.y-v1.y));var numerator=((v4.x-v3.x)*(v1.y-v3.y))-((v4.y-v3.y)*(v1.x-v3.x));var numerator2=((v2.x-v1.x)*(v1.y-v3.y))-((v2.y-v1.y)*(v1.x-v3.x));if(denom==0.0){return false;} + var ua=numerator/denom;var ub=numerator2/denom;return(ua>=0.0&&ua<=1.0&&ub>=0.0&&ub<=1.0);}};var that=this;var isIE=!!window.ActiveXObject;var w=document.documentElement.clientWidth,h=document.documentElement.clientHeight;var playerWidth=20,playerHeight=30;var playerVerts=[[-1*playerHeight/2,-1*playerWidth/2],[-1*playerHeight/2,playerWidth/2],[playerHeight/2,0]];var ignoredTypes=['HTML','HEAD','BODY','SCRIPT','TITLE','META','STYLE','LINK','SHAPE','LINE','GROUP','IMAGE','STROKE','FILL','SKEW','PATH','TEXTPATH'];var hiddenTypes=['BR','HR'];var FPS=50;var acc=300;var maxSpeed=600;var rotSpeed=360;var bulletSpeed=700;var particleSpeed=400;var timeBetweenFire=150;var timeBetweenBlink=250;var timeBetweenEnemyUpdate=isIE?10000:2000;var bulletRadius=2;var maxParticles=isIE?20:40;var maxBullets=isIE?10:20;this.flame={r:[],y:[]};this.toggleBlinkStyle=function(){if(this.updated.blink.isActive){removeClass(document.body,'ASTEROIDSBLINK');}else{addClass(document.body,'ASTEROIDSBLINK');} + this.updated.blink.isActive=!this.updated.blink.isActive;};addStylesheet(".ASTEROIDSBLINK .ASTEROIDSYEAHENEMY","outline: 2px dotted red;");this.pos=new Vector(100,100);this.lastPos=false;this.vel=new Vector(0,0);this.dir=new Vector(0,1);this.keysPressed={};this.firedAt=false;this.updated={enemies:false,flame:new Date().getTime(),blink:{time:0,isActive:false}};this.scrollPos=new Vector(0,0);this.bullets=[];this.enemies=[];this.dying=[];this.totalEnemies=0;this.particles=[];function updateEnemyIndex(){for(var i=0,enemy;enemy=that.enemies[i];i++) + removeClass(enemy,"ASTEROIDSYEAHENEMY");var all=document.body.getElementsByTagName('*');that.enemies=[];for(var i=0,el;el=all[i];i++){if(indexOf(ignoredTypes,el.tagName.toUpperCase())==-1&&el.prefix!='g_vml_'&&hasOnlyTextualChildren(el)&&el.className!="ASTEROIDSYEAH"&&el.offsetHeight>0){el.aSize=size(el);that.enemies.push(el);addClass(el,"ASTEROIDSYEAHENEMY");if(!el.aAdded){el.aAdded=true;that.totalEnemies++;}}}};updateEnemyIndex();var createFlames;(function(){var rWidth=playerWidth,rIncrease=playerWidth*0.1,yWidth=playerWidth*0.6,yIncrease=yWidth*0.2,halfR=rWidth/2,halfY=yWidth/2,halfPlayerHeight=playerHeight/2;createFlames=function(){that.flame.r=[[-1*halfPlayerHeight,-1*halfR]];that.flame.y=[[-1*halfPlayerHeight,-1*halfY]];for(var x=0;xw) + vec.x=0;else if(vec.x<0) + vec.x=w;if(vec.y>h) + vec.y=0;else if(vec.y<0) + vec.y=h;};function size(element){var el=element,left=0,top=0;do{left+=el.offsetLeft||0;top+=el.offsetTop||0;el=el.offsetParent;}while(el);return{x:left,y:top,width:element.offsetWidth||10,height:element.offsetHeight||10};};function addEvent(obj,type,fn){if(obj.addEventListener) + obj.addEventListener(type,fn,false);else if(obj.attachEvent){obj["e"+type+fn]=fn;obj[type+fn]=function(){obj["e"+type+fn](window.event);} + obj.attachEvent("on"+type,obj[type+fn]);}} + function removeEvent(obj,type,fn){if(obj.removeEventListener) + obj.removeEventListener(type,fn,false);else if(obj.detachEvent){obj.detachEvent("on"+type,obj[type+fn]);obj[type+fn]=null;obj["e"+type+fn]=null;}} + function arrayRemove(array,from,to){var rest=array.slice((to||from)+1||array.length);array.length=from<0?array.length+from:from;return array.push.apply(array,rest);};function applyVisibility(vis){for(var i=0,p;p=window.ASTEROIDSPLAYERS[i];i++){p.gameContainer.style.visibility=vis;}} + function getElementFromPoint(x,y){applyVisibility('hidden');var element=document.elementFromPoint(x,y);if(!element){applyVisibility('visible');return false;} + if(element.nodeType==3) + element=element.parentNode;applyVisibility('visible');return element;};function addParticles(startPos){var time=new Date().getTime();var amount=maxParticles;for(var i=0;i0&&element.offsetHeight>0)return false;if(indexOf(hiddenTypes,element.tagName)!=-1)return true;if(element.offsetWidth==0&&element.offsetHeight==0)return false;for(var i=0;i50){createFlames();this.updated.flame=nowTime;} + this.scrollPos.x=window.pageXOffset||document.documentElement.scrollLeft;this.scrollPos.y=window.pageYOffset||document.documentElement.scrollTop;if((this.keysPressed[code('up')])||(this.keysPressed[code('W')])){this.vel.add(this.dir.mulNew(acc*tDelta));drawFlame=true;}else{this.vel.mul(0.96);} + if((this.keysPressed[code('left')])||(this.keysPressed[code('A')])){forceChange=true;this.dir.rotate(radians(rotSpeed*tDelta*-1));} + if((this.keysPressed[code('right')])||(this.keysPressed[code('D')])){forceChange=true;this.dir.rotate(radians(rotSpeed*tDelta));} + if(this.keysPressed[code(' ')]&&nowTime-this.firedAt>timeBetweenFire){this.bullets.unshift({'dir':this.dir.cp(),'pos':this.pos.cp(),'startVel':this.vel.cp(),'cameAlive':nowTime});this.firedAt=nowTime;if(this.bullets.length>maxBullets){this.bullets.pop();}} + if(this.keysPressed[code('B')]){if(!this.updated.enemies){updateEnemyIndex();this.updated.enemies=true;} + forceChange=true;this.updated.blink.time+=tDelta*1000;if(this.updated.blink.time>timeBetweenBlink){this.toggleBlinkStyle();this.updated.blink.time=0;}}else{this.updated.enemies=false;} + if(this.keysPressed[code('esc')]){destroy.apply(this);return;} + if(this.vel.len()>maxSpeed){this.vel.setLength(maxSpeed);} + this.pos.add(this.vel.mulNew(tDelta));if(this.pos.x>w){window.scrollTo(this.scrollPos.x+50,this.scrollPos.y);this.pos.x=0;}else if(this.pos.x<0){window.scrollTo(this.scrollPos.x-50,this.scrollPos.y);this.pos.x=w;} + if(this.pos.y>h){window.scrollTo(this.scrollPos.x,this.scrollPos.y+h*0.75);this.pos.y=0;}else if(this.pos.y<0){window.scrollTo(this.scrollPos.x,this.scrollPos.y-h*0.75);this.pos.y=h;} + for(var i=this.bullets.length-1;i>=0;i--){if(nowTime-this.bullets[i].cameAlive>2000){this.bullets.splice(i,1);forceChange=true;continue;} + var bulletVel=this.bullets[i].dir.setLengthNew(bulletSpeed*tDelta).add(this.bullets[i].startVel.mulNew(tDelta));this.bullets[i].pos.add(bulletVel);boundsCheck(this.bullets[i].pos);var murdered=getElementFromPoint(this.bullets[i].pos.x,this.bullets[i].pos.y);if(murdered&&murdered.tagName&&indexOf(ignoredTypes,murdered.tagName.toUpperCase())==-1&&hasOnlyTextualChildren(murdered)&&murdered.className!="ASTEROIDSYEAH"){didKill=true;addParticles(this.bullets[i].pos);this.dying.push(murdered);this.bullets.splice(i,1);continue;}} + if(this.dying.length){for(var i=this.dying.length-1;i>=0;i--){try{if(this.dying[i].parentNode) + window.ASTEROIDS.enemiesKilled++;this.dying[i].parentNode.removeChild(this.dying[i]);}catch(e){}} + setScore();this.dying=[];} + for(var i=this.particles.length-1;i>=0;i--){this.particles[i].pos.add(this.particles[i].dir.mulNew(particleSpeed*tDelta*Math.random()));if(nowTime-this.particles[i].cameAlive>1000){this.particles.splice(i,1);forceChange=true;continue;}} + if(forceChange||this.bullets.length!=0||this.particles.length!=0||!this.pos.is(this.lastPos)||this.vel.len()>0){this.ctx.clear();this.ctx.drawPlayer();if(drawFlame) + this.ctx.drawFlames(that.flame);if(this.bullets.length){this.ctx.drawBullets(this.bullets);} + if(this.particles.length){this.ctx.drawParticles(this.particles);}} + this.lastPos=this.pos;setTimeout(updateFunc,1000/FPS);} + var updateFunc=function(){that.update.call(that);};setTimeout(updateFunc,1000/FPS);function destroy(){removeEvent(document,'keydown',eventKeydown);removeEvent(document,'keypress',eventKeypress);removeEvent(document,'keyup',eventKeyup);removeEvent(window,'resize',eventResize);isRunning=false;removeStylesheet("ASTEROIDSYEAHSTYLES");removeClass(document.body,'ASTEROIDSYEAH');this.gameContainer.parentNode.removeChild(this.gameContainer);};} + if(!window.ASTEROIDSPLAYERS) + window.ASTEROIDSPLAYERS=[];if(window.ActiveXObject){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(){if(script.readyState=='loaded'||script.readyState=='complete'){if(typeof G_vmlCanvasManager!="undefined") + 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();})(); \ No newline at end of file diff --git a/js/kickass.js b/js/kickass.js new file mode 100644 index 00000000..024bcff9 --- /dev/null +++ b/js/kickass.js @@ -0,0 +1,263 @@ +/* + Copyright (c) <2011, 2012> Rootof Creations HB, rootof.com, kickassapp.com +*/(function(window) { +var JSONP=(function(){var counter=0,head,query,key,window=this;function load(url){var script=document.createElement('script'),done=false;script.src=url;script.async=true;script.onload=script.onreadystatechange=function(){if(!done&&(!this.readyState||this.readyState==="loaded"||this.readyState==="complete")){done=true;script.onload=script.onreadystatechange=null;if(script&&script.parentNode){script.parentNode.removeChild(script);}}};if(!head){head=document.getElementsByTagName('head')[0];if(!head) +head=document.body;} +head.appendChild(script);} +function jsonp(url,params,callback){query="?";params=params||{};for(key in params){if(params.hasOwnProperty(key)){query+=encodeURIComponent(key)+"="+encodeURIComponent(params[key])+"&";}} +var jsonp="json"+(++counter);window[jsonp]=function(data){callback(data);try{delete window[jsonp];}catch(e){} +window[jsonp]=null;};load(url+query+"callback="+jsonp);return jsonp;} +return{get:jsonp};}());var CORS={request:function(url,params,callback){if(this.calledByExtension()){this._callbacks[this._callbackId++]=callback;window.postMessage(JSON.stringify({from:"kickassapp-page",url:url,type:"callApi",params:params}),"*");return;} +params=params||{};var query="?";for(key in params){if(params.hasOwnProperty(key)){query+=encodeURIComponent(key)+"="+encodeURIComponent(params[key])+"&";}} +var xhr=new XMLHttpRequest();xhr.onreadystatechange=function(){if(xhr.readyState==4){callback(JSON.parse(xhr.responseText));}} +xhr.open("GET",url+query);xhr.withCredentials=true;xhr.setRequestHeader("Content-Type","application/json");xhr.send();},calledByExtension:function(){return!!document.getElementById("kickass-has-been-initialized-yes-yes-yes");},_callbacks:{},_callbackId:0} +if(CORS.calledByExtension()){window.addEventListener("message",function(e){var messageData;try{messageData=JSON.parse(e.data);}catch(e){return;} +if(messageData.from==="kickassapp-extension"&&messageData.sanityCheck==="kickassapp-extension-version1"){var message=messageData.payload;if(message.type==="response"){CORS._callbacks[message.requestId](message.body);delete CORS._callbacks[message.requestId];}else if(message.type==="destroy"){window.KICKASSGAME.destroy();}}},false);}function getGlobalNamespace(){return window&&window.INSTALL_SCOPE?window.INSTALL_SCOPE:window;} +var Class=function(methods){var ret=function(){if(ret.$prototyping)return this;if(typeof this.initialize=='function') +return this.initialize.apply(this,arguments);};if(methods.Extends){ret.parent=methods.Extends;methods.Extends.$prototyping=true;ret.prototype=new methods.Extends;methods.Extends.$prototyping=false;} +for(var key in methods)if(methods.hasOwnProperty(key)) +ret.prototype[key]=methods[key];return ret;};if(typeof exports!='undefined')exports.Class=Class;var Vector=new Class({initialize:function(x,y){if(typeof x=='object'){this.x=x.x;this.y=x.y;}else{this.x=x;this.y=y;}},cp:function(){return new Vector(this.x,this.y);},mul:function(factor){this.x*=factor;this.y*=factor;return this;},mulNew:function(factor){return new Vector(this.x*factor,this.y*factor);},div:function(factor){this.x/=factor;this.y/=factor;return this;},divNew:function(factor){return new Vector(this.x/factor,this.y/factor);},add:function(vec){this.x+=vec.x;this.y+=vec.y;return this;},addNew:function(vec){return new Vector(this.x+vec.x,this.y+vec.y);},sub:function(vec){this.x-=vec.x;this.y-=vec.y;return this;},subNew:function(vec){return new Vector(this.x-vec.x,this.y-vec.y);},rotate:function(angle){var x=this.x,y=this.y;this.x=x*Math.cos(angle)-Math.sin(angle)*y;this.y=x*Math.sin(angle)+Math.cos(angle)*y;return this;},rotateNew:function(angle){return this.cp().rotate(angle);},setAngle:function(angle){var l=this.len();this.x=Math.cos(angle)*l;this.y=Math.sin(angle)*l;return this;},setAngleNew:function(angle){return this.cp().setAngle(angle);},setLength:function(length){var l=this.len();if(l)this.mul(length/l);else this.x=this.y=length;return this;},setLengthNew:function(length){return this.cp().setLength(length);},normalize:function(){var l=this.len();if(l==0) +return this;this.x/=l;this.y/=l;return this;},normalizeNew:function(){return this.cp().normalize();},angle:function(){return Math.atan2(this.y,this.x);},collidesWith:function(rect){return this.x>rect.x&&this.y>rect.y&&this.x-0.005)return 0;return l;},is:function(test){return typeof test=='object'&&this.x==test.x&&this.y==test.y;},dot:function(v2){return this.x*v2.x+this.y*v2.y;},inTriangle:function(a,b,c){var v0=c.subNew(a);var v1=b.subNew(a);var v2=p.subNew(a);var dot00=v0.dot(v0);var dot01=v0.dot(v1);var dot02=v0.dot(v2);var dot11=v1.dot(v1);var dot12=v1.dot(v2);var invDenom=1/(dot00*dot11-dot01*dot01);var u=(dot11*dot02-dot01*dot12)*invDenom;var v=(dot00*dot12-dot01*dot02)*invDenom;return(u>0)&&(v>0)&&(u+v<1);},distanceFrom:function(vec){return Math.sqrt(Math.pow((this.x-vec.x),2),Math.pow(this.y-vec.y,2));},toString:function(){return'[Vector('+this.x+', '+this.y+') angle: '+this.angle()+', length: '+this.len()+']';}});if(typeof exports!='undefined')exports.Vector=Vector; +var Rect=new Class({initialize:function(x,y,w,h){this.pos=new Vector(x,y);this.size={width:w,height:h};},hasPoint:function(point){return point.x>this.getLeft()&&point.xthis.getTop()&&point.ytween.duration){this.tweenFinished(tween,key);continue;} +var delta=tween.transition(tdelta/tween.duration);var changes=[];for(var i=0,t;t=tween.tweens[i];i++){var x=delta*(t[1]-t[0])+t[0];changes.push(x);} +this.fire(key,changes,delta);}},tweenStart:function(key,time){this.running[key]={startTime:time};var values=[];for(var i=0,tween;tween=this.tweens[key].tweens[i];i++) +values.push(tween[0]);this.fire(key,values,0);},tweenFinished:function(tween,key){var values=[];for(var i=0,t;t=tween.tweens[i];i++) +values.push(t[1]);this.fire(key,values,1);if(!tween.repeats){delete this.running[key];delete this.tweens[key];return;} +this.tweenStart(key,now());},fire:function(key,values,delta){for(var i=0,listener;listener=this.listeners[i];i++) +listener.set.call(listener,key,values,delta);}});var Tween={Linear:function(x){return x;},Quadratic:function(x){return x*x;},Quintic:function(x){return x*x*x;},Shake:function(x){return Math.sin(x);}}; +var GameGlobals={FPS:60,useAnimationFrame:false,boids:{flockRadius:400,size:100},path:function(){return"https://kickassapp.com/"+Array.prototype.slice.call(arguments).join("");},hasCanvas:(typeof document.createElement('canvas').getContext!=='undefined'),bulletColor:'black'};window.GameGlobals=GameGlobals; +if(!Array.prototype.indexOf){Array.prototype.indexOf=function(searchElement){if(this===void 0||this===null) +throw new TypeError();var t=Object(this);var len=t.length>>>0;if(len===0) +return-1;var n=0;if(arguments.length>0){n=Number(arguments[1]);if(n!==n) +n=0;else if(n!==0&&n!==(1/0)&&n!==-(1/0)) +n=(n>0||-1)*Math.floor(Math.abs(n));} +if(n>=len) +return-1;var k=n>=0?n:Math.max(len-Math.abs(n),0);for(;k"+ship.name+"!!");} +for(var i=0,player;player=this.players[i];i++){player.setShip(ship);}},changeWeapon:function(weapon,isInitial){this.weaponClass=weapon.cannonClass;if(!isInitial){this.ui.showMessage("Changed to "+weapon.name.toUpperCase()+"!!!!");} +for(var i=0,player;player=this.players[i];i++){player.setCannons(weapon.cannonClass);}},changeWeaponById:function(id,isInitial){if(Weapons[id]){this.changeWeapon(Weapons[id],isInitial);}},flyOutPlayers:function(x,y){for(var i=0,player;player=this.players[i];i++){player.flyTo(x,-player.size.height);player.isBound=false;}},flyInPlayers:function(){for(var i=0,player;player=this.players[i];i++){player.flyTo(player.pos.x,100,function(){this.isBound=true;});}},newRank:function(rank){this.ui.showMessage("OMG. You leveled up to: "+rank+'!
Be sure to check what cool new stuff you get in the menu.');},fireBomb:function(){this.bombManager.blow();},destroy:function(){removeEvent(document,'keydown',this.keydownEvent);removeEvent(document,'keypress',this.keydownEvent);removeEvent(document,'keyup',this.keyupEvent);for(var i=0,player;player=this.players[i];i++){player.destroy();} +this.bulletManager.destroy();this.explosionManager.destroy();this.menuManager.destroy();if(!GameGlobals.useAnimationFrame){clearInterval(this.loopTimer);} +getGlobalNamespace().KICKASSGAME=false;if(this.isCampaign()){document.location.reload();}},isCampaign:function(){return getGlobalNamespace().IS_CLOUDFLARE_GAME;},isMySite:function(){return!!getGlobalNamespace().KICKASS_SITE_KEY;},shouldShowAd:function(){return!this.mySite&&!this.isCampaign();},shouldShowMenu:function(){return!this.mySite&&!this.isCampaign();},shouldShowHowToImage:function(){return this.mySite||this.isCampaign();}});window.KickAss=KickAss; +var StatisticsManager=new Class({initialize:function(game){this.game=game;this.data={};this.data.startedPlaying=now();this.data.elementsDestroyed=0;this.data.shotsFired=0;this.data.distanceFlownInPixels=0;this.data.totalPointsThisSession=0;this.data.usedThrusters=0;this.lastUpdate=0;},usedThrusters:function(){this.data.usedThrusters=1;},increaseDistanceWithPixels:function(px){this.data.distanceFlownInPixels+=px;},increasePointsGainedWithPoints:function(points){this.data.totalPointsThisSession+=points;},addShotFired:function(){this.data.shotsFired++;if(this.game.audioManager.shot){this.game.audioManager.shot.play();}},addElementsDestroyed:function(){this.data.elementsDestroyed++;},update:function(tdelta){this.lastUpdate+=tdelta;if(this.lastUpdate>0.25){this.syncWithServer();this.lastUpdate=0;}},syncWithServer:function(){var fragment=[];for(var key in this.data)if(this.data.hasOwnProperty(key)){fragment.push(key+':'+this.data[key]);} +this.game.menuManager.sendMessageToMenu("stats:!"+fragment.join('|'));}}); +var MySite=new Class({initialize:function(key){this.key=key;},load:function(callback){CORS.request(GameGlobals.path('mysite/api.json'),{site_key:this.key,url:document.location.toString()},bind(this,function(data){if(data&&data.embed){this.mySiteData=data.embed;callback(true);}else{callback(false);}}));},install:function(){},getShipId:function(){return this.mySiteData&&this.mySiteData.settings.ship;},getShipConfig:function(){return this.mySiteData&&this.mySiteData.settings.ship_config;},getShareURL:function(){return this.mySiteData&&this.mySiteData.settings.share_url;}}); +var Menu=new Class({initialize:function(game){this.game=game;this.size={height:300};},generate:function(parent){this.container=document.createElement('div');this.container.className='KICKASSELEMENT';this.container.id='kickass-profile-menu';parent.appendChild(this.container);var shipId=getGlobalNamespace().KICKASSSHIPID||"";this.url=GameGlobals.path('intermediate_postmessage.html?url='+ +encodeURIComponent(getGlobalNamespace().KICKASSURL||document.location.href)+"&origin="+encodeURIComponent(document.location.href)+"&preship="+(shipId)+"&is_campaign="+(this.game.isCampaign()?"true":"")+"&is_mysite="+(this.game.isMySite()?"true":""));this.isSocketReady=false;this.socketIframe=document.createElement("iframe");this.socketIframe.frameborder='0';this.socketIframe.className='KICKASSELEMENT';this.socketIframe.width='100%';this.socketIframe.height=this.size.height+'px';this.container.appendChild(this.socketIframe);this.menuOrigin="https://kickassapp.com/".replace(/\/$/,"");this.socketIframe.src=this.url;this.onMessage=bind(this,function(event){if(event.origin!==this.menuOrigin&&event.origin!==this.menuOrigin.replace("http://","https://")){console.log("ignoring event from",event.origin);return;} +var message=event.data;if(message==="ready"){this.onGameReady();return;} +var t=message.split(':!');if(t.length!==2){return;} +var type=t.shift().replace(/^./g,function(match){return match.charAt(0).toUpperCase();});if(typeof this['messageType'+type]==="function"){this['messageType'+type](t.join(":!"));}});window.addEventListener("message",this.onMessage,false);this.game.registerElement(this.container);},socketPostMessage:function(message){this.socketIframe.contentWindow.postMessage(message,this.menuOrigin);},onGameReady:function(){this.isSocketReady=true;this.game.registerElement(this.container.getElementsByTagName('iframe')[0]);this.socketPostMessage("url:!"+(getGlobalNamespace().KICKASSURL||document.location.href));if(this.game.statisticsManager){this.game.statisticsManager.syncWithServer();} +this.game.menuManager.onGameReady();},sendMessage:function(message){if(!this.isSocketReady){return;} +if(message!=this.lastMessage){try{this.socketPostMessage(message);}catch(e){} +this.lastMessage=message;}},messageTypeChangeShip:function(pieces){pieces=pieces.split(",");var shipId=pieces[0];var weaponId=pieces[1];var isInitial=pieces[2]==='initial';if(this.shipId===shipId){return;} +if(isInitial&&getGlobalNamespace().KICKASSSHIP){return;} +this.shipId=shipId;CORS.request(GameGlobals.path('designer/ship/'+shipId+'/construction.json'),{ship_id:shipId,is_initial:isInitial?'1':'0'},bind(this,function(data){this.game.updateShips(data.data,isInitial);try{window.focus();}catch(e){}}));if(!isInitial){this.parent.hideMenu();}},messageTypeChangeWeapon:function(weaponId,isInitial){this.game.changeWeaponById(weaponId,isInitial);},messageTypeSetMultiplier:function(mod){mod=parseInt(mod,10);if(isNaN(mod)||!mod){return;} +this.game.multiplier=mod;},messageTypeNewRank:function(rank){this.game.newRank(rank);},messageTypePlayerMessage:function(message){this.game.ui.showMessage(message);},destroy:function(){this.game.unregisterElement(this.container);this.game.unregisterElement(this.iframe);window.removeEventListener("message",this.onMessage,false);this.container.parentNode.removeChild(this.container);}}); +var MenuManager=new Class({initialize:function(game){this.game=game;this.numPoints=0;if(!getGlobalNamespace().KICKASS_INLINE_CSS){this.includeCSS(GameGlobals.path('css/menustyles.css'));}},generateDefaults:function(){for(var id in Weapons)if(Weapons.hasOwnProperty(id)){this.addWeapon(Weapons[id],id);} +this.hideBombMenu();},create:function(){this.container=document.createElement('div');this.container.className='KICKASSELEMENT KICKASShidden '+(this.game.shouldShowMenu()?"":"KICKASSNOMENU");this.container.id='kickass-menu';if(this.game.shouldShowMenu()){this.container.style.bottom='-250px';this.container.style.display='none';}else{removeClass(this.container,"KICKASShidden");} +getAppContainerElement().appendChild(this.container);var adHTML=this.game.shouldShowAd()?'':"";this.container.innerHTML='
'+'
'+ +adHTML+'
'+'
    '+'
'+'
'+''+'
'+'
'+ +this.numPoints+'
'+'
Press esc to quit
'+ +this.getShareHTML()+'
'+''+'
';this.pointsTab=document.getElementById('kickass-pointstab');this.pointsTabWrapper=document.getElementById('kickass-pointstab-wrapper');this.points=document.getElementById('kickass-points');this.escToQuit=document.getElementById('kickass-esctoquit');this.howToImage=document.getElementById('kickass-howto-image');this.weaponsMenu=document.getElementById('kickass-weapons-menu');this.weaponsList=document.getElementById('kickass-weapons-list');this.bombLink=document.getElementById('kickass-bomb-menu');this.submitScoreLink=document.getElementById('kickass-link-highscores');this.menuLink=document.getElementById('kickass-link-menu');this.switchShipLink=document.getElementById('kickass-link-ships');var all=this.container.getElementsByTagName('*');for(var i=0;i';}else{return'';}}else{var url='https://www.facebook.com/kickassapp';if(this.game.mySite){if(this.game.mySite.getShareURL()){url=this.game.mySite.getShareURL();}else{return"";}} +return'';}},onGameReady:function(){this.container.style.display='block';if(this.game.shouldShowHowToImage()){setTimeout(bind(this,function(){removeClass(this.howToImage,"kickass-howto-invisible");}),10);setTimeout(bind(this,function(){addClass(this.howToImage,"kickass-howto-invisible");}),4000);}},navigateTo:function(page,dontShowMenu){if(!dontShowMenu){this.showMenu();} +if(this.menu){this.menu.socketPostMessage('navigate:!'+page);}},toggleMenu:function(){if(this.game.shouldShowMenu()){if(hasClass(this.container,'KICKASShidden')){this.showMenu();}else{this.hideMenu();}}else{this.showMenu();}},toggleWeaponsMenu:function(){if(hasClass(this.weaponsMenu,'KICKASShidden')){this.showWeaponsMenu();}else{this.hideWeaponsMenu();}},hideWeaponsMenu:function(){this.weaponsMenu.style.width='';addClass(this.weaponsMenu,'KICKASShidden');},showWeaponsMenu:function(){var last=this.weaponsMenu.getElementsByTagName('li');last=last[last.length-1];this.weaponsMenu.style.width=(last.offsetLeft+last.offsetWidth-47)+'px';removeClass(this.weaponsMenu,'KICKASShidden');},showMenu:function(){if(this.game.shouldShowMenu()){this.container.style.bottom='';removeClass(this.container,'KICKASShidden');}},hideMenu:function(){this.container.style.bottom='';addClass(this.container,'KICKASShidden');},showBombMenu:function(){this.bombLink.style.width="";},hideBombMenu:function(){this.bombLink.style.width="0px";},getHeight:function(){return this.container.clientHeight;},isVisible:function(){return!hasClass(this.container,'KICKASShidden');},addPoints:function(killed,pos){var points=killed*this.game.multiplier;this.numPoints+=points;this.points.innerHTML=this.numPoints;if(this.game.statisticsManager){this.game.statisticsManager.increasePointsGainedWithPoints(points);} +this.game.ui.addPointsBubbleAt(pos,points);},includeCSS:function(file){var link=document.createElement('link');link.rel='stylesheet';link.type='text/css';link.href=file;(document.head||document.body).appendChild(link);},sendMessageToMenu:function(fragment){if(this.menu){this.menu.sendMessage(fragment);}},addWeapon:function(weapon,id){var li=document.createElement('li');li.className='KICKASSELEMENT kickass-weapon-item';li.weapon=weapon;li.style.backgroundImage='url('+GameGlobals.path('css/gfx/kickass/weap-'+weapon.id+'.png')+')';li.innerHTML=''+weapon.name+'';this.weaponsList.appendChild(li);addEvent(li,'click',bind(this,function(e){stopEvent(e);this.changeWeapon(weapon);this.sendMessageToMenu("changeWeapon:!"+id);}));},changeWeapon:function(weapon){this.game.changeWeapon(weapon);},destroy:function(){var all=this.container.getElementsByTagName('*');for(var i=0;i1000.0){this.isBroken=false;this.lineOffsets=[];this.randomPos();} +return;} +if(!this.tween){if(this.game.isKeyPressed('left')||this.game.isKeyPressed('right')){if(this.game.isKeyPressed('left')) +this.rotateLeft(tdelta);if(this.game.isKeyPressed('right')) +this.rotateRight(tdelta);}else{this.stopRotate();} +if(this.game.isKeyPressed('up')) +this.activateThrusters();else +this.stopThrusters();} +if(this.game.isKeyPressed(' ')){this.isShooting=true;if(!this.isBroken) +this.shootPressed();}else if(this.isShooting){this.isShooting=false;this.shootReleased();} +if(this.currentRotation) +this.dir.setAngle(this.dir.angle()+this.currentRotation*tdelta);var frictionedAcc=this.acc.mulNew(tdelta).sub(this.vel.mulNew(tdelta*this.friction));this.vel.add(frictionedAcc);if(this.vel.len()>this.terminalVelocity) +this.vel.setLength(this.terminalVelocity);var posDelta=this.vel.mulNew(tdelta);this.pos.add(posDelta);if(this.game.statisticsManager){this.game.statisticsManager.increaseDistanceWithPixels(posDelta.len());} +var showFlames=!this.acc.is({x:0,y:0});for(var i=0,thruster;thruster=this.thrusters[i];i++){thruster.setIsShown(showFlames);thruster.update(tdelta);} +if(this.isBound) +this.checkBounds();if(!this.lastPos.is(this.pos)||this.currentRotation||this.forceRedraw){this.forceRedraw=false;this.sheet.clear();this.sheet.setAngle(this.dir.angle()+Math.PI/2);this.sheet.setPosition(this.pos);if(showFlames){for(var i=0,thruster;thruster=this.thrusters[i];i++) +thruster.drawTo(this.sheet);} +this.sheet.drawPlayer(this.verts);this.lastPos=this.pos.cp();} +for(var i=0,cannon;cannon=this.cannons[i];i++){cannon.update(tdelta);}},randomPos:function(){var w=this.game.windowSize.width;var h=this.game.windowSize.height;this.pos=new Vector(random(0,w),random(0,h));},checkBounds:function(){if(this.tween) +return;var w=this.game.windowSize.width;var h=this.game.windowSize.height;var rightBound=this.pos.x+this.sheet.rect.size.width/2;var bottomBound=this.pos.y+this.sheet.rect.size.height/2;if(rightBound>w){window.scrollTo(this.game.scrollPos.x+50,this.game.scrollPos.y);this.pos.x=0;}else if(this.pos.x<0){window.scrollTo(this.game.scrollPos.x-50,this.game.scrollPos.y);this.pos.x=w-this.sheet.rect.size.width/2;} +if(bottomBound>h){window.scrollTo(this.game.scrollPos.x,this.game.scrollPos.y+h*0.75);this.pos.y=0;}else if(this.pos.y<0){window.scrollTo(this.game.scrollPos.x,this.game.scrollPos.y-h*0.75);this.pos.y=h-this.sheet.rect.size.height/2;}},inRect:function(rect){var ret=false;for(var i=0,vert;vert=this.verts[i];i++){if(rect.hasPoint(new Vector(vert.x+this.pos.x,vert.y+this.pos.y))) +ret=true;} +return ret;},hit:function(by){if(this.isBroken)return;this.isBroken=true;this.deadTime=now();},activateThrusters:function(){if(this.game.statisticsManager){this.game.statisticsManager.usedThrusters();} +this.acc=(new Vector(500,0)).setAngle(this.dir.angle());},stopThrusters:function(){this.acc=new Vector(0,0);},rotateLeft:function(tdelta){this.currentRotation=Math.max(-Math.PI*2,this.currentRotation-Math.PI*10*tdelta);},rotateRight:function(tdelta){this.currentRotation=Math.min(Math.PI*2,this.currentRotation+Math.PI*10*tdelta);},stopRotate:function(){this.currentRotation=0;},getSizeFromVertsAndObjects:function(){var largestDistance=0;for(var i=0,vert;vert=this.verts[i];i++) +largestDistance=Math.max(largestDistance,(new Vector(vert)).len());for(var i=0,obj;obj=this.thrusters[i];i++){var p1=(new Vector(obj.pos.x-obj.size.width/2,obj.pos.y-obj.size.height/2)).rotate(obj.angle);var p2=(new Vector(obj.pos.x+obj.size.width/2,obj.pos.y-obj.size.height/2)).rotate(obj.angle);var p3=(new Vector(obj.pos.x-obj.size.width/2,obj.pos.y+obj.size.height/2)).rotate(obj.angle);var p4=(new Vector(obj.pos.x+obj.size.width/2,obj.pos.y+obj.size.height/2)).rotate(obj.angle);largestDistance=Math.max(largestDistance,p1.len(),p2.len(),p3.len(),p4.len());} +return{width:largestDistance*2,height:largestDistance*2};},calculateBounds:function(){return{x:Math.max(this.size.width,this.size.height)*1,y:Math.max(this.size.height,this.size.width)*1};},shootPressed:function(){for(var i=0,cannon;cannon=this.cannons[i];i++) +cannon.shootPressed();},shootReleased:function(){for(var i=0,cannon;cannon=this.cannons[i];i++) +cannon.shootReleased();},flyTo:function(x,y,callback){this.tween={start:{pos:this.pos.cp(),dir:this.dir.cp()},to:new Vector(x,y),callback:callback||function(){}};this.tween.time=this.getTimeforTween();},destroy:function(){this.sheet.destroy();}});var Thruster=new Class({initialize:function(data,ship){this.pos=new Vector(data.p);this.size={width:data.s.w,height:data.s.h};this.angle=data.a||0;this.ship=ship;this.isShown=false;this.flameY=1;this.fx=new Fx();this.fx.addListener(this);this.flames={r:[],y:[]};this.lastFrameUpdate=0;this.generateFlames();},update:function(tdelta){this.fx.update();if(now()-this.lastFrameUpdate>1000/60) +this.generateFlames();},set:function(key,value){switch(key){case'flames':this.flameY=value;break;}},setIsShown:function(isShown){if(!this.isShown&&isShown){this.flameY=0.0;this.generateFlames();this.fx.add('flames',{start:this.flameY,end:1,duration:250,transition:Tween.Quintic});} +this.isShown=isShown;},drawTo:function(sheet){sheet.drawFlames(this.flames,this.angle);},generateFlames:function(){var redWidth=this.size.width,redIncrease=this.size.width*0.05,yellowWidth=this.size.width*0.8,yellowIncrease=yellowWidth*0.1,halfRed=redWidth/2,halfYellow=yellowWidth/2,offsetY=-this.size.height/2,metaY=0;var px=this.pos.x;var py=this.pos.y-this.size.height/2;function vec(x,y){return new Vector(x,y);} +this.flames.r=[vec(-halfRed+px,py)];this.flames.y=[vec(-halfYellow+px,py)];this.flames.self=this;for(var x=0;x(lower right corner or F)");}},blow:function(){var message=this.game.ui.showMessage("3...",5000);delay(1000,function(){message.innerHTML="2...";},this);delay(2000,function(){message.innerHTML="1...";},this);delay(3000,function(){message.innerHTML="boom";},this);delay(3000,this.blowStuffUp,this);this.nextBomb=this.bombShowDelay;},blowStuffUp:function(){this.game.bulletManager.updateEnemyIndex();var index=this.game.bulletManager.enemyIndex;for(var i=0,el;(el=index[i])&&i<10;i++){var rect=getRect(el);var center=new Vector(rect.left+rect.width/2,rect.top+rect.height/2);this.game.explosionManager.addExplosion(center,el,MegaParticleExplosion);el.parentNode.removeChild(el);} +this.game.menuManager.hideBombMenu();this.nextBomb=this.bombShowDelay;},isReady:function(){return this.nextBomb===-1;}});var ELEMENTSTHATARENOTTOBEINCLUDED=['BR','SCRIPT','STYLE','TITLE','META','HEAD','OPTION','OPTGROUP','LINK'];var ELEMENTSIZETHRESHOLD=5;var BulletManager=new Class({initialize:function(game){this.game=game;this.lastBlink=0;this.blinkActive=false;this.enemyIndex=[];this.updateDelay=2.5;this.nextUpdate=this.updateDelay;},update:function(tdelta){if(this.game.isKeyPressed('B')){this.blink();}else if(this.blinkActive){this.endBlink();} +this.nextUpdate-=tdelta;if(this.nextUpdate<0){this.updateEnemyIndex();}},blink:function(){if(now()-this.lastBlink>250){for(var i=0,el;el=this.enemyIndex[i];i++){if(!this.blinkActive) +el.style.outline='1px solid red';else +el.style.outline=el.KICKASSOLDBORDER;} +this.blinkActive=!this.blinkActive;this.lastBlink=now();if(!this.blinkActive){this.updateEnemyIndex();}}},endBlink:function(){for(var i=0,el;el=this.enemyIndex[i];i++) +el.style.outline=el.KICKASSOLDBORDER;this.lastBlink=0;this.blinkActive=false;},updateEnemyIndex:function(){var all=document.getElementsByTagName('*');this.enemyIndex=[];for(var i=0,el;el=all[i];i++){if(this.isDestroyable(el)){this.enemyIndex.push(el);el.KICKASSOLDBORDER=el.style.outline||(document.defaultView.getComputedStyle(el,null).outline);}} +this.nextUpdate=this.updateDelay;},isDestroyable:function(element,ignoreSize){if(this.shouldIgnoreElement(element,ignoreSize)) +return false;for(var i=0,child;child=element.childNodes[i];i++){if(child.nodeType===1&&ELEMENTSTHATARENOTTOBEINCLUDED.indexOf(child.tagName)===-1&&(child.offsetWidth>=ELEMENTSIZETHRESHOLD&&child.offsetHeight>=ELEMENTSIZETHRESHOLD)&&document.defaultView.getComputedStyle(child,null).visibility!=='hidden'){return false;}} +return true;},isDestroyableFromCollision:function(element){return this.isDestroyable(element,true);},shouldIgnoreElement:function(element,ignoreSize){if(element.nodeType!==1) +return true;if(element==document.documentElement||element==document.body) +return true;if(ELEMENTSTHATARENOTTOBEINCLUDED.indexOf(element.tagName)!==-1) +return true;if(element.style.visibility=='hidden'||element.style.display=='none') +return true;if(typeof element.className=="string"&&element.className.indexOf('KICKASSELEMENT')!=-1) +return true;if(!ignoreSize){if(element.offsetWidth=this.game.scrollSize.y) +return true;return false;},destroy:function(){for(var key in this.bullets)if(this.bullets.hasOwnProperty(key)) +for(var i=0,bullet;bullet=this.bullets[key][i];i++) +bullet.destroy();this.bullets={};}});var SessionManager=new Class({initialize:function(game){this.game=game;this.isPlaying=false;},update:function(tdelta){if(this.isPlaying&&this.game.bulletManager.enemyIndex.length==0){this.weHaveWon();}},weHaveWon:function(){this.isPlaying=false;this.game.ui.showMessage("You're done!");if(this.game.isCampaign()){this.game.menuManager.showMenu();this.game.menuManager.navigateTo('highscores');}else{this.game.menuManager.showMenu();} +this.game.menuManager.sendMessageToMenu("gameFinished:!");}}); +var ExplosionManager=new Class({initialize:function(game){this.game=game;this.explosions=[];},update:function(tdelta){var time=now();for(var i=0,explosion;explosion=this.explosions[i];i++){if(time-explosion.bornAt>(explosion.ttl||500)){explosion.destroy();this.explosions.splice(i,1);continue;} +explosion.update(tdelta);}},addExplosion:function(pos,forElement,explosionClass){explosionClass=explosionClass||ParticleExplosion;var explosion=new explosionClass(pos,forElement);explosion.game=this.game;explosion.checkBounds();this.explosions.push(explosion);if(this.game.audioManager.explosion){this.game.audioManager.explosion.play();}},destroy:function(){for(var i=0,explosion;explosion=this.explosions[i];i++) +explosion.destroy();this.explosions=[];}});var Cannon=new Class({initialize:function(player,game,x,y,angle){this.player=player;this.game=game;this.pos=new Vector(x,y);this.angle=angle||0;},shootPressed:function(){},shootReleased:function(){},checkCollisions:function(){},getExplosionClass:function(){return ParticleExplosion;},update:function(tdelta){this.game.hideAll();this.checkCollisions(tdelta);this.game.showAll();},checkCollision:function(bullet){var hit=bullet.checkCollision();if(!hit) +return false;this.game.explosionManager.addExplosion(bullet.pos,hit,this.getExplosionClass());this.game.menuManager.addPoints(Math.min(hit.getElementsByTagName('*').length+1,100),bullet.pos);if(!hit.isShot){hit.parentNode.removeChild(hit);} +if(this.game.statisticsManager){this.game.statisticsManager.addElementsDestroyed();} +return true;},createBullet:function(bulletClass){var pos=this.getABulletPos();var dir=this.getABulletDir();var bullet=new bulletClass(pos,dir);bullet.game=this.game;bullet.manager=this;bullet.initCanvas();bullet.vel.add(bullet.vel.cp().setLength(this.player.vel.len()));return bullet;},getABulletPos:function(){return this.player.pos.cp().add(this.pos.cp().rotate(this.player.dir.angle()+Math.PI/2));},getABulletDir:function(){return this.player.dir.cp().rotate(this.angle);},destroy:function(){}});var LaserCannon=new Class({Extends:Cannon,initialize:function(player,game,x,y,angle){Cannon.prototype.initialize.apply(this,arguments);this.lasers=[];},getExplosionClass:function(){return SplitExplosion;},update:function(tdelta){if(!this.lasers.length) +return;this.removeOld();Cannon.prototype.update.call(this,tdelta);},checkCollisions:function(tdelta){for(var i=0,laser;laser=this.lasers[i];i++){laser.update(tdelta);if(this.checkCollision(laser)){}}},removeOld:function(){for(var i=0,laser;laser=this.lasers[i];i++){if(laser.outOfBounds){laser.destroy();this.lasers.splice(i,1);}}},shootPressed:function(){if(this.lasers.length>5){return;} +if(now()-this.lastFired<500){return;} +this.lastFired=now();if(this.game.statisticsManager){this.game.statisticsManager.addShotFired();} +this.lasers.push(this.createBullet(LaserBullet));},destroy:function(){if(this.lasers.length){for(var i=0,laser;laser=this.lasers[i];i++){laser.destroy();} +this.lasers=[];}}});var BallCannon=new Class({Extends:Cannon,initialize:function(){Cannon.prototype.initialize.apply(this,arguments);this.lastFired=0;this.bullets=[];},getExplosionClass:function(){return ParticleExplosion;},update:function(tdelta){if(!this.bullets.length){return;} +this.removeOld();Cannon.prototype.update.call(this,tdelta);},removeOld:function(){var time=now();for(var i=0,bullet;bullet=this.bullets[i];i++){if(time-bullet.bornAt>2000){bullet.destroy();this.bullets.splice(i,1);}}},checkCollisions:function(tdelta){for(var i=0,bullet;bullet=this.bullets[i];i++){bullet.update(tdelta);if(this.checkCollision(bullet)){bullet.destroy();this.bullets.splice(i,1);}}},shootPressed:function(){if(now()-this.lastFired<200){return;} +this.lastFired=now();this.addBullet();if(this.game.statisticsManager){this.game.statisticsManager.addShotFired();}},addBullet:function(){if(this.bullets.length>7){this.bullets[0].destroy();this.bullets.shift();} +var bullet=this.createBullet(Bullet);this.bullets.push(bullet);},destroy:function(){for(var i=0,bullet;bullet=this.bullets[i];i++){bullet.destroy();} +this.bullets=[];}}); +var Bullet=new Class({initialize:function(pos,dir){this.pos=pos.cp();this.dir=dir;this.vel=new Vector(500,500);this.bornAt=now();},initCanvas:function(){this.sheet=new Sheet(new Rect(this.pos.x,this.pos.y,5,5));this.sheet.drawBullet();},draw:function(){this.sheet.setPosition(this.pos);},update:function(tdelta){this.pos.add(this.vel.setAngle(this.dir.angle()).mulNew(tdelta));this.checkBounds();this.draw();},checkCollision:function(){var element=document.elementFromPoint(this.pos.x,this.pos.y);if(element&&element.nodeType==3) +element=element.parentNode;var didFind=element&&this.game.bulletManager.isDestroyableFromCollision(element)?element:false;return didFind;},checkBounds:function(){var w=this.game.windowSize.width;var h=this.game.windowSize.height;var rightBound=this.pos.x+this.sheet.rect.size.width/2;var bottomBound=this.pos.y+this.sheet.rect.size.height/2;if(rightBound>w) +this.pos.x=0;else if(this.pos.x<0) +this.pos.x=w-this.sheet.rect.size.width/2;if(bottomBound>h) +this.pos.y=0;else if(this.pos.y<0) +this.pos.y=h-this.sheet.rect.size.height/2;},destroy:function(){this.sheet.destroy();}});var LaserBullet=new Class({Extends:Bullet,initialize:function(){Bullet.prototype.initialize.apply(this,arguments);this.vel=new Vector(750,750);this.lastDrawPos=this.pos.cp();},initCanvas:function(){var s=Math.max(GameGlobals.laserImage.width,GameGlobals.laserImage.height);this.sheet=new Sheet(new Rect(0,0,s,s));},update:function(tdelta){Bullet.prototype.update.apply(this,arguments);},draw:function(){this.sheet.drawLaser(this.pos,this.dir);this.lastDrawPos=this.pos.cp();},checkBounds:function(){var w=this.game.windowSize.width;var h=this.game.windowSize.height;var rightBound=this.pos.x+this.sheet.rect.size.width/2;var bottomBound=this.pos.y+this.sheet.rect.size.height/2;if(rightBound>w||this.pos.x<0) +this.outOfBounds=true;if(bottomBound>h||this.pos.y<0) +this.outOfBounds=true;},destroy:function(){this.sheet.destroy();}});GameGlobals.laserImage=document.createElement('img');GameGlobals.laserImage.src=GameGlobals.path('css/gfx/kickass/laser.png'); +var Explosion=new Class({initialize:function(pos,element){this.bornAt=now();this.pos=pos.cp();},update:function(tdelta){},checkBounds:function(){},destroy:function(){}}); +var ParticleExplosion=new Class({Extends:Explosion,initialize:function(pos,element){Explosion.prototype.initialize.apply(this,arguments);this.particleVel=new Vector(150,0);this.particles=[];this.generateParticles();this.sheet=new Sheet(new Rect(pos.x,pos.y,250,250));},update:function(tdelta){for(var i=0,particle;particle=this.particles[i];i++) +particle.pos.add(particle.vel.mulNew(tdelta).mul(random(0.5,1.0)).setAngle(particle.dir.angle()));this.sheet.clear();this.sheet.drawExplosion(this.particles);},generateParticles:function(){for(var i=0,j=!GameGlobals.hasCanvas?10:40;iw) +this.pos.x-=right-w;if(bottom>h) +this.pos.y-=bottom-h;this.sheet.setPosition(this.pos);},destroy:function(){this.sheet.destroy();}}); +var MegaParticleExplosion=new Class({Extends:ParticleExplosion,initialize:function(pos,element){Explosion.prototype.initialize.apply(this,arguments);this.particleVel=new Vector(200,0);this.particles=[];this.generateParticles();this.sheet=new Sheet(new Rect(pos.x,pos.y,500,500));this.ttl=2000;this.generationDelay=0.6;this.generationTimes=2;this.nextGenerate=this.generationDelay;},update:function(tdelta){this.nextGenerate-=tdelta;if(this.nextGenerate<=0&&this.generationTimes>0){this.nextGenerate=this.generationDelay;this.generateParticles();this.generationTimes--;} +ParticleExplosion.prototype.update.call(this,tdelta);}});var SplitExplosion=new Class({Extends:Explosion,initialize:function(pos,element){if(!element)return;Explosion.prototype.initialize.apply(this,arguments);this.element=element;this.fx=new Fx();this.fx.addListener(this);this.start();},update:function(tdelta){if(!this.element)return;this.fx.update();},set:function(key,value){if(key=='opacity'){}},start:function(){var pieces=this.createClones();var left=pieces[0],right=pieces[1];var lT='rotate(-'+random(30,50)+'deg) translate(-100px, 40px)';var rT='rotate('+random(30,50)+'deg) translate(100px, 40px)';setStyles(left,{'transform':lT});setStyles(right,{'transform':rT});this.left=left;this.right=right;this.fx.add('opacity',{start:1,end:0.5,duration:500});},createClones:function(){var coords=getRect(this.element);var leftContainer=this.createContainer(coords);var rightContainer=this.createContainer(coords);var left=cloneElement(this.element);var right=cloneElement(this.element);addClass(left,'KICKASSELEMENT');addClass(right,'KICKASSELEMENT');var styles={margin:0,overflow:'hidden'};setStyles(left,styles);setStyles(right,styles);leftContainer.appendChild(left);rightContainer.appendChild(right);rightContainer.style.left=coords.left+coords.width/2+'px';rightContainer.scrollLeft+=coords.width/2;this.element.style.opacity=0;this.element.style.visibility='hidden';this.element.style.display='none';return each([leftContainer,rightContainer],function(el){el.style.transition='transform 500ms ease-in';});},createContainer:function(coords){var ret=document.createElement('div');setStyles(ret,{position:'absolute',left:coords.left,top:coords.top,width:coords.width*0.5,height:coords.height,overflow:'hidden'});getAppContainerElement().appendChild(ret);return ret;},destroy:function(){try{this.left.parentNode.removeChild(this.left);this.right.parentNode.removeChild(this.right);this.element.parentNode.removeChild(this.element);}catch(e){}}});var Weapons={1:{name:'Cannon',id:'cannon',cannonClass:BallCannon},2:{name:'Laser',id:'laser',cannonClass:LaserCannon}};var WeaponMap={'cannon':Weapons[1],'laser':Weapons[2]}; +var SheetCanvas=new Class({initialize:function(rect){this.canvas=document.createElement('canvas');this.canvas.className='KICKASSELEMENT';with(this.canvas.style){position='absolute';zIndex='1000000';} +GameGlobals.kickass.registerElement(this.canvas);if(this.canvas.getContext) +this.ctx=this.canvas.getContext('2d');this.rect=rect;this.angle=0;this.updateCanvas();getAppContainerElement().appendChild(this.canvas);},tracePoly:function(verts){if(!verts[0])return;this.ctx.save();this.ctx.translate(this.rect.size.width/2,this.rect.size.height/2);this.ctx.rotate(this.angle);this.ctx.beginPath();this.ctx.moveTo(verts[0].x,verts[0].y);for(var i=0;i