Maingron/MainOS

View on GitHub
Program Files/optisocubes/optisocubes.min.js

Summary

Maintainability
A
0 mins
Test Coverage
function Cube(){var b,c,d,e,p,v,l,F,y,r,z,N,P=!1,O=!1,D=!1,G=0,f=[],m=[],n=[],C=!1,g=!1,B=!1,w=!1,H=!0,x=[],J=!1,I=0,k=0,L=!1,R=!1,M=0,t=!1,u=0,h=!0,Q=0;this.constructor=function(A,g){b=A;c=g;F=.5*canvas.width-scale*(rows-1);y=canvas.height-scale*(cols+1)*.5;d=F+b*scale+c*scale;e=y+c*scale-b*scale*.5-c*scale*.5;p=Math.sqrt(scale*scale+.25*scale*scale);l=v=p=scale;z=r=800-e;f[0]=new PVector(d+scale,e-scale/2-r);f[1]=new PVector(d,e-r);f[2]=new PVector(d,e-l-r);f[3]=new PVector(d+scale,e-scale/2-l- r);for(var h=0;4>h;h++)m[h]=new PVector(0,0),m[h].makeEqualTo(f[h]),m[h].x-=scale,m[h].y-=scale/2;for(h=0;4>h;h++)n[h]=new PVector(0,0)};this.updateRiseFall=function(){(D||O)&&(B=!1,C=!1,g=!1,w=!1,G+=.1*fps.delta,30<G&&(G=30),D&&(r+=G*fps.delta)>=z-G*fps.delta&&(r=z,D=!1,G=0),O&&(r-=G*fps.delta)<=z+G*fps.delta&&(r=z,O=!1,G=0),E())};this.updateRotation=function(){if(B||g||C||w){L&&15>k?(k-=1*fps.delta,N=-1):(k+=1*fps.delta,N=1);var A=Math.PI/2;f[1].rotAround(f[0],N*I*A/25*fps.delta);f[2].rotAround(f[0],N*I*A/25*fps.delta);f[3].rotAround(f[0],N*I*A/25*fps.delta);24<k?(B&&(b++,B=!1),g&&(b--,g=!1),C&&(c--,C=!1),w&&(c++,w=!1),k=0,0<=l?(d=F+b*scale+c*scale,e=y+c*scale-b*scale*.5-c*scale*.5):(d=F+b*scale+c*scale,e=y+c*scale-b*scale*.5-c*scale*.5-scale),E(),J=!0):0>k&&(k=0,B=!1,w=!1,C=!1,g=!1,L=!1,E())}};this.updateHeight=function(){P&&(l<v-1.5*fps.delta?(l+=1.5*fps.delta,E()):l>v+1.5*fps.delta?(l-=1.5*fps.delta,E()):(l=v,E(),P=!1))};var S=function(){0<=l?(d=F+b*scale+c*scale,e=y+c*scale-b*scale*.5-c* scale*.5):(d=F+b*scale+c*scale,e=y+c*scale-b*scale*.5-c*scale*.5-scale);B&&(f[0].setXAndY(d+scale,e-scale/2-r),f[1].setXAndY(f[0].x-scale,f[0].y),f[2].setXAndY(f[0].x-scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l),I=1,0>l&&(f[0].setXAndY(d,e-r),f[1].setXAndY(f[0].x-scale,f[0].y),f[2].setXAndY(f[0].x-scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l)));g&&(f[0].setXAndY(d,e-r),f[1].setXAndY(f[0].x+scale,f[0].y),f[2].setXAndY(f[0].x+scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l),I=-1,0>l&&(f[0].setXAndY(d- scale,e+scale/2-r),f[1].setXAndY(f[0].x+scale,f[0].y),f[2].setXAndY(f[0].x+scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l)));C&&(f[0].setXAndY(d-scale,e-scale/2-r),f[1].setXAndY(f[0].x+scale,f[0].y),f[2].setXAndY(f[0].x+scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l),I=-1,0>l&&(f[0].setXAndY(d,e-r),f[1].setXAndY(f[0].x+scale,f[0].y),f[2].setXAndY(f[0].x+scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l)));w&&(f[0].setXAndY(d,e-r),f[1].setXAndY(f[0].x-scale,f[0].y),f[2].setXAndY(f[0].x-scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l),I=1,0>l&&(f[0].setXAndY(d+scale,e+scale/2-r),f[1].setXAndY(f[0].x-scale,f[0].y),f[2].setXAndY(f[0].x-scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l)));0>l&&(I=-I);H=!1};this.setIsStatic=function(){w=g=C=B=!1;E()};var E=function(){if(H=!0,L=!1,0<=l){d=F+b*scale+c*scale;e=y+c*scale-b*scale*.5-c*scale*.5;f[0].setXAndY(d+scale,e-scale/2-r);f[1].setXAndY(f[0].x-scale,f[0].y);f[2].setXAndY(f[0].x-scale,f[0].y-l);f[3].setXAndY(f[0].x,f[0].y-l);for(var A=0;A<f.length;A++)m[A].makeEqualTo(f[A]),m[A].x-=scale,m[A].y-=scale/2}else for(d=F+b*scale+c*scale,e=y+c*scale-b*scale*.5-c*scale*.5-scale,f[0].setXAndY(d,e-r),f[1].setXAndY(f[0].x-scale,f[0].y),f[2].setXAndY(f[0].x-scale,f[0].y-l),f[3].setXAndY(f[0].x,f[0].y-l),A=0;A<f.length;A++)m[A].makeEqualTo(f[A]),m[A].x+=scale,m[A].y+=scale/2};this.setRotBack=function(b){L=b};this.getHasMoved=function(){var b=J;return J=!1,b};this.getXPosition=function(){return b};this.getYPosition=function(){return c};this.getHPosition=function(){return r};this.getCubeHeight=function(){return l};this.getAniRightUp=function(){return B};this.getAniLeftDown=function(){return g};this.getAniLeftUp=function(){return C};this.getAniRightDown=function(){return w};this.getCanMoveDir=function(b){return x[b]};this.getIsOnTarget=function(){return R};this.getFade=function(){return t};this.setIsOnTarget=function(b){R=!1};this.setFade=function(b){t=b};this.target=function(d,e){d==b&&e==c&&(R=!0)};this.moveTo=function(d,e){b=d;c=e;r=floorTile[b][c].getHeight();E()};this.moveWithTiles=function(){var d=floorTile[b][c].getHeight();d>r&&(r=d,E())};this.rightWayUp=function(){P=!0;v=Math.sqrt(v*v)};this.setHeight=function(){l=p};this.setTargetCount=function(b){targetCount=0};this.setTH=function(b){z=r=-e+b};this.setTargetTH=function(b){z=b;z<r?O=!0:z>r?D=!0:r=z};this.setCanMove=function(){for(var b=0;4>b;b++)x[b]=!0};this.setTileHeights=function(d){z=d[b][c].getHeight();z<r?O=!0:z>r?D=!0:r=z;0<=c-1&&(0<l&&d[b][c-1].getHeight()>z||0>l&&d[b][c-1].getHeight()<z)&&(x[0]=!1);b+1<rows&&(0<l&&d[b+1][c].getHeight()>z||0>l&&d[b+1][c].getHeight()<z)&&(x[1]=!1);0<=b-1&&(0<l&&d[b-1][c].getHeight()>z||0>l&&d[b-1][c].getHeight()<z)&&(x[2]=!1);c+1<cols&&(0<l&&d[b][c+1].getHeight()>z||0>l&&d[b][c+1].getHeight()<z)&&(x[3]=!1)};this.checkEdgeOfTiles=function(){b+1>rows-1&&(x[1]=!1);0>b-1&&(x[2]=!1);c+1>cols-1&&(x[3]=!1);0>c-1&&(x[0]=!1)};this.checkOthers=function(d,e,f,l){0!=l||f||d==b&&e==c-1&&(x[0]=!1);1!=l||f||d==b+1&&e==c&&(x[1]=!1);2!=l||f||d==b-1&&e==c&&(x[2]=!1);3!=l||f||d==b&&e==c+1&&(x[3]=!1)};this.move=function(f){0==f&&0<c&&x[0]?(C=!0,S()):1==f&&b<rows-1&&x[1]?(B=!0,S()):2==f&&0<b&&x[2]?(g=!0,S()):3==f&&c<cols-1&&x[3]?(w=!0,S()):4==f&&(P=!0,v=-v);0<=l?(d=F+b*scale+c*scale,e=y+c*scale-b*scale*.5-c*scale*.5):(d=F+b*scale+c*scale,e=y+c*scale-b*scale*.5-c*scale*.5-scale);L=!1};this.getIsAnimating=function(){return!!(C||B||w||g||P||D||O)};var K=function(b,c,d,e){ct.beginPath();ct.moveTo(b.x,b.y);ct.lineTo(c.x,c.y);ct.lineTo(d.x,d.y);ct.lineTo(e.x,e.y);ct.closePath()},q=function(b){R?(0<=M&&100>M&&!H&&(M+=1*N*fps.delta),ct.fillStyle="rgba("+Math.round(M/100*b)+",0,"+Math.round(b*(1-M/100))+",1)"):t?(h=!1,100>u?u+=1*fps.delta:t=!1,ct.fillStyle="rgba("+Math.round(u/100*b)+",0,"+Math.round(b*(1-u/100))+",1)"):h?ct.fillStyle="rgba(0,0,"+Math.round(b)+",1)":(ct.fillStyle="rgba("+Math.round(b)+",0,0,1)",M=0,u=0);tileAnimation?(Q+=.03*fps.delta,ct.strokeStyle="rgba(255,255,255,"+(.5+(Math.sin(Q)+1)/4)+")"):(Q+=.015*fps.delta,ct.strokeStyle="rgba(255,255,255,"+(.25+(Math.sin(Q)+1)/4)+")");ct.lineWidth=1;ct.stroke();ct.fill()};this.display=function(){n[0].makeEqualTo(f[0]);for(var b=1;4>b;b++){var c=(f[b].x-f[0].x)/2;(C||w)&&(c*=-1);n[b].setXAndY(f[b].x,f[b].y-c)}for(b=0;b<f.length;b++)m[b].makeEqualTo(n[b]),0<=l?H?(m[b].x-=scale,m[b].y-=scale/2):g||B?(m[b].x-=scale,m[b].y-=scale/2):(m[b].x+=scale,m[b].y-=scale/2):H?(m[b].x+=scale,m[b].y+=scale/2):g||B?(m[b].x+=scale,m[b].y+=scale/2):(m[b].x-=scale,m[b].y+=scale/2);0<=l?(K(n[0],n[1],n[2],n[3]),C||w?q(50):g||B?q(150):H&&q(150),K(m[0],n[0],n[1],m[1]),C&&n[2].x<n[0].x?q(150*k/25):B&&n[2].x>n[0].x&&q(0+50*k/25),K(m[2],n[2],n[1],m[1]),B?q(50+200*k/25):g&&n[2].x<n[0].x?q(50+200*k/25):C?q(150+100*k/25):w&&n[2].x>n[0].x?q(150+100*k/25):H&&q(50),K(m[2],n[2],n[3],m[3]),C&&n[2].x>f[0].x?q(250-100*k/25):w?q(250-100*k/25):g?q(250-200*k/25):B&&n[2].x<f[0].x?q(250-100*k/25):H&&q(250),K(n[0],n[3],m[3],m[0]),g&&n[2].x>f[0].x?q(50-50*k/25):w&&n[2].x<f[0].x&&q(150-150*k/25)):(K(n[0],n[1],n[2],n[3]),C||w?q(50):g||B?q(150):H&&q(150),K(m[0],n[0],n[1],m[1]),g&&n[2].x<n[0].x?q(0+50*k/25):w&&n[2].x>n[0].x&&q(0+150*k/25),K(m[2],n[2],n[1],m[1]),B&&n[2].x>n[0].x?q(150+100*k/25):g?q(50+200*k/25):C&&n[2].x<n[0].x?q(150+100*k/25):w&&q(150+100*k/25),K(m[2],n[2],n[3],m[3]),C?q(250-100*k/25):w&&n[2].x<f[0].x?q(250-100*k/25):g&&n[2].x>f[0].x?q(250-200*k/25):B?q(250-200*k/25):H&&q(250),K(n[0],n[3],m[3],m[0]),C&&n[2].x>f[0].x?q(150-150*k/25):B&&n[2].x<f[0].x?q(50-50*k/25):H&&q(50))}}function getMousePos(b,c){var d=b.getBoundingClientRect();return{x:c.clientX-d.left,y:c.clientY-d.top}}function Sounds(){audiochannels=[];for(a=0;100>a;a++)audiochannels[a]=[],audiochannels[a].channel=new Audio,audiochannels[a].finished=-1;this.play=function(b){for(a=0;a<audiochannels.length;a++)if(thistime=new Date,audiochannels[a].finished<thistime.getTime()){audiochannels[a].finished=thistime.getTime()+1E3*document.getElementById(b).duration;audiochannels[a].channel.src=document.getElementById(b).src;audiochannels[a].channel.load();audiochannels[a].channel.play();break}}}function PVector(b,c){this.x=b;this.y=c;this.add=function(b){this.x+=b.x;this.y+=b.y};this.normalize=function(){var b=Math.sqrt(this.x*this.x+this.y*this.y);this.x/=b;this.y/=b};this.mult=function(b){this.x*=b;this.y*=b};this.div=function(b){this.x/=b;this.y/=b};this.mag=function(){return Math.sqrt(this.x*this.x+this.y*this.y)};this.limit=function(b){this.normalize();this.mult(b)};this.subAlt=function(b,c,p,v){this.x=b-p;this.y=c-v};this.sub=function(b){this.x-=b.x;this.y-=b.y};this.heading=function(){return Math.atan2(this.y,this.x)};this.rotAround=function(b,c){this.sub(b);var p=this.heading(),p=p+c,v=this.mag()*Math.cos(p),p=this.mag()*Math.sin(p),v=new PVector(v,p);v.add(b);this.x=v.x;this.y=v.y};this.makeCentreOfArray=function(b){for(var c=this.y=this.x=0;c<b.length;c++)this.x+=b[c].x,this.y+=b[c].y;this.div(b.length)};this.makeEqualTo=function(b){this.x=b.x;this.y=b.y};this.setXAndY=function(b,c){this.x=b;this.y=c};this.movePointBetween=function(b,c,p){this.x=(c.x-b.x)*p+b.x;this.y=(c.y-b.y)*p+b.y};this.moveAwayFromPoint=function(b,c){this.x-=b.x;this.y-=b.y;var p=Math.atan2(this.y,this.x),v=Math.cos(p)*c,p=Math.sin(p)*c;this.x+=v;this.y+=p;this.x+=b.x;this.y+=b.y}}function dist(b,c){var d=b.x-c.x,e=b.y-c.y;return Math.sqrt(d*d+e*e)}function angleBetween(b,c){return Math.atan2(c.y-b.y,c.x-b.x)}function angleThree(b,c,d){var e;c=angleBetween(b,c);b=angleBetween(b,d);return e=c>b?c-b:b-c,e>Math.PI&&(e=Math.PI-e),e}function angleThree2(b,c,d){var e=Math.pow(c.x-b.x,2)+Math.pow(c.y-b.y,2);c=Math.pow(c.x-d.x,2)+Math.pow(c.y-d.y,2);b=Math.pow(d.x-b.x,2)+Math.pow(d.y-b.y,2);return Math.acos((e+c-b)/Math.sqrt(4*e*c))}function FloorTile(){var b,c,d,e,p,v,l,F,y,r,z,N,P,O,D,G,f,m,n,C,g=0,B=0,w=30,H=!1,x=0,J=30,I=!1,k=!1,L=!1,R=0,M=!1,t=0,u=new PVector(0,0),h=[],Q=!1,S=!1,E=!1,K=!1,q=!1,A=!1,T=!1,V=!1,W=!1,X=!1,U=!1,Y=!1;this.constructor=function(f,l){b=f;c=l;var g=canvas.height-scale*(cols+1)*.5;d=.5*canvas.width-scale*(rows-1)+f*scale+l*scale;e=g+l*scale-f*scale*.5-l*scale*.5;R=2*rows-(rows-(f-l))+.1*f;for(g=0;4>g;g++)h[g]=new PVector(0,0)};this.update=function(){I&&0<=(x+=.075*fps.delta)&&(g=B+1.5*J*Math.sin(x),L?(g<w+.075*fps.delta||Math.sin(x)>Math.PI)&&(g=w,I=!1):(g>w||Math.sin(x)>Math.PI/2)&&(L=!0));k&&0<=(x+=.075*fps.delta)&&(g=B+1.05*J*Math.sin(x),L?(g>w-.075*fps.delta||Math.sin(x)>Math.PI)&&(g=w,k=!1):(g<w||Math.sin(x)>Math.PI/2)&&(L=!0))};this.display=function(){ct.lineWidth=1;(0==b||floorTile[b][c].getHeight()>floorTile[b-1][c].getHeight())&&(ct.beginPath(),ct.moveTo(d,e-g),ct.lineTo(d,e),ct.lineTo(d-scale,e-scale/2),ct.lineTo(d-scale,e-scale/2-g),ct.closePath(),ct.fillStyle="rgba(50,50,50,1)",ct.fill(),(0==b||floorTile[b][c].getHeight()>floorTile[b-1][c].getHeight()+20)&&(ct.fillStyle=v,ct.fill(),ct.fillStyle=p,ct.fill()),isOnMobile||(Q&&(ct.fillStyle=l,ct.fill()),S&&(ct.fillStyle=F,ct.fill()),E&&(ct.fillStyle=y,ct.fill()),K&&(ct.fillStyle=r,ct.fill())));(c==cols-1||floorTile[b][c].getHeight()>floorTile[b][c+1].getHeight())&&(ct.beginPath(),ct.moveTo(d,e-g),ct.lineTo(d,e),ct.lineTo(d+scale,e-scale/2),ct.lineTo(d+scale,e-scale/2-g),ct.closePath(),ct.fillStyle="rgba(125,125,125,1)",ct.fill(),(c==cols-1||floorTile[b][c].getHeight()>floorTile[b][c+1].getHeight()+20)&&(ct.fillStyle=z,ct.fill(),ct.fillStyle=N,ct.fill()),isOnMobile||(q&&(ct.fillStyle=P,ct.fill()),A&&(ct.fillStyle=O,ct.fill()),T&&(ct.fillStyle=D,ct.fill()),V&&(ct.fillStyle=G,ct.fill())));0<g&&(ct.beginPath(),ct.moveTo(d,e-g),ct.lineTo(d-scale,e-scale/2-g),ct.lineTo(d,e-scale-g),ct.lineTo(d+scale,e-scale/2-g),ct.closePath(),ct.fillStyle="rgba(200,200,200,1)",ct.fill(),isOnMobile||(W&&(ct.fillStyle=f,ct.fill()),X&&(ct.fillStyle=m,ct.fill()),U&&(ct.fillStyle=n,ct.fill()),Y&&(ct.fillStyle=C,ct.fill())),ct.strokeStyle="rgba(175,175,175,1)",ct.stroke())};this.calcGrd=function(h){Y=U=X=W=V=T=A=q=K=E=S=Q=!1;var k=e;0<b-1&&(k=floorTile[b-1][c].getHeight(),90>k?k=45:135>k&&(k=90),k=e-k);if(v=ct.createLinearGradient(d-scale/2,k,d-scale/2+45,k-90),v.addColorStop(0,"rgba(25,25,25,"+h+")"),v.addColorStop(.3,"rgba(50,50,50,"+h+")"),p=ct.createLinearGradient(d-scale/2,e-g-scale/2,d-scale/2-45,e-g-scale/2+90),p.addColorStop(0,"rgba(25,25,25,"+(1-h)+")"),p.addColorStop(.3,"rgba(50,50,50,"+(1-h)+")"),k=e,c+1<rows)k=floorTile[b][c+1].getHeight(),90>k?k=45:135>k&&(k=90),k=e-k;z=ct.createLinearGradient(d-scale/2,k,d-scale/2-45,k-90);z.addColorStop(0,"rgba(100,100,100,"+h+")");z.addColorStop(.3,"rgba(125,125,125,"+h+")");N=ct.createLinearGradient(d-scale/2,e-g-scale/2,d-scale/2+45,e-g-scale/2+90);N.addColorStop(0,"rgba(100,100,100,"+(1-h)+")");N.addColorStop(.3,"rgba(125,125,125,"+(1-h)+")");isOnMobile||(b+1<rows&&floorTile[b][c].getHeight()<floorTile[b+1][c].getHeight()&&(P=ct.createLinearGradient(d+scale,e-g/2,d,e-g/2),P.addColorStop(0,"rgba(125,125,125,"+(1-h)+")"),P.addColorStop(.5,"rgba(125,125,125,0)"),q=!0),c+1<cols&&floorTile[b][c].getHeight()>=floorTile[b][c+1].getHeight()+45&&0<b-1&&floorTile[b-1][c+1].getHeight()+45<=floorTile[b][c+1].getHeight()&&(O=ct.createLinearGradient(d,e-g/2,d+scale,e-g/2),O.addColorStop(0,"rgba(125,125,125,"+h+")"),O.addColorStop(.4,"rgba(125,125,125,0)"),A=!0),0<c-1&&floorTile[b][c].getHeight()<floorTile[b][c-1].getHeight()&&(l=ct.createLinearGradient(d-scale,e-g/2,d,e-g/2),l.addColorStop(0,"rgba(50,50,50,"+(1-h)+")"),l.addColorStop(.5,"rgba(50,50,50,0)"),Q=!0),0<b-1&&floorTile[b][c].getHeight()>floorTile[b- 1][c].getHeight()+10&&c+1<rows&&floorTile[b-1][c+1].getHeight()+10<floorTile[b-1][c].getHeight()&&(F=ct.createLinearGradient(d,e-g/2,d-scale,e-g/2),F.addColorStop(0,"rgba(50,50,50,"+h+")"),F.addColorStop(.4,"rgba(50,50,50,0)"),S=!0),D=ct.createLinearGradient(d,e-g/2,d+scale,e-g/2),D.addColorStop(0,"rgba(125,125,125,0)"),D.addColorStop(0,"rgba(125,125,125,0)"),y=ct.createLinearGradient(d,e-g/2,d+scale,e-g/2),y.addColorStop(0,"rgba(125,125,125,0)"),y.addColorStop(0,"rgba(125,125,125,0)"),c+1<cols?floorTile[b][c].getHeight()>floorTile[b][c+1].getHeight()&&(0<b-1?(0==b||floorTile[b][c].getHeight()>floorTile[b-1][c].getHeight())&&(D=ct.createLinearGradient(d-scale/2,e-g-scale/4,d+scale,e-scale-g+22.5),D.addColorStop(0,"rgba(100,100,100,"+(1-h)+")"),D.addColorStop(.8,"rgba(100,100,100,0)"),T=!0,y=ct.createLinearGradient(d+scale/2,e-g-scale/4,d-scale,e-scale-g+22.5),y.addColorStop(0,"rgba(25,25,25,"+(1-h)+")"),y.addColorStop(.8,"rgba(25,25,25,0)"),E=!0):0==b&&(D=ct.createLinearGradient(d- scale/2,e-g-scale/4,d+scale,e-scale-g+22.5),D.addColorStop(0,"rgba(100,100,100,"+(1-h)+")"),D.addColorStop(.8,"rgba(100,100,100,0)"),T=!0,y=ct.createLinearGradient(d+scale/2,e-g-scale/4,d-scale,e-scale-g+22.5),y.addColorStop(0,"rgba(25,25,25,"+(1-h)+")"),y.addColorStop(.8,"rgba(25,25,25,0)"),E=!0)):c==cols-1&&0<b-1?floorTile[b][c].getHeight()>floorTile[b-1][c].getHeight()&&(D=ct.createLinearGradient(d-scale/2,e-g-scale/4,d+scale,e-scale-g+22.5),D.addColorStop(0,"rgba(100,100,100,"+(1-h)+")"),D.addColorStop(.8,"rgba(100,100,100,0)"),T=!0,y=ct.createLinearGradient(d+scale/2,e-g-scale/4,d-scale,e-scale-g+22.5),y.addColorStop(0,"rgba(25,25,25,"+(1-h)+")"),y.addColorStop(.8,"rgba(25,25,25,0)"),E=!0):c==cols-1&&0==b&&(D=ct.createLinearGradient(d-scale/2,e-g-scale/4,d+scale,e-scale-g+22.5),D.addColorStop(0,"rgba(100,100,100,"+(1-h)+")"),D.addColorStop(.8,"rgba(100,100,100,0)"),T=!0,y=ct.createLinearGradient(d+scale/2,e-g-scale/4,d-scale,e-scale-g+22.5),y.addColorStop(0,"rgba(25,25,25,"+(1-h)+")"),y.addColorStop(.8,"rgba(25,25,25,0)"),E=!0),k=e,c+1<cols&&floorTile[b][c].getHeight()-90>=floorTile[b][c+1].getHeight()&&(k+=47),c+1<cols&&floorTile[b][c].getHeight()>=floorTile[b][c+1].getHeight()+45&&b+1<rows&&floorTile[b][c+1].getHeight()<=floorTile[b+1][c+1].getHeight()-45&&(G=ct.createLinearGradient(d-scale/2,k-g-scale/4,d+scale,k-scale-g+22.5),G.addColorStop(.8,"rgba(100,100,100,0)"),G.addColorStop(1,"rgba(100,100,100,"+h+")"),V=!0),k=e,0<b-1&&floorTile[b][c].getHeight()-90>=floorTile[b-1][c].getHeight()&&(k+=47),0<b-1&&floorTile[b][c].getHeight()>=floorTile[b-1][c].getHeight()+45&&0<c-1&&floorTile[b-1][c].getHeight()<=floorTile[b-1][c-1].getHeight()-45&&(r=ct.createLinearGradient(d+scale/2,k-g-scale/4,d-scale,k-scale-g+22.5),r.addColorStop(.8,"rgba(25,25,25,0)"),r.addColorStop(1,"rgba(25,25,25,"+h+")"),K=!0),0<c-1&&floorTile[b][c].getHeight()<floorTile[b][c-1].getHeight()&&(f=ct.createLinearGradient(d-scale/2,e-g-.75*scale,d+scale/2,e-g+.75*scale+5),f.addColorStop(0,"rgba(175,175,175,"+h+")"),f.addColorStop(.3,"rgba(175,175,175,0)"),W=!0),b+1<rows&&floorTile[b][c].getHeight()<floorTile[b+1][c].getHeight()&&(m=ct.createLinearGradient(d+scale/2,e-g-.75*scale,d-scale/2,e-g+.75*scale+5),m.addColorStop(0,"rgba(175,175,175,"+h+")"),m.addColorStop(.3,"rgba(175,175,175,0)"),X=!0),c==cols-1||floorTile[b][c].getHeight()>floorTile[b][c+1].getHeight()?(n=ct.createLinearGradient(d-scale/2,e-g-.75*scale,d+scale/2,e-g+.75*scale+5),n.addColorStop(.1,"rgba(175,175,175,0)"),n.addColorStop(.5,"rgba(175,175,175,"+(1-h)+")"),U=!0):U=!1,(0==b||floorTile[b][c].getHeight()>floorTile[b-1][c].getHeight())&&(C=ct.createLinearGradient(d+scale/2,e-g-.75*scale,d-scale/2,e-g+.75*scale+5),C.addColorStop(.1,"rgba(175,175,175,0)"),C.addColorStop(.5,"rgba(175,175,175,"+(1-h)+")"),Y=!0))};this.displayTarget=function(){h[0].setXAndY(d,e-g);h[1].setXAndY(d-scale,e-scale/2-g);h[2].setXAndY(d,e-scale-g);h[3].setXAndY(d+scale,e-scale/2-g);!H||tileAnimation||resetCubes||fadeCubes||(M||(t+=.05*fps.delta,ct.beginPath(),ct.moveTo(h[0].x,h[0].y),1>t?(u.movePointBetween(h[0],h[1],t),ct.lineTo(u.x,u.y)):2>t?(ct.lineTo(h[1].x,h[1].y),u.movePointBetween(h[1],h[2],t-1),ct.lineTo(u.x,u.y)):3>t?(ct.lineTo(h[1].x,h[1].y),ct.lineTo(h[2].x,h[2].y),u.movePointBetween(h[2],h[3],t-2),ct.lineTo(u.x,u.y)):4>t?(ct.lineTo(h[1].x,h[1].y),ct.lineTo(h[2].x,h[2].y),ct.lineTo(h[3].x,h[3].y),u.movePointBetween(h[3],h[0],t-3),ct.lineTo(u.x,u.y)):M=!0,ct.strokeStyle="rgba(0,0,255,1)",ct.stroke(),ct.save(),ct.scale(2,1),ct.beginPath(),ct.arc(u.x/2,u.y,3,0,2*Math.PI,!1),ct.fillStyle="rgba(200,200,255,0.75)",ct.fill(),ct.restore(),ct.beginPath(),ct.arc(u.x,u.y,1,0,2*Math.PI,!1),ct.fillStyle="white",ct.fill()),M&&(ct.beginPath(),ct.moveTo(h[0].x,h[0].y),ct.lineTo(h[1].x,h[1].y),ct.lineTo(h[2].x,h[2].y),ct.lineTo(h[3].x,h[3].y),ct.closePath(),ct.strokeStyle="rgba(0,0,255,1)",ct.stroke(),0<cube[0].getCubeHeight()?t+=.05*fps.delta:t-=.05*fps.delta,0>t?(t=3.99,u.movePointBetween(h[3],h[0],t-3)):1>t?u.movePointBetween(h[0],h[1],t):2>t?u.movePointBetween(h[1],h[2],t-1):3>t?u.movePointBetween(h[2],h[3],t-2):4>t?u.movePointBetween(h[3],h[0],t-3):4<=t&&(t=0,u.movePointBetween(h[0],h[1],t)),ct.save(),ct.scale(2,1),ct.beginPath(),ct.arc(u.x/2,u.y,3,0,2*Math.PI,!1),ct.fillStyle="rgba(200,200,255,0.15)",ct.fill(),ct.restore(),ct.beginPath(),ct.arc(u.x,u.y,1,0,2*Math.PI,!1),ct.fillStyle="rgba(255,255,255,0.4)",ct.fill()))};this.setIsTarget=function(b){H=b;M=!1;t=0};this.getIsTarget=function(){return H};this.getIsAnimating=function(){return!(!I&&!k)};this.setHeight=function(b){w=b;w>g?I=!0:w<g&&(k=!0);J=w-g;134<J&&(J-=15);89<J&&(J-=15);x=-R/2;B=g;L=!1};this.setHeight2=function(){w==g&&(I=!0,J=20,B=g,x=-R/2,L=!1)};this.getHeight=function(){return g}}function Level(){for(var b=[],c=0;4>c;c++)b[c]=!1;var d=0,e="",p=3,v=!1;this.display=function(){v&&(e="[      Restart from beginning? y/n      ]");for(var b=1;20>=b;b++)ct.beginPath(),ct.arc(20,canvas.height/21*b,5,0,2*Math.PI,!1),ct.lineWidth=1,ct.strokeStyle="#000000aa",ct.stroke(),b<currentLevel&&(ct.fillStyle="#000000aa",ct.fill());for(b=21;40>=b;b++)ct.beginPath(),ct.arc(canvas.width-20,canvas.height/21*(b-20),5,0,2*Math.PI,!1),ct.lineWidth=1,ct.strokeStyle="#000000aa",ct.stroke(),b<currentLevel&&(ct.fillStyle="#000000aa",ct.fill());1==currentLevel&&tileAnimation?(p-=.02*fps.delta,e="[            o  p  t  i  s  o  c  u  b  e  s            ]",0>=p&&(p=-1,e="[       w       ]",isOnMobile&&(e="[        swipe to move        ]")),ct.font="15pt Calibri",isOnMobile&&(ct.font="20pt Calibri"),ct.textAlign="center",ct.fillStyle="rgba(200,200,200,"+p+")",ct.fillText(e,canvas.width/2,canvas.height/5-30)):d!=currentLevel||tileAnimation? p=-1:(p+=.02*fps.delta,1<=p&&(p=1),ct.font="15pt Calibri",isOnMobile&&(ct.font="20pt Calibri"),ct.textAlign="center",ct.fillStyle="rgba(200,200,200,"+p+")",ct.fillText(e,canvas.width/2,canvas.height/5-30));d=currentLevel};this.setLevel=function(c){for(var d=0;d<rows;d++)for(var p=0;p<cols;p++)floorTile[d][p].setIsTarget(!1);for(d=0;d<cube.length;d++)cube[d].setTargetCount(0);this.setRAndC(0,rows,0,cols,45);0<c&&8>c?1<cube.length?cube.splice(1,cube.length-1):1>cube.length&&(cube[0]=new Cube,cube[0].constructor(1,rows-2),b[0]=!0):8<=c&&17>c?(1>cube.length&&(cube[0]=new Cube,cube[0].constructor(1,rows-2),b[0]=!0),2>cube.length?(cube[1]=new Cube,cube[1].constructor(1,rows-2),b[1]=!0):2<cube.length&&cube.splice(2,cube.length-2)):17<=c&&28>c?(1>cube.length&&(cube[0]=new Cube,cube[0].constructor(1,rows-2),b[0]=!0),2>cube.length&&(cube[1]=new Cube,cube[1].constructor(1,rows-2),b[1]=!0),3>cube.length?(cube[2]=new Cube,cube[2].constructor(1,rows-2),b[2]=!0):3<cube.length&&cube.splice(3,cube.length-3)):28<=c&&41>=c&&(1>cube.length&&(cube[0]=new Cube,cube[0].constructor(1,rows-2),b[0]=!0),2>cube.length&&(cube[1]=new Cube,cube[1].constructor(1,rows-2),b[1]=!0),3>cube.length&&(cube[2]=new Cube,cube[2].constructor(1,rows-2),b[2]=!0),4>cube.length&&(cube[3]=new Cube,cube[3].constructor(1,rows-2),b[3]=!0));1==c?(floorTile[1][1].setIsTarget(!0),cube[0].moveTo(1,rows-2),e="[       w       ]",isOnMobile&&(e="[        swipe to move        ]")):2==c?(floorTile[7][1].setIsTarget(!0),cube[0].moveTo(1,1),e="[       d       ]",isOnMobile&&(e="[     swipe & hold to keep moving    ]")):3==c?(this.setRAndC(5,rows,0,cols,90),floorTile[7][7].setIsTarget(!0),cube[0].moveTo(7,1),e="[       s       ]",isOnMobile&&(e="[     tap to shift    ]")):4==c?(this.setRAndC(5,rows,0,cols,90),floorTile[1][7].setIsTarget(!0),cube[0].moveTo(7,7),e="[       a       ]",isOnMobile&&(e="")):5==c?(this.setRAndC(0,rows,0,4,90),floorTile[1][1].setIsTarget(!0),cube[0].moveTo(1,7),e="[     shift     ]",isOnMobile&&(e="[     tap to shift    ]")):6==c?(this.setRAndC(0,rows,0,4,90),this.setRAndC(5,rows,0,4,135),floorTile[7][1].setIsTarget(!0),cube[0].moveTo(1,1),e=" "):7==c?(this.setRAndC(0,rows,0,4,90),this.setRAndC(5,rows,0,cols,90),this.setRAndC(5,rows,0,4,135),floorTile[1][1].setIsTarget(!0),cube[0].moveTo(7,1)):8==c?(this.setRAndC(0,rows,0,3,90),floorTile[4][1].setIsTarget(!0),floorTile[4][7].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(1,7)):9==c?(this.setRAndC(6,rows,0,cols,90),this.setRAndC(6,7,cols-1,cols,45),floorTile[7][1].setIsTarget(!0),floorTile[7][7].setIsTarget(!0),cube[0].moveTo(4,1),cube[1].moveTo(4,7)):10==c?(this.setRAndC(rows-3,rows,0,3,90),floorTile[1][1].setIsTarget(!0),floorTile[1][5].setIsTarget(!0),cube[0].moveTo(7,1),cube[1].moveTo(7,7)):11==c?(this.setRAndC(rows-5,rows,0,5,90),floorTile[3][1].setIsTarget(!0),floorTile[7][5].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(1,5)):12==c?(this.setRAndC(rows-5,rows,0,5,90),floorTile[6][1].setIsTarget(!0),floorTile[7][2].setIsTarget(!0),cube[0].moveTo(3,1),cube[1].moveTo(7,5)):13==c?(this.setRAndC(6,rows,0,cols,90),this.setRAndC(0,rows,0,3,90),floorTile[1][1].setIsTarget(!0),floorTile[7][7].setIsTarget(!0),cube[0].moveTo(6,1),cube[1].moveTo(7,2)):14==c?(this.setRAndC(5,rows,0,4,90),floorTile[2][6].setIsTarget(!0),floorTile[7][1].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(7,7)):15==c?(this.setRAndC(5,rows,0,4,90),floorTile[2][4].setIsTarget(!0),floorTile[4][6].setIsTarget(!0),cube[0].moveTo(2,6),cube[1].moveTo(7,1)):16==c?(this.setRAndC(6,rows,0,cols,90),this.setRAndC(0,rows,0,3,90),this.setRAndC(4,rows,0,5,135),floorTile[3][1].setIsTarget(!0),floorTile[7][5].setIsTarget(!0),cube[0].moveTo(2,4),cube[1].moveTo(4,6)):17==c?(this.setRAndC(3,rows,0,3,90),this.setRAndC(6,rows,0,6,90),floorTile[1][1].setIsTarget(!0),floorTile[4][4].setIsTarget(!0),floorTile[7][7].setIsTarget(!0),cube[0].moveTo(3,1),cube[1].moveTo(7,5),cube[2].moveTo(1,7)):18==c?(this.setRAndC(0,rows,0,3,90),this.setRAndC(0,1,2,3,45),floorTile[7][4].setIsTarget(!0),floorTile[1][5].setIsTarget(!0),floorTile[7][6].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(4,4),cube[2].moveTo(7,7)):19==c?(this.setRAndC(3,rows,0,6,90),this.setRAndC(6,rows,0,cols,90),this.setRAndC(6,rows,0,3,135),floorTile[4][1].setIsTarget(!0),floorTile[4][4].setIsTarget(!0),floorTile[7][7].setIsTarget(!0),cube[0].moveTo(7,4),cube[1].moveTo(1,5),cube[2].moveTo(7,6)):20==c?(this.setRAndC(0,rows,0,7,90),this.setRAndC(6,rows,0,4,135),floorTile[1][1].setIsTarget(!0),floorTile[2][4].setIsTarget(!0),floorTile[4][5].setIsTarget(!0),cube[0].moveTo(4,1),cube[1].moveTo(4,4),cube[2].moveTo(7,7)):21==c?(this.setRAndC(1,rows,0,cols-1,90),this.setRAndC(5,rows,0,4,135),this.setRAndC(0,2,cols-2,cols,45),floorTile[1][6].setIsTarget(!0),floorTile[2][7].setIsTarget(!0),floorTile[4][4].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(2,4),cube[2].moveTo(4,5)):22==c?(this.setRAndC(7,rows,0,cols,90),this.setRAndC(0,rows,0,3,135),this.setRAndC(0,3,0,3,90),this.setRAndC(0,1,2,3,45),floorTile[1][1].setIsTarget(!0),floorTile[1][5].setIsTarget(!0),floorTile[7][6].setIsTarget(!0),cube[0].moveTo(1,6),cube[1].moveTo(2,7),cube[2].moveTo(4,4)):23==c?(this.setRAndC(4,rows,0,cols,90),this.setRAndC(0,rows,0,4,135),this.setRAndC(6,rows,0,6,135),floorTile[5][1].setIsTarget(!0),floorTile[1][2].setIsTarget(!0),floorTile[7][3].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(1,5),cube[2].moveTo(7,6)):24==c?(this.setRAndC(3,rows,0,6,90),this.setRAndC(6,rows,0,3,135),floorTile[7][1].setIsTarget(!0),floorTile[4][4].setIsTarget(!0),floorTile[7][7].setIsTarget(!0),cube[0].moveTo(5,1),cube[1].moveTo(1,2),cube[2].moveTo(7,3)):25==c?(this.setRAndC(5,rows,0,cols,90),this.setRAndC(3,5,0,1,90),floorTile[1][1].setIsTarget(!0),floorTile[2][4].setIsTarget(!0),floorTile[1][7].setIsTarget(!0),cube[0].moveTo(7,1),cube[1].moveTo(4,4),cube[2].moveTo(7,7)):26==c?(this.setRAndC(3,6,0,cols,90),this.setRAndC(6,rows,0,cols,135),this.setRAndC(3,4,cols-2,cols,45),floorTile[1][2].setIsTarget(!0),floorTile[4][3].setIsTarget(!0),floorTile[7][4].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(2,4),cube[2].moveTo(1,7)):27==c?(this.setRAndC(6,rows,0,cols,90),this.setRAndC(0,rows,0,3,90),this.setRAndC(4,rows,0,5,135),floorTile[2][1].setIsTarget(!0),floorTile[7][6].setIsTarget(!0),floorTile[7][1].setIsTarget(!0),cube[0].moveTo(1,2),cube[1].moveTo(4,3),cube[2].moveTo(7,4)):28==c?(this.setRAndC(5,rows,0,4,90),floorTile[3][2].setIsTarget(!0),floorTile[3][5].setIsTarget(!0),floorTile[6][2].setIsTarget(!0),floorTile[6][5].setIsTarget(!0),cube[0].moveTo(2,1),cube[1].moveTo(7,6),cube[2].moveTo(7,1),cube[3].moveTo(1,7)):29==c?(this.setRAndC(3,rows,0,3,90),this.setRAndC(6,rows,0,6,90),floorTile[0][2].setIsTarget(!0),floorTile[3][5].setIsTarget(!0),floorTile[6][8].setIsTarget(!0),floorTile[6][2].setIsTarget(!0),cube[0].moveTo(3,2),cube[1].moveTo(3,5),cube[2].moveTo(6,2),cube[3].moveTo(6,5)):30==c?(this.setRAndC(0,rows,0,3,90),this.setRAndC(0,1,2,3,45),this.setRAndC(8,9,3,4,90),floorTile[2][5].setIsTarget(!0),floorTile[4][3].setIsTarget(!0),floorTile[4][7].setIsTarget(!0),floorTile[6][5].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(4,4),cube[2].moveTo(7,7),cube[3].moveTo(7,1)):31==c?(this.setRAndC(3,rows,0,6,90),this.setRAndC(6,rows,0,cols,90),this.setRAndC(6,rows,0,3,135),floorTile[4][1].setIsTarget(!0),floorTile[4][4].setIsTarget(!0),floorTile[7][7].setIsTarget(!0),floorTile[7][1].setIsTarget(!0),cube[0].moveTo(2,5),cube[1].moveTo(4,3),cube[2].moveTo(4,7),cube[3].moveTo(6,5)):32==c?(this.setRAndC(2,rows,0,cols,90),this.setRAndC(5,rows,0,3,135),floorTile[3][1].setIsTarget(!0),floorTile[3][4].setIsTarget(!0),floorTile[3][7].setIsTarget(!0),floorTile[6][7].setIsTarget(!0),cube[0].moveTo(4,1),cube[1].moveTo(4,4),cube[2].moveTo(7,7),cube[3].moveTo(7,1)):33==c?(this.setRAndC(1,rows,0,cols-1,90),this.setRAndC(5,rows,0,4,135),this.setRAndC(0,2,cols-2,cols,45),floorTile[1][0].setIsTarget(!0),floorTile[8][7].setIsTarget(!0),floorTile[1][6].setIsTarget(!0),floorTile[2][7].setIsTarget(!0),cube[0].moveTo(3,1),cube[1].moveTo(3,4),cube[2].moveTo(3,7),cube[3].moveTo(6,7)):34==c?(this.setRAndC(7,rows,0,cols,90),this.setRAndC(0,rows,0,3,135),this.setRAndC(0,3,0,3,90),this.setRAndC(0,1,2,3,45),floorTile[1][1].setIsTarget(!0),floorTile[1][7].setIsTarget(!0),floorTile[7][1].setIsTarget(!0),floorTile[7][7].setIsTarget(!0),cube[0].moveTo(1,0),cube[1].moveTo(8,7),cube[2].moveTo(1,6),cube[3].moveTo(2,7)):35==c?(this.setRAndC(0,rows,0,4,90),this.setRAndC(5,rows,0,cols,135),this.setRAndC(3,rows,0,2,135),floorTile[1][6].setIsTarget(!0),floorTile[2][2].setIsTarget(!0),floorTile[5][1].setIsTarget(!0),floorTile[6][6].setIsTarget(!0),cube[0].moveTo(1,1),cube[1].moveTo(1,7),cube[2].moveTo(7,1),cube[3].moveTo(7,7)):36==c?(this.setRAndC(3,rows,0,6,90),this.setRAndC(6,rows,0,3,135),floorTile[7][1].setIsTarget(!0),floorTile[1][1].setIsTarget(!0),floorTile[7][7].setIsTarget(!0),floorTile[4][4].setIsTarget(!0),cube[0].moveTo(1,6),cube[1].moveTo(2,2),cube[2].moveTo(5,1),cube[3].moveTo(6,6)):37==c?(this.setRAndC(5,rows,0,cols,90),this.setRAndC(3,5,0,1,90),floorTile[3][0].setIsTarget(!0),floorTile[5][0].setIsTarget(!0),floorTile[7][6].setIsTarget(!0),floorTile[2][6].setIsTarget(!0),cube[0].moveTo(7,1),cube[1].moveTo(1,1),cube[2].moveTo(7,7),cube[3].moveTo(4,4)):38==c?(this.setRAndC(0,rows,0,6,90),this.setRAndC(0,rows,0,3,135),this.setRAndC(0,2,5,6,45),this.setRAndC(0,1,2,3,90),floorTile[1][7].setIsTarget(!0),floorTile[7][1].setIsTarget(!0),floorTile[3][7].setIsTarget(!0),floorTile[5][4].setIsTarget(!0),cube[0].moveTo(3,0),cube[1].moveTo(5,0),cube[2].moveTo(7,6),cube[3].moveTo(2,6)):39==c?(this.setRAndC(6,rows,0,cols,90),this.setRAndC(0,rows,0,3,90),this.setRAndC(4,rows,0,5,135),floorTile[3][1].setIsTarget(!0),floorTile[7][5].setIsTarget(!0),floorTile[5][2].setIsTarget(!0),floorTile[6][3].setIsTarget(!0),cube[0].moveTo(1,7),cube[1].moveTo(7,1),cube[2].moveTo(3,7),cube[3].moveTo(5,4)):40==c?(this.setRAndC(3,rows,0,3,90),this.setRAndC(6,rows,0,6,90),floorTile[1][2].setIsTarget(!0),floorTile[5][1].setIsTarget(!0),floorTile[7][3].setIsTarget(!0),floorTile[6][7].setIsTarget(!0),cube[0].moveTo(3,1),cube[1].moveTo(7,5),cube[2].moveTo(5,2),cube[3].moveTo(6,3)):41==c&&(e="[        You  took  "+moveCounter+"  moves        ]",cube[0].moveTo(1,2),cube[1].moveTo(5,1),cube[2].moveTo(7,3),cube[3].moveTo(6,7));for(d=0;d<cols;d++)for(p=0;p<rows;p++)floorTile[d][p].setHeight2();for(d=0;d<b.length;d++)b[d]&&(b[d]=!1,cube[d].setTH(800),cube[d].setTargetTH(160),cube[d].setIsStatic())};this.setRAndC=function(b,c,d,e,p){for(;b<c;b++)for(var v=d;v<e;v++)floorTile[b][v].setHeight(p)};this.setDisplayReset=function(b){(v=b)||(e="")};this.next=function(b){tileAnimation||(currentLevel+=b,this.setLevel(currentLevel))}}var levels,cube=[],floorTile=[],scale=20,tileAnimation=!1,currentLevel=1,storedLevel="C:/Program Files/optisocubes/storedLevel.dat",storedMoves="C:/Program Files/optisocubes/storedMoves.dat";loadfile("C:/Program Files/optisocubes")||savefile("C:/Program Files/optisocubes"," ",1);var rows=9,cols=9,leftUpPressed=!1,rightUpPressed=!1,leftDownPressed=!1,rightDownPressed=!1,spacePressed=!1,spaceHeld=!1,buttonReleased=!1,cubesAnimating=!1,levelChanging=!1,resetCubes=!1,fadeCubes=!0,moveCounter=0,levelMoveCounter=0,resetMenu=!1,grd,touchStart=new PVector(0,0),touchCurrent=new PVector(0,0),touchTapStart,touchTapTime=300,touchRangeInner=25,touchRangeOuter=35,isOnMobile=!1,mobileTested=!1,setUp=function(){0<cube.length&&cube.splice(0,cube.length);scale=20;tileAnimation=!1;currentLevel=1;cols=rows=9;resetCubes=levelChanging=cubesAnimating=buttonReleased=spaceHeld=spacePressed=rightDownPressed=leftDownPressed=rightUpPressed=leftUpPressed=!1;fadeCubes=!0;levelMoveCounter=moveCounter=0;resetMenu=!1;levels=new Level;for(var b=0;b<rows;b++){floorTile[b]=[];for(var c=0;c<cols;c++)floorTile[b][c]=new FloorTile,floorTile[b][c].constructor(b,c)}try{"undefined"!=typeof Storage&&(loadfile("C:/Program Files/optisocubes/storedLevel.dat")&&!isNaN(loadfile("C:/Program Files/optisocubes/storedLevel.dat"))? (currentLevel=Number(loadfile("C:/Program Files/optisocubes/storedLevel.dat")),savefile("C:/Program Files/optisocubes/storedLevel.dat",Number(currentLevel),1)):(currentLevel=1,savefile("C:/Program Files/optisocubes/storedLevel.dat",Number(currentLevel),1)),loadfile("C:/Program Files/optisocubes/storedMoves.dat")&&!isNaN(loadfile("C:/Program Files/optisocubes/storedMoves.dat"))?(moveCounter=Number(loadfile("C:/Program Files/optisocubes/storedMoves.dat")),savefile("C:/Program Files/optisocubes/storedMoves.dat",Number(moveCounter),1)):(moveCounter=0,savefile("C:/Program Files/optisocubes/storedMoves.dat",Number(moveCounter),1)))}catch(d){currentLevel=1,moveCounter=0}levels.setLevel(currentLevel);grd=ct.createLinearGradient(0,canvas.height/2,canvas.width,canvas.height/2);grd.addColorStop(0,"rgba(255, 233, 0, 1.000)");grd.addColorStop(.15,"rgba(255, 255, 0, 1.000)");grd.addColorStop(.85,"rgba(255, 255, 0, 1.000)");grd.addColorStop(1,"rgba(255, 233, 0, 1.000)")},updateGame=function(){mobileTested||(isMobile.any()&&(isOnMobile=!0),mobileTested=!0);tileAnimation=!1;for(var b=0;b<rows;b++)for(var c=0;c<cols;c++)floorTile[b][c].update(),floorTile[b][c].getIsAnimating()&&(tileAnimation=!0);if(resetMenu)levels.setDisplayReset(!0);else if(resetCubes){cubesAnimating=!1;for(b=0;b<cube.length;b++)cube[b].getIsAnimating()&&(cubesAnimating=!0);if(cubesAnimating)for(b=0;b<cube.length;b++)cube[b].setIsStatic(),cube[b].updateRiseFall(),cube[b].updateHeight();else{for(b=0;b<cube.length;b++)cube[b].setTargetTH(160);fadeCubes=!0;resetCubes=!1;currentLevel++;moveCounter+=levelMoveCounter;levelMoveCounter=0;levels.setLevel(currentLevel);saveStates()}}else if(tileAnimation)for(b=0;b<cube.length;b++)cube[b].updateRiseFall();else if(fadeCubes){for(b=0;b<cube.length;b++)cube[b].setIsOnTarget(!1),cube[b].setFade(!0);cube[0].getFade()&&(fadeCubes=!1)}else if(!tileAnimation){for(b=0;b<cube.length;b++)cube[b].setCanMove();for(b=0;b<cube.length;b++)cube[b].setTileHeights(floorTile);cubesAnimating=!1;for(b=0;b<cube.length;b++)cube[b].getIsAnimating()&&(cubesAnimating=!0);for(b=0;b<cube.length;b++)cube[b].checkEdgeOfTiles();for(var d=0;d<cube.length;d++)for(b=0;b<cube.length;b++)for(c=0;c<cube.length;c++)if(b!=c)for(var e=0;4>e;e++)cube[b].checkOthers(cube[c].getXPosition(),cube[c].getYPosition(),cube[c].getCanMoveDir(e),e);if(buttonReleased){for(b=0;b<cube.length;b++)cube[b].setRotBack(!0);buttonReleased=!1}if(!cubesAnimating)for(b=0;b<cube.length;b++)leftUpPressed&&cube[b].move(0),rightUpPressed&&cube[b].move(1),leftDownPressed&&cube[b].move(2),rightDownPressed&&cube[b].move(3),spacePressed&&cube[b].move(4);spacePressed=!1;for(b=0;b<cube.length;b++)cube[b].updateRiseFall(),cube[b].updateRotation(),cube[b].updateHeight();if(!cubesAnimating){for(b=0;b<cube.length;b++)cube[b].setIsOnTarget(!1);for(b=0;b<rows;b++)for(c=0;c<cols;c++)if(floorTile[b][c].getIsTarget())for(e=0;e<cube.length;e++)cube[e].target(b,c)}for(b=c=0;b<cube.length;b++)cube[b].getIsOnTarget()&&c++;if(c==cube.length)for(resetCubes=!0,b=0;b<cube.length;b++)cube[b].rightWayUp()}c=!1;for(b=0;b<cube.length;b++)cube[b].getHasMoved()&&(c=!0);c&&levelMoveCounter++;fps.update()},drawGame=function(){ct.fillStyle=grd;ct.fillRect(0,0,canvas.width,canvas.height);var b;b=0<cube.length?(cube[0].getCubeHeight()+scale)/(2*scale):0;for(var c=rows-1;0<=c;c--)for(var d=0;d<cols;d++)floorTile[c][d].calcGrd(b),floorTile[c][d].display();for(c=rows-1;0<=c;c--)for(d=0;d<cols;d++)floorTile[c][d].displayTarget();if(0<cube.length){b=[];d=!1;for(c=0;c<cube.length;c++)(cube[c].getAniLeftDown()||cube[c].getAniRightUp())&&(d=!0);if(d){for(c=p=0;c<2*rows;c++)for(d=0;d<c+1;d++)if(0<rows-(c-d)&&d<cols)for(var e=0;e<cube.length;e++)cube[e].getXPosition()==rows-(c-d)-1&&cube[e].getYPosition()==d&&(b[p++]=e);if(0>cube[0].getCubeHeight())for(c=cube.length-1;0<=c;c--)cube[b[c]].display();else for(c=0;c<cube.length;c++)cube[b[c]].display()}else{for(var p=0,c=0;c<cols;c++)for(d=rows-1;0<=d;d--)for(e=0;e<cube.length;e++)cube[e].getXPosition()==c&&cube[e].getYPosition()==d&&(b[p++]=e);if(0<cube[0].getCubeHeight())for(c=cube.length-1;0<=c;c--)cube[b[c]].display();else for(c=0;c<cube.length;c++)cube[b[c]].display()}}levels.display()};canvas.addEventListener("mousemove",function(b){b=getMousePos(canvas,b);mouseX=b.x;mouseY=b.y},!1);canvas.addEventListener("touchstart",function(){if(!b)var b=event;b.preventDefault();touchTapStart=(new Date).getTime();touchStart.setXAndY(b.targetTouches[0].pageX-canvas.offsetLeft,b.targetTouches[0].pageY-canvas.offsetTop)},!1);canvas.addEventListener("touchmove",function(b){b||(b=event);if(b.preventDefault(),leftUpPressed=!1,rightUpPressed=!1,leftDownPressed=!1,rightDownPressed=!1,touchCurrent.setXAndY(b.targetTouches[0].pageX-canvas.offsetLeft,b.targetTouches[0].pageY-canvas.offsetTop),dist(touchStart,touchCurrent)>touchRangeOuter)b=(dist(touchStart,touchCurrent)-touchRangeOuter)/dist(touchStart,touchCurrent),touchStart.movePointBetween(touchStart,touchCurrent,b);b=angleBetween(touchStart,touchCurrent);levelChanging||(dist(touchStart,touchCurrent)>touchRangeInner?0>=b&&b>=-Math.PI/2?rightUpPressed=!0:b<=-Math.PI/2&&b>=-Math.PI?leftUpPressed=!0:b<=Math.PI/2&&0<=b?rightDownPressed=!0:b<=Math.PI&&b>=Math.PI/2&&(leftDownPressed=!0):(leftUpPressed=!1,rightUpPressed=!1,leftDownPressed=!1,rightDownPressed=!1))},!1);canvas.addEventListener("touchend",function(){rightDownPressed=leftDownPressed=rightUpPressed=leftUpPressed=!1;touchTapEnd=(new Date).getTime();touchTapEnd<touchTapStart+touchTapTime&&(spacePressed=!0)},!1);document.body.addEventListener("touchcancel",function(){rightDownPressed=leftDownPressed=rightUpPressed=leftUpPressed=!1;touchTapEnd=(new Date).getTime();touchTapEnd<touchTapStart+touchTapTime&&(spacePressed=!0)},!1);document.addEventListener("keydown",function(b){if(leftUpPressed=!1,rightUpPressed=!1,leftDownPressed=!1,rightDownPressed=!1,spacePressed=!1,levelChanging||(87==b.keyCode||38==b.keyCode?(leftUpPressed=!0,b.preventDefault()):68==b.keyCode||39==b.keyCode?(rightUpPressed=!0,b.preventDefault()):65==b.keyCode||37==b.keyCode?(leftDownPressed=!0,b.preventDefault()):83==b.keyCode||40==b.keyCode?(rightDownPressed=!0,b.preventDefault()):16!=b.keyCode&&32!=b.keyCode||(spacePressed||spaceHeld||(spacePressed=!0,spaceHeld=!0),b.preventDefault())),82==b.keyCode){levels.next(-1);resetCubes=!0;for(var c=levelMoveCounter=0;c<cube.length;c++)cube[c].setHeight()}resetMenu&&(89==b.keyCode&&(resetMenu=!1,deleteStates(),resetCubes=!0,currentLevel=0,levels.setDisplayReset(!1),setUp()),78==b.keyCode&&(resetMenu=!1,levels.setDisplayReset(!1)));13==b.keyCode&&(resetMenu=!0)});document.addEventListener("keyup",function(b){87==b.keyCode||38==b.keyCode?(leftUpPressed=!1,buttonReleased=!0):68==b.keyCode||39==b.keyCode?(rightUpPressed=!1,buttonReleased=!0):65==b.keyCode||37==b.keyCode?(leftDownPressed=!1,buttonReleased=!0):83==b.keyCode||40==b.keyCode?(rightDownPressed=!1,buttonReleased=!0):16!=b.keyCode&&32!=b.keyCode||(spaceHeld=!1)});var mainloop=function(){updateGame();drawGame()},animFrame=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||null;if(null!==animFrame){var recursiveAnim=function(){mainloop();animFrame(recursiveAnim,canvas)};setUp();animFrame(recursiveAnim,canvas)}else{var ONE_FRAME_TIME=1E3/60;setInterval(mainloop,ONE_FRAME_TIME)}var fps={current:0,last:0,lastUpdated:Date.now(),delta:0,previous:Date.now(),draw:function(){ct.fillStyle="white";ct.fillRect(0,0,50,25);ct.font="12pt Arial";ct.fillStyle="black";ct.textBaseline="top";ct.textAlign="left";ct.fillText(fps.last+"fps",5,5)},update:function(){fps.current++;fps.delta=(Date.now()-fps.previous)/(1E3/60);fps.previous=Date.now();5<fps.delta&&(fps.delta=5);1E3<=Date.now()-fps.lastUpdated&&(fps.last=fps.current,fps.current=0,fps.lastUpdated=Date.now())}},saveStates=function(){try{"undefined"!=typeof Storage&&(loadfile("C:/Program Files/optisocubes/storedLevel.dat"),savefile("C:/Program Files/optisocubes/storedLevel.dat",Number(currentLevel),1),loadfile("C:/Program Files/optisocubes/storedMoves.dat"),savefile("C:/Program Files/optisocubes/storedMoves.dat",Number(moveCounter),1))}catch(b){}},loadStates=function(){"undefined"!=typeof Storage&&(loadfile("C:/Program Files/optisocubes/storedLevel.dat")? currentLevel=Number(loadfile("C:/Program Files/optisocubes/storedLevel.dat")):(currentLevel=1,savefile("C:/Program Files/optisocubes/storedLevel.dat",Number(currentLevel),1)))},deleteStates=function(){try{"undefined"!=typeof Storage&&(loadfile("C:/Program Files/optisocubes/storedLevel.dat")&&localStorage.removeItem("C:/Program Files/optisocubes/storedLevel.dat"),loadfile("C:/Program Files/optisocubes/storedMoves.dat")&&localStorage.removeItem("C:/Program Files/optisocubes/storedMoves.dat"))}catch(b){}},isMobile={Android:function(){return navigator.userAgent.match(/Android/i)},BlackBerry:function(){return navigator.userAgent.match(/BlackBerry/i)},iOS:function(){return navigator.userAgent.match(/iPhone|iPad|iPod/i)},Opera:function(){return navigator.userAgent.match(/Opera Mini/i)},Windows:function(){return navigator.userAgent.match(/IEMobile/i)},any:function(){return isMobile.Android()||isMobile.BlackBerry()||isMobile.iOS()||isMobile.Opera()||isMobile.Windows()}};

// Changes made to .min.js:
// parent.loadfile() -> loadfile()
// parent.savefile() -> savefile()
// Changed "yellow" -> "#000000aa"
// "context" -> "ct"
// TODO: Find latest unminified .js and add the changes