(function(w,z){function qa(a){return a<<1}function ra(a){return a<<1}function S(){return z.pointerLockElement===x||z.mozPointerLockElement===x||z.webkitPointerLockElement===x}function aa(){a.fillStyle="#000000";a.font="35px NovaSquare";a.fillText("Please do not embed our website, thank you.",400-a.measureText("Please do not embed our website, thank you.").width/2,300);a.font="16px NovaSquare";a.fillText("Play the game on http://cursors.io/",400-a.measureText("Play the game on http://cursors.io/").width/ 2,330);top.location="http://cursors.io";throw"Please do not embed our website, thank you.";}function sa(a){T(a)}function U(a,b){F=a;G=b;k=p=a;l=s=b;A=p<<1;B=s<<1}function ta(a){if(y)return H=!1,T(a),!1;S()?V||(V=!0,U(k,l)):(V=!1,y||I.checked||x.requestPointerLock&&x.requestPointerLock());if(H)H=!1,J();else if(T(a),(a.ctrlKey||a.shiftKey)&&!C.checked)W=!0,N=k,O=l;else if(100Math.abs(b)+Math.abs(a)&&X(A+b,B+a)}else a.offsetX?X(a.offsetX,a.offsetY):a.layerX&&X(a.layerX,a.layerY);if(y)k=p,l=s;else if(Y(),!S()||p==k&&s==l||(a=b=0,p>k&&(b=1),s>l&&(a=1),p=k,s=l,A=(p<<1)+b,B=(s<<1)+a),W&&(N!=k||O!=l)&&50>1;s=B>>1}function Y(){var a=k,b=l;if(P(k,l)){var c;a:{c=k;var d=l,f=[],e=new Uint8Array(12E4);f.push([c,d]);e[c+400*d]=1;do{var h=f.shift(),g=h[0],h=h[1];if(!(0>g||0>h||400<=g||300<=h)){if(!P(g,h)){c={x:g,y:h};break a}e[g-1+400*h]||(f.push([g-1,h]),e[g-1+400*h]=1);e[g+1+400*h]||(f.push([g+1,h]),e[g+1+400*h]=1);e[g+400*(h-1)]||(f.push([g,h-1]),e[g+400*(h-1)]=1);e[g+400*(h+1)]||(f.push([g,h+1]),e[g+400* (h+1)]=1)}}while(0=b.x+b.width||l>=b.y+b.height)){a=!0;break a}a=!1}a&&J()}function Z(){Q.set(Ca);m=[];D=[];L=[]}function wa(){Z();console.log("Connected!")}function ya(a){Z();console.log("Socket closed: "+a.reason)}function za(a){console.log("Socket error")}function Da(a,b){for(var c="",d=0,f=0;0!=(f=a.getUint8(b));++b)d<<= 8,d|=f,f&128||(c+=String.fromCharCode(d),d=0);0!=d&&(c+=String.fromCharCode(d));return[c,b+1]}function Ea(a,b){setTimeout(function(){var c=a.getUint16(b,!0),d=0;a:for(;d=c+4?u=Math.max(u,b.getUint32(c,!0)):a.byteLength>=c+2&&(u=Math.max(u,b.getUint16(c,!0)));Y();break;case 5:U(b.getUint16(1,!0),b.getUint16(3,!0)),9<=b.byteLength?u=Math.max(u,b.getUint32(5,!0)):7<=b.byteLength&&(u=Math.max(u,b.getUint16(5, !0))),Y()}}function J(a,b){if(!y&&!H&&null!=q&&q.readyState==WebSocket.OPEN&&("undefined"==typeof a&&(a=k),"undefined"==typeof b&&(b=l),a!=F||b!=G)){var c=new ArrayBuffer(9),d=new DataView(c);d.setUint8(0,1);d.setUint16(1,a,!0);d.setUint16(3,b,!0);d.setUint32(5,u,!0);q.send(c);F=a;G=b}}function ua(a,b){if(!y&&null!=q&&q.readyState==WebSocket.OPEN){var c=new ArrayBuffer(9),d=new DataView(c);d.setUint8(0,2);d.setUint16(1,a,!0);d.setUint16(3,b,!0);d.setUint32(5,u,!0);q.send(c)}}function ka(a,b,c){function d(){c.x= a.getUint16(b,!0);b+=2;c.y=a.getUint16(b,!0);b+=2;c.width=a.getUint16(b,!0);b+=2;c.height=a.getUint16(b,!0);b+=2}function f(){for(var d=a.getUint32(b,!0).toString(16);6>d.length;)d="0"+d;b+=4;c.color="#"+d}var e=a.getUint8(b);b+=1;c.type=e;switch(e){case 255:break;case 0:c.x=a.getUint16(b,!0);b+=2;c.y=a.getUint16(b,!0);b+=2;c.size=a.getUint8(b);b+=1;c.isCentered=!!a.getUint8(b);b+=1;e=Da(a,b);c.text=e[0];b=e[1];break;case 1:d();var h=!c.color;f();var e=c.x|0,g=c.y|0,k=c.width|0,l=c.height|0;if(h)for(h= g;ha.getUint16(b,!0)&&(c.lastClickAt=t):c.lastClickAt=0;c.count=a.getUint16(b,!0);b+=2;f();break;default:throw Error("Unknown object type "+e);}return b}function la(){a.clearRect(0,0,800,600);a.save();if(null!=q&&q.readyState!=WebSocket.OPEN||H){var n;if(null==q)n="Click to begin";else switch(q.readyState){case WebSocket.CONNECTING:n= "Connecting";break;case WebSocket.CLOSING:case WebSocket.CLOSED:n="Lost connection to server";break;default:n="Click to begin"}a.font="60px NovaSquare";a.fillText(n,400-a.measureText(n).width/2,315);ma();na(!1)}else{a.fillStyle="#000000";a.save();a.globalAlpha=1;Ga();for(n=0;nb.width|| 40>b.height?(a.font="30px NovaSquare",a.fillText(b.count,c+f/2-a.measureText(b.count).width/2,d+e/2+10)):(a.font="60px NovaSquare",a.fillText(b.count,c+f/2-a.measureText(b.count).width/2,d+e/2+20));a.globalAlpha=1}else if(4==b.type){c=b.x<<1;d=b.y<<1;f=b.width<<1;e=b.height<<1;a.fillStyle=b.color;a.strokeStyle=b.color;a.globalAlpha=1;a.fillRect(c,d,f,e);a.globalAlpha=.2;a.fillStyle="#000000";a.fillRect(c,d,f,e);a.globalAlpha=1;a.fillStyle=b.color;var h=150>t-b.lastClickAt,g=h?8:12;a.fillRect(c+g, d+g,f-2*g,e-2*g);a.strokeStyle="#000000";a.globalAlpha=.1;a.beginPath();a.moveTo(c,d);a.lineTo(c+g,d+g);a.moveTo(c+f,d);a.lineTo(c+f-g,d+g);a.moveTo(c,d+e);a.lineTo(c+g,d+e-g);a.moveTo(c+f,d+e);a.lineTo(c+f-g,d+e-g);a.moveTo(c,d);a.rect(c,d,f,e);a.rect(c+g,d+g,f-2*g,e-2*g);a.stroke();a.fillStyle="#000000";a.globalAlpha=.5;50>b.width||50>b.height?(a.font="35px NovaSquare",a.fillText(b.count,c+f/2-a.measureText(b.count).width/2,d+e/2+13)):(a.font="45px NovaSquare",a.fillText(b.count,c+f/2-a.measureText(b.count).width/ 2,d+e/2+16));h&&(a.fillStyle="#000000",a.globalAlpha=.15,a.fillRect(c+g,d+g,f-2*g,e-2*g));a.globalAlpha=1}}a.restore();y||(a.font="12px NovaSquare",a.strokeStyle="#000000",a.fillStyle="#FFFFFF",a.lineWidth=2.5,n=ia?"Area too full, not all cursors are shown":30=c?(L.splice(n,1),--n):(1=d?(D.splice(n,1),--n):(c*=50,a.beginPath(),a.globalAlpha=.3*d,a.arc(b[0],b[1],c,0,2*Math.PI,!1),a.stroke())}a.restore()}function na(n){if(y)a.save(),a.globalAlpha=1,a.drawImage(M,A-5,B-5);else{var b=0,c=0;p!=k||s!=l?(a.save(),n&&(a.globalAlpha=.2,a.fillStyle="#FF0000",a.beginPath(),a.arc(A+2,B+8,20,0,2*Math.PI,!1),a.fill()),a.globalAlpha=.5,a.drawImage(M,A-5,B-5,23,30),a.restore()):(b=A&1,c=B&1);a.save();n&&(a.globalAlpha= .2,a.fillStyle="#FFFF00",a.beginPath(),a.arc((k<<1)+b+2,(l<<1)+c+8,20,0,2*Math.PI,!1),a.fill());a.globalAlpha=1;a.drawImage(Ha,(k<<1)+b-5,(l<<1)+c-5,23,30)}a.restore()}function ja(a,b){this.oldX=this.newX=a;this.oldY=this.newY=b;this.time=t}function oa(a){return a*a*(3-2*a)}function ea(a,b,c,d){a|=0;b|=0;c|=0;d|=0;if(P(a,b))return{x:a,y:b};if(a==c&&b==d)return{x:c,y:d};var f=a,e=b;c=c-a|0;d=d-b|0;var h=0,g=0,k=0,l=0;0>c?h=-1:0d?g=-1:0c?k=-1:0d?l=-1:0>1;for(d=0;d<=m&&!P(a,b);d++)f=a,e=b,c+=p,c>=m?(c-=m,a+=h,b+=g):(a+=k,b+=l);return{x:f,y:e}}function fa(a,b,c,d){a=ea(a,b,c,d);return a.x==c&&a.y==d}function P(a,b){return 0>a||400<=a||0>b||300<=b?!0:Q[a+400*b]}var Aa="file:"==w.location.protocol,E,a,x,ha=0,p=0,s=0,A=0,B=0,k=0,l=0,F=-1,G=-1,I=null,C=null,M=new Image;M.src="img/cursor.png";var Ha=M,y=-1!=w.location.search.indexOf("editor"),D=[],L=[],t=0,ba=0,q=null,ga= -1,v={},$=0,ia=!1,W=!1,N=0,O=0,da=0,V=!1,H=!y&&!0,Q=new Uint8Array(12E4),m=[],K=[],R=w.devicePixelRatio;Array.prototype.remove=function(a){a=this.indexOf(a);return-1!=a?(this.splice(a,1),!0):!1};var u=0;ja.prototype={oldX:0,oldY:0,newX:0,newY:0,time:0,getX:function(){var a=this.newX-this.oldX,b=(t-this.time)/100,b=oa(0>=b?0:1<=b?1:b);return this.oldX+b*a},getY:function(){var a=this.newY-this.oldY,b=(t-this.time)/100,b=oa(0>=b?0:1<=b?1:b);return this.oldY+b*a}};var pa=function(){function n(){var a= 0,b=0,c=p/10,d=s/10;hc)var e=c,c=a,a=e;b>d&&(e=d,d=b,b=e);return{sx:a,sy:b,fx:c,fy:d}}function b(){e=!0;h=p/10;g=s/10}function c(a){return"0x"+parseInt(a.slice(1),16).toString(16).toUpperCase()}function d(a,b,c,d,e){a={x:10*~~(k/10)-~~(a/2)+c,y:10*~~(l/10)-~~(b/2)+d,width:a,height:b};for(var f in e)e.hasOwnProperty(f)&&(a[f]=e[f]);return a}function f(a,b){for(var c= null,d=Number.POSITIVE_INFINITY,e=0;e wallByColor["+u.length+"];\n"),b=new Uint8Array(1200),d=[],e=0;30>e;++e)for(var f=0;40>f;++f)if(!b[f+40*e]){var g=v[f+40*e];if(0!=g){for(var h=f;40>f&&v[f+40*e]==g&&!b[f+40*e];)b[f+40*e]=!0,++f;var k=f--,n=k-h,l=e++;a:for(;30>e;){for(var p=h;pr&&(r=u.length)):83==b?(++r, r>u.length&&(r=0)):66==b?1>=r||m.push(d(40,40,5,5,{type:4,color:u[r-1],colorCode:r-1,count:5})):90==b?m.pop():87==b?m.push(d(50,50,-5,-5,{type:2,isBad:!1})):79==b?(q=k,t=l):78==b?1>=r||m.push(d(40,40,0,0,{type:3,color:u[r-1],colorCode:r-1,count:1})):37==b?(b=f(p,s),null!=b&&(a.shiftKey?b.width-=10:(b.x-=10,b.width+=10),0==b.width&&m.splice(m.indexOf(b),1))):39==b?(b=f(p,s),null!=b&&(a.shiftKey?(b.x+=10,b.width-=10):b.width+=10,0==b.width&&m.splice(m.indexOf(b),1))):38==b?(b=f(p,s),null!=b&&(a.shiftKey? b.height-=10:(b.y-=10,b.height+=10),0==b.height&&m.splice(m.indexOf(b),1))):40==b&&(b=f(p,s),null!=b&&(a.shiftKey?(b.y+=10,b.height-=10):b.height+=10,0==b.height&&m.splice(m.indexOf(b),1)))}});return{renderEditor:function(){if(y){a.save();a.fillStyle="#FF0000";a.strokeStyle="#FF0000";a.lineWidth=1;a.globalAlpha=.09;a.beginPath();for(var b=0;400>b;b+=10)a.moveTo((b<<1)+.5,0),a.lineTo((b<<1)+.5,600);for(var c=0;300>c;c+=10)a.moveTo(0,(c<<1)+.5),a.lineTo(800,(c<<1)+.5);a.stroke();a.lineWidth=2;a.beginPath(); a.moveTo(400.5,0);a.lineTo(400.5,600);a.moveTo(0,300.5,0);a.lineTo(800,300.5);a.stroke();a.lineWidth=1;a.globalAlpha=1;a.fillStyle="#000000";for(var d=n(),c=0;300>c;c+=10)for(b=0;400>b;b+=10){var f=b/10|0,g=c/10|0,h=v[f+40*g];e&&f>=d.sx&&f=d.sy&&g