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 / Wall.java < prev   
Encoding:
Java Source  |  1996-04-23  |  1.8 KB  |  82 lines

  1.  
  2. import java.awt.Graphics;
  3. import java.awt.Point;
  4. import java.awt.Color;
  5.  
  6. public class Wall {
  7.   public int left, right, top, bottom;
  8.   public int width, height;
  9.   private Color color;
  10.   private Graphics g;
  11.  
  12.   public Wall (int x1, int y1, int x2, int y2, Color color, Graphics g) {
  13.     System.out.println("Wall:: New Wall!");
  14.  
  15.     left = x1; right = x2; top = y1; bottom = y2;
  16.  
  17.     width = right - left;
  18.     height = bottom - top;
  19.  
  20.     this.g = g;
  21.     this.color = color;
  22.   }
  23.  
  24.   public boolean outofBounds(Ball b) {
  25.     if (b.bottom().y > bottom + 2) {
  26.       b.play(BricksConstants.EFX_LOST_BALL);
  27.       return true;
  28.     } else {
  29.       return false;
  30.     }
  31.   }
  32.  
  33.   public boolean impact (Ball b) {
  34.  
  35.     if (b.left().x + b.speedx() - 1 < left) {
  36.  
  37.       b.play(BricksConstants.EFX_IMPACT_WALL);
  38.       b.impact(BricksConstants.IMPACT_LEFT, top, bottom, 0.05f);
  39.  
  40.     } else if (b.right().x + b.speedx() + 1 > right) {
  41.  
  42.       b.play(BricksConstants.EFX_IMPACT_WALL);
  43.       b.impact(BricksConstants.IMPACT_RIGHT, top, bottom, 0.05f);
  44.  
  45.     } else if (b.top().y + b.speedy() - 1 < top) {
  46.  
  47.       b.play(BricksConstants.EFX_IMPACT_WALL);
  48.       b.impact(BricksConstants.IMPACT_TOP, left, right, 0.05f);
  49.  
  50. /*
  51.     } else if (b.bottom().y + b.speedy() + 1 > bottom) {
  52.  
  53.       b.play(BricksConstants.EFX_IMPACT_WALL);
  54.       b.impact(BricksConstants.IMPACT_BOTTOM, left, right, 0.05f);
  55. */
  56.  
  57.     } else {
  58.       // no impact
  59.       return false;
  60.     }
  61.  
  62.     return true;
  63.  
  64.   }
  65.  
  66.   public void draw () {
  67.     synchronized(g) {
  68.       g.setColor(color);
  69.       g.drawLine(left, top, left, height);
  70.       g.drawLine(width, top, width, height);
  71.       g.drawLine(left, top, width, top);
  72. //      g.drawRect(left, top, width, height);
  73.     }
  74.   }
  75.  
  76.   public String toString () {
  77.     return "Wall::";
  78.   }
  79.  
  80. }
  81.  
  82.