-
Notifications
You must be signed in to change notification settings - Fork 0
/
duckhunt.min.js
1 lines (1 loc) · 3.76 KB
/
duckhunt.min.js
1
function duckhunt(a){function b(a,d){!a.shot&&(d>m||0>=l)?(a.orientationNum=2,c(a)):!a.shot&&m>=d&&(a.leftOffset>=s.offsetWidth-n?(a.e.className="duckhunt_sprites duckhunt_duck duckhunt_hoz_flip",a.slopeX=-k()):a.leftOffset<=0&&(a.e.className="duckhunt_sprites duckhunt_duck",a.slopeX=k()),a.topOffset<=0?(a.slopeY=k(),a.orientationNum=a.slopeX/a.slopeY<1.03?0:1):a.topOffset>=s.offsetHeight-o&&(a.slopeY=-k(),a.orientationNum=a.slopeX/a.slopeY<1.03?0:1),a.topOffset+=8*a.slopeY,a.leftOffset+=8*a.slopeX,a.e.style.top=a.topOffset+"px",a.e.style.left=a.leftOffset+"px",a.spriteNum=2==a.spriteNum?0:a.spriteNum+1,a.e.style.backgroundPosition=p[a.spriteNum]+"px "+q[a.orientationNum]+"px",setTimeout(function(){b(a,d+1)},50))}function c(a){a.topOffset-=15,a.e.style.top=a.topOffset+"px",a.spriteNum=2==a.spriteNum?0:a.spriteNum+1,a.e.style.backgroundPosition=p[a.spriteNum]+"px "+q[a.orientationNum]+"px",a.topOffset>-o?setTimeout(function(){c(a)},50):(a.finished=!0,f())}function d(){var a="duck1"==this.id?t:u;return l>0&&2!=a.orientationNum&&(a.shot=!0,a.e.style.backgroundPosition="-435px -145px",setTimeout(function(){a.e.style.backgroundPosition="-435px -290px",e(a,!1)},400)),!1}function e(a,b){a.e.className=b?"duckhunt_sprites duckhunt_duck duckhunt_hoz_flip":"duckhunt_sprites duckhunt_duck",a.topOffset+=30,a.e.style.top=a.topOffset+"px",a.topOffset<s.offsetHeight+o?setTimeout(function(){e(a,!b)},50):(a.finished=!0,f())}function f(){if(t.finished&&u.finished){var a=s.appendChild(document.createElement("div"));a.style.top=s.offsetHeight+o+"px",a.className="duckhunt_sprites duckhunt_dog",t.shot&&u.shot?(a.style.backgroundPosition="0px -435px",a.style.width="250px"):t.shot||u.shot?(a.style.backgroundPosition="-250px -435px",a.style.width="200px"):(a.style.backgroundPosition="-450px -435px",a.style.width="150px"),a.style.top=s.offsetHeight+"px",g(a,!0)}}function g(b,c){var d=s.offsetHeight-parseInt(b.style.top);160>d&&c?(b.style.top=parseInt(b.style.top)-20+"px",setTimeout(function(){g(b,c)},60)):d>0&&!c?(b.style.top=parseInt(b.style.top)+20+"px",setTimeout(function(){g(b,c)},60)):d>=160&&"-450px -435px"==b.style.backgroundPosition?h(b,8):d>=160?setTimeout(function(){g(b,!c)},1e3):(document.body.removeChild(r),a&&a())}function h(a,b){b>0?(a.style.backgroundPosition="-450px -435px"==a.style.backgroundPosition?"-600px -435px":"-450px -435px",setTimeout(function(){h(a,b-1)},110)):g(a,!1)}function i(){if(l>0){var a=t.e.className,b=u.e.className;l--,r.style.backgroundColor="rgb(0, 0, 0)",s.style.backgroundColor="rgb(0, 0, 0)",t.e.style.backgroundColor="rgb(255, 255, 255)",u.e.style.backgroundColor="rgb(255, 255, 255)",t.e.style.backgroundImage="none",u.e.style.backgroundImage="none",setTimeout(function(){r.style.backgroundColor="",s.style.backgroundColor="",t.e.style.backgroundColor=null,u.e.style.backgroundColor=null,t.e.style.backgroundImage=null,u.e.style.backgroundImage=null,t.e.className=a,u.e.className=b},100)}}function j(){return Math.round(.8*Math.random()*s.offsetWidth)+.1*s.offsetWidth}function k(){return Math.atan(90*Math.random())}var l=3,m=100,n=145,o=145,p=[0,-145,-290],q=[0,-145,-290],r=document.body.appendChild(document.createElement("div"));r.className="duckhunt_overlay";var s=r.appendChild(document.createElement("div"));s.className="duckhunt_overlay",s.onclick=i;var t=new Object({e:s.appendChild(document.createElement("div")),spriteNum:0,orientationNum:1,slopeX:k(),slopeY:0,shot:!1,finished:!1,topOffset:s.offsetHeight,leftOffset:j()}),u=new Object({e:s.appendChild(document.createElement("div")),spriteNum:0,orientationNum:0,slopeX:-k(),slopeY:0,shot:!1,finished:!1,topOffset:s.offsetHeight,leftOffset:j()});t.e.id="duck1",u.e.id="duck2",t.e.className="duckhunt_sprites duckhunt_duck",u.e.className="duckhunt_sprites duckhunt_duck duckhunt_hoz_flip",t.e.onclick=d,u.e.onclick=d,b(t,1),b(u,1)}