home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 12,000 to 12,999 / 12000.zip / AOLDLs / Online-Tools / Java-Applets / JAVAAPPS.lzh / JAVAAPPS / BRICK / BRICK.EXE / Paddle.java < prev    next >
Encoding:
Java Source  |  1996-04-23  |  2.3 KB  |  94 lines

  1.  
  2. import java.awt.Graphics;
  3. import java.awt.Color;
  4. import java.awt.Point;
  5.  
  6. public class Paddle {
  7.   int x, y, width, height;
  8.   private int max_speed;
  9.   private Color color;
  10.   private Point tmp;
  11.   private Graphics g;
  12.  
  13.   public Paddle (int x, int y, int width, int height, Color color, Graphics g) {
  14.     System.out.println("Paddle:: New Paddle!");
  15.  
  16.     this.x = x;
  17.     this.y = y;
  18.     this.width = width;
  19.     this.height = height;
  20.     this.color = color;
  21.     this.g = g;
  22.  
  23.     max_speed = Integer.MAX_VALUE;
  24.  
  25.     System.out.println(toString());
  26.   }
  27.  
  28.   public boolean impact (Ball b) {
  29. //    System.out.println(this + "Checking for impact.");
  30.  
  31.     if 
  32.     ((tmp = b.bottom()).x + b.speedx() > x - 2 && tmp.x + b.speedx() < x + width + 2 && 
  33.     tmp.y + b.speedy() > y && tmp.y + b.speedy() <= y + height) {
  34.  
  35.       b.play(BricksConstants.EFX_IMPACT_PADDLE);
  36.       b.impact(BricksConstants.IMPACT_BOTTOM, x, x + width, 0.5f);
  37.  
  38. /*
  39.     } else if 
  40.     ((tmp = b.top()).x >= x && tmp.x <= x + width && tmp.y >= y && tmp.y <= y + height) {
  41.       b.play(BricksConstants.EFX_IMPACT_PADDLE);
  42.       b.impact(BricksConstants.IMPACT_TOP, x, x + width, 1f);
  43.  
  44.     } else if
  45.     ((tmp = b.right()).x >= x && tmp.x <= x + width && tmp.y >= y && tmp.y <= y + height) {
  46.       b.play(BricksConstants.EFX_IMPACT_PADDLE);
  47.       b.impact(BricksConstants.IMPACT_RIGHT, y, y + height, 0.0f);
  48.  
  49.     } else if 
  50.     ((tmp = b.left()).x >= x && tmp.x <= x + width && tmp.y >= y && tmp.y <= y + height) {
  51.       b.play(BricksConstants.EFX_IMPACT_PADDLE);
  52.       b.impact(BricksConstants.IMPACT_LEFT, y, y + height, 0.0f);
  53.  
  54. */
  55.  
  56.     } else {
  57. //    System.out.println(this + "no impact.");
  58.       return false;
  59.     }
  60.  
  61.     return true;
  62.   }
  63.  
  64.   public void setMaxSpeed(int max) {
  65.     max_speed = max;
  66.   }
  67.  
  68.   public void moveX(int newx) {
  69.     if (java.lang.Math.abs(newx - x) > max_speed) 
  70.       x = newx / java.lang.Math.abs(newx) * max_speed;
  71.     else 
  72.       x = newx;
  73.   }
  74.  
  75.   public void draw () {
  76.     synchronized(g) {
  77.       g.setColor(color);
  78.       g.fillRect(x, y, width, height);
  79.     }
  80.   }
  81.  
  82.   public void undraw () {
  83.     synchronized(g) {
  84.       g.setColor(Color.black);
  85.       g.fillRect(x, y, width, height);
  86.     }
  87.   }
  88.  
  89.   public String toString() {
  90.     return ("Paddle:: (" + x + "," + y + "):");
  91.   }
  92. }
  93.  
  94.