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