/**
* A rope is made of multiple points connected via lines and each point only need
* interact with the point directly before or ahead of it. One point being fixed at a
* certain location means that all points will eventually all end up at at the x
* location of the fixed point.
*
* Known bugs:
* - A while after the cutting the rope, the rope may start freaking out and
* expanding all across the screen. (Fixed I think)
* - When cutting the rope when the rope isn't moving left or right, the dropping
* animation isn't all that great. (Fixed I think)
* - Rotation on the candy is crap.
*
* Controls:
* - Hold shift and move your mouse to move the pin point
* - Cut the rope by clicking near a part of the rope
**/
var externals;
var ROPE_MAX_DISTANCE = 8;
frameRate(60);
imageMode(CENTER);
var currentLevel = 0;
var images = [];
var canvas = "";
var drawImage = function(object, x, y, w, h, opacity) {
if(object === undefined) {
return;
}
if(object.content === undefined) {
return;
}
var content = object.content;
content.globalAlpha = opacity === undefined? 1.0 : opacity;
content.drawImage(object.image, x, y, w, h);
content.globalAlpha = 1.0;
};
var levels = [];
var Level = function(rope, omX, omY) {
this.rope = rope;
this.omX = omX;
this.omY = omY;
this.handX = -250;
this.handOut = false;
this.drawRope = false;
this.handCount = 0;
this.ropeAlpha = 0.0;
this.candyAlpha = 0.0;
this.levelOver = false;
this.levelOverCount = 0;
this.drawLevel = function() {
var lastNode = this.rope.points[this.rope.points.length - 1];
if(dist(lastNode.x, lastNode.y, 200, this.omY) >= 80) {
drawImage(images[2], this.omX - 25, this.omY - 25, 50, 50);
} else if(dist(lastNode.x, lastNode.y, 200, this.omY) >= 20) {...