(function(){function w(){g+=q?-12:r?12:0;h+=s?-12:t?12:0;var b=f/2,i=480-b;g=k(n(g,i),b);h=k(n(h,i),b);d+=j.acos(u)*o*v;e+=j.asin(u)*x*v;var i=d,p=e;e>g-b&&e<g+b+20&&d>10&&d<30||e>h-b&&e<h+b+20&&d>610&&d<630?o*=-1:(d=k(n(d,630),10),e=k(n(e,470),10),i>d&&l++,i<d&&m++,o*=i!=d?-1:1,x*=p!=e?-1:1);a.clearRect(0,0,640,480);a.fillRect(0,g-f/2,20,f);a.fillRect(620,h-f/2,20,f);a.fillRect(d-10,e-10,20,20);a.textAlign="left";a.fillText(l,40,40);a.textAlign="right";a.fillText(m,600,40);f-=f>60?0.1:0;v+=0.001; k(l,m)>14&&y(l-m)>1?(a.clearRect(0,0,640,480),a.textAlign="center",a.fillText(l>m?"Left":"Right win!",320,240)):setTimeout(w,20)}c.width=640;c.height=480;c.style.border="1px solid black";a.font="48px sans-serif";var q=0,r=0,s=0,t=0,p=document;p.onkeydown=function(b){b=b.keyCode;q|=b==65;r|=b==90;s|=b==75;t|=b==77};p.onkeyup=function(b){b=b.keyCode;q&=b!=65;r&=b!=90;s&=b!=75;t&=b!=77};var j=Math,n=j.min,k=j.max,y=j.abs,g=240,h=240,d=320,e=240,u=j.random()-0.5,l=0,m=0,o=y(u%0.1)>0.05?-1:1,x=-o,v=8, f=140;w()})();
(function(){
c.width = 640;c.height=480;c.style.border = '1px solid black';
a.font = '48px sans-serif';
var pl1t = 0,pl1b = 0,pl2t = 0,pl2b = 0;
var doc = document;
doc.onkeydown = function(evt){
var c = evt.keyCode;
pl1t |= c==65;
pl1b |= c==90;
pl2t |= c==75;
pl2b |= c==77;
}
doc.onkeyup = function(evt){
var c = evt.keyCode;
pl1t &= c!=65;
pl1b &= c!=90;
pl2t &= c!=75;
pl2b &= c!=77;
}
var m = Math,mn=m.min,mx=m.max,ma=m.abs;
var player1pos = 240, player2pos = 240,
ballX = 320, ballY = 240, ballAngle = m.random()-0.5,
player1score = 0, player2score = 0,
speedX = ma(ballAngle%0.1)>0.05?-1:1,speedY = -speedX,speed=8,
height = 140;
var loop = function(){
player1pos+=pl1t?-12:pl1b?12:0;
player2pos+=pl2t?-12:pl2b?12:0;
var top2 = height/2,
top1 = 480-top2;
player1pos = mx(mn(player1pos,top1),top2)
player2pos = mx(mn(player2pos,top1),top2)
ballX += m.acos(ballAngle)*speedX*speed;
ballY += m.asin(ballAngle)*speedY*speed;
var oldballX = ballX,
oldballY = ballY;
if((ballY > player1pos-top2 && ballY < player1pos+top2+20 && ballX > 10 && ballX < 30) || (ballY > player2pos-top2 && ballY < player2pos+top2+20 && ballX > 610 && ballX < 630)){
speedX *= -1;
}else{
ballX = mx(mn(ballX,630),10);
ballY = mx(mn(ballY,470),10);
if(oldballX > ballX)player1score++;
if(oldballX < ballX)player2score++;
speedX *= oldballX!=ballX?-1:1;
speedY *= oldballY!=ballY?-1:1;
}
a.clearRect(0,0,640,480)
a.fillRect(0,player1pos-height/2,20,height);
a.fillRect(620,player2pos-height/2,20,height);
a.fillRect(ballX-10,ballY-10,20,20);
a.textAlign = 'left';
a.fillText(player1score,40,40)
a.textAlign = 'right';
a.fillText(player2score,600,40)
height-=height>60?0.1:0;
speed += 0.001;
if(!(mx(player1score,player2score) > 14 && ma(player1score-player2score)>1)){
setTimeout(loop,20);
}else{
a.clearRect(0,0,640,480);
a.textAlign = 'center';
a.fillText(player1score>player2score?'Left':'Right'+' win!',320,240)
}
}
loop();
})();