topical media & game development

talk show tell print

student-twitter-flock-Tree.ax

student-twitter-flock-Tree.ax (swf ) [ flash ] flex


  package {
          import mx.controls.Image;
          
          public class @ax-student-twitter-flock-Tree {
                  private var x:int, y:int;
                  private var radius:int = 75;
                  public var image:Image;
                  
                  public function @ax-student-twitter-flock-Tree (x:int, y:int, image:Image):void {
                          this.x = x;
                          this.y = y;
                      
                          this.image = image;
                          this.image.x = x - 75;
                          this.image.y = y - 75;
                  }
                  
                  public function getX ():int {
                          return this.x;
                  }
                  public function getY ():int {
                          return this.y;
                  }
                  public function getRadius ():int {
                          return this.radius;
                  }
                  public function getImage ():Image {
                          return this.image;
                  }
                  
                  public function distanceToBoid (boid:student_twitter_flock_Boid):int {
                          var distX:int = this.x - boid.getX(),
                                  distY:int = this.y - boid.getY();
                          return Math.sqrt(distX * distX + distY * distY);
                  }
                  
                  public function shake (boids:Array):void {
                          // Find all boids within the tree radius and give them a random impulse.
                          // The result is that they scatter.
  
                          for(var i:int = 0; i < boids.length; i++) {
                                  if (this.distanceToBoid(boids[i]) <= this.radius) {
                                          boids[i].addRandomImpulse (10.0);
                                  }
                          }
                  }
          }
  }
  


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