O código do vídeo não mais o mesmo ao fazer o donwload da biblioteca no GitHub.
p5.prototype.collideRectCircle = function (rx, ry, rw, rh, cx, cy, diameter) {
//2d
// temporary variables to set edges for testing
var testX = cx;
var testY = cy;
// which edge is closest?
if (cx < rx){ testX = rx // left edge
}else if (cx > rx+rw){ testX = rx+rw } // right edge
if (cy < ry){ testY = ry // top edge
}else if (cy > ry+rh){ testY = ry+rh } // bottom edge
// // get distance from closest edges
var distance = this.dist(cx,cy,testX,testY)
// if the distance is less than the radius, collision!
if (distance <= diameter/2) {
return true;
}
return false;
};
// p5.vector version of collideRectCircle
p5.prototype.collideRectCircleVector = function(r, sz, c, diameter){
return p5.prototype.collideRectCircle(r.x,r.y, sz.x,sz.y, c.x,c.y, diameter)
}
p5.prototype.collideCircleCircle = function (x, y,d, x2, y2, d2) {
//2d
if( this.dist(x,y,x2,y2) <= (d/2)+(d2/2) ){
return true;
}
return false;
};
// p5.vector version of collideCircleCircle
p5.prototype.collideCircleCircleVector = function(p1,d, p2, d2){
return p5.prototype.collideCircleCircle(p1.x,p1.y, d, p2.x,p2.y, d2)
}
p5.prototype.collidePointCircle = function (x, y, cx, cy, d) {
//2d
if( this.dist(x,y,cx,cy) <= d/2 ){
return true;
}
return false;
};