learning processing

Page 203

184

Learning Processing void draw() { background(255);

catcher.setLocation(mouseX,mouseY); // Set catcher location catcher.display(); // Display the catcher

// Check the timer if (timer.isFinished()) { println("2 seconds have passed!"); timer.start(); }

// Deal with raindrops // Initialize one drop drops[totalDrops] = new Drop(); //Increment totalDrops totalDrops++; // If we hit the end of the array if (totalDrops >= drops.length) { totalDrops = 0; // Start over }

From Part 1. The Catcher!

From Part 3. The Timer!

From Part 4. The Raindrops!

// Move and display all drops for (int i = 0; i < totalDrops; i++) { drops[i].move(); drops[i].display(); } }

The next step is to take these concepts we have developed and have them work together. For example, we should only create a new raindrop whenever two seconds have passed (as indicated by the timer’s isFinished( ) function). // Check the timer if (timer.isFinished()) { // Deal with raindrops // Initialize one drop drops[totalDrops] = new Drop(); // Increment totalDrops totalDrops++; // If we hit the end of the array if (totalDrops >= drops.length) { totalDrops = 0; // Start over } timer.start(); }

Objects working together! Here when the timer “is finished,” a Drop object is added (by incrementing “totalDrops”).

We also need to find out when the Catcher object intersects a Drop. In Section 10.5, we tested for intersection by calling the intersect( ) function we wrote inside the Ball class.


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.