xxxxxxxxxx
56
let rockX = [40, 0, 0, 0];
let rockY = [200, 0, 0, 0];
let rockSpeedX = [0, 0, 0, 0];
let rockSpeedY = [0, 0, 0, 0];
let hasHitWall = false;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
if (rockX[0] > width - 20 && hasHitWall == false) {
console.log('yes');
for (let i=1; i < 4; i++) {
rockX[i] = rockX[0];
rockY[i] = rockY[0];
rockSpeedX[i] = random(-2, -0.1);
rockSpeedY[i] = random(0.1, 0.3);
}
hasHitWall = true;
}
console.log(rockSpeedX[1], rockSpeedY[1]);
for (let i=0; i < 4; i++) {
if (rockX[i] == 0 && rockY[i] == 0) {
continue;
}
ellipse(rockX[i], rockY[i], 10, 10);
rockX[i] = rockX[i] + rockSpeedX[i];
rockY[i] = rockY[i] + rockSpeedY[i];
if (rockSpeedY[i] != 0) {
rockSpeedY[i] = rockSpeedY[i] + 0.2;
}
}
for (let i=0; i < 4; i++) {
if (rockX[i] > 350 && rockX[i] < 370 && rockY > height) {
console.log('hit!');
}
}
rect(350, height-20, 20, 20);
}
function mousePressed() {
let dx = mouseX - rockX[0];
let dy = mouseY - rockY[0];
rockSpeedX[0] = dx * -1;
rockSpeedY[0] = dy * -1;
}