Skip to content

Instantly share code, notes, and snippets.

@janeoa
Created February 24, 2021 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save janeoa/2d3e06c753b83f0a907d50506063cc5a to your computer and use it in GitHub Desktop.
Save janeoa/2d3e06c753b83f0a907d50506063cc5a to your computer and use it in GitHub Desktop.
breakout
class brick {
constructor(x, y) {
this.x = x;
this.y = y;
}
destroy(){
this.x = 10000000;
this.y = 10000000;
}
draw(){
rect(10+45*this.x,10+15*this.y,40,10)
}
}
briks = [];
ball = {
x:200, y:200, z:60
}
function setup() {
a = 10;
b = 20;
createCanvas(400, 400);
for ( a = 0; a <= 3; a=a+1 ){
for ( b = 0; b <= 7; b=b+1 ){
briks.push(new brick(b,a));
briks[briks.length-1].draw();
}
}
// for a in range(0,10)
}
function draw() {
background(220)
circle(ball.x,ball.y, 10)
ball.x = mouseX
ball.y = mouseY
for(i =0; i<briks.length; i++){
if(briks[i].x-20 < ball.x && briks[i].x+20 > ball.x &&
briks[i].y-5 < ball.y && briks[i].y+5 < ball.y){
briks[i].destroy()
}
briks[i].draw()
}
for ( a = 0; a <= 3; a=a+1 ){
for ( b = 0; b <= 7; b=b+1 ){
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment