Some please help me with my code

Hi, my name is Bryce,

 I am confused about how to make the squares disappear once to circle hits them. Here is my code

// circX is for the smaller circle
let circX;
// circY is for the smaller circle
let circY;
//bulletX is for the shooting bullet
let bulletX;
//bulletX is for the shooting bullet
let bulletY;
// is for the first blue rect
let rect1x=0;
let rect1y=0;
// is for the second green rect
let rect2xx=40;
let rect2yy=0;
// is for the third red rect
let rect3xxx=80;
let rect3yyy=0;
// is for the fourth pink rect
let rect4xxxx=120;
let rect4yyyy=0;
// is for the fifth blue rect
let rect5xxxxx=160;
let rect5yyyyy=0;
// is for the sixth green rect
let rect6xxxxxx=200;
let rect6yyyyyy=0;
// is for the seventh red rect
let rect7xxxxxxx=240;
let rect7yyyyyyy=0;
// is for the eighth pink rect
let rect8xxxxxxxx=280;
let rect8yyyyyyyy=0;
// is for the ninth blue rect
let rect9xxxxxxxxx=320;
let rect9yyyyyyyyy=0;
// is for the tenth green rect
let rect10xxxxxxxxxx=360;
let rect10yyyyyyyyyy=0;

// is for the mouseX to lead the object
let myMouseX;
// is for the mouseY to lead the object
let myMouseY;
// to enable shooting
let shoot = false;

function setup() {
createCanvas(400, 400);
}

function draw() {
background(“turquoise”);
// for the bullet to follow the mouse
bulletx = mouseX;

// to activate the bullet
circle(bulletx, mouseY, 10);

if (bulletx >= rect1x){
rect1x = 5;
}

//middle line
rect (0,250,400,0);

// rect1
stroke (“Black”);
fill (“Blue”);
rect (rect1x,rect1y,40,40);
// rect2
stroke (“Black”);
fill (“green”);
rect (rect2xx,rect2yy,40,40);
// rect3
stroke (“Black”);
fill (“red”);
rect (rect3xxx,rect3yyy,40,40);
// rect4
stroke (“Black”);
fill (“pink”);
rect (rect4xxxx,rect4yyyy,40,40);
// rect5
stroke (“Black”);
fill (“Blue”);
rect (rect5xxxxx,rect5yyyyy,40,40);
// rect6
stroke (“Black”);
fill (“green”);
rect (rect6xxxxxx,rect6yyyyyy,40,40);
// rect7
stroke (“Black”);
fill (“red”);
rect (rect7xxxxxxx,rect7yyyyyyy,40,40);
// rect8
stroke (“black”);
fill (“pink”);
rect (rect8xxxxxxxx,rect8yyyyyyyy,40,40);
// rect9
stroke (“Black”);
fill (“Blue”);
rect (rect9xxxxxxxxx,rect9yyyyyyyyy,40,40);
// rect10
stroke (“Black”);
fill (“green”);
rect (rect10xxxxxxxxxx,rect10yyyyyyyyyy,40,40);

circX = mouseX;
circY = mouseY;

// all is for the boundries for the purple circle
if (circY <= 275){
circY = 275;
}
if (circX <= 25){
circX = 25;
}
if (circY >= 375){
circY = 375;
}
if (circX >= 375){
circX = 375;
}

// big circle
stroke(“Yellow”);
fill (“Purple”);
circle(circX, circY,50);

if (mouseIsPressed){
if (mouseButton === LEFT){
shoot = true;
myMouseX = mouseX;
myMouseY = mouseY;
}
}
// to enable shooting
if (shoot == true){
myMouseY = myMouseY - 5;

// smaller circle
stroke("yellow");
fill("red");
circle(myMouseX,myMouseY,10);

}

}

Please don’t open new threads for the same topic: Help with my code

sorry i just don’t get it do you have any help

You need to detect when a circle hits a square.

When this occurs, you know you need to stop drawing that square. This means you will somehow need to track if a square is still being shown or not.

In the example I gave you before, that is accomplished by a is_visible variable in the Box class. If you look at it in detail, you can see that a Box is only drawn when its is_visible variable is true.

1 Like