topical media & game development
graphic-processing-learning-10-example-10-7-example-10-7.pde / pde
// Learning Processing
// Daniel Shiffman
// http://www.learningprocessing.com
// Example 10-7: Drops one at a time
// An array of drops
Drop[] drops = new Drop[1000];
// New variable to keep track of total number of drops we want to use!
int totalDrops = 0;
void setup() {
size(400,400);
smooth();
background(0);
}
void draw() {
background(255);
// 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
}
// Move and display drops
for (int i = 0; i < totalDrops; i++ ) { // New! We no longer move and display all drops, but rather only the “totalDrops” that are currently present in the game.
drops[i].move();
drops[i].display();
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.