1 /**
  2  * Wooden walls
  3  * @param {Number} w
  4  * @param {Number} h
  5  * @param {Number} x
  6  * @param {Number} y
  7  * @constructor
  8  */
  9 function BB_Wall(w, h, x, y) {
 10 	this.set(w, h, x, y);
 11 }
 12 
 13 /**
 14  * Extends CP_Item
 15  */
 16 BB_Wall.prototype = new CP_Item();
 17 
 18 /**
 19  * Check ball collision
 20  * @param {BB_Ball} ball
 21  * @returns {Boolean}
 22  */
 23 BB_Wall.prototype.check = function(ball) {
 24 	var r = ball.r,
 25 		x = ball.ox(),
 26 		y = ball.oy(),
 27 		x1 = this.x,
 28 		y1 = this.y,
 29 		x2 = x1 + this.w,
 30 		y2 = y1 + this.h;
 31 	if (x >= x1 && x <= x2) {
 32 		//top
 33 		if (y < y1 && y1 - y < r) {
 34 			ball.oy(y1 - r);
 35 			ball.bounce(1, -1);
 36 			return true;
 37 		}
 38 		//bottom
 39 		if (y > y2 &&  y - y2 < r) {
 40 			ball.oy(y2 + r);
 41 			ball.bounce(1, -1);
 42 			return true;
 43 		}
 44 	}
 45 	if (y >= y1 && y <= y2) {
 46 		//left
 47 		if (x < x1 && x1 - x < r) {
 48 			ball.ox(x1 - r);
 49 			ball.bounce(-1, 1);
 50 			return true;
 51 		}
 52 		//right
 53 		if (x > x2 &&  x - x2 < r) {
 54 			ball.ox(x2 + r);
 55 			ball.bounce(-1, 1);
 56 			return true;
 57 		}
 58 	}
 59 	//top left
 60 	if (x < x1 && y < y1) {
 61 		return ball.check(x1, y1, true);
 62 	}
 63 	//bottom left
 64 	if (x < x1 && y > y2) {
 65 		return ball.check(x1, y2, true);		
 66 	}
 67 	//top right
 68 	if (x > x2 && y < y1) {
 69 		return ball.check(x2, y1, true);
 70 	}
 71 	//bottom right
 72 	if (x > x2 && y > y2) {
 73 		return ball.check(x2, y2, true);
 74 	}
 75 	return false;	
 76 };
 77