if(window.innerWidth > 400){
WINDOW_WIDTH = window.innerWidth;
if(window.innerHeight > 500){
WINDOW_HEIGHT = window.innerHeight;
createCanvas(WINDOW_WIDTH, WINDOW_HEIGHT, WEBGL);
colorMode(HSB, 360, 100, 100);
BLOCK_WIDTH = (width - MERGIN * 2) / BLOCK_NUM_X;
BLOCK_DEPTH = DEPTH / BLOCK_NUM_Z;
ball = new Ball(random(-width / 2 + MERGIN + RADIUS * 2,width / 2 - MERGIN - RADIUS * 2), random(-10, 10), random(- RADIUS * 2, -DEPTH + RADIUS * 2));
function mousePressed() {
translate(-width / 2 + MERGIN, - height / 2 + MERGIN, 0);
rect(0,0, DEPTH, height - MERGIN * 2);
translate(width / 2 - MERGIN, - height / 2 + MERGIN, 0);
rect(0,0, DEPTH, height - MERGIN * 2);
translate(- width / 2 + MERGIN, - height / 2 + MERGIN, -DEPTH);
rect(0, 0, width - MERGIN * 2, height - MERGIN * 2);
translate(- width / 2 + MERGIN, - height / 2 + MERGIN, -DEPTH);
rect(0, 0, width - MERGIN * 2, DEPTH);
if(mouseX < BAR_WIDTH / 2 + MERGIN){
this.x = BAR_WIDTH / 2 + MERGIN - width / 2;
}else if( mouseX > width - (BAR_WIDTH / 2 + MERGIN)){
this.x = width / 2 - (BAR_WIDTH / 2 + MERGIN);
this.x = mouseX - width / 2;
translate(this.x, BAR_Y, -DEPTH/2);
box(BAR_WIDTH, BAR_HEIGHT, DEPTH);
if(px >= this.x - BAR_WIDTH / 2 &&
px <= this.x + BAR_WIDTH / 2 &&
translate(0, BAR_Y - BAR_HEIGHT / 2 - 1,pz);
circle(px,0, RADIUS * 3);
this.v = createVector(random(para), -1, random(para));
if(this.x - RADIUS <= - width / 2 + MERGIN ||
this.x + RADIUS >= width / 2 - MERGIN){
if(this.y - RADIUS <= - height / 2 + MERGIN){
if(this.z - RADIUS <= - DEPTH ||
if(this.x >= px - BAR_WIDTH / 2 &&
this.x <= px + BAR_WIDTH / 2 &&
this.y + RADIUS >= BAR_Y - BAR_HEIGHT / 2 &&
this.y + RADIUS <= BAR_Y - BAR_HEIGHT / 2 + SPEED){
else if(this.x + RADIUS >= px - BAR_WIDTH / 2 &&
this.x - RADIUS <= px + BAR_WIDTH / 2 &&
this.y >= BAR_Y - BAR_HEIGHT / 2 &&
this.y <= BAR_Y + BAR_HEIGHT / 2 &&
this.x = this.x + SPEED * this.v.x;
this.y = this.y + SPEED * this.v.y;
this.z = this.z + SPEED * this.v.z;
translate(this.x, this.y, this.z);
for(let i = 0; i < BLOCK_NUM_X; i++){
this.blockHitFlg[i] = [];
for(let j = 0; j < BLOCK_NUM_Y; j++){
this.blockHitFlg[i][j] = [];
for(let k = 0; k < BLOCK_NUM_Z; k++){
this.blockHitFlg[i][j][k] = 0;
for(let i = 0; i < BLOCK_NUM_X; i++){
for(let j = 0; j < BLOCK_NUM_Y; j++){
for(let k = 0; k < BLOCK_NUM_Z; k++){
if(this.blockHitFlg[i][j][k] == 0){
if(ball.x + RADIUS >= i * BLOCK_WIDTH + MERGIN - width / 2 &&
ball.x - RADIUS < (i + 1) * BLOCK_WIDTH + MERGIN - width / 2 &&
ball.y >= j * BLOCK_HEIGHT + MERGIN - height / 2 &&
ball.y < (j + 1) * BLOCK_HEIGHT + MERGIN - height / 2 &&
ball.z >= - (k + 1) * BLOCK_DEPTH &&
ball.z < - k * BLOCK_DEPTH){
this.blockHitFlg[i][j][k] = 1;
} else if(ball.x >= i * BLOCK_WIDTH + MERGIN - width / 2 &&
ball.x < (i + 1) * BLOCK_WIDTH + MERGIN - width / 2 &&
ball.y + RADIUS >= j * BLOCK_HEIGHT + MERGIN - height / 2 &&
ball.y - RADIUS < (j + 1) * BLOCK_HEIGHT + MERGIN - height / 2 &&
ball.z >= - (k + 1) * BLOCK_DEPTH &&
ball.z < - k * BLOCK_DEPTH){
this.blockHitFlg[i][j][k] = 1;
} else if(ball.x >= i * BLOCK_WIDTH + MERGIN - width / 2 &&
ball.x < (i + 1) * BLOCK_WIDTH + MERGIN - width / 2 &&
ball.y >= j * BLOCK_HEIGHT + MERGIN - height / 2 &&
ball.y < (j + 1) * BLOCK_HEIGHT + MERGIN - height / 2 &&
ball.z + RADIUS >= - (k + 1) * BLOCK_DEPTH &&
ball.z - RADIUS < - k * BLOCK_DEPTH){
this.blockHitFlg[i][j][k] = 1;
fill(map(k, 0, BLOCK_NUM_Z - 1, 100, 360), map(j, 0, BLOCK_NUM_Y - 1, 80, 40), 70);
translate(i * BLOCK_WIDTH + MERGIN + BLOCK_WIDTH / 2 - width / 2,
j * BLOCK_HEIGHT + MERGIN + BLOCK_HEIGHT / 2 - height / 2,
- k * BLOCK_DEPTH - BLOCK_DEPTH / 2);
box(BLOCK_WIDTH, BLOCK_HEIGHT, BLOCK_DEPTH);
directionalLight(0, 0, 90, 0, 1, -1);
textAlign(CENTER, CENTER);
text("CLICK TO START",0,0);
bar.drawShadow(ball.x, ball.y, ball.z);
if(ball.y > height && block.clearFlg == 0){
textAlign(CENTER, CENTER);
textAlign(CENTER, CENTER);