#Collision Check

5 messages · Page 1 of 1 (latest)

heady fossil
#

Do you have a class for the circles? If so all you need is to create an instance of a circle and store it in an array and call its draw method

sick sandal
#

i also need help with this🥲 i have a class and instances, but idk how to do the array part

hearty lion
#

Turns out my original code wasn't working because of a simple parser error 😭 so sorry

#

i solved it by : @sick sandal

let carrots = [];
let totalCarrots = 10;

//setup
for (let i = 0; i < totalCarrots; i++){
carrots[i] = new Carrot();
}
//draw
for (let i = 0; i < totalCarrots; i++){
carrots[i].display();
carrots[i].move();
}

class Carrot {
constructor (){
this.x = random(width);
this.y = (0);
this.w = 20;
this.h = 20;
}
display(){
ellipse(this.x,this.y,this.w,this.w)
}
move(){
this.y+=random(1,20);
if (this.y>600){
this.y = 0;
this.x = random(600)
}
}
checkCollision(){
if (dist(this.x,this.y,rabbit1.x,rabbit1.y)<30){
print("Score!")
scoreP1= +1;
}
}
}

sick sandal
#

omg thank youu!!