text: "use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}var _createClass=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}();window.addEventListener("DOMContentLoaded",function(){new Game("game-canvas")});var Game=function(){function a(b){var c=this;_classCallCheck(this,a);var d=document.getElementById(b);this.engine=new BABYLON.Engine(d,!0),this.scene=new BABYLON.Scene(this.engine),this.spinForce=null,this.sounds=[],this.textures=[],this.canShoot=!1,this.ball=null,window.addEventListener("resize",function(){c.engine.resize()}),this.run()}return _createClass(a,[{key:"run",value:function(){var a=this,b=new BABYLON.AssetsManager(this.scene);b.addMeshTask("stadium","","./assets/","kicker.babylon");var c=[{name:"ambient",path:"assets/sounds/ambient.wav",loop:!0,playOnLoaded:!0,volume:.35},{name:"goal",path:"assets/sounds/goal.wav",loop:!1,playOnLoaded:!1,volume:1.6},{name:"whistle",path:"assets/sounds/whistle.wav",loop:!1,playOnLoaded:!1,volume:.75},{name:"whistle2",path:"assets/sounds/whistle2.wav",loop:!1,playOnLoaded:!1,volume:.75},{name:"kick",path:"assets/sounds/kick.wav",loop:!1,playOnLoaded:!1,volume:1},{name:"wall",path:"assets/sounds/wall.wav",loop:!1,playOnLoaded:!1,volume:1.5},{name:"miss",path:"assets/sounds/miss.wav",loop:!1,playOnLoaded:!1,volume:1.5}];c.forEach(function(c){var d=b.addBinaryFileTask(c.name,c.path);d.onSuccess=function(b){a.sounds[b.name]=new BABYLON.Sound(b.name,b.data,a.scene,function(){a.sounds[b.name].setVolume(c.volume),c.playOnLoaded&&a.sounds[b.name].play()},{loop:c.loop})}});var d=[{name:"ball",path:"assets/gui/ball.png"},{name:"volume",path:"assets/gui/volume.png"},{name:"mute",path:"assets/gui/mute.png"},{name:"touchkick",path:"assets/gui/touchkick.png"}];d.forEach(function(c){var d=b.addTextureTask(c.name,c.path);d.onSuccess=function(b){a.textures[b.name]=b.texture}}),b.onFinish=function(){a._initScene(),a.scene.executeWhenReady(function(){a.engine.runRenderLoop(function(){a.scene.render()})}),a._initGame(),a._initGui()},b.load()}},{key:"_initScene",value:function(){this.scene.enablePhysics();var a=new BABYLON.HemisphericLight("",new BABYLON.Vector3(0,1,0),this.scene);a.intensity+=1;var b=new BABYLON.FreeCamera("camera",new BABYLON.Vector3(-35,9.5,-7),this.scene),c=this.scene.getMeshByName("net");b.setTarget(c.position),b.attachControl(this.scene.getEngine().getRenderingCanvas());var d=BABYLON.Mesh.CreateBox("skyBox",1500,this.scene),e=new BABYLON.StandardMaterial("skyBox",this.scene);e.backFaceCulling=!1,e.reflectionTexture=new BABYLON.CubeTexture("assets/skybox/TropicalSunnyDay",this.scene),e.reflectionTexture.coordinatesMode=BABYLON.Texture.SKYBOX_MODE,e.diffuseColor=new BABYLON.Color3(0,0,0),e.specularColor=new BABYLON.Color3(0,0,0),d.material=e,this.ball=this.scene.getMeshByName("ball"),this.startingPosition=this.ball.position.clone()}},{key:"_initGui",value:function(){var a=this,b=new bGUI.GUISystem(this.scene);b.enableClick();var c=new bGUI.GUIPanel("vol",this.textures.volume,null,b);c.relativePosition(new BABYLON.Vector3(.05,.05,0));var d=new bGUI.GUIPanel("mute",this.textures.mute,null,b);d.relativePosition(new BABYLON.Vector3(.05,.05,0)),d.setVisible(!1),d.onClick=function(){BABYLON.Engine.audioEngine.setGlobalVolume(1),d.setVisible(!1),c.setVisible(!0)},c.onClick=function(){BABYLON.Engine.audioEngine.setGlobalVolume(0),c.setVisible(!1),d.setVisible(!0)};var e=new bGUI.GUIPanel("ball",this.textures.ball,null,b);e.relativePosition(new BABYLON.Vector3(.85,.75,0));var f=new bGUI.GUIPanel("touchkick",this.textures.touchkick,null,b);f.relativePosition(new BABYLON.Vector3(.85,.5,0));var g=new Timer(2e3,this.scene,{autostart:!0,immediate:!0,repeat:-1});g.callback=function(){f.flip(500)},g.onFinish=function(){f.dispose()};var h=null;e.onClick=function(){a.canShoot=!0};var i=BABYLON.Tools.GetPointerPrefix(),j=function(a){return.125*(-a*a+5*a)};this.scene.getEngine().getRenderingCanvas().addEventListener(i+"up",function(){a.canShoot&&!function(){var c=a.scene.pick(a.scene.pointerX,a.scene.pointerY,null,b.getCamera());c.hit&&(h=e.mesh.position.subtract(c.pickedPoint),h=h.divide(e.mesh.scaling).scaleInPlace(2).scaleInPlace(4),h.y*=3,h.z=0),a.spinForce=h.clone(),a.ball.applyImpulse(new BABYLON.Vector3(0,a.spinForce.y,30),a.ball.position.subtract(h)),a.sounds.kick.play(),a.spinForce.z=a.spinForce.y=0;var d=0,f=new Timer(100,a.scene,{autostart:!0,autodestroy:!0,immediate:!0,repeat:10});f.callback=function(){a.spinForce&&(a.ball.applyImpulse(a.spinForce.scale(j(d)),a.ball.position),d+=.4)},f.onFinish=function(){a.spinForce=null},a.canShoot=!1,h=null}()}),b.updateCamera()}},{key:"resetBall",value:function(){this.ball.isInGoal=!1,this.ball.isOut=!1,this.spinForce=null,this.ball.position.copyFrom(this.startingPosition),this.ball.updatePhysicsBodyPosition(),this.ball.body.body.linearVelocity.scaleEqual(0),this.ball.body.body.angularVelocity.scaleEqual(0),this.canShoot=!1}},{key:"_initGame",value:function(){var a=this;this.ball.body=this.ball.setPhysicsState(BABYLON.PhysicsEngine.SphereImpostor,{mass:.41,friction:.2,restitution:.8}),this.scene.registerBeforeRender(function(){a.ball.position.y<=7.6&&a.ball.body.body.linearVelocity.scaleEqual(.97),(a.ball.position.z>30||a.ball.position.z<-3)&&!a.ball.isOut&&(a.ball.isOut=!0,a.sounds.miss.play(),setTimeout(function(){a.resetBall()},1200))});var b=this.scene.getMeshByName("body0");b.isVisible=!1,this.scene.registerBeforeRender(function(){b.intersectsMesh(a.ball)&&!a.ball.isInGoal&&(a.spinForce&&a.spinForce.scaleInPlace(0),a.ball.body.body.linearVelocity.scaleEqual(0),a.ball.body.body.angularVelocity.scaleEqual(0),a.ball.isInGoal=!0,a.sounds.goal.play(),setTimeout(function(){a.resetBall()},1200))});var c=this.scene.getMeshByName("wall"),d=0;this.scene.registerBeforeRender(function(){c.position.x+=.175*Math.cos(d),c.position.y+=.075*Math.cos(1.5*d),d+=.1,c.updatePhysicsBodyPosition(),c.intersectsMesh(a.ball)&&a.sounds.wall.play()})}}]),a}(),_createClass=function(){function a(a,b){for(var c=0;c<b.length;c++){var d=b[c];d.enumerable=d.enumerable||!1,d.configurable=!0,"value"in d&&(d.writable=!0),Object.defineProperty(a,d.key,d)}}return function(b,c,d){return c&&a(b.prototype,c),d&&a(b,d),b}}(),Timer=function(){function a(b,c){var d=this,e=arguments.length<=2||void 0===arguments[2]?{}:arguments[2];_classCallCheck(this,a),this._scene=c,this.maxTime=this.currentTime=b,this.isOver=!1,this.paused=!1,this.started=!1,this.callback=null,this.onFinish=null,this.repeat=e.repeat||1,this.autostart=e.autostart||!1,this.autodestroy=e.autodestroy||!1,this.immediate=e.immediate||!1,this._registeredFunction=function(){!d.started||d.isOver||d.paused||d._update()},c.registerBeforeRender(this._registeredFunction),this.autostart&&this.start()}return _createClass(a,[{key:"reset",value:function(){this.currentTime=this.maxTime,this.isOver=!1,this.started=!1,this.paused=!1}},{key:"start",value:function(){this.started=!0}},{key:"pause",value:function(){this.paused=!0}},{key:"stop",value:function(){this.started=!1,this.reset(),this.autodestroy&&this._destroy()}},{key:"_destroy",value:function(){this._scene.unregisterBeforeRender(this._registeredFunction)}},{key:"resume",value:function(){this.paused=!1}},{key:"_update",value:function(){this.currentTime-=this._scene.getEngine().getDeltaTime(),(this.currentTime<=0||this.immediate)&&(this.immediate=!1,this.isOver=!0,-1!=this.repeat&&this.repeat--,this.callback&&this.callback(),this.repeat>0||-1==this.repeat?(this.reset(),this.start()):(this.onFinish&&this.onFinish(),this.autodestroy&&this._destroy()))}}]),a}();