xxxxxxxxxx
50
/*
----- Coding Tutorial by Patt Vira -----
Name: Interactive Colliding Objects
Video Tutorial: https://youtu.be/lhUkKFMOw0Q?si=35u95389SXDQAX9_
Connect with Patt: @pattvira
https://www.pattvira.com/
----------------------------------------
*/
let circles = [];
let rectangles = [];
let ball;
function setup() {
createCanvas(400, 400);
ball = new Ball(mouseX, mouseY);
c = new Circle(width/2, height/2);
}
function draw() {
background(255);
ball.x = mouseX;
ball.y = mouseY;
ball.drawBall();
if (floor(random(10)) == 1) {
circles.push(new Circle());
rectangles.push(new Rect())
}
for (let i=0; i<circles.length; i++) {
ball.collided(circles[i]);
if (circles[i].y >= height+50) {
circles.splice(i, 1);
}
circles[i].moveCircle();
circles[i].drawCircle();
}
for (let i=0; i<rectangles.length; i++) {
ball.collided(rectangles[i]);
if (rectangles[i].y >= height+50) {
rectangles.splice(i, 1);
}
rectangles[i].moveRect();
rectangles[i].drawRect();
}
}