diff --git a/js/katamari.js b/js/katamari.js index 736ccb10..26d5e740 100644 --- a/js/katamari.js +++ b/js/katamari.js @@ -1 +1,43 @@ -var BORDER_STYLE="1px solid #bbb",CSS_TRANSFORM=null,CSS_TRANSFORM_ORIGIN=null,POSSIBLE_TRANSFORM_PREFIXES=["-webkit-","-moz-","-o-","-ms-",""],khFirst=!1;function getCssTransform(){var t,e,o=document.createElement("div");for(t=0;t0){e.push(o);return}if(o.childNodes&&!o.khIgnore)for(l=0,n=i(o),r=o.childNodes.length;l0&&0===s[0].length&&s.shift(),o=0;o0&&((i=document.createElement("span")).innerHTML=r[o],l.insertBefore(i,e),n(i)),o0&&(i=document.createTextNode(s[o]),l.insertBefore(i,e));l.removeChild(e)})},this.addTagNames=function(t,e){var o,i,l,r,s=t.tagName&&t.tagName.toLowerCase();if(!t.khIgnore){if(-1!==e.indexOf(s)&&n(t),t.getElementsByTagName)for(o=0;oT())&&(l=(o=getClosestPoint(s,a,e=t))[0]-s,c=Math.sqrt(l*l+(r=o[1]-a)*r),d=0-S,f=o[0]-e.left,h=o[1]-e.top,g=c*Math.cos(p=Math.atan2(r,l)-S),_=c*Math.sin(p),b=e.el.cloneNode(!0),m=jQuery(e.el),y={el:b,attX:g,attY:_,attT:"translate("+Math.round(g)+"px,"+Math.round(_)+"px) rotate("+d+"rad)",r:c,offTh:p,offPhi:0-x,diag:e.diag,removeR:c+e.diag,visible:!1,display:m.css("display")},u.push(y),E=e,$=Math.pow(3*(T()+gridObjVol(E)*v)/(4*Math.PI),1/3),b.style.position="absolute",b.style.left=-f+"px",b.style.top=-h+"px",b.style.setProperty(CSS_TRANSFORM_ORIGIN,f+"px "+h+"px",null),b.style.display="none",b.style.color=m.css("color"),b.style.textDecoration=m.css("text-decoration"),b.style.fontSize=m.css("font-size"),b.style.fontWeight=m.css("font-weight"),b.khIgnore=!0,i.appendChild(b),n&&n.play_pop(),!0)}function I(t){var e=S+t.offTh,o=x+t.offPhi,n=t.r*Math.cos(e),i=t.r*Math.sin(e),l=t.r*Math.cos(S-t.offTh+Math.PI)-n,r=t.r*Math.sin(S-t.offTh+Math.PI)-i,c=(-Math.cos(o)+1)/2,d=n+c*l,f=i+c*r,h=t.r*Math.sin(o);return h<0&&Math.sqrt(d*d+f*f)+t.diag<$?(t.visible&&(t.visible=!1,t.el.style.display="none"),!1):(t.visible||(t.visible=!0,t.el.style.display=t.display),t.el.style.zIndex=h>0?501:499,t.el.style.setProperty(CSS_TRANSFORM,"translate("+s+"px,"+a+"px) rotate("+S+"rad) scaleX("+Math.cos(o)+") "+t.attT,null),!0)}function P(t){i.removeChild(t.el),delete t.el}this.init=function(){(l=document.createElement("canvas")).width=2*$,l.height=2*$,l.style.cssText="position: absolute; z-index: 500;",t.appendChild(l),r=l.getContext("2d"),i=document.createElement("div"),t.appendChild(i)},this.setRadius=function(t){$=t},this.getState=function(){return{x:s,y:a,vx:c,vy:d,radius:$,th:S,phi:x}},this.setState=function(t){s=t.x,a=t.y,c=t.vx,d=t.vy,$=t.radius,S=t.th,x=t.phi},this.setXY=function(t,e){s=t,a=e},this.setTh=function(t){S=t},this.setPhi=function(t){x=t},this.setColor=function(t){g=t},this.setDocSize=function(t,e){h=t,p=e},this.setAccel=function(t){m=t},this.setAccelTarget=function(t,e){_=t,b=e},this.updatePhysics=function(){var t,o,i,l=s,r=a,f=!1;m?(c+=.5*Math.cos(i=Math.atan2(b-a,_-s)),d+=.5*Math.sin(i)):(c*=.95,d*=.95),s+=c,a+=d,s-$<0?(f=!0,s=$+1,c=-c):s+$>h&&(f=!0,s=h-$-1,c=-c),a-$<0?(f=!0,a=$+1,d=-d):a+$>p&&(f=!0,a=p-$-1,d=-d),(0!==c||0!==d)&&(S=Math.atan2(d,c),x-=Math.sqrt((t=s-l)*t+(o=a-r)*o)/$),e.removeIntersecting(s,a,$,E),this.draw(),f&&n&&n.play_bounce()},this.draw=function(){var t,e,o=0;for(!function t(){var e,o,n,i,c,d,h,p,u,_,b;for(l.style.left=s-$+"px",l.style.top=a-$+"px",$!=f&&(l.width=2*$+1,l.height=2*$+1,f=$),r.clearRect(0,0,2*$,2*$),r.fillStyle="#fff",r.beginPath(),r.arc($,$,$-1,0,2*Math.PI,!0),r.fill(),r.strokeStyle=g,r.beginPath(),r.arc($,$,$-1,0,2*Math.PI,!0),r.stroke(),r.fillStyle=g,e=$+$*Math.cos(S+Math.PI/16),o=$+$*Math.sin(S+Math.PI/16),n=$+$*Math.cos(S-Math.PI/16),i=$+$*Math.sin(S-Math.PI/16),c=$+$*Math.cos(S+15*Math.PI/16)-e,d=$+$*Math.sin(S+15*Math.PI/16)-o,h=0;h<2*Math.PI;h+=Math.PI/7)p=(-Math.cos(x+h)+1)/2,u=(-Math.cos(x+h+Math.PI/32)+1)/2,_=Math.sin(x+h),b=Math.sin(x+h+Math.PI/32),_>0&&b>0&&(r.beginPath(),r.moveTo(e+p*c,o+p*d),r.lineTo(e+u*c,o+u*d),r.lineTo(n+u*c,i+u*d),r.lineTo(n+p*c,i+p*d),r.fill())}(),t=u.length;--t>=0;)if((e=u[t]).removeR<$)u.splice(t,1).map(P);else if(I(e)&&++o>y){u.splice(0,t).map(P);break}}}function preventDefault(t){return t.preventDefault(),t.returnValue=!1,!1}function Game(t,e,o){var e,n,i,l;function r(){n.setDocSize(jQuery(document).width()-5,jQuery(document).height()-5)}(n=new PlayerBall(t,e,o,!1)).init(),n.setXY(300,300),window.scrollTo(0,200),r(),document.addEventListener("touchstart",function(t){if(1===t.touches.length)return n.setAccel(!0),preventDefault(t)},!0),document.addEventListener("touchmove",function(t){n.setAccelTarget(t.touches[0].pageX,t.touches[0].pageY)},!0),document.addEventListener("touchend",function(t){if(0===t.touches.length)return n.setAccel(!1),preventDefault(t)},!0),-5!==o.MOUSEB&&(document.addEventListener("mousemove",function(t){n.setAccelTarget(t.pageX,t.pageY)},!0),document.addEventListener("mousedown",function(t){if(t.button===o.MOUSEB)return n.setAccel(!0),preventDefault(t)},!0),document.addEventListener("mouseup",function(t){if(t.button===o.MOUSEB)return n.setAccel(!1),preventDefault(t)},!0),0===o.MOUSEB?document.addEventListener("click",function(t){if(0===t.button)return preventDefault(t)},!0):2===o.MOUSEB&&document.addEventListener("contextmenu",preventDefault,!0)),i=setInterval(function(){n.updatePhysics()},25),l=setInterval(r,1e3)}function whenAllLoaded(t,e,o){o.finalize(jQuery(document).width(),jQuery(document).height()),jQuery("#loadingp").empty(),jQuery("").click(function(){var n,i,l;jQuery("#bgmusicc").attr("checked")&&((i=document.getElementById("khbgmusic"))||((i=document.createElement("audio")).id="khbgmusic",i.loop="loop",i.src="https://cdn.jsdelivr.net/gh/skysthelimitt/e-gamepass/js/katamari.mp3",t.appendChild(i)),i.play()),l={color:jQuery("#khcolor").val(),VOL_MULT:parseFloat(jQuery("#vol_mult").val()),MAX_ATTACHED_VISIBLE:parseInt(jQuery("#maxAtt").val(),10),CHECK_VOLS:!!jQuery("#checkv").attr("checked"),MOUSEB:parseInt(jQuery("#mouseb").val(),10)},t.removeChild(e),n=new Game(t,o,l)}).appendTo("#loadingp")}function buildPopup(t){var e=document.createElement("div");return e.style.cssText="position: fixed;left: 50%;top: 50%;width: 400px;margin-left:-200px;margin-top:-150px;border:1px solid black;background-color:white;color:black;padding:20px;font-size:13px;text-align:left;z-index:501;",e.innerHTML='

Katamari!

Controls: Hold down to control the ball!




Loading!

',t.appendChild(e),e.getElementsByTagName("button")[0].addEventListener("click",function(){t.removeChild(e)},!0),e}function main(){var t,e,o;(t=document.createElement("div")).khIgnore=!0,document.body.appendChild(t),o=buildPopup(t),setTimeout(function(){var n,i,l;for(window.khNodes.addWords(document.body),n=0,i=document.body.childNodes.length;n0){textEls.push(el);return}if(!el.childNodes||el.khIgnore){return}shouldAdd=shouldAddChildren(el);for(i=0,len=el.childNodes.length;i0&&ws[0].length===0){ws.shift()}for(i=0;i0){n=document.createElement('span');n.innerHTML=words[i];p.insertBefore(n,textEl);addDomNode(n)}if(i0){n=document.createTextNode(ws[i]);p.insertBefore(n,textEl)}}p.removeChild(textEl)}buildTextEls(el,shouldAddChildren(el));textEls.map(wordsToSpans)};this.addTagNames=function(el,tagNames){var tname=el.tagName&&el.tagName.toLowerCase(),i,j,els,len;if(el.khIgnore){return}if(tagNames.indexOf(tname)!==-1){addDomNode(el)}if(!el.getElementsByTagName){return}for(i=0;igetVol()){return false}attachGridObj(go);return true}this.updatePhysics=function(){var oldX=x,oldY=y,dx,dy,bounce=false,accelTh;if(accel){accelTh=Math.atan2(accelTargetY-y,accelTargetX-x);vx+=Math.cos(accelTh)*0.5;vy+=Math.sin(accelTh)*0.5}else{vx*=0.95;vy*=0.95}x+=vx;y+=vy;if(x-radius<0){bounce=true;x=radius+1;vx= -vx}else if(x+radius>docW){bounce=true;x=docW-radius-1;vx= -vx}if(y-radius<0){bounce=true;y=radius+1;vy= -vy}else if(y+radius>docH){bounce=true;y=docH-radius-1;vy= -vy}if(vx!==0||vy!==0){th=Math.atan2(vy,vx);dx=x-oldX;dy=y-oldY;phi-=Math.sqrt(dx*dx+dy*dy)/radius}stickyNodes.removeIntersecting(x,y,radius,removeIntCb);this.draw();if(bounce&&sounds){sounds.play_bounce()}};function drawBall(){var sx1,sy1,sx2,sy2,dx,dy,i,pct1,pct2,z1,z2;canvas_el.style.left=(x-radius)+'px';canvas_el.style.top=(y-radius)+'px';if(radius!=lastR){canvas_el.width=2*radius+1;canvas_el.height=2*radius+1;lastR=radius}canvas_ctx.clearRect(0,0,2*radius,2*radius);canvas_ctx.fillStyle="#fff";canvas_ctx.beginPath();canvas_ctx.arc(radius,radius,radius-1,0,Math.PI*2,true);canvas_ctx.fill();canvas_ctx.strokeStyle=color;canvas_ctx.beginPath();canvas_ctx.arc(radius,radius,radius-1,0,Math.PI*2,true);canvas_ctx.stroke();canvas_ctx.fillStyle=color;sx1=radius+radius*Math.cos(th+Math.PI/16);sy1=radius+radius*Math.sin(th+Math.PI/16);sx2=radius+radius*Math.cos(th-Math.PI/16);sy2=radius+radius*Math.sin(th-Math.PI/16);dx=(radius+radius*Math.cos(th+Math.PI*15/16))-sx1;dy=(radius+radius*Math.sin(th+Math.PI*15/16))-sy1;for(i=0;i0&&z2>0){canvas_ctx.beginPath();canvas_ctx.moveTo(sx1+pct1*dx,sy1+pct1*dy);canvas_ctx.lineTo(sx1+pct2*dx,sy1+pct2*dy);canvas_ctx.lineTo(sx2+pct2*dx,sy2+pct2*dy);canvas_ctx.lineTo(sx2+pct1*dx,sy2+pct1*dy);canvas_ctx.fill()}}}function drawAttached(att){var oth=th+att.offTh,ophi=phi+att.offPhi,ox=att.r*Math.cos(oth),oy=att.r*Math.sin(oth),dx=(att.r*Math.cos((th-att.offTh)+Math.PI))-ox,dy=(att.r*Math.sin((th-att.offTh)+Math.PI))-oy,pct=(-Math.cos(ophi)+1)/2,cx=ox+pct*dx,cy=oy+pct*dy,oz=att.r*Math.sin(ophi);if(oz<0&&Math.sqrt(cx*cx+cy*cy)+att.diag0)?501:499;att.el.style.setProperty(CSS_TRANSFORM,'translate('+x+'px,'+y+'px) rotate('+th+'rad) scaleX('+Math.cos(ophi)+') '+att.attT,null);return true}function onAttachedRemoved(att){attachedDiv.removeChild(att.el);delete att.el}this.draw=function(){var i,att,numAttachedVisible=0;drawBall();for(i=attached.length;--i>=0;){att=attached[i];if(att.removeRMAX_ATTACHED_VISIBLE){attached.splice(0,i).map(onAttachedRemoved);break}}}}}function preventDefault(event){event.preventDefault();event.returnValue=false;return false}function Game(gameDiv,stickyNodes,ballOpts){var stickyNodes,player1,physicsInterval,resizeInterval,listeners=[];player1=new PlayerBall(gameDiv,stickyNodes,ballOpts,false);player1.init();player1.setXY(300,300);window.scrollTo(0,200);function on_resize(){player1.setDocSize(jQuery(document).width()-5,jQuery(document).height()-5)}on_resize();document.addEventListener('touchstart',function(event){if(event.touches.length===1){player1.setAccel(true);return preventDefault(event)}},true);document.addEventListener('touchmove',function(event){player1.setAccelTarget(event.touches[0].pageX,event.touches[0].pageY)},true);document.addEventListener('touchend',function(event){if(event.touches.length===0){player1.setAccel(false);return preventDefault(event)}},true);if(ballOpts.MOUSEB!==-5){document.addEventListener('mousemove',function(event){player1.setAccelTarget(event.pageX,event.pageY)},true);document.addEventListener('mousedown',function(event){if(event.button===ballOpts.MOUSEB){player1.setAccel(true);return preventDefault(event)}},true);document.addEventListener('mouseup',function(event){if(event.button===ballOpts.MOUSEB){player1.setAccel(false);return preventDefault(event)}},true);if(ballOpts.MOUSEB===0){document.addEventListener('click',function(event){if(event.button===0){return preventDefault(event)}},true)}else if(ballOpts.MOUSEB===2){document.addEventListener('contextmenu',preventDefault,true)}}physicsInterval=setInterval(function(){player1.updatePhysics()},25);resizeInterval=setInterval(on_resize,1000)}function whenAllLoaded(gameDiv,popup,stickyNodes){stickyNodes.finalize(jQuery(document).width(),jQuery(document).height());jQuery('#loadingp').empty();jQuery('').click(function(){var game,ballOpts;ballOpts={color:jQuery('#khcolor').val(),VOL_MULT:parseFloat(jQuery('#vol_mult').val()),MAX_ATTACHED_VISIBLE:parseInt(jQuery('#maxAtt').val(),10),CHECK_VOLS:(jQuery('#checkv').attr('checked'))?true:false,MOUSEB:parseInt(jQuery('#mouseb').val(),10)};gameDiv.removeChild(popup);game=new Game(gameDiv,stickyNodes,ballOpts)}).appendTo('#loadingp')}function buildPopup(gameDiv){var d=document.createElement('div'),b;d.style.cssText='\ +position: fixed;\ +left: 50%;\ +top: 50%;\ +width: 400px;\ +margin-left:-200px;\ +margin-top:-150px;\ +border:1px solid black;\ +background-color:white;\ +color:black;\ +padding:20px;\ +font-size:13px;\ +text-align:left;\ +z-index:501;';d.innerHTML='

\ +\ +Katamari!

\ +\ +

Controls: Hold down to control the ball!

\ +
\ +
\ +
\ +
\ +
\ +

Loading!

';gameDiv.appendChild(d);d.getElementsByTagName('button')[0].addEventListener('click',function(){gameDiv.removeChild(d)},true);return d}function main(){var gameDiv,checkInterval,stickyNodes,popup;gameDiv=document.createElement('div');gameDiv.khIgnore=true;document.body.appendChild(gameDiv);popup=buildPopup(gameDiv);setTimeout(function(){var i,len,el;window.khNodes.addWords(document.body);for(i=0,len=document.body.childNodes.length;i