{"main":"void setup(){\r\nsize(400,400);\r\n}\r\n\r\nvar deBug=false;//set to true to turn on debug info\r\n\r\n/**Players Data*/\r\nvar P={\r\n x:280,y:280,//players x and y cords\r\n xv:0,yv:0,//players x and y velocity\r\n w:20,h:20,//players width and height\r\n sx:280,sy:280,//players spawn cords\r\n};\r\n/**Cameras Data*/\r\nvar Cam={\r\n x:P.x,y:P.y,////camera X and Y\r\n xt:P.x,yt:P.y,//camera target X and Y\r\n Espeed:0.06,//easing speed\r\n Mbs:60,//movement box size\r\n};\r\nvar Level=-1;//what level the player is on\r\nvar oldlevel=0;//the last level the player was on\r\nvar Mw=800,Mh=600;//map width and height\r\nvar dashed=false;//if player dashed\r\nvar diedT=0;//death timer\r\nvar gravity=0.1;// the games gravitys\r\nvar levelName=\"none\";\r\nvar blocks = [];//array for storing blocks\r\nvar pardstor = [];//particle storage array\r\nvar Estor = [];//entity storage array\r\nvar Timer = {C:millis(),S:0,M:0};\r\nvar input = [];//stores user key input\r\nvoid keyPressed(){input[keyCode] = true;};\r\nvoid keyReleased(){input[keyCode] = false;};\r\nrectMode(CENTER);\r\ntextAlign(CENTER);\r\nnoStroke();\r\nvar rectCol = function(x1,y1,w1,h1,x2,y2,w2,h2){\r\n if(\r\n x1>(x2-w2/2)-(w1/2)&&\r\n x1<(x2+w2/2)+(w1/2)&&\r\n y1>(y2-h2/2)-(h1/2)&&\r\n y1<(y2+h2/2)+(h1/2)\r\n ){\r\n return true;\r\n }else{\r\n return false;\r\n }\r\n};\r\n\r\n\r\n//-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n//Blocks and effects code\r\n//-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n{\r\n/**\r\n * ============================ \r\n * -======== Particle ========- \r\n * ============================\r\n*/\r\nvar jumpPard = function(pos,posV) {\r\n this.pos = pos.get();\r\n this.posV = posV.get();\r\n this.LiveT = 255.0;\r\n this.size = random(3,10);\r\n};\r\njumpPard.prototype.run = function() {\r\n this.pos.add(this.posV);\r\n this.LiveT -= 6;\r\n noStroke();\r\n fill(153, 0, 255,this.LiveT);\r\n rect(this.pos.x, this.pos.y, this.size, this.size);\r\n};\r\njumpPard.prototype.isDead = function() {\r\n if (this.LiveT < 0) {return true;} else {return false;}\r\n};\r\nvar GravParticle = function(position,xv,yv,x,y,w,h) {\r\n this.position = position.get();\r\n this.LiveT = 255.0;\r\n this.size = random(5,10);\r\n this.xv=xv;\r\n this.yv=yv;\r\n this.x=x;\r\n this.y=y;\r\n this.w=w;\r\n this.h=h;\r\n \r\n};\r\nGravParticle.prototype.run = function() {\r\n this.LiveT -= 6;\r\n this.position.x+=this.xv/2;\r\n this.position.y+=this.yv/2;\r\n if(!rectCol(this.position.x,this.position.y,1,1,this.x,this.y,this.w-10,this.h-10)){\r\n this.LiveT=-10;\r\n } \r\n noStroke();\r\n fill(255, 255, 255,150);\r\n ellipse(this.position.x, this.position.y, \r\n this.size+abs(this.xv), this.size+abs(this.yv));\r\n};\r\nGravParticle.prototype.isDead = function() {\r\n if (this.LiveT <= 0){return true;} else {return false;}\r\n};\r\nvar dieD = function(pos,c) {\r\n this.pos=pos.get();\r\n this.w=random(5,10);this.h=random(5,10);\r\n this.xv=random(-3,3);this.yv=0;\r\n this.LiveT=300;\r\n this.c=c;\r\n}; // vars\r\ndieD.prototype.run = function() {\r\n noStroke();\r\n this.LiveT--;\r\n fill(red(this.c), green(this.c), blue(this.c),this.LiveT);\r\n rect(this.pos.x, this.pos.y,this.w,this.h);\r\n \r\n this.pos.x+=this.xv;\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n if(this.xv>0){\r\n this.pos.x=blocks[i].x-(this.w/2+blocks[i].w/2);\r\n this.xv=0;\r\n }else \r\n if(this.xv<0){\r\n this.pos.x=blocks[i].x+(this.w/2+blocks[i].w/2);\r\n this.xv=0;\r\n }\r\n }\r\n }\r\n for (var i = Estor.length-1; i >= 0; i--) {\r\n var p = Estor[i];\r\n //if(p.Crate){\r\n if(p.solid){\r\n if(p.pos.x!==this.pos.x||p.pos.y!==this.pos.y){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n p.pos.x,p.pos.y,p.w,p.h)\r\n ){\r\n if(this.xv>0){\r\n this.pos.x=p.pos.x-(this.w/2+p.w/2);\r\n p.xv=this.xv;\r\n this.xv=0;\r\n }else \r\n if(this.xv<0){\r\n this.pos.x=p.pos.x+(this.w/2+p.w/2);\r\n p.xv=this.xv;\r\n this.xv=0;\r\n }\r\n } \r\n }\r\n } \r\n } \r\n this.pos.y+=this.yv;\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n if(this.yv>0){\r\n this.pos.y=blocks[i].y-(this.h/2+blocks[i].h/2);\r\n this.yv=0;\r\n }else \r\n if(this.yv<0){\r\n this.pos.y=blocks[i].y+(this.h/2+blocks[i].h/2);\r\n this.yv=0;\r\n }\r\n }\r\n }\r\n for (var i = Estor.length-1; i >= 0; i--) {\r\n var p = Estor[i];\r\n //if(p.Crate){\r\n if(p.solid){\r\n if(p.pos.x!==this.pos.x||p.pos.y!==this.pos.y){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n p.pos.x,p.pos.y,p.w,p.h)\r\n ){\r\n if(this.yv>0){\r\n this.pos.y=p.pos.y-(this.h/2+p.h/2);\r\n p.yv=this.yv;\r\n this.yv=0;\r\n }else \r\n if(this.yv<0){\r\n this.pos.y=p.pos.y+(this.h/2+p.h/2);\r\n p.yv=this.yv;\r\n this.yv=0;\r\n }\r\n } \r\n }\r\n }\r\n }\r\n \r\n this.xv/=1.1;\r\n //this.yv/=1.1;\r\n this.yv+=0.3; \r\n this.yv=constrain(this.yv,-8,7);\r\n this.xv=constrain(this.xv,-12,12);\r\n};//Main code\r\ndieD.prototype.isDead = function() {\r\nif (this.LiveT <= 0) {return true;} else {return false;}\r\n};\r\n/**\r\n * ============================\r\n * -======== ENTITYS =========- \r\n * ============================\r\n*/\r\n\r\n/**COLORED BUTTON ENTITY FUNCTION */ \r\n//Estor.push(new button(new PVector(X,Y),color(COLOR)));\r\nvar button = function(pos,c){\r\nthis.pos=pos.get();\r\nthis.c=c;\r\nthis.button=true;\r\nthis.open=false;\r\nthis.solid=false;\r\n};\r\nbutton.prototype.run = function() {\r\n fill(this.c);\r\n if(this.open){\r\n rect(this.pos.x,this.pos.y+2,15,5);\r\n }else{\r\n rect(this.pos.x,this.pos.y,15,10);\r\n }\r\n \r\n fill(150,150,150);\r\n rect(this.pos.x,this.pos.y+7,20,5);\r\n \r\n if(dist(this.pos.x,this.pos.y,P.x,P.y)<20){\r\n this.open=true;\r\n }else{\r\n this.open=false;\r\n }\r\n for (var i = Estor.length-1; i >= 0; i--) {\r\n var p = Estor[i];\r\n if(p.Crate){\r\n if(p.pos.x!==this.pos.x||p.pos.y!==this.pos.y){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,1,1,p.pos.x,p.pos.y,p.w,p.h)\r\n ){\r\n this.open=true;\r\n }\r\n }\r\n }\r\n } \r\n\r\n};\r\nbutton.prototype.Xc = function() {};\r\nbutton.prototype.Yc = function() {};\r\nbutton.prototype.isDead = function() {};\r\n\r\nvar badG = function(pos,w,h) {\r\n this.Crate=false;\r\n this.solid=false;\r\n this.pos=pos.get();\r\n this.w=w;this.h=h;\r\n this.xv=0;this.yv=0;\r\n this.m=0.6;\r\n this.kill=false;\r\n this.canMoveR=true;\r\n this.canMoveL=true;\r\n}; // vars\r\nbadG.prototype.run = function() {\r\n noStroke();\r\n fill(13, 194, 0,250);\r\n rect(this.pos.x, this.pos.y,this.w,this.h);\r\n \r\n this.xv+=this.m;\r\n \r\n this.pos.x+=this.xv;\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n if(this.xv>0){\r\n this.pos.x=blocks[i].x-(this.w/2+blocks[i].w/2);\r\n this.m*=-1;\r\n this.xv=0;\r\n this.canMoveR=false;\r\n }else \r\n if(this.xv<0){\r\n this.pos.x=blocks[i].x+(this.w/2+blocks[i].w/2);\r\n this.m*=-1;\r\n this.xv=0;\r\n this.canMoveL=false;\r\n }\r\n }\r\n }\r\n for (var i = Estor.length-1; i >= 0; i--) {\r\n var p = Estor[i];\r\n //if(p.Crate){\r\n if(p.solid){\r\n if(p.pos.x!==this.pos.x||p.pos.y!==this.pos.y){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n p.pos.x,p.pos.y,p.w,p.h)\r\n ){\r\n\r\n if(this.xv>0){\r\n this.pos.x=p.pos.x-(p.xv+this.w/2+p.w/2);\r\n // p.xv=this.xv;\r\n this.m*=-1;\r\n this.xv=0;\r\n this.canMoveR=false;\r\n }else \r\n if(this.xv<0){\r\n this.pos.x=p.pos.x+(p.xv+this.w/2+p.w/2);\r\n // p.xv=this.xv;\r\n this.m*=-1;\r\n this.xv=0;\r\n this.canMoveL=false;\r\n }\r\n } \r\n }\r\n } \r\n } \r\n this.pos.y+=this.yv;\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n if(this.yv>0){\r\n this.pos.y=blocks[i].y-(this.h/2+blocks[i].h/2);\r\n this.yv=0;\r\n }else \r\n if(this.yv<0){\r\n this.pos.y=blocks[i].y+(this.h/2+blocks[i].h/2);\r\n this.yv=0;\r\n }\r\n }\r\n }\r\n for (var i = Estor.length-1; i >= 0; i--) {\r\n var p = Estor[i];\r\n //if(p.Crate){\r\n if(p.solid){\r\n if(p.pos.x!==this.pos.x||p.pos.y!==this.pos.y){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n p.pos.x,p.pos.y,p.w,p.h)\r\n ){\r\n if(this.yv>0){\r\n this.pos.y=p.pos.y-(this.h/2+p.h/2);\r\n p.yv=this.yv;\r\n this.yv=0;\r\n }else \r\n if(this.yv<0||p.yv>0){\r\n this.pos.y=p.pos.y+(this.h/2+p.h/2);\r\n p.yv=this.yv;\r\n this.yv=0;\r\n\r\n this.kill=true;\r\n this.canMoveR=false;this.canMoveL=false;\r\n for(var i=0;i<20;i++){\r\n pardstor.push(new dieD(\r\n new PVector(this.pos.x+random(-this.w/2,this.w/2),\r\n this.pos.y+random(-this.h/2,this.h/2)),\r\n color(13, 194, 0)));\r\n }\r\n }\r\n } \r\n }\r\n }\r\n }\r\n if(!this.canMoveR&&!this.canMoveL&&!this.kill){\r\n for(var i=0;i<20;i++){\r\n pardstor.push(new dieD(\r\n new PVector(this.pos.x+random(-this.w/2,this.w/2),this.pos.y+random(-this.h/2,this.h/2)),\r\n color(13, 194, 0)));\r\n }\r\n this.kill=true;\r\n }\r\n this.xv/=1.1;\r\n this.yv/=1.1;\r\n this.yv+=0.3; \r\n this.yv=constrain(this.yv,-8,7);\r\n this.xv=constrain(this.xv,-5,5);\r\n this.canMoveR=true;this.canMoveL=true;\r\n};//Main code\r\nbadG.prototype.Xc = function() {\r\n\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n diedT++;\r\n for(var i=0;i<5;i++){\r\n pardstor.push(new dieD(\r\n new PVector(P.x+random(-20,20),P.y+random(-20,20)),color(255, 0, 0)));\r\n } \r\n }\r\n};//X collision\r\nbadG.prototype.Yc = function() {\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n diedT++;\r\n for(var i=0;i<5;i++){\r\n pardstor.push(new dieD(\r\n new PVector(P.x+random(-20,20),P.y+random(-20,20)),color(255, 0, 0)));\r\n }\r\n }\r\n};//Y collision\r\n\r\n\r\n\r\n/**COLORED DOOR ENTITY FUNCTION */ \r\n//Estor.push(new Door(new PVector(X,Y),width,height,color(COLOR)));\r\nvar Door = function(pos,w,h,c) {\r\n this.pos=pos.get();\r\n this.open=false;\r\n this.solid=true;\r\n this.w=w;\r\n this.h=h;\r\n this.c=c;\r\n};\r\nDoor.prototype.run = function() {\r\n noStroke();\r\n if(this.open){\r\n fill(red(this.c),green(this.c),blue(this.c),100);\r\n }else{\r\n fill(this.c);\r\n } \r\n rect(this.pos.x, this.pos.y,this.w,this.h);\r\n this.open=false;\r\n for (var i = Estor.length-1; i >= 0; i--) {\r\n var p = Estor[i];\r\n if(p.button&&this.c===p.c&&p.open){\r\n this.open=true; \r\n } \r\n }\r\n if(this.open){this.solid=false;}else{this.solid=true;}\r\n \r\n \r\n};//Main code\r\nDoor.prototype.Xc = function() {\r\n if(!this.open){\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n if(P.xv>0){\r\n P.x=this.pos.x-(P.w/2+this.w/2);\r\n P.xv=0;\r\n gravity+=0.1;\r\n }else \r\n if(P.xv<0){\r\n P.x=this.pos.x+(P.w/2+this.w/2);\r\n P.xv=0;\r\n gravity+=0.1;\r\n }\r\n }\r\n }\r\n};//X collision\r\nDoor.prototype.Yc = function() {\r\n if(!this.open){\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n if(P.yv>0){\r\n P.y=this.pos.y-(P.h/2+this.h/2);\r\n P.yv=0;\r\n gravity=0;\r\n }else \r\n if(P.yv<0){\r\n P.y=this.pos.y+(P.h/2+this.h/2);\r\n P.yv=0;\r\n gravity=0.1;\r\n }\r\n }\r\n }\r\n};//Y collision\r\n\r\n/**CRATE ENTITY FUNCTION*/\r\n//Estor.push(new Crate(new PVector(X,Y),width,height));\r\nvar Crate = function(pos,w,h) {\r\n this.Crate=true;\r\n this.solid=true;\r\n this.pos=pos.get();\r\n this.w=w;this.h=h;\r\n this.xv=0;this.yv=0;\r\n}; // vars\r\nCrate.prototype.run = function() {\r\n noStroke();\r\n fill(173, 146, 38,250);\r\n rect(this.pos.x, this.pos.y,this.w,this.h);\r\n \r\n fill(217, 188, 22,250);\r\n rect(this.pos.x, this.pos.y,this.w-5,this.h-5);\r\n \r\n \r\n this.pos.x+=this.xv;\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n if(this.xv>0){\r\n this.pos.x=blocks[i].x-(this.w/2+blocks[i].w/2);\r\n this.xv=0;\r\n }else \r\n if(this.xv<0){\r\n this.pos.x=blocks[i].x+(this.w/2+blocks[i].w/2);\r\n this.xv=0;\r\n }\r\n }\r\n }\r\n for (var i = Estor.length-1; i >= 0; i--) {\r\n var p = Estor[i];\r\n //if(p.Crate){\r\n if(p.solid){\r\n if(p.pos.x!==this.pos.x||p.pos.y!==this.pos.y){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n p.pos.x,p.pos.y,p.w,p.h)\r\n ){\r\n if(this.xv>0){\r\n this.pos.x=p.pos.x-(this.w/2+p.w/2);\r\n p.xv=this.xv;\r\n this.xv=0;\r\n }else \r\n if(this.xv<0){\r\n this.pos.x=p.pos.x+(this.w/2+p.w/2);\r\n p.xv=this.xv;\r\n this.xv=0;\r\n }\r\n } \r\n }\r\n } \r\n } \r\n this.pos.y+=this.yv;\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n if(this.yv>0){\r\n this.pos.y=blocks[i].y-(this.h/2+blocks[i].h/2);\r\n this.yv=0;\r\n }else \r\n if(this.yv<0){\r\n this.pos.y=blocks[i].y+(this.h/2+blocks[i].h/2);\r\n this.yv=0;\r\n }\r\n }\r\n }\r\n for (var i = Estor.length-1; i >= 0; i--) {\r\n var p = Estor[i];\r\n //if(p.Crate){\r\n if(p.solid){\r\n if(p.pos.x!==this.pos.x||p.pos.y!==this.pos.y){\r\n if(\r\n rectCol(this.pos.x,this.pos.y,this.w,this.h,\r\n p.pos.x,p.pos.y,p.w,p.h)\r\n ){\r\n if(this.yv>0){\r\n this.pos.y=p.pos.y-(this.h/2+p.h/2);\r\n p.yv=this.yv;\r\n this.yv=0;\r\n }else \r\n if(this.yv<0){\r\n this.pos.y=p.pos.y+(this.h/2+p.h/2);\r\n p.yv=this.yv;\r\n this.yv=0;\r\n }\r\n } \r\n }\r\n }\r\n }\r\n this.xv/=1.1;\r\n this.yv/=1.1;\r\n this.yv+=0.3; \r\n this.yv=constrain(this.yv,-8,7);\r\n this.xv=constrain(this.xv,-12,12);\r\n};//Main code\r\nCrate.prototype.Xc = function() {\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n if(P.xv>0){\r\n this.xv=P.xv/1.5;\r\n P.x=this.pos.x-(P.w/2+this.w/2);\r\n P.xv=0;\r\n gravity+=0.1;\r\n }else \r\n if(P.xv<0){\r\n this.xv=P.xv/1.5;\r\n P.x=this.pos.x+(P.w/2+this.w/2);\r\n P.xv=0;\r\n gravity+=0.1;\r\n }\r\n }\r\n};//X collision\r\nCrate.prototype.Yc = function() {\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n if(this.yv<0&&P.y<=this.pos.y-(this.h/2)){\r\n P.y=this.pos.y-((P.h/2+this.h/2)+1);\r\n P.yv=this.yv;\r\n }else\r\n if(this.yv>0&&P.y>=this.pos.y+(this.h/2)&&(gravity===0||P.yv===0||P.yv===0.25)){\r\n diedT++;\r\n for(var i=0;i<20;i++){\r\n pardstor.push(new dieD(\r\n new PVector(P.x+random(-20,20),P.y+random(-20,20)),color(255, 0, 0)));\r\n }\r\n }else\r\n if(P.yv>0){\r\n P.y=this.pos.y-(P.h/2+this.h/2);\r\n P.yv=0;\r\n gravity=0;\r\n }else \r\n if(P.yv<0){\r\n \r\n this.yv=P.yv/2;\r\n P.y=this.pos.y+(P.h/2 + this.h/2);\r\n P.yv=0;\r\n gravity=0.1;\r\n }\r\n \r\n }\r\n};//Y collision\r\n\r\n/**DIEBLOCK (FADING BLOCK) FUNCTION */\r\n//Estor.push(new dieblock(new PVector(X,Y),width,height));\r\nvar dieblock = function(pos,w,h) {\r\n this.pos = pos.get();\r\n this.w=w;\r\n this.h=h;\r\n this.LiveT=300;\r\n this.solid=true;\r\n this.Touched=false;\r\n}; \r\ndieblock.prototype.run = function() {\r\n if(!this.Touched){\r\n this.LiveT+=0.1;\r\n this.LiveT*=1.05;\r\n this.Touched=false;\r\n }\r\n if(this.LiveT<=0){\r\n this.Touched=false;\r\n } \r\n if(this.Touched){\r\n this.LiveT-=10;\r\n }\r\n \r\n this.LiveT=constrain(this.LiveT,0,300);\r\n noStroke();\r\n fill(153, 151, 153,this.LiveT);\r\n rect(this.pos.x, this.pos.y,this.w,this.h);\r\n // fill(255, 0, 0);\r\n // text(this.LiveT,this.pos.x, this.pos.y);\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n this.solid=false;\r\n this.Touched=true;\r\n } \r\n}; \r\ndieblock.prototype.Xc = function() {\r\n if(this.LiveT>50){\r\n this.solid=true;\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n //\r\n this.Touched=true;\r\n if(P.xv>0){//player hits block on the left\r\n P.x=this.pos.x-(P.w/2+this.w/2);\r\n P.xv=0;// reset player x velocity\r\n gravity+=0.1;\r\n }else \r\n if(P.xv<0){//player hits block on the right\r\n P.x=this.pos.x+(P.w/2+this.w/2);\r\n P.xv=0;// reset player x velocity\r\n gravity+=0.1;\r\n }\r\n // P.x+=P.xv;\r\n }}\r\n};\r\ndieblock.prototype.Yc = function() {\r\n if(this.LiveT>50){\r\n this.solid=true;\r\n if(\r\n P.x>(this.pos.x-this.w/2)-P.w/2&&\r\n P.x<(this.pos.x+this.w/2)+P.w/2&&\r\n P.y>(this.pos.y-this.h/2)-P.h/2&&\r\n P.y<(this.pos.y+this.h/2)+P.h/2\r\n ){\r\n this.Touched=true;\r\n if(P.yv>0){//player hits block on the top\r\n P.y=this.pos.y-(P.h/2+this.h/2);\r\n P.yv=0;// reset player y velocity\r\n gravity=0;// no gravity if touching top\r\n }else \r\n if(P.yv<0){//player hits block on the bottem\r\n P.y=this.pos.y+(P.h/2+this.h/2);\r\n P.yv=0;// reset player y velocity\r\n gravity=0.1;// adds grivity \r\n }\r\n // P.y+=P.yv;\r\n \r\n }}\r\n};\r\nvar aDB = function(x,y,w,h){\r\nEstor.push(new dieblock(new PVector(x,y),w,h));\r\n};//Add Die block ( more compact )\r\n\r\n/**BLOCK EXAMPLE FUNCTION*/\r\n// touchExample(X,Y,width,height);\r\nvar touchExample = function(x,y,w,h){\r\n if(rectCol(P.x,P.y,P.w,P.h,x,y,w,h)){\r\n // if player touchs\r\n }else{\r\n //if player does not touch\r\n }\r\n rect(x,y,w,h);\r\n};\r\n\r\n/**PLATFORM FUNCTION*/\r\n// platForm(X,Y,width,height);\r\nvar platForm = function(x,y,w,h){\r\n if(rectCol(P.x,P.y,P.w,P.h,x,y,w,h)){\r\n if(!(input[DOWN]||input[83])&&P.yv>0&&P.y<y-h/2){\r\n P.y=(y-h/2)-P.w/2;\r\n P.yv=0;// reset player y velocity\r\n gravity=0;// no gravity if touching top\r\n dashed=false;\r\n }\r\n }\r\n fill(5,5,5,150);\r\n rect(x,y-h/2,w,2);\r\n fill(5,5,5,20);\r\n rect(x,y,w,h);\r\n};\r\n\r\n/**KILL BLOCK (LAVA) FUNCTION*/\r\n// killB(X,Y,width,height);\r\nvar killB = function(x,y,w,h){\r\n if(rectCol(P.x,P.y,P.w,P.h,x,y,w,h)&&diedT<=0){\r\n diedT++;\r\n for(var i=0;i<20;i++){\r\n pardstor.push(new dieD(\r\n new PVector(P.x+random(-20,20),P.y+random(-20,20)),color(255, 0, 0)));\r\n } \r\n }\r\n fill(200-sin(millis())*30, 80, 0);\r\n rect(x,y,w,h);\r\n};\r\n\r\n/**HELP SIGN FUNCTION*/\r\n// helpSign(X,Y,displayText);\r\nvar helpSign = function(x,y,txt){\r\nif(dist(P.x,P.y,x,y)<20){\r\n textSize(15);\r\n \r\n fill(255, 255, 255);\r\n text(txt,P.x,P.y-48);\r\n \r\n fill(0, 0, 0);\r\n text(txt,P.x,P.y-50);\r\n }\r\n fill(181, 181, 181);\r\n rect(x,y,40,30);\r\n fill(230, 207, 230);\r\n rect(x,y,32,21);\r\n};\r\n\r\n/**GRAVITY BUBBLE FUNCTION*/\r\n// Grav(X,Y,width,height,VXadd,VYadd);\r\nvar Grav = function(x,y,w,h,vx,vy){\r\n if(rectCol(P.x,P.y,P.w,P.h,x,y,w,h)){\r\n gravity+=vy;\r\n P.xv+=vx;\r\n for(var i=0;i<2;i++){\r\n pardstor.push(new jumpPard(\r\n new PVector(P.x+random(-20,20),P.y+random(-20,20)),\r\n new PVector((P.xv/random(2,10))*-1,(P.yv/random(2,10))*-1)));\r\n } \r\n }\r\n for(var i=Estor.length-1;i>=0;i--){//loops through and run entitys\r\n var p=Estor[i];\r\n \r\n if(rectCol(p.pos.x,p.pos.y,p.w,p.h,x,y,w,h)){ \r\n p.xv+=vx;\r\n p.yv+=vy;\r\n } \r\n }\r\n \r\n fill(0, 255, 255,80);\r\n rect(x,y,w,h);\r\n if(random(0,2)>1){\r\n pardstor.push(new GravParticle(\r\n new PVector(x+random(-w/2,w/2),y+random(-h/2,h/2)),vx,vy,x,y,w,h)\r\n );\r\n }\r\n}; \r\n\r\n/**CHECK POINT FUNCTION*/\r\n// checkP(X,Y);\r\nvar checkP = function(x,y){\r\nif(dist(P.x,P.y,x,y)<20){\r\n P.sx=x;\r\n P.sy=y;\r\n }\r\n if(x===P.sx&&y===P.sy){\r\n fill(0, 255, 0,150);\r\n }else{\r\n fill(255, 0, 0,150);\r\n }\r\n ellipse(x,y,40,40);\r\n};\r\n\r\n/**NEXT LEVEL FUNCTION*/\r\n// nxtlvl(X,Y);\r\nvar nxtlvl = function(x,y){\r\nif(dist(P.x,P.y,x,y)<20){\r\n Level++;\r\n }\r\n fill(196, 0, 255,150);\r\n \r\n ellipse(x,y,40,40);\r\n};\r\n\r\n\r\n}\r\n//-=-=-=-=-=-=-=-=-=-=-=-=-=\r\n\r\n// Level array\r\nvar Levels = [\r\n/**\r\n{\r\n onStart:function(){ *//*things that happen when the level starts ( happens once )*//**\r\n blocks = [\r\n (@BLOCKS_HERE)\r\n ];\r\n \r\n P={x:0,y:0,xv:0,yv:0,w:20,h:20,sx:@SPAWN_X,sy:@SPAWN_Y,}; <-- @PLAYER_ARRAY\r\n Mw=@MAP_WIDTH;\r\n Mh=@MAP_HEIGHT;\r\n \r\n @ADD_ENTITYS_AND_OTHER_THINGS_HERE\r\n\r\n },mainLvl:function(){ *//*things that happen when the level is active ( loops )*//**\r\n \r\n @BLOCK_FUNCTIONS_HERE\r\n \r\n }\r\n},\r\n*/\r\n//================================== \r\n{\r\n onStart:function(){\r\n levelName=\'Tutorial\'; \r\n blocks = [\r\n {x:550,y:450,w:70,h:10},\r\n {x:295,y:450,w:200,h:10},\r\n {x:100,y:350,w:201,h:20},\r\n {x:325,y:350,w:250,h:20},\r\n {x:0,y:300,w:10,h:600},\r\n {x:800,y:300,w:10,h:600},\r\n {x:400,y:600,w:800,h:10},\r\n {x:550,y:250,w:200,h:10},\r\n {x:454,y:204,w:10,h:100},\r\n {x:454,y:20,w:10,h:200},\r\n {x:645,y:154,w:10,h:100},\r\n {x:645,y:354,w:10,h:400}, \r\n {x:258,y:158,w:400,h:10},\r\n {x:380,y:320,w:10,h:70},\r\n \r\n {x:300,y:570,w:51,h:20},\r\n {x:150,y:570,w:51,h:20},\r\n {x:450,y:570,w:51,h:20},\r\n ];\r\n P={x:280,y:280,xv:0,yv:0,w:20,h:20,sx:280,sy:280,};\r\n Mw=800;\r\n Mh=600;\r\n //Crate\r\n /*\r\n Estor.push(new button(new PVector(220,330),color(0,150,0)));\r\n Estor.push(new Door(new PVector(380,225),10,120,color(0,150,0)));\r\n Estor.push(new Door(new PVector(320,225),50,10,color(0, 150, 0)));\r\n \r\n Estor.push(new button(new PVector(250,330),color(150,0,0)));\r\n //Estor.push(new Door(new PVector(380,225),10,120,color(150,150,0)));\r\n Estor.push(new Door(new PVector(320,255),50,10,color(150,0,0)));\r\n \r\n Estor.push(new Crate(new PVector(325,200),20,20,0,0));\r\n */\r\n //Estor.push(new Crate(new PVector(345,280),20,25,0,0));\r\n //Estor.push(new Crate(new PVector(345,220),5,5,0,0));\r\n \r\n \r\n // Estor.push(new dieblock(new PVector(300,570),51,20));\r\n // Estor.push(new dieblock(new PVector(150,570),51,20));\r\n // Estor.push(new dieblock(new PVector(450,570),51,20));\r\n // Estor.push(new dieblock(new PVector(100,455),190,20));\r\n },\r\n mainLvl:function(){\r\n nxtlvl(50,300); \r\n killB(420,460,450,10);\r\n killB(260,590,550,10);\r\n killB(260,155,260,10);\r\n killB(550,240,180,10);\r\n platForm(550,350,200,20);\r\n platForm(460,159,50,12);\r\n platForm(720,275,150,12);\r\n checkP(300,420);\r\n checkP(590,550);\r\n Grav(722,440,145,330,0,-6);\r\n Grav(150,250,90,180,1.2,0);\r\n Grav(715,180,80,50,0,-8);\r\n Grav(645,70,20,80,-5,-1);\r\n helpSign(280,320,\"Use [A] or [D] / Arrows to move\"); \r\n helpSign(350,320,\"Press [W] / [UP] to jump\\nthe longer you hold the higher you jump\");\r\n helpSign(540,320,\"Press [S] / [DOWN] to drop down\"); \r\n helpSign(350,425,\"this is a check point\\nif you died you respawn here\"); \r\n helpSign(420,135,\"Press [UP] or [W] + [SPACE] to dash\"); \r\n helpSign(720,245,\"Hold jump in a gravity bubble\\nto boost\");\r\n },\r\n},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'the down fall\'; \r\nblocks=[\r\n{x:5,y:500,w:10,h:1000},\r\n{x:205,y:995,w:390,h:10},\r\n{x:395,y:495,w:10,h:990},\r\n{x:200,y:5,w:380,h:10},\r\n{x:40,y:105,w:60,h:10},\r\n{x:280,y:895,w:220,h:10},\r\n\r\n];\r\nP={x:37,y:61,xv:0,yv:0,w:20,h:20,sx:37,sy:61,};\r\nMw=400;Mh=1000;\r\n},mainLvl:function(){\r\nnxtlvl(345,967);\r\nGrav(200,505,380,790,0,-P.yv/3);\r\nplatForm(230,105,320,10);\r\nkillB(200,245,200,30);\r\nkillB(55,360,90,20);\r\nkillB(345,360,90,20);\r\nkillB(245,450,290,20);\r\nkillB(90,585,160,30);\r\nkillB(310,585,160,30);\r\nkillB(115,680,30,40);\r\nkillB(245,715,290,30);\r\nkillB(90,815,160,30);\r\nkillB(310,815,160,30);\r\nkillB(245,860,30,60);\r\nkillB(200,880,60,20);\r\n\r\ncheckP(200,550);\r\n\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'pushing the limit\';\r\nblocks=[\r\n{x:250,y:490,w:500,h:20},\r\n{x:110,y:470,w:0,h:20},\r\n{x:105,y:470,w:10,h:20},\r\n{x:295,y:470,w:10,h:20},\r\n{x:385,y:395,w:190,h:10},\r\n{x:400,y:355,w:160,h:70},\r\n{x:295,y:255,w:10,h:10},\r\n{x:385,y:245,w:190,h:10},\r\n{x:185,y:475,w:10,h:10},\r\n{x:215,y:475,w:10,h:10},\r\n{x:250,y:245,w:80,h:10},\r\n{x:145,y:245,w:90,h:10},\r\n{x:10,y:240,w:20,h:480},\r\n{x:490,y:240,w:20,h:480},\r\n{x:235,y:210,w:10,h:20},\r\n{x:220,y:195,w:20,h:30},\r\n{x:165,y:175,w:130,h:10},\r\n{x:235,y:185,w:10,h:30},\r\n{x:170,y:95,w:140,h:10},\r\n{x:250,y:10,w:460,h:20},\r\n{x:105,y:85,w:10,h:10},\r\n{x:145,y:210,w:90,h:60},\r\n{x:430,y:60,w:100,h:80},\r\n{x:145,y:360,w:90,h:80},\r\n{x:255,y:360,w:90,h:80},\r\n{x:310,y:45,w:140,h:50},\r\n{x:390,y:190,w:20,h:40},\r\n{x:310,y:195,w:140,h:10},\r\n\r\n];\r\nEstor.push(new Crate(new PVector(410,285),20,70,0,0));\r\nEstor.push(new Crate(new PVector(220,225),20,30,0,0));\r\nEstor.push(new Crate(new PVector(210,80),140,20,0,0));\r\nP={x:452,y:289,xv:0,yv:0,w:20,h:20,sx:452,sy:289,};\r\nMw=500;Mh=500;\r\n},mainLvl:function(){\r\nnxtlvl(449,443);\r\nkillB(200,465,180,10);\r\nplatForm(440,175,80,10);\r\nplatForm(440,205,80,10);\r\nGrav(35,250,30,460,0,-2);\r\nkillB(200,360,20,60);\r\nkillB(310,185,140,10);\r\nGrav(310,135,140,90,0,10);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'Doors and buttons \';\r\nblocks=[\r\n{x:250,y:495,w:480,h:10},\r\n{x:5,y:250,w:10,h:500},\r\n{x:495,y:250,w:10,h:500},\r\n{x:105,y:395,w:10,h:190},\r\n{x:135,y:395,w:10,h:190},\r\n{x:120,y:305,w:20,h:10},\r\n{x:75,y:235,w:130,h:10},\r\n{x:170,y:305,w:60,h:10},\r\n{x:205,y:270,w:10,h:80},\r\n{x:135,y:225,w:10,h:10},\r\n{x:205,y:90,w:10,h:180},\r\n{x:305,y:235,w:190,h:10},\r\n{x:350,y:305,w:280,h:10},\r\n{x:465,y:150,w:10,h:300},\r\n\r\n];\r\nEstor.push(new button(new PVector(120,485),color(255,0,0)));\r\nEstor.push(new Crate(new PVector(120,320),20,20,0,0));\r\nEstor.push(new Door(new PVector(55,415),90,30,color(255, 0, 0)));\r\n\r\nEstor.push(new button(new PVector(30,225),color(0,255,0)));\r\nEstor.push(new Crate(new PVector(100,220),20,20,0,0));\r\nEstor.push(new Door(new PVector(205,205),10,50,color(0, 255, 0)));\r\n\r\nEstor.push(new Crate(new PVector(480,30),20,40,0,0));\r\nEstor.push(new button(new PVector(30,225),color(0,255,0)));\r\n\r\nEstor.push(new button(new PVector(350,225),color(255,255,0)));\r\nEstor.push(new button(new PVector(300,225),color(255,0,255)));\r\nEstor.push(new button(new PVector(250,225),color(155,255,0)));\r\nEstor.push(new button(new PVector(480,290),color(255,155,0)));\r\n\r\nEstor.push(new Door(new PVector(480,65),20,10,color(255, 255, 0)));\r\nEstor.push(new Door(new PVector(480,135),20,10,color(255, 0, 255)));\r\nEstor.push(new Door(new PVector(480,215),20,10,color(155, 255, 0)));\r\nEstor.push(new Door(new PVector(430,235),60,10,color(255, 155, 0)));\r\nP={x:50,y:474,xv:0,yv:0,w:20,h:20,sx:50,sy:474,};\r\nMw=500;Mh=500;\r\n},mainLvl:function(){\r\nnxtlvl(239,270);\r\nplatForm(55,450,90,20);\r\nplatForm(55,380,90,20);\r\nplatForm(55,330,90,20);\r\nplatForm(170,270,60,20);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'speed is key\'; \r\nblocks=[\r\n{x:210,y:390,w:20,h:180},\r\n{x:220,y:210,w:440,h:20},\r\n{x:300,y:490,w:580,h:20},\r\n{x:395,y:195,w:10,h:10},\r\n{x:380,y:190,w:20,h:20},\r\n{x:105,y:195,w:10,h:10},\r\n{x:120,y:190,w:20,h:20},\r\n{x:365,y:70,w:10,h:140},\r\n{x:135,y:70,w:10,h:140},\r\n{x:65,y:5,w:130,h:10},\r\n{x:5,y:105,w:10,h:190},\r\n{x:595,y:50,w:10,h:100},\r\n{x:480,y:5,w:220,h:10},\r\n{x:490,y:95,w:60,h:10},\r\n{x:515,y:65,w:10,h:50},\r\n{x:455,y:155,w:10,h:130},\r\n{x:445,y:210,w:10,h:20},\r\n{x:595,y:300,w:10,h:400},\r\n{x:5,y:360,w:10,h:280},\r\n];\r\naDB(150,310,40,20);\r\naDB(275,310,50,20);\r\naDB(-10,-10,0,0);\r\naDB(375,310,50,20);\r\naDB(475,310,50,20);\r\naDB(360,185,20,10);\r\naDB(340,185,20,10);\r\naDB(320,185,20,10);\r\naDB(300,185,20,10);\r\naDB(280,185,20,10);\r\naDB(260,185,20,10);\r\naDB(240,185,20,10);\r\naDB(220,185,20,10);\r\naDB(200,185,20,10);\r\naDB(180,185,20,10);\r\naDB(160,185,20,10);\r\naDB(140,185,20,10);\r\nP={x:150,y:443,xv:0,yv:0,w:20,h:20,sx:150,sy:443,};\r\nMw=600;Mh=600;\r\n},mainLvl:function(){\r\ncheckP(480,60); \r\nnxtlvl(45,172);\r\nplatForm(75,430,50,20);\r\nplatForm(75,370,50,20);\r\nplatForm(75,310,50,20);\r\nkillB(405,475,370,10);\r\nkillB(250,195,240,10);\r\nkillB(250,145,240,10);\r\nGrav(555,125,70,230,0,-10);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'the factory\'; \r\nblocks=[\r\n{x:400,y:795,w:780,h:10},\r\n{x:795,y:400,w:10,h:800},\r\n{x:10,y:400,w:0,h:800},\r\n{x:5,y:400,w:10,h:800},\r\n{x:165,y:505,w:250,h:10},\r\n{x:135,y:545,w:250,h:10},\r\n{x:295,y:645,w:10,h:290},\r\n{x:335,y:610,w:10,h:300},\r\n{x:170,y:465,w:320,h:10},\r\n{x:80,y:775,w:140,h:30},\r\n{x:125,y:705,w:50,h:10},\r\n{x:225,y:765,w:130,h:10},\r\n{x:230,y:780,w:120,h:20},\r\n{x:255,y:640,w:10,h:180},\r\n{x:165,y:690,w:10,h:40},\r\n{x:135,y:695,w:10,h:10},\r\n{x:470,y:735,w:260,h:10},\r\n{x:675,y:785,w:10,h:10},\r\n{x:705,y:785,w:10,h:10},\r\n{x:715,y:780,w:10,h:20},\r\n{x:725,y:775,w:10,h:30},\r\n{x:735,y:770,w:10,h:40},\r\n{x:745,y:765,w:10,h:50},\r\n{x:755,y:760,w:10,h:60},\r\n{x:765,y:755,w:10,h:70},\r\n{x:775,y:750,w:10,h:80},\r\n{x:785,y:745,w:10,h:90},\r\n{x:595,y:690,w:10,h:80},\r\n{x:580,y:655,w:20,h:10},\r\n{x:355,y:655,w:30,h:10},\r\n{x:320,y:405,w:560,h:10},\r\n{x:635,y:375,w:10,h:70},\r\n{x:715,y:340,w:150,h:0},\r\n{x:715,y:345,w:150,h:10},\r\n{x:710,y:285,w:160,h:10},\r\n{x:515,y:395,w:10,h:10},\r\n{x:85,y:705,w:30,h:10},\r\n\r\n];\r\nEstor.push(new button(new PVector(550,785),color(0,255,0)));\r\nEstor.push(new button(new PVector(650,785),color(0,0,255)));\r\n\r\n\r\nEstor.push(new button(new PVector(160,785),color(255,0,0)));\r\n//Estor.push(new Crate(new PVector(120,320),20,20,0,0));\r\nEstor.push(new Door(new PVector(635,315),10,50,color(0, 255, 0)));\r\nEstor.push(new Door(new PVector(645,315),10,50,color( 0, 0,255)));\r\n\r\nEstor.push(new Door(new PVector(255,745),10,30,color(255,0,0)));\r\n\r\nEstor.push(new Crate(new PVector(145,680),10,40,0,0));\r\nEstor.push(new Crate(new PVector(55,685),30,30,0,0));\r\naDB(505,655,30,10);\r\naDB(445,655,30,10);\r\nEstor.push(new Crate(new PVector(585,385),30,30,0,0));\r\nP={x:100,y:647,xv:0,yv:0,w:20,h:20,sx:100,sy:647,};\r\nMw=800;Mh=800;\r\n},mainLvl:function(){\r\n helpSign(100,675,\"press [R] to restart level\"); \r\nnxtlvl(765,315);\r\nGrav(315,485,30,30,0,3);\r\nGrav(315,630,30,260,0,3);\r\nGrav(315,775,30,30,3,0);\r\nGrav(275,650,30,220,0,-3);\r\nGrav(165,525,250,30,-3,0);\r\nGrav(25,520,30,40,0,-3);\r\nGrav(155,485,290,30,3,0);\r\nplatForm(230,725,40,10);\r\nplatForm(190,685,40,10);\r\nplatForm(690,685,80,10);\r\nplatForm(355,605,30,10);\r\nplatForm(355,555,30,10);\r\nplatForm(355,505,30,10);\r\nplatForm(355,465,30,10);\r\nkillB(465,720,250,20);\r\nplatForm(25,435,30,10);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'a level name\'; \r\nblocks=[\r\n{x:195,y:340,w:350,h:20},\r\n{x:260,y:310,w:20,h:40},\r\n{x:260,y:230,w:20,h:40},\r\n{x:395,y:320,w:50,h:60},\r\n{x:260,y:180,w:20,h:60},\r\n{x:345,y:200,w:150,h:20},\r\n{x:525,y:300,w:30,h:100},\r\n{x:145,y:140,w:250,h:20},\r\n{x:145,y:140,w:250,h:20},\r\n{x:185,y:50,w:170,h:20},\r\n{x:530,y:145,w:20,h:210},\r\n{x:465,y:345,w:90,h:10},\r\n{x:425,y:430,w:350,h:20},\r\n{x:260,y:480,w:20,h:80},\r\n{x:225,y:590,w:90,h:20},\r\n{x:190,y:465,w:20,h:230},\r\n{x:585,y:530,w:30,h:20},\r\n];\r\nEstor.push(new dieblock(new PVector(465,300),90,20));\r\nEstor.push(new dieblock(new PVector(315,50),30,20));\r\nEstor.push(new dieblock(new PVector(395,50),30,20));\r\nEstor.push(new dieblock(new PVector(465,50),30,20));\r\nEstor.push(new dieblock(new PVector(500,385),20,70));\r\nEstor.push(new dieblock(new PVector(480,385),20,70));\r\nEstor.push(new dieblock(new PVector(460,385),20,70));\r\nEstor.push(new dieblock(new PVector(440,385),20,70));\r\nEstor.push(new dieblock(new PVector(420,385),20,70));\r\nEstor.push(new dieblock(new PVector(400,385),20,70));\r\nEstor.push(new dieblock(new PVector(380,385),20,70));\r\nEstor.push(new dieblock(new PVector(360,385),20,70));\r\nEstor.push(new dieblock(new PVector(340,385),20,70));\r\nEstor.push(new dieblock(new PVector(225,430),50,20));\r\nEstor.push(new dieblock(new PVector(225,450),50,20));\r\nEstor.push(new dieblock(new PVector(225,470),50,20));\r\nEstor.push(new dieblock(new PVector(225,490),50,20));\r\nEstor.push(new dieblock(new PVector(345,570),50,20));\r\nEstor.push(new dieblock(new PVector(450,550),60,20));\r\nEstor.push(new dieblock(new PVector(535,570),50,20));\r\nP={x:293,y:178,xv:0,yv:0,w:20,h:20,sx:178,sy:293,};\r\nMw=600;Mh=600;\r\n},mainLvl:function(){\r\nkillB(320,320,100,20);\r\nplatForm(60,50,80,20);\r\nplatForm(60,100,80,20);\r\nkillB(465,330,90,20);\r\nnxtlvl(580,500);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'Insert level related pun here\';\r\nblocks=[\r\n{x:10,y:5,w:0,h:10},\r\n{x:5,y:295,w:10,h:590},\r\n{x:300,y:595,w:600,h:10},\r\n{x:595,y:295,w:10,h:590},\r\n{x:205,y:455,w:10,h:70},\r\n{x:250,y:495,w:0,h:30},\r\n{x:255,y:505,w:10,h:70},\r\n{x:200,y:505,w:60,h:10},\r\n{x:255,y:440,w:10,h:40},\r\n{x:205,y:545,w:10,h:70},\r\n{x:255,y:555,w:10,h:30},\r\n{x:230,y:425,w:40,h:10},\r\n{x:285,y:545,w:10,h:90},\r\n{x:295,y:505,w:10,h:10},\r\n{x:315,y:475,w:170,h:10},\r\n{x:185,y:425,w:30,h:10},\r\n{x:55,y:430,w:90,h:0},\r\n{x:10,y:425,w:0,h:10},\r\n{x:55,y:425,w:90,h:10},\r\n{x:210,y:330,w:20,h:60},\r\n{x:250,y:330,w:20,h:60},\r\n{x:255,y:415,w:10,h:10},\r\n{x:205,y:415,w:10,h:10},\r\n\r\n];\r\nEstor.push(new Crate(new PVector(265,465),30,10,0,0));\r\nEstor.push(new Crate(new PVector(195,495),30,10,0,0));\r\nEstor.push(new Crate(new PVector(190,585),80,10,0,0));\r\nEstor.push(new Crate(new PVector(240,460),20,20,0,0));\r\nEstor.push(new Crate(new PVector(230,320),20,20,0,0));\r\nEstor.push(new Door(new PVector(65,360),10,120,color(255, 0, 0)));\r\nEstor.push(new Door(new PVector(225,345),10,30,color(0, 255, 0)));\r\nEstor.push(new Door(new PVector(235,345),10,30,color(0, 0, 255)));\r\nEstor.push(new button(new PVector(230,415),color(255,0,0)));\r\nEstor.push(new button(new PVector(400,585),color(0,255,0)));\r\nEstor.push(new button(new PVector(470,585),color(0,0,255)));\r\nP={x:49,y:559,xv:0,yv:0,w:20,h:20,sx:49,sy:559,};\r\nMw=600;Mh=600;\r\n},mainLvl:function(){\r\nnxtlvl(32,387);\r\nplatForm(135,505,70,10);\r\nplatForm(125,555,50,10);\r\nplatForm(135,465,70,10);\r\nplatForm(135,425,70,10);\r\nplatForm(475,475,150,10);\r\nGrav(570,495,40,190,0,-1);\r\nGrav(270,545,20,90,0,-1);\r\nGrav(280,490,40,20,5,0);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'the piston\';\r\nblocks=[\r\n{x:125,y:295,w:230,h:10},\r\n{x:275,y:295,w:50,h:10},\r\n//{x:295,y:195,w:10,h:190},\r\n{x:235,y:405,w:10,h:210},\r\n{x:245,y:505,w:10,h:10},\r\n{x:255,y:405,w:10,h:210},\r\n{x:195,y:275,w:10,h:30},\r\n{x:170,y:275,w:40,h:30},\r\n{x:140,y:285,w:20,h:10},\r\n{x:70,y:285,w:20,h:10},\r\n{x:35,y:275,w:50,h:30},\r\n{x:105,y:105,w:190,h:10},\r\n{x:250,y:585,w:40,h:10},\r\n{x:15,y:445,w:10,h:290},\r\n{x:200,y:95,w:20,h:10},\r\n{x:295,y:185,w:10,h:170},\r\n{x:325,y:295,w:50,h:10},\r\n{x:345,y:195,w:10,h:190},\r\n{x:320,y:105,w:40,h:10},\r\n];\r\nEstor.push(new Crate(new PVector(245,275),90,30,0,0));\r\nEstor.push(new Crate(new PVector(245,405),10,190,0,0));\r\naDB(375,105,50,10);\r\naDB(475,245,50,10);\r\naDB(385,305,50,10);\r\naDB(475,435,50,10);\r\naDB(370,565,60,10);\r\nEstor.push(new button(new PVector(95,285),color(255, 0, 0)));\r\nEstor.push(new button(new PVector(310,285),color(255, 0, 0)));\r\nEstor.push(new button(new PVector(330,285),color(0, 255, 0)));\r\n\r\nEstor.push(new Door(new PVector(245,305),10,10,color(255, 0, 0)));\r\nEstor.push(new Door(new PVector(100,135),40,10,color(0, 255, 0)));\r\nEstor.push(new Crate(new PVector(110,120),20,20,0,0));\r\naDB(145,575,30,10);\r\nP={x:33,y:223,xv:0,yv:0,w:20,h:20,sx:33,sy:223,};\r\nMw=600;Mh=600;\r\n},mainLvl:function(){\r\nnxtlvl(69,354);\r\nGrav(245,405,10,190,0,-0.8);\r\nkillB(125,305,210,10);\r\nGrav(145,450,70,100,-0.1,-6);\r\ncheckP(320,75);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'possible\';\r\nblocks=[\r\n{x:200,y:295,w:200,h:10},\r\n{x:105,y:245,w:10,h:90},\r\n{x:295,y:245,w:10,h:90},\r\n\r\n];\r\nP={x:131,y:273,xv:0,yv:0,w:20,h:20,sx:131,sy:273,};\r\nMw=400;Mh=400;\r\n},mainLvl:function(){\r\nnxtlvl(268,274);\r\nkillB(200,270,80,40);\r\nkillB(200,185,80,50);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'TESTING\'; \r\nblocks=[\r\n{x:500,y:690,w:1000,h:20},\r\n{x:990,y:340,w:20,h:680},\r\n{x:10,y:340,w:20,h:680},\r\n];\r\nP={x:503,y:397,xv:0,yv:0,w:20,h:20,sx:503,sy:397,};\r\n//Estor.push(new Crate(new PVector(500,5),960,10,0,0));\r\nMw=1000;Mh=700;\r\nfor(var y=0;y<160;y+=20){\r\nfor(var x=0;x<160;x+=20){\r\nEstor.push(new Crate(new PVector(600+x,500+y),20,20,0,0));\r\n}}\r\nEstor.push(new badG(new PVector(203,506),20,60));\r\n\r\n},mainLvl:function(){\r\nnxtlvl(-1000,-1000);\r\nfill(255, 0, 0);\r\ntextSize(50);\r\n\r\nGrav(805,600,100,200,0,-10);\r\ntext(\"no more levels\",500,600);\r\n}},\r\n//==================================\r\n{onStart:function(){\r\nlevelName=\'none\';\r\nblocks=[\r\n{x:300,y:490,w:600,h:0},\r\n{x:300,y:495,w:600,h:10},\r\n{x:5,y:245,w:10,h:490},\r\n{x:595,y:245,w:10,h:490},\r\n{x:105,y:475,w:10,h:30},\r\n{x:505,y:475,w:10,h:30},\r\n{x:255,y:395,w:490,h:10},\r\n{x:495,y:375,w:10,h:30},\r\n{x:65,y:380,w:10,h:20},\r\n{x:325,y:305,w:530,h:10},\r\n{x:195,y:255,w:10,h:90},\r\n{x:305,y:290,w:10,h:20},\r\n{x:105,y:255,w:10,h:90},\r\n{x:150,y:250,w:100,h:100},\r\n{x:535,y:290,w:10,h:20},\r\n{x:535,y:290,w:10,h:20},\r\n{x:265,y:295,w:10,h:10},\r\n{x:265,y:135,w:10,h:270},\r\n\r\n\r\n];\r\nEstor.push(new Crate(new PVector(130,470),40,40,0,0));\r\nEstor.push(new badG(new PVector(205,465),10,50,0,0));\r\nEstor.push(new badG(new PVector(120,380),20,20,0,0));\r\nEstor.push(new badG(new PVector(450,380),20,20,0,0));\r\nEstor.push(new Crate(new PVector(265,280),10,20,0,0));\r\nEstor.push(new Crate(new PVector(170,195),60,10,0,0));\r\nEstor.push(new badG(new PVector(215,295),10,10,0,0));\r\nEstor.push(new badG(new PVector(245,295),10,10,0,0));\r\nEstor.push(new badG(new PVector(235,275),10,10,0,0));\r\nEstor.push(new badG(new PVector(215,255),10,10,0,0));\r\nEstor.push(new badG(new PVector(375,295),50,10,0,0));\r\nP={x:38,y:469,xv:0,yv:0,w:20,h:20,sx:38,sy:469,};\r\nMw=600;Mh=600;\r\n},mainLvl:function(){\r\nnxtlvl(564,273);\r\nplatForm(565,455,50,10);\r\nplatForm(545,395,90,10);\r\nplatForm(35,305,50,10);\r\nplatForm(35,255,50,10);\r\nplatForm(30,345,40,10);\r\n}},\r\n\r\n//==================================\r\n//paste code here\r\n//and restart the program if oh noes says theres an error\r\n\r\n];\r\n\r\nvar MainDraw = function(){\r\n pushMatrix();\r\n \r\n translate(width/2,height/2);//centers Cam\r\n translate(-Cam.x,-Cam.y);//moves Cam\r\n\r\n if(deBug){\r\n stroke(0, 0, 0,50);\r\n for(var x=0;x<Mw;x+=10){\r\n if(x%100===0){strokeWeight(3);}else{strokeWeight(1);}\r\n line(x,0,x,Mh);\r\n }\r\n for(var y=0;y<Mh;y+=10){\r\n if(y%100===0){strokeWeight(3);}else{strokeWeight(1);}\r\n line(0,y,Mw,y);\r\n }\r\n noStroke();\r\n }\r\n\r\n \r\n fill(110, 110, 110);//fill for the blocks ( never use fill in a loop )\r\n for(var i=0;i<blocks.length;i++){//loops through and displays blocks\r\n rect(blocks[i].x,blocks[i].y,blocks[i].w+1,blocks[i].h+1);\r\n }\r\n //loops through entity storage and runs them\r\n\r\n //Draws Main Level\r\n Levels[Level].mainLvl();\r\n\r\n \r\n for(var i=Estor.length-1;i>=0;i--){//loops through and run entitys\r\n var p=Estor[i];p.run();\r\n if (p.kill) {\r\n Estor.splice(i, 1);\r\n }\r\n }\r\n \r\n for(var i=pardstor.length-1;i>=0;i--){//loops through and run particles \r\n var p = pardstor[i];p.run();\r\n if (p.isDead()) {\r\n pardstor.splice(i, 1);\r\n }\r\n }\r\n\r\n //player display\r\n if(diedT<=0){\r\n fill(255, 0, 0);//player color\r\n quad((round(P.x)-(P.h/2)-1)+P.xv,(round(P.y)-(P.h/2)-1),\r\n (round(P.x)+(P.h/2)+1)+P.xv,(round(P.y)-(P.h/2)-1),\r\n (round(P.x)+(P.h/2)+1)-P.xv,(round(P.y)+(P.h/2)+1),\r\n (round(P.x)-(P.h/2)-1)-P.xv,(round(P.y)+(P.h/2)+1)\r\n );\r\n } \r\n \r\n if(deBug){//some debug stuff\r\n fill(0, 0, 0,80);\r\n fill(0, 0, 0);\r\n ellipse(P.x,P.y,5,5);\r\n stroke(0, 0, 0,80);\r\n noFill();\r\n stroke(0, 0, 0,250);\r\n line(P.x,P.y,P.x+P.xv*5,P.y+P.yv*5);\r\n rect(round(P.x+P.xv*-1),round(P.y+P.yv*-1),P.w+1,P.h+1);\r\n stroke(0, 0, 0,50);\r\n noStroke();\r\n }\r\n popMatrix();\r\n};//main game function\r\nvar Camera = function(){\r\n //Cam movement block X test\r\n if(!(P.x>=Cam.x-Cam.Mbs&&P.x<=Cam.x+Cam.Mbs)){\r\n Cam.xt=P.x;\r\n } \r\n //Cam movement block Y test\r\n if(!(P.y>=Cam.y-Cam.Mbs&&P.y<=Cam.y+Cam.Mbs)){\r\n Cam.yt=P.y;\r\n }\r\n Cam.x+=(Cam.xt-Cam.x)*Cam.Espeed;//Cam X easing\r\n Cam.y+=(Cam.yt-Cam.y)*Cam.Espeed;//Cam Y easing\r\n Cam.x=constrain(Cam.x,0+width/2,Mw-width/2);//keep Cam X on the map\r\n Cam.y=constrain(Cam.y,0+height/2,Mh-height/2);//keep Cam Y on the map\r\n};//camera function\r\nvar Controls = function(){\r\n //Jump\r\n if((input[UP]||input[87])&&gravity===0){\r\n gravity-=7;//decrease gravity\r\n } \r\n \r\n //Variable Jump Height\r\n if(!(input[UP]||input[87])&&gravity<0){\r\n gravity/=1.5;\r\n }\r\n \r\n //Dashing\r\n if(gravity===0){dashed=false;}else\r\n if((input[UP]||input[87])&&input[32]&&dashed===false){\r\n for(var i=0;i<10;i++){\r\n pardstor.push(new jumpPard(\r\n new PVector(P.x+random(-20,20),P.y+random(-20,20)),\r\n new PVector((P.xv/random(2,10))*-1,(P.yv/random(2,10))*-1)));\r\n } \r\n P.xv*=100;\r\n gravity-=3;\r\n dashed=true;\r\n \r\n }\r\n //Move Right/Left\r\n if(input[RIGHT]||input[68]){\r\n P.xv+=1.2;//increase x veliocity\r\n }else \r\n if(input[LEFT]||input[65]){\r\n P.xv-=1.2;//decrease x veliocity\r\n } \r\n \r\n};//controls\r\nvar MainCol = function(){\r\n /** test for y collisions */ \r\n P.y+=P.yv;//adds to players y based on y velocity\r\n for(var i=Estor.length-1;i>=0;i--){//loops through entitys Y collision\r\n var p=Estor[i];p.Yc();\r\n }\r\n // loops through and test for collisions\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(P.x,P.y,P.w,P.h,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n if(P.yv>0){//player hits block on the top\r\n P.y=blocks[i].y-(P.h/2+blocks[i].h/2);\r\n P.yv=0;//reset player y velocity\r\n gravity=0;//no gravity if touching top\r\n dashed=false;\r\n }else \r\n if(P.yv<0){//player hits block on the bottem\r\n P.y=blocks[i].y+(P.h/2+blocks[i].h/2);\r\n P.yv=0;//reset player y velocity\r\n gravity=0.1;// adds grivity \r\n }\r\n }\r\n }\r\n /** test for x collisions */\r\n P.x+=P.xv;//adds to players x based on x velocity\r\n for(var i=Estor.length-1;i>=0;i--){//loops through entitys X collision\r\n var p=Estor[i];p.Xc();\r\n }\r\n // loops through and test for collisions\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(P.x,P.y,P.w,P.h,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n if(P.xv>0){//player hits block on the left\r\n P.x=blocks[i].x-(P.w/2+blocks[i].w/2);\r\n P.xv=0;//reset player x velocity\r\n gravity+=0.1;\r\n }else \r\n if(P.xv<0){//player hits block on the right\r\n P.x=blocks[i].x+(P.w/2+blocks[i].w/2);\r\n P.xv=0;//reset player x velocity\r\n gravity+=0.1;\r\n }\r\n }\r\n }\r\n\r\n\r\n};//collison code\r\nvar phyX = function(){\r\n P.yv=gravity;// player y velocity = gravity\r\n if(gravity===0){P.xv/=1.5;}else{P.xv/=1.2;}\r\n if(gravity>0){gravity*=1.1;}//speeds up player falling\r\n P.yv/=1.2; //slows player down\r\n gravity+=0.3;// increases gravity (falling)\r\n gravity=constrain(gravity,-8,7);//keeps gravity within reason\r\n P.xv=constrain(P.xv,-12,12);// constrains x velocity\r\n};//physics code\r\n \r\ndraw = function() {\r\n //draws the background\r\n background(235, 235, 235);\r\n \r\n MainDraw();//draws the main game\r\n if(diedT<=0){\r\n MainCol();//collision code\r\n Camera();//Camera code\r\n Controls();//Controls\r\n phyX();//physics\r\n }else{\r\n diedT++;\r\n if(diedT>=100){\r\n diedT=0;\r\n P.x=-1000;\r\n } \r\n }\r\n textSize(20);\r\n fill(18, 18, 18);\r\n text(levelName,200,18);\r\n if(deBug){\r\n fill(0, 0, 0);\r\n textSize(10);\r\n textAlign(LEFT);\r\n text(\"(\"+round(P.x)+\" , \"+round(P.y)+\")\\n(\"+round(P.xv)+\" \"+round(P.yv)+\")\\n\"+gravity,10,20);\r\n textAlign(CENTER);\r\n text(\"(\"+round(mouseX+(Cam.x-width/2))+\",\"+\r\n round(mouseY+(Cam.y-height/2))+\")\",mouseX,mouseY-10);\r\n for(var i=0;i<blocks.length;i++){\r\n if(\r\n rectCol(round(mouseX+(Cam.x-width/2)),round(mouseY+(Cam.y-height/2)),1,1,\r\n blocks[i].x,blocks[i].y,blocks[i].w,blocks[i].h)\r\n ){\r\n textSize(10);\r\n fill(0, 0, 0);\r\n text(i,mouseX,mouseY+30);\r\n }\r\n }\r\n fill(0, 0, 0);\r\n if(mouseIsPressed){\r\n P.x=round(mouseX+(Cam.x-width/2));\r\n P.y=round(mouseY+(Cam.y-height/2));\r\n }\r\n FPSgraph(50,5);\r\n }\r\n\r\n //kills player if they leave the map\r\n if(P.x<-200||P.x>Mw+200||P.y<-200||P.y>Mh+200){\r\n P.xv=0;\r\n P.yv=0;\r\n P.x=P.sx;\r\n P.y=P.sy;\r\n }\r\n //level change\r\n if(Level!==oldlevel){\r\n Timer.C=millis();Timer.S=0;Timer.M=0;\r\n Estor=[];\r\n pardstor=[];\r\n Levels[Level].onStart();\r\n oldlevel=Level;\r\n P.x=P.sx;\r\n P.y=P.sy;\r\n P.xv=0;P.yv=0;\r\n Cam.x=P.x;Cam.y=P.y;//camera X and Y\r\n Cam.xt=P.x;Cam.yt=P.y;\r\n }\r\n //level restart\r\n if(input[82]){\r\n Timer.C=millis();Timer.S=0;Timer.M=0;\r\n Estor=[];\r\n pardstor=[];\r\n Levels[Level].onStart();\r\n P.x=P.sx;P.y=P.sy;\r\n P.xv=0;P.yv=0;\r\n Cam.x=P.x;Cam.y=P.y;//camera X and Y\r\n Cam.xt=P.x;Cam.yt=P.y;\r\n }\r\n if(input[78]&&Level!==Levels.length-1){\r\n Level++;\r\n Levels[Level].onStart();\r\n }\r\n \r\n if(millis()-Timer.C>=1000){\r\n Timer.C=millis();\r\n Timer.S++;\r\n if(Timer.S>=60){\r\n Timer.M++;\r\n Timer.S=0;\r\n } \r\n }\r\n fill(0, 0, 0,50);\r\n text(Timer.M+\":\"+Timer.S+\":\"+round((millis()-Timer.C)/10),200,395);\r\n};\r\nLevel++;\r\nLevels[Level].onStart();"}