| 25 | // func is the main function by which the bouncing back of ball is occuring |
| 26 | // or if ball touches the wall behind rods , then game is over ! |
| 27 | function func(){ |
| 28 | ball.style.position="relative"; |
| 29 | |
| 30 | var id = setInterval(function(){ |
| 31 | |
| 32 | |
| 33 | ball.style.top=top_value+"px"; |
| 34 | ball.style.left=left_value+"px"; |
| 35 | |
| 36 | top_value+=top_value1; |
| 37 | left_value+=left_value1; |
| 38 | |
| 39 | |
| 40 | if((ball.offsetTop>screen.availHeight-130 || ball.offsetTop<10)){ |
| 41 | clearInterval(id); |
| 42 | setTimeout(function(){ alert("GAME OVER! , Your score is "+i+" and maximum score till now is "+localStorage.getItem("maximum_score"));},500); |
| 43 | setTimeout(function(){ location.reload();},500); |
| 44 | |
| 45 | |
| 46 | } |
| 47 | if(ball.offsetLeft>a.offsetLeft && ball.offsetLeft<a.offsetLeft+250 && ball.offsetTop+50>b.offsetTop){ |
| 48 | // bounce |
| 49 | top_value1=-5; |
| 50 | |
| 51 | } |
| 52 | if(ball.offsetLeft>a.offsetLeft && ball.offsetLeft<a.offsetLeft+250 && ball.offsetTop<a.offsetTop+25){ |
| 53 | // bounce |
| 54 | top_value1=5; |
| 55 | } |
| 56 | if(ball.offsetLeft<=0){ |
| 57 | // bounce |
| 58 | left_value1=5; |
| 59 | |
| 60 | } |
| 61 | if(ball.offsetLeft>=screen.availWidth-60){ |
| 62 | // bounce |
| 63 | left_value1=-5; |
| 64 | } |
| 65 | |
| 66 | |
| 67 | |
| 68 | |
| 69 | |
| 70 | },20); |
| 71 | } |
| 72 | |
| 73 | |
| 74 | |