Skip to content

Instantly share code, notes, and snippets.

@SharkFinPro
Created September 20, 2020 03:21
Show Gist options
  • Save SharkFinPro/9ed5e4f36e5d2896183cd975fe82ef70 to your computer and use it in GitHub Desktop.
Save SharkFinPro/9ed5e4f36e5d2896183cd975fe82ef70 to your computer and use it in GitHub Desktop.
/** Main Variables **/
var clicked,
pressed,
keys = {},
candies = [],
bombs = [],
platforms = [],
lavas = [],
boosts = [],
ends = [],
waters = [],
quicksands = [],
bouncers = [],
scene = 'menu',
level = 1,
levelGen,
shadow = 0;
/** General Functions **/
mousePressed = function() {
clicked = true;
};
mouseReleased = function() {
clicked = false;
};
keyPressed = function() {
keys[keyCode] = true;
pressed = true;
};
keyReleased = function() {
delete keys[keyCode];
pressed = false;
};
var rectToRectCollide = function(box1X, box1Y, box1Width, box1Height, box2X, box2Y, box2Width, box2Height) {
return box1X + box1Width > box2X + 1 && box1X < box2X + box2Width - 1 && box1Y + box1Height > box2Y + 1 && box1Y < box2Y + box2Height - 1;
};
var circleToRectCollide = function(boxX, boxY, boxWidth, boxHeight, circleX, circleY, circleRadius) {
var cx = circleX - max(boxX, min(circleX, boxX + boxWidth)); // X distance mouse is from rectangle
var cy = circleY - max(boxY, min(circleY, boxY + boxHeight)); // Y distance mouse is from rectangle
return (cx * cx + cy * cy) < (circleRadius * circleRadius); // See if X&Y distance mouse is from rectangle is equal to or less than 0
};
var resetLevels = function() {
candies = [];
bombs = [];
platforms = [];
lavas = [];
boosts = [];
ends = [];
waters = [];
quicksands = [];
bouncers = [];
};
var setShadows = function() {
shadow = 0;
};
/** Images **/
// stalagmites + stalactites for cave
var cavePoints = [];
for(var i = 0; i <= width; i += 10){
cavePoints.push({
x: i,
y: width-(width/5) + random(100, -100)
});
}
var stalagmites = function(x, y, color){
noStroke();
if(x === 0 && y === 0){
strokeWeight(3);
stroke(184, 223, 255, 100);
}
fill(color);
beginShape();
vertex(0, height);
for(var i in cavePoints){
vertex(cavePoints[i].x + x, cavePoints[i].y + y);
}
vertex(width, height);
endShape();
};
var stalactites = function(x, y, color){
pushMatrix();
translate(width, height);
rotate(180);
stalagmites(x, y, color);
popMatrix();
};
var images = {
"cobblestoneBG": function(){
background(0, 0, 0);
noStroke();
for(var i = -45; i < width; i += 50){
for(var j = 0; j < height; j += 35){
noStroke();
fill(random(50));
pushMatrix();
translate(((j/50)%1)*34 + i, j);
rotate(random(-10, 10));
rect(0, 0, 45, 30, random(30));
fill(0, 0, 0, random(70));
rect(0, 0, 45, random(10));
for(var k = 0; k < 3; k++){
fill(0);
triangle(0, 30, random(10), 30, random(45), random(20, 30));
triangle(45, 30, random(35, 45), 30, random(45), random(20, 30));
triangle(0, 0, random(10), 0, random(45), random(10));
triangle(45, 0, random(35, 45), 0, random(45), random(10));
}
popMatrix();
}
}
filter(BLUR, 1.5);
return get(0, 0, width, height);
},
"caveBG": function(){
strokeWeight(10);
for(var i = 0; i <= width; i += 10){
stroke(lerpColor(
color(0, 7, 13), // The left color
color(51, 77, 102), // The right color
i/width
));
line(i, 0, i, height);
}
stalagmites(-100, -80, color(0, 0, 0, 50));
stalagmites(40, -60, color(0, 0, 0, 100));
stalagmites(-30, -40, color(0, 0, 0, 150));
stalagmites(10, -20, color(0, 0, 0, 205));
stalagmites(0, 0, color(0, 0, 0, 255));
stalactites(-100, -80, color(0, 0, 0, 50));
stalactites(40, -60, color(0, 0, 0, 100));
stalactites(-30, -40, color(0, 0, 0, 150));
stalactites(10, -20, color(0, 0, 0, 205));
stalactites(0, 0, color(0, 0, 0, 255));
noFill();
strokeWeight(10);
for(var i = width*2; i > 0; i -= 20){
stroke(0, 0, 0, i/4);
ellipse(width/2, height/2, i, i);
}
filter(BLUR, 3);
return get(0, 0, width, height);
},
"lavaBlock": function(){
noStroke();
fill(255, 127, 80);
rect(0, 0, 25, 25);
noStroke();
return get(0, 0, 25, 25);
},
'door': function() {
noStroke();
pushMatrix();
translate(15, 48);
scale(1, 1);
noStroke();
fill(59, 28, 8);
rect(-8, -10, 98, 150);
rect(-15, -43, 115, 28);
fill(48, 24, 8);
rect(0, -3, 82, 10);
fill(138, 68, 51);
rect(-15, -48, 115, 30);
rect(2, 0, 80, 150);
fill(107, 54, 35);
rect(0, 0, 80, 150);
rect(-15, -48, 111, 30);
fill(23, 2, 8, 30);
for (var i = 0; i < 80; i += 9) {
(rect)(0, 0, i, 150, 0, 5, 5, 0);
(rect)(-15, -48, i * 1.4, 30, 0, 5, 5, 0);
}
(fill)(0, 40);
ellipse(60, 83, 15, 15);
fill(199, 69, 46);
ellipse(63, 80, 15, 15);
fill(224, 185, 29, 150);
ellipse(62, 79, 8, 10);
fill(255, 255, 255, 100);
ellipse(59, 77, 5, 5);
popMatrix();
return get(0, 0, 115, 236);
},
'menuBG': function(){
background(16, 34, 41);
noStroke();
for(var i = 0; i < 333; i++){
var aasdlfkjrekjfkjwldfksf = random(6);
var n = random(216, 350);
var c = random(360);
fill(255, 255, 255, random(155));
ellipse(300 + sin(c) * n, 300 + cos(c) * n, aasdlfkjrekjfkjwldfksf, aasdlfkjrekjfkjwldfksf);
}
fill(242, 242, 198, 30);
for(var i = 0; i < 150; i += 25){
ellipse(300, 300, 400 + i, 400 + i);
}
fill(214, 210, 167);
ellipse(300, 300, 400, 400);
fill(255, 255, 255, 20);
for(var i = 0; i < 150; i += 25){
ellipse(300, 300, 250 + i, 250 + i);
}
fill(122, 58, 1);
ellipse(300, 600, 1000, 240);
for(var i = 0; i < 240; i += 20){
fill(2, 14, 20, 50);
ellipse(300, 600, 1000, i);
}
pushMatrix();
translate(20, 0);
fill(0, 0, 0, 100);
quad(37, 601, 338, 600, 352, 490, 200, 496);
fill(43, 43, 43);
beginShape();
vertex(200, 500);
vertex(300, 510);
bezierVertex(302, 444, 293, 368, 310, 300);
bezierVertex(287, 290, 236, 250, 219, 215);
bezierVertex(184, 290, 176, 284, 158, 306);
bezierVertex(189, 379, 186, 443, 200, 500);
endShape();
fill(61, 61, 61);
beginShape();
vertex(353, 490);
vertex(299, 510);
bezierVertex(289, 444, 293, 368, 309, 300);
vertex(374, 282);
bezierVertex(352, 344, 336, 440, 353, 490);
endShape();
fill(89, 89, 89);
beginShape();
vertex(411, 294);
bezierVertex(358, 338, 315, 325, 317, 327);
bezierVertex(270, 290, 236, 250, 218, 215);
bezierVertex(272, 215, 261, 223, 311, 216);
bezierVertex(326, 215, 336, 276, 407, 292);
endShape();
fill(20, 19, 19);
beginShape();
vertex(141, 314);
bezierVertex(186, 275, 196, 250, 218, 220);
vertex(224, 231);
bezierVertex(221, 255, 196, 277, 161, 313);
endShape();
noFill();
strokeWeight(9);
stroke(105, 101, 101);
bezier(411, 298, 358, 338, 315, 325, 317, 321);
strokeWeight(9);
stroke(117, 112, 112);
bezier(317, 322, 270, 290, 236, 250, 218, 220);
bezier(141, 310, 186, 275, 196, 250, 218, 220);
fill(23, 23, 23);
strokeWeight(5);
stroke(0);
beginShape();
vertex(258, 364);
vertex(266, 504);
vertex(224, 500);
vertex(210, 384);
bezierVertex(200, 321, 247, 288, 258, 365);
endShape();
strokeWeight(3);
line(232, 500, 214, 339);
line(241, 500, 226, 326);
line(251, 500, 240, 326);
line(260, 500, 252, 344);
noStroke();
fill(145, 92, 23);
ellipse(248, 421, 20, 20);
fill(214, 202, 30, 80);
ellipse(246, 419, 12, 13);
ellipse(245, 418, 5, 5);
fill(201, 159, 44);
stroke(0);
beginShape();
vertex(317, 437);
bezierVertex(289, 372, 351, 326, 336, 432);
endShape(CLOSE);
noStroke();
fill(255, 255, 255, 50);
quad(314, 418, 336, 424, 338, 409, 312, 384);
quad(314, 418, 336, 410, 334, 386, 312, 408);
stroke(0);
line(326, 372, 326, 435);
line(311, 409, 337, 405);
popMatrix();
pushStyle();
pushMatrix();
translate(300, 135);
rotate(5);
rectMode(CENTER);
textAlign(CENTER, CENTER);
textFont(createFont('Avenir Bold'));
noStroke();
fill(0, 0, 0);
rect(57, 34, 209, 31);
rect(0, 0, 387, 60);
rect(-57, -34, 239, 25);
fill(25);
rect(0, 0, 380, 53);
fill(217, 143, 32);
textSize(45);
text('TRICK OR TREAT', 0, 0);
rect(57, 34, 201, 21);
rect(-57, -34, 235, 21);
fill(25);
textSize(15);
text('A NIGHT AT PAPA KETT\'S', 57, 34);
text('CHESTER BANKS + SHARKFIN', -57, -34);
popMatrix();
popStyle();
return get(0, 0, 600, 600);
},
'chocolateBar': function(){
noStroke();
fill(153, 72, 43);
rect(0, 0, 50, 50);
for(var i = 0; i < 4; i++){
pushMatrix();
translate(0 + (i > 1 ? -46.5 : 0) + (i * 23), ((i > 1) ? 23 : 0) - 1);
fill(255, 255, 255, 30);
triangle(3, 3, 3, 25, 25, 3);
fill(0, 0, 0, 80);
triangle(25, 25, 3, 25, 25, 3);
fill(153, 72, 43);
rect(5, 5, 17, 18);
fill(235, 217, 211, 30);
rect(5, 5, 4, 18, 10);
popMatrix();
}
return get(0, 0, 50, 50);
},
'mint': function(){
noStroke();
fill(242, 220, 220);
ellipse(25, 25, 50, 50);
for(var i = 0; i < 360; i += 45){
pushMatrix();
translate(25, 25);
rotate(i);
fill(230, 43, 96);
arc(0, 0, 50, 50, 0, 16);
rotate(27);
arc(0,0, 50, 50, 0, 5);
popMatrix();
}
fill(255, 255, 255, 50);
ellipse(23, 23, 43, 42);
ellipse(22, 21, 37, 37);
return get(0, 0, 50, 50);
},
'eminem': function(){
textAlign(CENTER, CENTER);
noStroke();
fill(79, 140, 214);
ellipse(25, 25, 50, 50);
fill(255, 255, 255, 50);
ellipse(23, 23, 43, 42);
ellipse(22, 21, 25, 25);
textSize(27);
fill(255, 255, 255, 200);
text('m', 25, 21);
return get(0, 0, 50, 50);
},
'candyCorn': function(){
noStroke();
fill(230, 146, 43);
arc(25, 35, 40, 30, 0, 180);
fill(230, 214, 43);
arc(25, 35, 40, 70, -180, 0);
arc(25, 35, 40, 4, 0, 180);
fill(237, 234, 204);
arc(25, 18, 29, 37, -180, 0);
arc(25, 18, 29, 5, 0, 180);
noFill();
stroke(255, 255, 255);
strokeWeight(5);
bezier(12, 20, 14, 13, 22, 0, 28, 4);
stroke(255, 255, 255, 100);
strokeWeight(12);
bezier(13, 27, 14, 16, 22, 0, 28, 7);
stroke(0, 0, 0, 20);
bezier(18, 43, 30, 47, 43, 38, 37, 24);
return get(0, 0, 50, 50);
},
'sucker': function(){
noStroke();
fill(182, 76, 224);
ellipse(25, 25, 50, 50);
fill(237, 156, 237, 50);
ellipse(22, 22, 35, 35);
fill(237, 156, 237, 50);
ellipse(18, 20, 15, 15);
noFill();
stroke(134, 30, 179);
strokeWeight(7);
arc(25,28, 48, 12, 0, 180);
stroke(255, 255, 255, 50);
strokeWeight(2);
arc(25,26, 48, 12, 0, 180);
return get(0, 0, 50, 50);
},
};
for(var i in images) {
if(typeof images[i] !== 'object') {
(background)(0, 0);
images[i] = images[i]();
}
}
var candy = ['mint', 'eminem', 'candyCorn', 'sucker'];
/** Player **/
var Player = {
alive: true,
lives: 3,
candy: 0,
x: 0,
y: 0,
width: 25,
height: 25,
gravity: 0.4,
xvel: 0,
yvel: 0,
speed: 0.5,
maxSpeed: 5,
jumpHeight: 8,
maxFallSpeed: 12,
falling: true,
swimming: false,
bouncing: false,
sinking: false,
run: function() {
this.logKeys();
if(scene === 'platformer') {
this.updatePlatformer();
} else if(scene === 'catcher') {
this.updateCatcher();
} else if(scene === 'jumper') {
this.updateJumper();
}
this.display();
},
display: function() {
noStroke();
fill(42, 139, 200);
rect(this.x, this.y, this.width, this.height);
},
logKeys: function() {
if(keys[LEFT]) {
this.xvel -= this.speed;
}
if(keys[RIGHT]){
this.xvel += this.speed;
}
if(this.xvel > this.maxSpeed){
this.xvel = this.maxSpeed;
}
if(this.xvel < -this.maxSpeed){
this.xvel = -this.maxSpeed;
}
if(keys[UP] && !this.falling && !this.swimming && !this.bouncing) {
this.yvel = -this.jumpHeight;
} else if(keys[UP] && this.swimming) {
this.yvel -= 0.5;
} else if(keys[UP] && this.bouncing && !this.falling) {
this.yvel = -this.jumpHeight * 2;
}
},
updatePlatformer: function() {
this.xvel /= 1.15;
this.yvel += this.gravity;
if(this.sinking) {
this.xvel /= 2;
this.yvel = 0.5;
}
this.x += this.xvel;
this.collideWith(this.xvel, 0, platforms);
this.collideWith(0, this.yvel, bouncers);
this.falling = true;
this.y += this.yvel;
if(this.bouncing && this.collideWith(0, this.yvel, platforms)) {
this.bouncing = false;
}
this.collideWith(0, this.yvel, platforms);
this.collideWith(0, this.yvel, bouncers);
this.swimming = false;
this.sinking = false;
},
updateCatcher: function() {
this.xvel /= 1.15;
this.yvel += this.gravity;
this.x += this.xvel;
this.x = constrain(this.x, 0, width - this.width);
this.falling = true;
this.y += this.yvel;
if(this.y > 600 - this.height) {
this.falling = false;
this.yvel = 0;
this.y = 600 - this.height;
}
},
updateJumper: function() {
if(clicked) {
this.yvel = -this.jumpHeight;
}
this.pressing = false;
this.yvel += this.gravity;
this.falling = true;
this.y += this.yvel;
if(this.yvel > this.maxFallSpeed){
this.yvel = this.maxFallSpeed;
}
},
collideWith: function(xv, yv, entities) {
for (var i = 0; i < entities.length; i++) {
var entity = entities[i];
if(this.y + this.height > entity.y && this.y < entity.y + entity.height && this.x + this.width > entity.x && this.x < entity.x + entity.width) {
if(yv > 0) { // Bottom
this.yvel = 0;
this.falling = false;
this.y = entity.y - this.height;
}
if(yv < 0) { // Top
this.yvel = 0;
this.falling = true;
this.y = entity.y + entity.height;
}
if(xv > 0) { // Right
this.xvel = 0;
this.x = entity.x - this.width;
}
if(xv < 0) { // Left
this.xvel = 0;
this.x = entity.x + entity.width;
}
}
}
}
};
/** Platformer **/
var Block = function(x, y, w, h) {
this.x = x;
this.y = y;
this.width = w || 25;
this.height = h || 25;
};
Block.prototype.run = function() {
if(this.update) {
this.update();
}
this.display();
};
Block.prototype.display = function() {
noStroke();
fill(125);
rect(this.x, this.y, this.width, this.height);
};
var Platform = function(x, y) {
Block.call(this, x, y);
};
Platform.prototype = Object.create(Block.prototype);
Platform.prototype.update = function() {
};
var Lava = function(x, y) {
Block.call(this, x, y);
};
Lava.prototype = Object.create(Block.prototype);
Lava.prototype.display = function() {
imageMode(CORNER);
image(images.lavaBlock, this.x, this.y, this.width, this.height);
};
Lava.prototype.update = function() {
if(rectToRectCollide(Player.x, Player.y, Player.width, Player.height, this.x, this.y, this.width, this.height)) {
setShadows();
Player.alive = false;
}
};
var Water = function(x, y) {
Block.call(this, x, y);
};
Water.prototype = Object.create(Block.prototype);
Water.prototype.display = function() {
noStroke();
fill(0, 200, 255, 100);
rect(this.x, this.y, this.width, this.height);
};
Water.prototype.update = function() {
if(rectToRectCollide(Player.x, Player.y, Player.width, Player.height, this.x, this.y, this.width, this.height)) {
Player.swimming = true;
}
};
var Candy = function(x, y) {
Block.call(this, x, y);
this.type = candy[~~random(0, candy.length)];
};
Candy.prototype = Object.create(Block.prototype);
Candy.prototype.display = function() {
imageMode(CORNER);
image(images[this.type], this.x, this.y, this.width, this.height);
};
Candy.prototype.update = function() {
if(rectToRectCollide(Player.x, Player.y, Player.width, Player.height, this.x, this.y, this.width, this.height)) {
Player.candy++;
candies.splice(candies.indexOf(this), 1);
}
};
var Quicksand = function(x, y) {
Block.call(this, x, y);
};
Quicksand.prototype = Object.create(Block.prototype);
Quicksand.prototype.display = function() {
noStroke();
fill(110, 97, 78);
rect(this.x, this.y, this.width, this.height);
};
Quicksand.prototype.update = function() {
if(rectToRectCollide(Player.x, Player.y, Player.width, Player.height, this.x, this.y, this.width, this.height)) {
Player.sinking = true;
}
};
var Bouncer = function(x, y) {
Block.call(this, x, y + 25 - 25 / 6, 25, 25 / 6);
};
Bouncer.prototype = Object.create(Block.prototype);
Bouncer.prototype.display = function() {
noStroke();
fill(27, 235, 0);
rect(this.x, this.y, this.width, this.height);
};
Bouncer.prototype.update = function() {
if(rectToRectCollide(Player.x, Player.y, Player.width, Player.height, this.x, this.y, this.width, this.height)) {
Player.bouncing = true;
}
};
var End = function(x, y) {
Block.call(this, x, y);
};
End.prototype = Object.create(Block.prototype);
End.prototype.display = function() {
imageMode(CORNER);
image(images.chocolateBar, this.x, this.y, this.width, this.height);
};
End.prototype.update = function() {
if(rectToRectCollide(Player.x, Player.y, Player.width, Player.height, this.x, this.y, this.width, this.height)) {
level++;
resetLevels();
levelGen();
}
};
var levels = [
[
[1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1],
[1, 0, 0, 1, 1, 2, 1, 1, 1, 2, 1, 1, 0, 0, 1, 1, 2, 1, 1, 1, 1, 2, 1, 1],
[1, 0, 0, 1, 2, 2, 2, 0, 1, 2, 1, 0, 0, 0, 1, 2, 0, 2, 1, 0, 1, 2, 1, 1],
[1, 0, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 2, 0, 2, 1],
[1, 0, 0, 0, 2, 0, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,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1][y].length; x++) {
switch(levels[level - 1][y][x]) {
case 1:
platforms.push(new Platform(x * 25, y * 25));
break;
case 2:
lavas.push(new Lava(x * 25, y * 25));
break;
case 3:
waters.push(new Water(x * 25, y * 25));
break;
case 4:
candies.push(new Candy(x * 25, y * 25));
break;
case 5:
break;
case 6:
quicksands.push(new Quicksand(x * 25, y * 25));
break;
case 7:
bouncers.push(new Bouncer(x * 25, y * 25));
break;
case 8:
ends.push(new End(x * 25, y * 25));
break;
case 9:
Player.x = x * 25;
Player.y = y * 25;
break;
}
}
}
};
/** Catcher **/
var Item = function(x, y, width, height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
this.xvel = 0;
this.yvel = random(1, 3);
};
Item.prototype.run = function() {
if(this.update) {
this.update();
}
if(this.display) {
this.display();
}
};
var Candy2 = function(x, y, d) {
Item.call(this, x, y, d, d);
this.d = d;
this.type = candy[~~random(0, candy.length)];
};
Candy2.prototype = Object.create(Item.prototype);
Candy2.prototype.display = function() {
imageMode(CORNER);
image(images[this.type], this.x, this.y, this.d, this.d);
};
Candy2.prototype.update = function() {
this.xvel /= 1.01;
this.x += this.xvel;
this.y += this.yvel;
if(this.y > height) {
candies.splice(candies.indexOf(this), 1);
}
if(circleToRectCollide(Player.x, Player.y, Player.width, Player.height, this.x, this.y, this.d)) {
Player.candy++;
candies.splice(candies.indexOf(this), 1);
}
};
var Bomb = function(x, y, d) {
Item.call(this, x, y, d, d);
this.d = d;
};
Bomb.prototype = Object.create(Item.prototype);
Bomb.prototype.display = function() {
noStroke();
fill(75);
ellipse(this.x, this.y, this.d, this.d);
};
Bomb.prototype.update = function() {
this.xvel /= 1.01;
this.x += this.xvel;
this.y += this.yvel;
if(this.y > height) {
Player.lives -= 1;
bombs.splice(bombs.indexOf(this), 1);
}
};
var Boost = function(x, y, d) {
Item.call(this, x, y, d, d);
this.d = d;
};
Boost.prototype = Object.create(Item.prototype);
Boost.prototype.display = function() {
noStroke();
fill(175, 175, 42);
ellipse(this.x, this.y, this.d, this.d);
};
Boost.prototype.update = function() {
this.xvel /= 1.01;
this.x += this.xvel;
this.y += this.yvel;
if(this.y > height) {
boosts.splice(boosts.indexOf(this), 1);
}
};
/** Jumper **/
var Item = function(x, y, w, h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.xvel = 0;
this.yvel = random(1, 3);
};
Item.prototype.run = function() {
if(this.update) {
this.update();
}
if(this.display) {
this.display();
}
};
var Candy3 = function(x, y, d) {
Item.call(this, x, y, d, d);
this.xvel = this.x > 600 ? -random(1, 3) : random(1, 3);
this.yvel = 0;
this.d = d;
};
Candy3.prototype = Object.create(Item.prototype);
Candy3.prototype.display = function() {
pushMatrix();
translate(this.x, this.y);
rotate(frameCount + this.x);
noStroke();
fill(42, 150, 42);
triangle(0 - this.d / 1.5, 0 - this.d / 3, 0 - this.d / 1.5, 0 + this.d / 3, 0, 0);
triangle(0 + this.d / 1.5, 0 - this.d / 3, 0 + this.d / 1.5, 0 + this.d / 3, 0, 0);
fill(42, 175, 42);
ellipse(0, 0, this.d, this.d);
popMatrix();
};
Candy3.prototype.update = function() {
this.x += this.xvel;
this.y += this.yvel;
if(circleToRectCollide(Player.x, Player.y, Player.width, Player.height, this.x, this.y, this.d / 2)) {
Player.candy++;
candies.splice(candies.indexOf(this), 1);
}
};
/** Set Game Variables **/
var setPlatformer = function() {
Player.width = 25;
Player.height = 25;
Player.jumpHeight = 8;
resetLevels();
levelGen();
};
var setCatcher = function() {
Player.width = 50;
Player.height = 75;
Player.jumpHeight = 10;
resetLevels();
};
var setJumper = function() {
Player.width = 50;
Player.height = 75;
Player.jumpHeight = 7;
Player.gravity = 0.3;
Player.x = 275;
Player.maxFallSpeed = 10;
resetLevels();
};
/** House Party **/
var Avatar = function(name, x, z) {
this.name = name;
this.x = random(200, 1000);
this.z = random(15, 35);
this.xDestination = this.x;
this.zDestination = this.z;
this.timer = random(100);
this.freq = random(30, 200);
};
Avatar.prototype.run = function() {
this.update();
this.display();
};
Avatar.prototype.display = function() {
imageMode(CENTER);
pushMatrix();
translate(this.x, 375 + this.z);
scale(this.z / 30);
image(getImage("avatars/" + this.name), 0, 100);
popMatrix();
};
Avatar.prototype.update = function() {
this.timer++;
if (this.timer > this.freq) {
this.xDestination = this.x + random(-150, 150);
this.zDestination = this.z + random(-5, 5);
this.timer = 0;
}
this.x += (this.xDestination - this.x) / 20;
this.z += (this.zDestination - this.z) / 20;
this.z = constrain(this.z, 15, 50);
this.x = constrain(this.x, 200, 1200);
};
var houseParty = {
x: 0,
door: function(x, name, callback) {
imageMode(CENTER);
image(images.door, x, 382);
textAlign(CENTER, CENTER);
textFont(createFont('Avenir Bold'), 14);
fill(110, 58, 21);
text(name, x, 280);
fill(166, 101, 58);
text(name, x, 278);
if(mouseX > x + this.x - 53 && mouseY > 302 && mouseX < x + this.x + 53 && mouseY < 462) {
if(mouseIsPressed && callback) {
callback();
}
}
},
medal: function(x, y, sz, color, r) {
noStroke();
pushMatrix();
translate(x, y);
rotate(r);
scale(sz / 300);
fill(color);
ellipse(-7, -4, 402, 400);
(fill)(0, 50);
triangle(-24, -49, 16, 41, -86, 20);
(fill)(0, 30);
triangle(-24, -49, -97, -75, -86, 20);
fill(79, 79, 79, 10);
triangle(-24, -49, -97, -75, -59, -114);
fill(255, 255, 255, 20);
triangle(-22, -47, 9, -86, -59, -114);
(fill)(0, 30);
triangle(-23, -45, 6, -84, 68, -48);
fill(43, 165, 218);
fill(255, 255, 255, 10);
triangle(-19, -44, 16, 41, 66, -48);
fill(242, 223, 138, 30);
triangle(106, 45, 16, 41, 66, -51);
fill(34, 190, 212);
fill(255, 255, 255, 30);
triangle(-131, -165, -97, -73, -56, -114);
fill(255, 255, 255, 100);
triangle(-129, -163, -35, -203, -59, -114);
fill(255, 255, 255, 50);
triangle(-129, -163, -35, -203, -85, -189);
fill(255, 255, 255, 150);
triangle(18, -203, -35, -203, -59, -114);
fill(255, 255, 255, 30);
triangle(18, -203, 29, -148, -59, -114);
fill(255, 255, 255, 150);
triangle(6, -84, 29, -148, -59, -114);
fill(255, 255, 255, 100);
triangle(6, -84, 29, -148, 60, -108);
fill(255, 255, 255, 50);
triangle(69, -191, 29, -148, 60, -108);
(fill)(0, 10);
triangle(69, -191, 29, -148, 18, -204);
fill(255, 255, 255, 50);
triangle(6, -84, 66, -49, 60, -108);
(fill)(0, 90);
triangle(-56, 87, 15, 41, -86, 20);
(fill)(0, 40);
triangle(-56, 87, 15, 41, 30, 100);
(fill)(0, 70);
triangle(105, 44, 15, 41, 30, 100);
(fill)(0, 150);
triangle(105, 44, 115, 158, 30, 100);
(fill)(0, 120);
triangle(105, 44, 115, 158, 179, 75);
(fill)(0, 90);
triangle(105, 44, 194, 23, 179, 75);
(fill)(0, 60);
triangle(105, 44, 194, 23, 67, -48);
(fill)(0, 80);
triangle(141, -33, 194, 23, 67, -48);
(fill)(0, 20);
triangle(141, -33, 59, -109, 67, -48);
fill(255, 255, 255, 20);
triangle(109, -169, 59, -109, 69, -191);
(fill)(0, 10);
triangle(109, -169, 59, -109, 154, -128);
fill(255, 255, 255, 30);
triangle(113, -58, 59, -109, 154, -128);
(fill)(0, 30);
triangle(113, -58, 178, -82, 154, -128);
fill(255, 255, 255, 20);
triangle(113, -58, 178, -82, 142, -32);
(fill)(0, 50);
triangle(194, -31, 178, -82, 142, -32);
(fill)(0, 100);
triangle(141, -33, 194, 23, 194, -31);
(fill)(0, 150);
triangle(156, 115, 115, 158, 179, 75);
(fill)(0, 170);
triangle(71, 183, 115, 158, 30, 100);
(fill)(0, 120);
triangle(71, 183, 3, 147, 30, 100);
(fill)(0, 80);
triangle(-56, 87, 3, 147, 30, 100);
(fill)(0, 130);
triangle(-56, 87, 3, 147, -32, 196);
(fill)(0, 150);
triangle(-56, 87, -132, 157, -32, 196);
(fill)(0, 140);
triangle(-56, 87, -132, 157, -167, 121);
(fill)(0, 70);
triangle(-56, 87, -134, 42, -167, 121);
(fill)(0, 50);
triangle(-192, 78, -134, 42, -167, 121);
(fill)(0, 50);
triangle(-56, 87, -134, 42, -85, 21);
fill(255, 255, 255, 30);
triangle(-118, -23, -134, 42, -85, 21);
fill(255, 255, 255, 70);
triangle(-118, -23, -134, 42, -208, 23);
(fill)(0, 30);
triangle(-192, 78, -134, 42, -208, 23);
(fill)(0, 20);
triangle(-118, -23, -97, -74, -85, 21);
(fill)(0, 50);
triangle(-118, -23, -97, -74, -169, -125);
fill(255, 255, 255, 60);
triangle(-130, -163, -97, -74, -169, -125);
fill(255, 255, 255, 150);
triangle(-118, -23, -194, -82, -169, -124);
fill(255, 255, 255, 100);
triangle(-118, -23, -194, -82, -207, -30);
fill(255, 255, 255, 80);
triangle(-118, -23, -207, 23, -207, -30);
(fill)(0, 180);
triangle(-87, 182, -132, 157, -32, 196);
(fill)(0, 180);
triangle(70, 182, 3, 147, -32, 196);
(fill)(0, 180);
triangle(70, 182, 23, 196, -32, 196);
popMatrix();
},
winstonBall: function(x, y, sz, r) {
pushMatrix();
translate(x, y);
rotate(r);
scale(sz / 50);
this.medal(0, 0, 300, color(230, 255, 0));
this.medal(-66, -80, 37, color(46, 48, 28), 153);
this.medal(128, -90, 37, color(46, 48, 28), 153);
this.medal(71, 35, 126, color(219, 28, 44), 186);
popMatrix();
},
avatars: [
new Avatar("mr-pants"),
new Avatar("mr-pink"),
new Avatar("orange-juice-squid"),
new Avatar("old-spice-man"),
new Avatar("purple-pi"),
new Avatar("spunky-sam"),
new Avatar("duskpin-sapling"),
new Avatar("duskpin-ultimate"),
new Avatar("marcimus"),
new Avatar("robot_female_1"),
new Avatar("robot_female_2"),
new Avatar("robot_female_3"),
new Avatar("robot_male_1"),
new Avatar("robot_male_2"),
new Avatar("robot_male_3"),
new Avatar("starky-sapling"),
new Avatar("starky-ultimate"),
new Avatar("aqualine-tree"),
],
run: function() {
this.update();
this.display();
},
display: function() {
pushMatrix();
translate(this.x, 0);
strokeWeight(2);
for (var i = 0; i < 140; i++) {
stroke(lerpColor(color(99, 59, 34), color(54, 28, 10), i / 140));
line(i, i, 1300 - i, i);
}
for (var i = 0; i < 142; i++) {
stroke(lerpColor(color(120, 39, 70), color(36, 4, 35), i / 140));
line(i, height - i, width - i + 700, height - i);
}
noFill();
strokeWeight(5);
(stroke)(0, 30);
for (var j = 459; j < 595; j += 21) {
beginShape();
for (var i = 0; i < 1216; i += 50) {
vertex(i, j + ((j / 15) - 20));
vertex(i + 25, j);
}
endShape();
}
strokeWeight(2);
for (var i = 0; i < 140; i++) {
stroke(lerpColor(color(79, 39, 13), color(56, 32, 16), i / 140));
line(i, height - i, i, i);
}
for (var i = 0; i < 140; i++) {
stroke(lerpColor(color(79, 39, 13), color(46, 22, 6), i / 140));
line(700 + width - i, height - i, 700 + width - i, i);
}
noStroke();
(fill)(0, 50);
rect(138, 140, 4, 322);
for (var i = -47; i < 129; i += 50) {
(fill)(0, (i / 10) + 60);
quad(i, i, i, 614 - (i * 1.15), i + 23, 583 - (i * 1.15), i + 23, 24 + i);
quad(i - 14, -16 + i, i - 14, 623 - (i * 1.15), i - 9, 615 - (i * 1.15), i - 9, -9 + i);
}
pushMatrix();
translate(1303, 0);
scale(-1, 1);
for (var i = -24; i < 129; i += 50) {
(fill)(0, (i / 10) + 60);
quad(i, i, i, 614 - (i * 1.15), i + 23, 583 - (i * 1.15), i + 23, 24 + i);
quad(i - 14, -16 + i, i - 14, 623 - (i * 1.15), i - 9, 615 - (i * 1.15), i - 9, -9 + i);
}
popMatrix();
for (var i = 16; i < 1004; i += 50) {
(fill)(0, 30);
rect(140 + i, 140, 7, 312);
(fill)(0, 50);
rect(152 + i, 140, 23, 312);
}
noFill();
stroke(59, 28, 8);
strokeWeight(10);
quad(-39, 630, 142, 457, 1160, 457, 1330, 630);
quad(-39, -30, 142, 143, 1160, 143, 1330, -30);
(stroke)(0, 100);
strokeWeight(3);
quad(-39, 633, 142, 460, 1160, 460, 1330, 630);
this.door(215, 'CANDY CATCH', function() {
setShadows();
scene = 'catcher';
setCatcher();
});
this.door(415, 'SPOOKY CLIMB');
this.door(615, 'CHOCOTILES', function() {
setShadows();
scene = 'platformer';
setPlatformer();
});
this.door(815, 'CANDY JUMP', function() {
setShadows();
scene = 'jumper';
setJumper();
});
this.door(1015, 'SWEET DREAMS');
noFill();
stroke(61, 61, 61);
strokeWeight(6);
bezier(525, 260 + sin(frameCount) * 10, 514, 175, 537, 164, 525, 100);
this.winstonBall(525, 260 + sin(frameCount) * 20, 8, sin(frameCount / 3) * 550);
this.avatars.sort(function(a, b) {
return a.z - b.z;
});
for (var i = 0; i < this.avatars.length; i++) {
this.avatars[i].run();
}
popMatrix();
},
update: function() {
if(keys[LEFT] || keys[RIGHT]) {
if (keys[LEFT] && this.x < 0) {
this.x += 4;
}
if (keys[RIGHT] && this.x > -700) {
this.x -= 4;
}
} else {
if (mouseX < 100 && this.x < 0) {
this.x += 4;
}
if (mouseX > 500 && this.x > -700) {
this.x -= 4;
}
}
}
};
/** Overlay **/
var overlay = function() {
imageMode(CENTER);
image(images.mint, 15, 15, 25, 25);
textFont(createFont('Trebuchet MS Bold'), 20);
textAlign(LEFT, CENTER);
fill(0);
text(Player.candy, 30, 15);
};
/** Draw **/
var draw = function() {
switch(scene) {
default:{
background(245);
}break;
case 'menu':{
background(0);
pushMatrix();
translate(random(-0.5, 0.5), random(-0.5, 0.5));
image(images.menuBG, 0, 0);
textAlign(CENTER, CENTER);
textFont(createFont('Avenir Bold'), 30);
fill(255, 255, 255, 50);
text('c l i c k t o b e g i n', 300 + sin(frameCount * 2) * 20, 550);
if(mouseIsPressed && !clicked) {
setShadows();
scene = 'houseparty';
}
popMatrix();
}break;
case 'shop':{
background(101, 67, 33);
}break;
case 'houseparty':{
background(46, 22, 6);
houseParty.run();
}break;
case 'platformer':{
if(!Player.alive) {
background(200, 42, 42);
textAlign(CENTER, CENTER);
textFont(createFont('Trebuchet MS Bold'), 100);
fill(245);
text('You Died!', 300, 300);
} else {
background(255, 228, 196);
imageMode(CORNER);
image(images.caveBG, 0, 0);
platforms.forEach(function(platform) {
platform.run();
});
ends.forEach(function(end) {
end.run();
});
waters.forEach(function(water) {
water.run();
});
lavas.forEach(function(lava) {
lava.run();
});
quicksands.forEach(function(quicksand) {
quicksand.run();
});
bouncers.forEach(function(bouncer) {
bouncer.run();
});
for(var i = candies.length; i > 0; i--) {
candies[i - 1].run();
}
Player.run();
overlay();
}
}break;
case 'catcher':{
if(frameCount%75 === 0) {
var c = ~~random(1, 3) === 1 ? candies.push(new Candy2(random(0, 600), 0, random(20, 50))) : bombs.push(new Bomb(random(0, 600), 0, random(20, 50)));
}
background(200);
for(var i = candies.length; i > 0; i--) {
candies[i - 1].run();
}
for(var i = bombs.length; i > 0; i--) {
bombs[i - 1].run();
}
Player.run();
overlay();
}break;
case 'jumper':{
background(200);
if(frameCount%30 === 0) {
var side = ~~random(1, 3) === 1 ? candies.push(new Candy3(-50, random(0, 600), random(20, 50))) : candies.push(new Candy3(650, random(0, 600), random(20, 50)));
}
for(var i = candies.length; i > 0; i--) {
candies[i - 1].run();
}
Player.run();
overlay();
}break;
}
if(255 - shadow >= 0) {
noStroke();
(fill)(0, 255 - shadow);
rect(0, 0, width, height);
shadow += 2;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment