Hello everyone! I’m new to Processing and attempting to create a version of Breakout. I am nearing the end of my project but I didn’t find any good way/solution to make my bricks disappear when the ball hits them. I feel like I maybe did something wrong and that might be the reason why I don’t find any way to make it work properly.
I tried to make it work with a boolean (checkCollisionWithRec) but it didn’t work at all.
Based on my code, do tou see any solution I could use to make it work? Your answers and help would be very appreciated! Thank you!
Here is what it looks like :
//Variables de ma balle
int xBalle = 650;
int yBalle = 400;
int xSpeed = 3;
int ySpeed = 3;
//Variables des briques
float by;
float bx;
float bh = 30; //Hauteur
float bw = 100; //Largeur
//Variables du paddle
int xPaddle = 600;
int yPaddle = 650;
int Paddle = 100;
void setup(){
size(1200,800);
}
void draw(){
background(0);
//Je fais bouger ma balle
xBalle = xBalle + xSpeed; //
if (xBalle > width || xBalle < 0){ //Ma balle ne sort pas de l'écran par les côtés
xSpeed = xSpeed * -1; //Inverse vitesse
}
yBalle = yBalle + ySpeed; //
if (yBalle > height || yBalle < 0){ //Ma balle ne sort pas de l'écran par le haut et le bas
ySpeed = ySpeed * -1; //Inverse vitesse
}
//Je dessine ma balle
fill(255);
stroke(255);
ellipse (xBalle,yBalle,20,20);
//Je fais bouger mon paddle - keyPressed
if (keyPressed){
if(keyCode == RIGHT){
//Déplacement du paddle à droite en x
xPaddle = xPaddle + 10;
} else if (keyCode == LEFT){
//Déplacement du paddle à gauche
xPaddle = xPaddle - 10;
}
}
//Le paddle ne sort pas de l'écran par les côtés
if (xPaddle > width)
xPaddle = width;
if (xPaddle < 0)
xPaddle = 0;
//Je dessine mon paddle
fill(255);
stroke(255);
rectMode(CENTER);
rect(xPaddle,yPaddle,200,10);
//Ma balle rebondit sur le paddle
if ((xPaddle - Paddle) < xBalle && (xPaddle + Paddle) > xBalle &&
(yPaddle - 10) < yBalle && (yPaddle) > yBalle) {
// Si la balle rebondit sur le paddle, inverse la vitesse
ySpeed = - ySpeed;
}
//Je dessine mes briques
//Première boucle (hauteur)
for (float by = 1; by < 6; by++) { //6-1=5
//Seconde boucle (largeur)
for (float bx = 1; bx < 11; bx++) { //11-1=10
fill(255);
stroke(255);
rect(bx * 110, by * 50, bw, bh);
}
}
//Détection entre ma balle et les briques
}