Created
February 24, 2021 16:33
-
-
Save janeoa/2d3e06c753b83f0a907d50506063cc5a to your computer and use it in GitHub Desktop.
breakout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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