topical media & game development

talk show tell print

graphic-processing-algorithm-Ch03-p83-MyGroup.pde / pde



  class MyGroup {
  
    // members of class
    MyShape[] shapes;           // array of shapes
    int numShapes;              //number of shapes
    boolean isSelected = false;     // is this shape selected?
  
    //********** Constructor
    MyGroup(int numInputShapes, MyShape[] inputShapes){
  
      numShapes = numInputShapes;
      shapes = new MyShape[numShapes];
  
      for(int i=0; i<numShapes; i++)
        shapes[i] = inputShapes[i];
    }
  
    //********** Move
    void move(float xoff, float yoff){
  
      for(int i=0; i<numShapes; i++)
        shapes[i].move(xoff, yoff);
    }
  
    //*********** draw
    void draw( ){
  
      for(int i=0; i<numShapes; i++)
        shapes[i].draw();
  
    }
  
    //******** Select
    boolean select(float xpick, float ypick, float tolerance){
      for(int i=0; i<numShapes; i++){
        if(shapes[i].select(xpick, ypick, tolerance)==true){
          isSelected = true; 
          return true;
        }
        else {
          isSelected = false;
        }
      }
      return false;
    }
  
  }
  


(C) Æliens 04/09/2009

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.