xxxxxxxxxx
43
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 10-10: The raindrop catching game
let drops; // An array of drop objects
let totalDrops = 0; // totalDrops
function setup() {
createCanvas(480, 270);
drops = []; // Create empty array
//New timer object
timer = new Timer(50);
timer.start();
}
function draw() {
background(255);
//add a drop to the array every time the timer finishes
if (timer.isFinished()) {
drops[totalDrops] = new Drop();
totalDrops++;
//limit array length to 1000
if (totalDrops > 1000) {
totalDrops = 0;
}
timer.start(); //restart timer
}
// 2. WRITE CODE TO Move and display all drops in the array
// Move and display all drops in the array
for (let i = 0; i < totalDrops; i++) {
drops[i].move();
drops[i].display();
}
}