Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void checkHitBlock() {
- boolean hit = false;
- int i = model.getSize() - 1;
- while(i > -1) {
- Block b = model.getBlock(i);
- if(checkHitY(b)) {
- if(checkHitX(b)) {
- addToScore(b.getValue());
- model.hitBlock(i);
- dy = -dy;
- i = model.getSize() - 1;
- }
- }
- i--;
- }
- }
- public boolean checkHitX(Block b) {
- int x = ballX + (ballSize/2);
- if (x >= b.getX() && x <= (b.getX()+b.getWidth())) {
- return true;
- } else {
- return false;
- }
- }
- public boolean checkHitY(Block b) {
- if (ballY >= (b.getY()+b.getHeight() - Math.abs(dy)) && ballY <= (b.getY()+b.getHeight())) {
- return true;
- } else if ((ballY + ballSize) >= b.getY() && (ballY + ballSize)<= (b.getY() + Math.abs(dy))) {
- return true;
- } else {
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement