createCanvas(windowWidth, windowHeight);
joueur.x = windowWidth / 2;
joueur.y = windowHeight - 20;
balle.x = windowWidth / 2;
balle.y = windowHeight - 100;
var mabrique = new Brique(0,0);
var angle = random(QUARTER_PI, 3 * QUARTER_PI);
balle.v = createVector(cos(angle) * balle.vitesse, -sin(angle) * balle.vitesse);
for (var x = 0; x < grille.colonnes; x++) {
for (var y = 0; y < grille.lignes; y++) {
grille.briques[x].push(new Brique(x, y));
rect(joueur.x, joueur.y, joueur.largeur, joueur.hauteur);
for (var x in grille.briques) {
for (var y in grille.briques[x]) {
grille.briques[x][y].dessiner();
joueur.x -= joueur.vitesse;
} else if (keyCode == 39) {
joueur.x += joueur.vitesse;
function collisionJoueur() {
return balle.x >= joueur.x - joueur.largeur / 2 &&
balle.x <= joueur.x + joueur.largeur / 2 &&
balle.y >= joueur.y - joueur.hauteur / 2 &&
balle.y <= joueur.y + joueur.hauteur / 2
function actualiserBalle() {
balle.x += balle.v.x / fps;
balle.y += balle.v.y / fps;
if (balle.x >= windowWidth) {
balle.x = windowWidth - balle.r;
balle.v.x -= joueur.vitesse;
} else if (keyCode == 39) {
balle.v.x += joueur.vitesse;
ellipse(balle.x, balle.y, balle.r);
function Brique(colonne, ligne) {
this.x = grille.ecartGauche + grille.largeur / grille.colonnes * colonne;
this.y = grille.ecartHaut + grille.hauteur / grille.lignes * ligne;
this.dessiner = function() {
if (balle.x > this.x - grille.largeurBriques &&
balle.x < this.x + grille.largeurBriques &&
balle.y > this.y - grille.hauteurBriques &&
balle.y < this.y + grille.hauteurBriques) {
if (balle.x < this.x + grille.largeurBriques && balle.x > this.x - grille.largeurBriques) {
if ((balle.y < this.y + grille.hauteurBriques && balle.y > this.y + grille.hauteurBriques - balle.r)
|| (balle.y > this.y - grille.hauteurBriques && balle.y < this.y - grille.hauteurBriques + balle.r)) {
if (balle.y < this.y + grille.hauteurBriques && balle.y > this.y - grille.hauteurBriques) {
if (balle.x < this.x + grille.largeurBriques && balle.x > this.x + grille.largeurBriques - balle.r
|| balle.x > this.x - grille.largeurBriques && balle.x < this.x - grille.largeurBriques + balle.r) {
rect(this.x, this.y, this.x + grille.largeurBriques, this.y + grille.hauteurBriques);