xxxxxxxxxx
var y = 0;
var g = 0.98;
var vball = 3;
var bricks = [];
var bx = 30;
var by = 60;
var r,g_,b;
var isplaying = false;
var score = 0;
function setup() {
createCanvas(windowWidth, windowHeight);
for (let i=0;i<8;i++){
bricks[i] = new Bricks(bx,by,90,20);
bx += 80;
by += 80;
}
}
function draw() {
background(100);
if (!isplaying){
background(0);
textAlign(CENTER);
fill(255);
textSize(50);
text('press to begin',width/2, height/2);}
if (isplaying){
for (let i=0;i<bricks.length;i++) bricks[i].draw();
stroke(0);
fill(255,0,0);
circle(mouseX, y, 20);
y += vball;
vball += g;
// ??????????????????
//for (let i=0;i<bricks.length;i++){
//if (y>bricks[i].y){
//vball = -0.8*vball;}}
for(let i = 0;i<bricks.length;i++)
{
if(bricks[i].collide(mouseX, y))
{
vball = -0.8*vball;
score+=1;
}
}
if(y<-height) score=0;
push();
textAlign(CENTER);
textSize(50);
stroke(255);
r = random(255);
g_ =random(255);
b = random(255);
fill(r,g_,b,120);
text(score, 650, 200);
pop();
push();
textSize(30);
r = random(255);
g_ =random(255);
b = random(255);
fill(r,g_,b,120);
stroke(255);
text('enjoy this lil boring ball while it still bounces :)',750,300);
pop();
}
}
function keyPressed(){
isplaying = true;
}
class Bricks{
constructor(x=width/2,y=height/2,w=10,h=10){
this.x = x;
this.y = y;
this.w = w;
this.h = h;
this.bump = true;}
draw(){
stroke(0);
fill(255);
rect(this.x,this.y,this.w,this.h);}
// function below copied from class example
collide(_x, _y){
if(_x>this.x&&_x<(this.x+this.w)&&_y>this.y&&_y<(this.y+this.h)){
this.bump = false;
return(true);}
else{
return(false);}
}
}