topical media & game development

talk show tell print

graphic-processing-learning-09-example-9-11-Ball.pde / pde



  // Learning Processing
  // Daniel Shiffman
  // http://www.learningprocessing.com
  
  // Example 9-11: Resizing an array using append()
  
  class Ball {
    float x;
    float y;
    float speed;
    float w;
    
    Ball(float tempX, float tempY, float tempW) {
      x = tempX;
      y = tempY;
      w = tempW;
      speed = 0;
    }
    
    void gravity() {
      // Add gravity to speed
      speed = speed + gravity;
    }
    
    void move() {
      // Add speed to y location
      y = y + speed;
      // If square reaches the bottom
      // Reverse speed
      if (y > height) {
        speed = speed * -0.95;
        y = height;
      }
    }
    
    void display() {
      // Display the circle
      fill(175);
      stroke(0);
      ellipse(x,y,w,w);
    }
  }  
  


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