topical media & game development

talk show tell print

graphic-processing-learning-10-example-10-10-Catcher.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 10-10: The raindrop catching game
  
  class Catcher {
    float r;   // radius
    color col; // color
    float x,y; // location
    
    Catcher(float tempR) {
      r = tempR;
      col = color(50,10,10,150);
      x = 0;
      y = 0;
    }
    
    void setLocation(float tempX, float tempY) {
      x = tempX;
      y = tempY;
    }
  
    void display() {
      stroke(0);
      fill(col);
      ellipse(x,y,r*2,r*2);
    }
    
    // A function that returns true or false based on
    // if the catcher intersects a raindrop
    boolean intersect(Drop d) {
      // Calculate distance
      float distance = dist(x,y,d.x,d.y); 
      
      // Compare distance to sum of radii
      if (distance < r + d.r) { 
        return true;
      } else {
        return false;
      }
    }
  }
  


(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.