Advertisement
Guest User

ballbreaker

a guest
Apr 5th, 2011
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.79 KB | None | 0 0
  1. public void checkHitBlock() {
  2.         boolean hit = false;
  3.         int i = model.getSize() - 1;
  4.         while(i > -1) {
  5.             Block b = model.getBlock(i);
  6.             if(checkHitY(b)) {
  7.                 if(checkHitX(b)) {
  8.                     addToScore(b.getValue());
  9.                     model.hitBlock(i);
  10.                     dy = -dy;
  11.                     i = model.getSize() - 1;
  12.                 }
  13.             }
  14.             i--;
  15.         }
  16.     }
  17.  
  18. public boolean checkHitX(Block b) {
  19.         int x = ballX + (ballSize/2);
  20.         if (x >= b.getX() && x <= (b.getX()+b.getWidth())) {
  21.             return true;
  22.         } else {
  23.             return false;
  24.         }
  25.     }
  26.        
  27.     public boolean checkHitY(Block b) {
  28.         if (ballY >= (b.getY()+b.getHeight() - Math.abs(dy)) && ballY <= (b.getY()+b.getHeight())) {
  29.             return true;
  30.         } else if ((ballY + ballSize) >= b.getY() && (ballY + ballSize)<= (b.getY() + Math.abs(dy))) {
  31.             return true;
  32.         } else {
  33.             return false;
  34.         }
  35.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement