lkarch.org/tools/flappybird/__game-scripts.js
Lucas Kent e39465ad2f Changes to be committed:
new file:   Files/flashplayer_32_sa.exe
	new file:   favicon.ico
	new file:   globe.gif
	new file:   imgs/download.png
	new file:   imgs/zuck.jpg
	new file:   index.html
	new file:   other.ico
	new file:   script.js
	new file:   site.webmanifest
	new file:   sitemap.html
	new file:   styles/backround.css
	new file:   styles/border.css
	new file:   styles/fonts/Titillium_Web/OFL.txt
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-Black.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-Bold.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-BoldItalic.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-ExtraLight.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-ExtraLightItalic.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-Italic.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-Light.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-LightItalic.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-Regular.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-SemiBold.ttf
	new file:   styles/fonts/Titillium_Web/TitilliumWeb-SemiBoldItalic.ttf
	new file:   styles/fonts/webfontkit-20221027-163353/generator_config.txt
	new file:   styles/fonts/webfontkit-20221027-163353/specimen_files/grid_12-825-55-15.css
	new file:   styles/fonts/webfontkit-20221027-163353/specimen_files/specimen_stylesheet.css
	new file:   styles/fonts/webfontkit-20221027-163353/stylesheet.css
	new file:   styles/fonts/webfontkit-20221027-163353/titilliumweb-extralight-demo.html
	new file:   styles/fonts/webfontkit-20221027-163353/titilliumweb-extralight-webfont.woff
	new file:   styles/fonts/webfontkit-20221027-163353/titilliumweb-extralight-webfont.woff2
	new file:   styles/fonts/webfontkit-20221027-165950/generator_config.txt
	new file:   styles/fonts/webfontkit-20221027-165950/specimen_files/grid_12-825-55-15.css
	new file:   styles/fonts/webfontkit-20221027-165950/specimen_files/specimen_stylesheet.css
	new file:   styles/fonts/webfontkit-20221027-165950/stylesheet.css
	new file:   styles/fonts/webfontkit-20221027-165950/titilliumweb-bold-demo.html
	new file:   styles/fonts/webfontkit-20221027-165950/titilliumweb-bold-webfont.woff
	new file:   styles/fonts/webfontkit-20221027-165950/titilliumweb-bold-webfont.woff2
	new file:   styles/style.css
	new file:   tools/2048/.gitignore
	new file:   tools/2048/.jshintrc
	new file:   tools/2048/CONTRIBUTING.md
	new file:   tools/2048/LICENSE.txt
	new file:   tools/2048/README.md
	new file:   tools/2048/Rakefile
	new file:   tools/2048/favicon.ico
	new file:   tools/2048/index.html
	new file:   tools/2048/js/animframe_polyfill.js
	new file:   tools/2048/js/application.js
	new file:   tools/2048/js/bind_polyfill.js
	new file:   tools/2048/js/classlist_polyfill.js
	new file:   tools/2048/js/game_manager.js
	new file:   tools/2048/js/grid.js
	new file:   tools/2048/js/html_actuator.js
	new file:   tools/2048/js/keyboard_input_manager.js
	new file:   tools/2048/js/local_storage_manager.js
	new file:   tools/2048/js/tile.js
    new file:   tools/2048/meta/apple-touch-icon.png
	new file:   tools/webretro/cores/neocd_libretro.js
	new file:   tools/webretro/cores/neocd_libretro.wasm
	new file:   tools/webretro/cores/nestopia_libretro.js
	new file:   tools/webretro/cores/nestopia_libretro.wasm
	new file:   tools/webretro/cores/o2em_libretro.js
	new file:   tools/webretro/cores/o2em_libretro.wasm
	new file:   tools/webretro/cores/opera_libretro.js
	new file:   tools/webretro/cores/opera_libretro.wasm
2022-11-02 08:40:01 -04:00

1 line
24 KiB
JavaScript

!function(){if("performance"in window==!1&&(window.performance={}),Date.now=Date.now||function(){return(new Date).getTime()},"now"in window.performance==!1){var n=window.performance.timing&&window.performance.timing.navigationStart?window.performance.timing.navigationStart:Date.now();window.performance.now=function(){return Date.now()-n}}}();var TWEEN=TWEEN||function(){var n=[];return{getAll:function(){return n},removeAll:function(){n=[]},add:function(t){n.push(t)},remove:function(t){var r=n.indexOf(t);-1!==r&&n.splice(r,1)},update:function(t){if(0===n.length)return!1;var r=0;for(t=void 0!==t?t:window.performance.now();r<n.length;)n[r].update(t)?r++:n.splice(r,1);return!0}}}();TWEEN.Tween=function(n){var t=n,r={},i={},o={},u=1e3,e=0,a=!1,f=!1,c=!1,s=0,h=null,l=TWEEN.Easing.Linear.None,p=TWEEN.Interpolation.Linear,E=[],w=null,d=!1,I=null,v=null,M=null;for(var m in n)r[m]=parseFloat(n[m],10);this.to=function(n,t){return void 0!==t&&(u=t),i=n,this},this.start=function(n){for(var u in TWEEN.add(this),f=!0,d=!1,h=void 0!==n?n:window.performance.now(),h+=s,i){if(i[u]instanceof Array){if(0===i[u].length)continue;i[u]=[t[u]].concat(i[u])}void 0!==r[u]&&(r[u]=t[u],r[u]instanceof Array==!1&&(r[u]*=1),o[u]=r[u]||0)}return this},this.stop=function(){return f?(TWEEN.remove(this),f=!1,null!==M&&M.call(t),this.stopChainedTweens(),this):this},this.stopChainedTweens=function(){for(var n=0,t=E.length;n<t;n++)E[n].stop()},this.delay=function(n){return s=n,this},this.repeat=function(n){return e=n,this},this.yoyo=function(n){return a=n,this},this.easing=function(n){return l=n,this},this.interpolation=function(n){return p=n,this},this.chain=function(){return E=arguments,this},this.onStart=function(n){return w=n,this},this.onUpdate=function(n){return I=n,this},this.onComplete=function(n){return v=n,this},this.onStop=function(n){return M=n,this},this.update=function(n){var f,M,m;if(n<h)return!0;for(f in!1===d&&(null!==w&&w.call(t),d=!0),m=l(M=(M=(n-h)/u)>1?1:M),i)if(void 0!==r[f]){var T=r[f]||0,g=i[f];g instanceof Array?t[f]=p(g,m):("string"==typeof g&&(g=g.startsWith("+")||g.startsWith("-")?T+parseFloat(g,10):parseFloat(g,10)),"number"==typeof g&&(t[f]=T+(g-T)*m))}if(null!==I&&I.call(t,m),1===M){if(e>0){for(f in isFinite(e)&&e--,o){if("string"==typeof i[f]&&(o[f]=o[f]+parseFloat(i[f],10)),a){var O=o[f];o[f]=i[f],i[f]=O}r[f]=o[f]}return a&&(c=!c),h=n+s,!0}null!==v&&v.call(t);for(var N=0,W=E.length;N<W;N++)E[N].start(h+u);return!1}return!0}},TWEEN.Easing={Linear:{None:function(n){return n}},Quadratic:{In:function(n){return n*n},Out:function(n){return n*(2-n)},InOut:function(n){return(n*=2)<1?.5*n*n:-.5*(--n*(n-2)-1)}},Cubic:{In:function(n){return n*n*n},Out:function(n){return--n*n*n+1},InOut:function(n){return(n*=2)<1?.5*n*n*n:.5*((n-=2)*n*n+2)}},Quartic:{In:function(n){return n*n*n*n},Out:function(n){return 1- --n*n*n*n},InOut:function(n){return(n*=2)<1?.5*n*n*n*n:-.5*((n-=2)*n*n*n-2)}},Quintic:{In:function(n){return n*n*n*n*n},Out:function(n){return--n*n*n*n*n+1},InOut:function(n){return(n*=2)<1?.5*n*n*n*n*n:.5*((n-=2)*n*n*n*n+2)}},Sinusoidal:{In:function(n){return 1-Math.cos(n*Math.PI/2)},Out:function(n){return Math.sin(n*Math.PI/2)},InOut:function(n){return.5*(1-Math.cos(Math.PI*n))}},Exponential:{In:function(n){return 0===n?0:Math.pow(1024,n-1)},Out:function(n){return 1===n?1:1-Math.pow(2,-10*n)},InOut:function(n){return 0===n?0:1===n?1:(n*=2)<1?.5*Math.pow(1024,n-1):.5*(2-Math.pow(2,-10*(n-1)))}},Circular:{In:function(n){return 1-Math.sqrt(1-n*n)},Out:function(n){return Math.sqrt(1- --n*n)},InOut:function(n){return(n*=2)<1?-.5*(Math.sqrt(1-n*n)-1):.5*(Math.sqrt(1-(n-=2)*n)+1)}},Elastic:{In:function(n){var t,r=.1;return 0===n?0:1===n?1:(!r||r<1?(r=1,t=.1):t=.4*Math.asin(1/r)/(2*Math.PI),-r*Math.pow(2,10*(n-=1))*Math.sin((n-t)*(2*Math.PI)/.4))},Out:function(n){var t,r=.1;return 0===n?0:1===n?1:(!r||r<1?(r=1,t=.1):t=.4*Math.asin(1/r)/(2*Math.PI),r*Math.pow(2,-10*n)*Math.sin((n-t)*(2*Math.PI)/.4)+1)},InOut:function(n){var t,r=.1;return 0===n?0:1===n?1:(!r||r<1?(r=1,t=.1):t=.4*Math.asin(1/r)/(2*Math.PI),(n*=2)<1?r*Math.pow(2,10*(n-=1))*Math.sin((n-t)*(2*Math.PI)/.4)*-.5:r*Math.pow(2,-10*(n-=1))*Math.sin((n-t)*(2*Math.PI)/.4)*.5+1)}},Back:{In:function(n){return n*n*(2.70158*n-1.70158)},Out:function(n){return--n*n*(2.70158*n+1.70158)+1},InOut:function(n){var t=2.5949095;return(n*=2)<1?n*n*((t+1)*n-t)*.5:.5*((n-=2)*n*((t+1)*n+t)+2)}},Bounce:{In:function(n){return 1-TWEEN.Easing.Bounce.Out(1-n)},Out:function(n){return n<1/2.75?7.5625*n*n:n<2/2.75?7.5625*(n-=1.5/2.75)*n+.75:n<2.5/2.75?7.5625*(n-=2.25/2.75)*n+.9375:7.5625*(n-=2.625/2.75)*n+.984375},InOut:function(n){return n<.5?.5*TWEEN.Easing.Bounce.In(2*n):.5*TWEEN.Easing.Bounce.Out(2*n-1)+.5}}},TWEEN.Interpolation={Linear:function(n,t){var r=n.length-1,i=r*t,o=Math.floor(i),u=TWEEN.Interpolation.Utils.Linear;return t<0?u(n[0],n[1],i):t>1?u(n[r],n[r-1],r-i):u(n[o],n[o+1>r?r:o+1],i-o)},Bezier:function(n,t){for(var r=0,i=n.length-1,o=Math.pow,u=TWEEN.Interpolation.Utils.Bernstein,e=0;e<=i;e++)r+=o(1-t,i-e)*o(t,e)*n[e]*u(i,e);return r},CatmullRom:function(n,t){var r=n.length-1,i=r*t,o=Math.floor(i),u=TWEEN.Interpolation.Utils.CatmullRom;return n[0]===n[r]?(t<0&&(o=Math.floor(i=r*(1+t))),u(n[(o-1+r)%r],n[o],n[(o+1)%r],n[(o+2)%r],i-o)):t<0?n[0]-(u(n[0],n[0],n[1],n[1],-i)-n[0]):t>1?n[r]-(u(n[r],n[r],n[r-1],n[r-1],i-r)-n[r]):u(n[o?o-1:0],n[o],n[r<o+1?r:o+1],n[r<o+2?r:o+2],i-o)},Utils:{Linear:function(n,t,r){return(t-n)*r+n},Bernstein:function(n,t){var r=TWEEN.Interpolation.Utils.Factorial;return r(n)/r(t)/r(n-t)},Factorial:function(){var n=[1];return function(t){var r=1;if(n[t])return n[t];for(var i=t;i>1;i--)r*=i;return n[t]=r,r}}(),CatmullRom:function(n,t,r,i,o){var u=.5*(r-n),e=.5*(i-t),a=o*o;return(2*t-2*r+u+e)*(o*a)+(-3*t+3*r-2*u-e)*a+u*o+t}}},function(n){"function"==typeof define&&define.amd?define([],function(){return TWEEN}):"undefined"!=typeof module&&"object"==typeof exports?module.exports=TWEEN:void 0!==n&&(n.TWEEN=TWEEN)}(this);var AddToScore=pc.createScript("addToScore");AddToScore.attributes.add("bird",{type:"entity"}),AddToScore.prototype.initialize=function(){this.lastX=this.entity.getPosition().x},AddToScore.prototype.update=function(t){var i=this.app,o=this.bird.getPosition().x,e=this.entity.getPosition().x;e<=o&&this.lastX>o&&i.fire("game:addscore"),this.lastX=e};var Medal=pc.createScript("medal");Medal.attributes.add("blank",{type:"asset",assetType:"material",array:!1}),Medal.attributes.add("bronze",{type:"asset",assetType:"material",array:!1}),Medal.attributes.add("silver",{type:"asset",assetType:"material",array:!1}),Medal.attributes.add("gold",{type:"asset",assetType:"material",array:!1}),Medal.attributes.add("platinum",{type:"asset",assetType:"material",array:!1}),Medal.prototype.initialize=function(){var a=this.app;this.materials={},this.materials.platinum=this.platinum.resource,this.materials.gold=this.gold.resource,this.materials.silver=this.silver.resource,this.materials.bronze=this.bronze.resource,this.materials.blank=this.blank.resource,a.root.findByName("Sparkle").enabled=!1,this.entity.model.material=this.materials.blank,a.on("ui:setmedal",function(e){this.entity.model.material=e>=40?this.materials.platinum:e>=30?this.materials.gold:e>=20?this.materials.silver:e>=10?this.materials.bronze:this.materials.blank,a.root.findByName("Sparkle").enabled=e>=10},this),this.on("enable",function(){a.root.findByName("Sparkle").enabled=!1,this.entity.model.material=this.materials.blank})};function storageAvailable(e){try{var t=window[e],o="__storage_test__";return t.setItem(o,o),t.removeItem(o),!0}catch(e){return!1}}var Game=pc.createScript("game");Game.prototype.initialize=function(){var e=this.app;this.score=0,this.bestScore=0,storageAvailable("localStorage")&&(this.bestScore=localStorage.getItem("Flappy Bird Best Score"),null===this.bestScore&&(this.bestScore=0)),e.on("game:menu",function(){e.fire("screen:fade"),setTimeout(function(){e.root.findByName("Game").findByName("Bird").enabled=!1,e.fire("pipes:reset"),e.fire("ground:start"),e.root.findByName("Game Over Screen").enabled=!1,e.root.findByName("Menu Screen").enabled=!0},250)},this),e.on("game:getready",function(){this.score=0,e.fire("ui:score",this.score),e.fire("screen:fade"),setTimeout(function(){e.root.findByName("Menu Screen").enabled=!1,e.root.findByName("Game Screen").enabled=!0,e.root.findByName("Get Ready").model.enabled=!0,e.root.findByName("Tap").model.enabled=!0;var t=e.root.findByName("Game").findByName("Bird");t.enabled=!0,t.script.bird.reset()},250)},this),e.on("game:play",function(){e.fire("pipes:start"),e.fire("ui:fadegetready")},this),e.on("game:pause",function(){e.root.findByName("Pause Button").enabled=!1,e.root.findByName("Play Button").enabled=!0},this),e.on("game:unpause",function(){e.root.findByName("Pause Button").enabled=!0,e.root.findByName("Play Button").enabled=!1},this),e.on("game:gameover",function(){e.root.findByName("Game Screen").enabled=!1,e.root.findByName("Game Over Screen").enabled=!0,e.root.findByName("New").enabled=this.score>this.bestScore,this.bestScore=Math.max(this.score,this.bestScore),storageAvailable("localStorage")&&localStorage.setItem("Flappy Bird Best Score",this.bestScore.toString()),e.fire("pipes:stop"),e.fire("ground:stop"),e.fire("ui:fade"),e.fire("game:audio","Swoosh"),setTimeout(function(){e.fire("ui:showscoreboard",this.score),e.fire("ui:current",this.score),e.fire("ui:best",this.bestScore),e.fire("game:audio","Swoosh")}.bind(this),500),setTimeout(function(){e.fire("ui:setmedal",this.score)}.bind(this),1e3)},this),e.on("game:addscore",function(){this.score++,e.fire("game:audio","Point"),e.fire("ui:score",this.score)},this),e.on("game:share",function(){var e=screen.width/2-320,t=screen.height/2-190,o="https://twitter.com/intent/tweet?text="+encodeURIComponent("I scored "+this.score+" in Flappy Bird! Beat that! http://flappybird.playcanvas.com/ Powered by @playcanvas #webgl #html5"),i=window.open(o,"name","toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=640, height=380, top="+t+", left="+e);window.focus&&i&&i.focus()},this),e.on("game:audio",function(e){this.entity.sound.play(e)},this)},Game.prototype.update=function(e){TWEEN.update()};var Button=pc.createScript("button");Button.attributes.add("diplacement",{type:"number",default:.00390625}),Button.attributes.add("event",{type:"string"}),Button.prototype.initialize=function(){this.pressed=!1,this.min=new pc.Vec3,this.max=new pc.Vec3,this.mouseDownListener=function(e){this.press(e.clientX,e.clientY)}.bind(this),this.mouseUpListener=function(e){this.release()}.bind(this),this.touchStartListener=function(e){var t=e.changedTouches[0];this.press(t.clientX,t.clientY)}.bind(this),this.touchEndListener=function(e){this.release()}.bind(this),window.addEventListener("mousedown",this.mouseDownListener,{passive:!1}),window.addEventListener("mouseup",this.mouseUpListener,{passive:!1}),window.addEventListener("touchstart",this.touchStartListener,{passive:!1}),window.addEventListener("touchend",this.touchEndListener,{passive:!1}),this.on("enable",function(){window.addEventListener("mousedown",this.mouseDownListener,{passive:!1}),window.addEventListener("mouseup",this.mouseUpListener,{passive:!1}),window.addEventListener("touchstart",this.touchStartListener,{passive:!1}),window.addEventListener("touchend",this.touchEndListener,{passive:!1})}),this.on("disable",function(){this.pressed=!1,window.removeEventListener("mousedown",this.mouseDownListener,{passive:!1}),window.removeEventListener("mouseup",this.mouseUpListener,{passive:!1}),window.removeEventListener("touchstart",this.touchStartListener,{passive:!1}),window.removeEventListener("touchend",this.touchEndListener,{passive:!1})})},Button.prototype.checkForClick=function(e,t){var s=this.app.root.findByName("Camera"),i=this.entity.model.model.meshInstances[0].aabb;return s.camera.worldToScreen(i.getMin(),this.min),s.camera.worldToScreen(i.getMax(),this.max),e>=this.min.x&&e<=this.max.x&&t>=this.max.y&&t<=this.min.y},Button.prototype.press=function(e,t){this.checkForClick(e,t)&&(this.pressed=!0,this.entity.translate(0,-this.diplacement,0))},Button.prototype.release=function(){var e=this.app;this.pressed&&(this.pressed=!1,this.entity.translate(0,this.diplacement,0),e.fire(this.event),e.fire("game:audio","Swoosh"))};var Sparkle=pc.createScript("sparkle");Sparkle.attributes.add("radius",{type:"number",default:1}),Sparkle.prototype.initialize=function(){var i=this.app;this.initialPos=this.entity.getLocalPosition().clone(),i.on("ui:sparkle",function(){var i=Math.random()*Math.PI*2,t=Math.cos(i)*this.radius*Math.random(),a=Math.sin(i)*this.radius*Math.random();this.entity.setLocalPosition(this.initialPos.x+t,this.initialPos.y+a,this.initialPos.z)},this)};var Tween=pc.createScript("tween");Tween.attributes.add("event",{type:"string"}),Tween.attributes.add("duration",{type:"number",default:1}),Tween.attributes.add("startPos",{type:"vec3",default:[0,0,0]}),Tween.attributes.add("endPos",{type:"vec3",default:[0,0,0]}),Tween.attributes.add("startScale",{type:"vec3",default:[1,1,1]}),Tween.attributes.add("endScale",{type:"vec3",default:[1,1,1]}),Tween.attributes.add("easing",{type:"number",enum:[{Linear:0},{Quadratic:1},{Cubic:2},{Quartic:3},{Quintic:4},{Sinusoidal:5},{Exponential:6},{Circular:7},{Elastic:8},{Back:9},{Bounce:10}]}),Tween.attributes.add("inOut",{type:"number",enum:[{In:0},{Out:1},{InOut:2}]});var easingFuncs=[[TWEEN.Easing.Linear.None,TWEEN.Easing.Linear.None,TWEEN.Easing.Linear.None],[TWEEN.Easing.Quadratic.In,TWEEN.Easing.Quadratic.Out,TWEEN.Easing.Quadratic.InOut],[TWEEN.Easing.Cubic.In,TWEEN.Easing.Cubic.Out,TWEEN.Easing.Cubic.InOut],[TWEEN.Easing.Quartic.In,TWEEN.Easing.Quartic.Out,TWEEN.Easing.Quartic.InOut],[TWEEN.Easing.Quintic.In,TWEEN.Easing.Quintic.Out,TWEEN.Easing.Quintic.InOut],[TWEEN.Easing.Sinusoidal.In,TWEEN.Easing.Sinusoidal.Out,TWEEN.Easing.Sinusoidal.InOut],[TWEEN.Easing.Exponential.In,TWEEN.Easing.Exponential.Out,TWEEN.Easing.Exponential.InOut],[TWEEN.Easing.Circular.In,TWEEN.Easing.Circular.Out,TWEEN.Easing.Circular.InOut],[TWEEN.Easing.Elastic.In,TWEEN.Easing.Elastic.Out,TWEEN.Easing.Elastic.InOut],[TWEEN.Easing.Back.In,TWEEN.Easing.Back.Out,TWEEN.Easing.Back.InOut],[TWEEN.Easing.Bounce.In,TWEEN.Easing.Bounce.Out,TWEEN.Easing.Bounce.InOut]];Tween.prototype.initialize=function(){var t=this.app,i=this.entity;this.initialPos=this.entity.getPosition().clone(),this.initialScl=this.entity.getLocalScale().clone(),t.on(this.event,function(){var t={px:this.startPos.x,py:this.startPos.y,pz:this.startPos.z,sx:this.startScale.x,sy:this.startScale.y,sz:this.startScale.z},n={px:this.endPos.x,py:this.endPos.y,pz:this.endPos.z,sx:this.endScale.x,sy:this.endScale.y,sz:this.endScale.z};this.tween=new TWEEN.Tween(t).to(n,Math.floor(1e3*this.duration)).easing(easingFuncs[this.easing][this.inOut]).onUpdate(function(){i.setPosition(this.px,this.py,this.pz),i.setLocalScale(this.sx,this.sy,this.sz)}),this.tween.start()},this),this.on("enable",function(){this.entity.setPosition(this.initialPos),this.entity.setLocalScale(this.initialScl)}),this.on("attr",function(i,n,a){t.fire(this.event)})},Tween.prototype.update=function(t){},Tween.prototype.swap=function(t){};var Bird=pc.createScript("bird");Bird.attributes.add("flapVelocity",{type:"number",default:1}),Bird.attributes.add("gravity",{type:"number",default:5}),Bird.attributes.add("lowestHeight",{type:"number",default:-.25}),Bird.attributes.add("radius",{type:"number",default:.068}),Bird.prototype.initialize=function(){var t=this.app;this.velocity=0,this.state="ready",this.pipes=[],this.circle={x:0,y:0,r:0},this.rect={x:0,y:0,w:0,h:0},this.initialPos=this.entity.getPosition().clone(),this.initialRot=this.entity.getRotation().clone();var i=t.root.findByName("Pipes").findByName("Pipe 1");this.pipes.push(i.findByName("Pipe Up")),this.pipes.push(i.findByName("Pipe Down")),i=t.root.findByName("Pipes").findByName("Pipe 2"),this.pipes.push(i.findByName("Pipe Up")),this.pipes.push(i.findByName("Pipe Down")),t.on("game:pause",function(){this.state="paused"},this),t.on("game:unpause",function(){this.state="play"},this),this.flapListener=this.flap.bind(this),window.addEventListener("mousedown",this.flapListener,{passive:!1}),window.addEventListener("touchstart",this.flapListener,{passive:!1}),this.on("enable",function(){window.addEventListener("mousedown",this.flapListener,{passive:!1}),window.addEventListener("touchstart",this.flapListener,{passive:!1}),this.state="getready"}),this.on("disable",function(){window.removeEventListener("mousedown",this.flapListener,{passive:!1}),window.removeEventListener("touchstart",this.flapListener,{passive:!1})})},Bird.prototype.reset=function(){var t=this.app;this.velocity=0,this.state="getready",this.entity.setPosition(this.initialPos),this.entity.setRotation(this.initialRot),t.fire("bird:flapstart")},Bird.prototype.flap=function(t){var i=this.app;t&&t.preventDefault(),"getready"===this.state&&(i.fire("game:play"),this.state="play"),"play"===this.state&&(i.fire("game:audio","Flap"),this.velocity=this.flapVelocity)},Bird.prototype.die=function(t){var i=this.app;this.state="dead",i.fire("game:audio","Hit"),i.fire("bird:flapstop"),i.fire("game:gameover"),t&&setTimeout(function(){i.fire("game:audio","Die")},500)},Bird.prototype.circleRectangleIntersect=function(t,i){var e=t.x,s=t.y,a=t.r,r=i.x,n=i.y,p=i.w,o=i.h,h=Math.abs(e-r-p/2),d=Math.abs(s-n-o/2);if(h>p/2+a)return!1;if(d>o/2+a)return!1;if(h<=p/2)return!0;if(d<=o/2)return!0;var l=h-p/2,y=d-o/2;return l*l+y*y<=a*a},Bird.prototype.update=function(t){var i=this.app,e="play"===this.state,s="dead"===this.state;e&&i.keyboard.wasPressed(pc.KEY_SPACE)&&this.flap();var a=this.entity.getPosition();if((e||s)&&a.y>=this.lowestHeight){this.velocity-=this.gravity*t,this.entity.translate(0,this.velocity*t,0);var r=pc.math.clamp(this.velocity,-2,-.75);r+=1,this.entity.setLocalEulerAngles(0,0,90*r)}if(e){a.y<this.lowestHeight&&this.die(!1);var n=this.rect,p=this.circle;p.x=a.x,p.y=a.y,p.r=this.radius;for(var o=0;o<this.pipes.length;o++){var h=this.pipes[o],d=h.model.meshInstances[0].aabb,l=d.getMin(),y=d.getMax();n.x=l.x,n.y=l.y,n.w=y.x-l.x,n.h="Pipe Down"===h.name?1e3:y.y-l.y,this.circleRectangleIntersect(p,n)&&this.die(!0)}}};var CameraAspect=pc.createScript("cameraAspect");CameraAspect.prototype.initialize=function(){this.currentOrthoHeight=this.entity.camera.orthoHeight},CameraAspect.prototype.update=function(t){var e=this.app.graphicsDevice.canvas,i=e.width/e.height,r=pc.math.clamp(.72/i,1,1.28);r!==this.currentOrthoHeight&&(this.entity.camera.orthoHeight=r,this.currentOrthoHeight=r)};var Score=pc.createScript("score");function splitNumber(e,t){var a=e.toString();t.length=0;for(var r=0,s=a.length;r<s;r++)t.push(+a.charAt(r))}Score.attributes.add("center",{type:"boolean",default:!1}),Score.attributes.add("name",{type:"string",default:"score"}),Score.attributes.add("zero",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("one",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("two",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("three",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("four",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("five",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("six",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("seven",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("eight",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("nine",{type:"asset",assetType:"material",array:!1}),Score.attributes.add("blank",{type:"asset",assetType:"material",array:!1}),Score.prototype.initialize=function(){var e=this.app,t=["zero","one","two","three","four","five","six","seven","eight","nine","blank"];this.materials=[];for(var a=0,r=t.length;a<r;a++){var s=this[t[a]].resource;this.materials.push(s)}var i=[];e.on("ui:"+this.name,function(e){splitNumber(e,i);i.length;for(var t=this.entity.getChildren().length;i.length<t;)i.unshift(10);for(var a=0;a<t;a++){this.entity.findByName("Digit "+a).model.material=this.materials[i[a]]}},this)};var PipeHeight=pc.createScript("pipeHeight");PipeHeight.prototype.initialize=function(){var i=this.app;this.pipe1=i.root.findByName("Pipe 1"),this.pipe2=i.root.findByName("Pipe 2"),this.pipe3=i.root.findByName("Pipe 3"),this.heights=[],this.heights.push(.75*(Math.random()-.5)),this.heights.push(.75*(Math.random()-.5)),this.heights.push(.75*(Math.random()-.5)),this.setPipeHeights(),i.on("pipes:cycle",function(){this.heights.shift(),this.heights.push(.75*(Math.random()-.5)),this.setPipeHeights()},this)},PipeHeight.prototype.setPipeHeights=function(){var i;i=this.pipe1.getLocalPosition(),this.pipe1.setLocalPosition(i.x,this.heights[0],i.z),i=this.pipe2.getLocalPosition(),this.pipe2.setLocalPosition(i.x,this.heights[1],i.z),i=this.pipe3.getLocalPosition(),this.pipe3.setLocalPosition(i.x,this.heights[2],i.z)};var Sine=pc.createScript("sine");Sine.attributes.add("amplitudeScale",{type:"number",default:1}),Sine.attributes.add("frequencyScale",{type:"number",default:1}),Sine.prototype.initialize=function(){this.timer=0},Sine.prototype.update=function(t){t*=this.frequencyScale,this.timer+=t,this.entity.setLocalPosition(0,Math.sin(this.timer)*this.amplitudeScale,0)};var Scroll=pc.createScript("scroll");Scroll.attributes.add("startEvent",{type:"string",default:"start"}),Scroll.attributes.add("stopEvent",{type:"string",default:"stop"}),Scroll.attributes.add("resetEvent",{type:"string",default:"reset"}),Scroll.attributes.add("cycleEvent",{type:"string",default:"cycle"}),Scroll.attributes.add("startX",{type:"number",default:1}),Scroll.attributes.add("endX",{type:"number",default:-1}),Scroll.attributes.add("speed",{type:"number",default:1}),Scroll.attributes.add("frozen",{type:"boolean",default:!1}),Scroll.prototype.initialize=function(){var t=this.app;this.paused=!1,this.initialPos=this.entity.getPosition().clone(),this.initialRot=this.entity.getRotation().clone(),t.on(this.resetEvent,function(){this.entity.setPosition(this.initialPos),this.entity.setRotation(this.initialRot)},this),t.on(this.startEvent,function(){this.frozen=!1},this),t.on(this.stopEvent,function(){this.frozen=!0},this),t.on("game:pause",function(){this.paused=!0},this),t.on("game:unpause",function(){this.paused=!1},this)},Scroll.prototype.update=function(t){var i=this.app;if(!this.frozen&&!this.paused){var e=this.entity.getLocalPosition();e.x<this.endX&&(this.entity.setLocalPosition(this.startX,e.y,e.z),i.fire(this.cycleEvent)),this.entity.translateLocal(this.speed,0,0)}};var SpriteAnim=pc.createScript("spriteAnim");SpriteAnim.attributes.add("speed",{type:"number",default:1}),SpriteAnim.attributes.add("startEvent",{type:"string",default:"start"}),SpriteAnim.attributes.add("stopEvent",{type:"string",default:"stop"}),SpriteAnim.attributes.add("finishEvent",{type:"string",default:"finish"}),SpriteAnim.prototype.initialize=function(){var t=this.app;this.time=0,this.frozen=!1,this.paused=!1,this.lastFrame=0,t.on(this.startEvent,function(){this.frozen=!1},this),t.on(this.stopEvent,function(){this.frozen=!0},this),t.on("game:pause",function(){this.paused=!0},this),t.on("game:unpause",function(){this.paused=!1},this)},SpriteAnim.prototype.update=function(t){var i=this.app;if(!this.frozen&&!this.paused){this.time+=t;for(var e=this.entity.children,s=Math.floor(this.time*this.speed)%e.length,n=0,a=e.length;n<a;n++)e[n].model.meshInstances[0].visible=s===n;0===s&&0===this.lastFrame&&i.fire(this.finishEvent),this.lastFrame=s}};var Fade=pc.createScript("fade");Fade.attributes.add("event",{type:"string"}),Fade.attributes.add("type",{type:"number",enum:[{In:0},{Out:1},{InOut:2}]}),Fade.attributes.add("duration",{type:"number",default:.25}),Fade.prototype.initialize=function(){var t=this.app;this.timer=0,t.on(this.event,function(){this.timer=this.duration},this)},Fade.prototype.update=function(t){if(this.timer>0){this.timer=Math.max(this.timer-t,0);var e,a=(this.duration-this.timer)/this.duration;switch(this.type){case 0:e=a;break;case 1:e=1-a;break;case 2:e=4*Math.abs((a/2+.25)%.5-.25)}var i=this.entity.model,r=i.enabled;r&&0===e?(i.enabled=!1,e=1):!r&&e>0&&(i.enabled=!0);var d=i.material;d.opacity=e,d.update()}};