text: class Lynx2D{constructor(){this.CONTEXT={},this.GAME={RUNNING:!1,DEBUG:!1,DRAW_COLLIDERS:!1,BUFFER:[],UI:[],COLLIDERS:[],EVENTS:[],MOVE_MOUSE_EVENTS:[],GO_MOUSE_EVENTS:[],UI_MOUSE_EVENTS:[],ON_RESIZE_EVENTS:[],LAYER_DRAW_EVENTS:[],LOOPS:[],SCALE:1,INIT:function(t){this.METRICS.DATE=(new Date).getSeconds(),this.METRICS.DATA.COUNTER=new lx.UIMultiText([new lx.UIText("FPS: 0 (0)"),new lx.UIText("UPS: 0 (60)")],25,35,16),t&&(this.SETTINGS.FPS=t),this.RUNNING=!0,this.REQUEST_FRAME()},METRICS:{DATE:0,DATA:{FRAMES:0,UPDATES:0,R_DT:0,U_DT:0,TIMESTAMP:0,P_TIMESTAMP:0},UPDATE:function(){if(this.DATE!=(new Date).getSeconds()){if(this.DATE=(new Date).getSeconds(),lx.GAME.DEBUG){let t=this.DATA.COUNTER.TextLine(0),i=this.DATA.COUNTER.TextLine(1);t.Text("FPS: "+this.DATA.FRAMES+" ("+lx.GAME.SETTINGS.FPS+")"),i.Text("UPS: "+this.DATA.UPDATES+" ("+lx.GAME.SETTINGS.UPS+")");let s=this.DATA.FRAMES-lx.GAME.SETTINGS.FPS,E=this.DATA.UPDATES-lx.GAME.SETTINGS.UPS;s<.2*-lx.GAME.SETTINGS.FPS?t.Color("#ff4d4d"):s<.1*-lx.GAME.SETTINGS.FPS?t.Color("#ff8533"):t.Color("whitesmoke"),E<.2*-lx.GAME.SETTINGS.UPS?i.Color("#ff4d4d"):E<.1*-lx.GAME.SETTINGS.UPS?i.Color("#ff8533"):i.Color("whitesmoke")}this.DATA.FRAMES=0,this.DATA.UPDATES=0}}},LOG:{RECORDED:[],MAX_RECORDS:10,WARNING:function(t,i){this.PRINT(t,i,"orange")},ERROR:function(t,i){this.PRINT(t,i,"red")},PRINT:function(t,i,s){for(let t=0;t<this.RECORDED.length;t++)if(this.RECORDED[t]===i)return;this.RECORDED.push(lx.HASH_CODE(i)),this.RECORDED.length>=this.MAX_RECORDS&&this.RECORDED.splice(0,1);let E=i.stack?i.stack:i;console.log("%c"+t+":%c "+E,"color: "+s+";","")}},SETTINGS:{FPS:60,UPS:60,VSYNC:!1,AA:!0,LIMITERS:{PARTICLES:300}},PHYSICS:{STEPS:60},TIMESTAMP:function(){return window.performance&&window.performance.now?window.performance.now():(new Date).getTime()},CLEAR:function(){lx.CONTEXT.GRAPHICS.clearRect(0,0,lx.CONTEXT.GRAPHICS.canvas.width,lx.CONTEXT.GRAPHICS.canvas.height)},RESET:function(){this.BUFFER=[],this.EVENTS=[],this.UI=[],this.COLLIDERS=[],this.LAYER_DRAW_EVENTS=[],this.LOOPS=[],this.GO_MOUSE_EVENTS=[],this.UI_MOUSE_EVENTS=[],this.ON_RESIZE_EVENTS=[],this.MOVE_MOUSE_EVENTS=[],delete lx.CONTEXT.CONTROLLER.TARGET,delete this.FOCUS},LOOP:function(){if(lx.GAME.RUNNING){lx.GAME.METRICS.DATA.TIMESTAMP=lx.GAME.TIMESTAMP();const t=Math.min(1,(lx.GAME.METRICS.DATA.TIMESTAMP-lx.GAME.METRICS.DATA.P_TIMESTAMP)/1e3);lx.GAME.METRICS.DATA.U_DT+=t,lx.GAME.METRICS.DATA.R_DT+=t;let i=1/lx.GAME.SETTINGS.UPS;for(;lx.GAME.METRICS.DATA.U_DT>=i;)lx.GAME.METRICS.DATA.U_DT-=i,lx.GAME.UPDATE();let s=1/lx.GAME.SETTINGS.FPS;lx.GAME.SETTINGS.VSYNC&&(s=0),lx.GAME.METRICS.DATA.R_DT>=s&&(lx.GAME.METRICS.DATA.R_DT-=s,lx.GAME.RENDER()),lx.GAME.METRICS.DATA.P_TIMESTAMP=lx.GAME.METRICS.DATA.TIMESTAMP}lx.GAME.REQUEST_FRAME()},UPDATE:function(){this.EVENTS.forEach(function(t){if(null!=t&&("key"==t.TYPE&&lx.CONTEXT.CONTROLLER.KEYS[t.EVENT]||"mousebutton"==t.TYPE&&lx.CONTEXT.CONTROLLER.MOUSE.BUTTONS[t.EVENT]))for(let i=0;i<t.CALLBACK.length;i++)if(null!=t.CALLBACK[i])try{let s=lx.CONTEXT.CONTROLLER.MOUSE.POS;if(null!=lx.GAME.FOCUS){let t=lx.GAME.FOCUS.Position(),i=lx.GetDimensions();s=lx.GAME.TRANSLATE_FROM_FOCUS({X:t.X+s.X-i.width,Y:t.Y+s.Y-i.height})}t.CALLBACK[i]({mousePosition:lx.CONTEXT.CONTROLLER.MOUSE.POS,worldPosition:s,state:1})}catch(t){lx.GAME.LOG.ERROR("EventUpdateError",t)}});for(let t=0;t<this.BUFFER.length;t++)if(null!=this.BUFFER[t]){let i=0;for(let s=0;s<this.BUFFER[t].length;s++)if(null!=this.BUFFER[t][s])try{this.BUFFER[t][s].UPDATE(),i++}catch(t){lx.GAME.LOG.ERROR("GameObjectUpdateError",t)}else try{this.BUFFER[t].splice(s,1);for(let i=s;i<this.BUFFER[t].length;i++)null!=this.BUFFER[t][i]&&(this.BUFFER[t][i].BUFFER_ID=i);s--}catch(t){lx.GAME.LOG.ERROR("BufferCleaningError",t)}0==i&&(this.BUFFER[t]=[])}let t={};this.COLLIDERS.forEach(function(i){null!=i&&lx.GAME.COLLIDERS.forEach(function(s){if(null!=s&&i.COLLIDER_ID!=s.COLLIDER_ID&&t[i]!=s)try{s.CHECK_COLLISION(i)&&(t[s]=i)}catch(t){lx.GAME.LOG.ERROR("ColliderUpdateError",t)}})}),this.LOOPS.forEach(function(t){try{t&&"function"==typeof t&&t()}catch(t){lx.GAME.LOG.ERROR("LoopHandleError",t)}}),this.UI.forEach(function(t){try{null!=t&&t.UPDATE()}catch(t){lx.GAME.LOG.ERROR("UIElementUpdateError",t)}}),this.AUDIO.UPDATE(),lx.GAME.SETTINGS.FPS<=0&&(lx.GAME.SETTINGS.FPS=1),this.METRICS.UPDATE(),this.METRICS.DATA.UPDATES++},RENDER:function(){this.CLEAR(),lx.CONTEXT.GRAPHICS.imageSmoothingEnabled=this.SETTINGS.AA;for(let t=0;t<this.BUFFER.length;t++){try{null!=this.BUFFER[t]&&this.BUFFER[t].forEach(function(t){null!=t&&t.RENDER()})}catch(t){lx.GAME.LOG.ERROR("BufferRenderError",t)}try{if(null!=this.LAYER_DRAW_EVENTS[t])for(let i=0;i<this.LAYER_DRAW_EVENTS[t].length;i++)null!=this.LAYER_DRAW_EVENTS[t][i]&&this.LAYER_DRAW_EVENTS[t][i](lx.CONTEXT.GRAPHICS)}catch(t){lx.GAME.LOG.ERROR("LayerDrawEventError",t)}}this.DEBUG&&this.METRICS.DATA.COUNTER.RENDER(),this.DRAW_COLLIDERS&&this.COLLIDERS.forEach(function(t){null!=t&&t.RENDER()});for(let t=0;t<this.UI.length;t++)null!=this.UI[t]&&(null!=this.UI[t].UI_ID?this.UI[t].RENDER():this.UI[t]=void 0);this.METRICS.DATA.FRAMES++},REQUEST_FRAME:function(){window.requestAnimationFrame(lx.GAME.LOOP)},ADD_TO_BUFFER:function(t,i){null==this.BUFFER[i]&&(this.BUFFER[i]=[]);for(let s=0;s<this.BUFFER[i].length+1;s++)if(null==this.BUFFER[i][s])return this.BUFFER[i][s]=t,s},SWITCH_BUFFER_POSITION:function(t,i){if(-1===t.BUFFER_ID||-1===i.BUFFER_ID||t.BUFFER_LAYER!==i.BUFFER_LAYER)return;let s=t.BUFFER_ID;t.BUFFER_ID=i.BUFFER_ID,i.BUFFER_ID=s,this.BUFFER[t.BUFFER_LAYER][t.BUFFER_ID]=t,this.BUFFER[t.BUFFER_LAYER][i.BUFFER_ID]=i},ADD_LOOPS:function(t){if(null==t)return-1;for(let i=0;i<this.LOOPS.length+1;i++)if(null==this.LOOPS[i])return this.LOOPS[i]=t,i},ADD_EVENT:function(t,i,s){for(let E=0;E<this.EVENTS.length;E++)if(null!=this.EVENTS[E]&&this.EVENTS[E].TYPE==t&&this.EVENTS[E].EVENT==i)for(let t=0;t<=this.EVENTS[E].CALLBACK.length;t++)if(null==this.EVENTS[E].CALLBACK[t])return this.EVENTS[E].CALLBACK[t]=s,t;for(let E=0;E<this.EVENTS.length+1;E++)if(null==this.EVENTS[E])return this.EVENTS[E]={TYPE:t,EVENT:i,CALLBACK:[s]},E},INVALIDATE_EVENT:function(t,i){for(let s=0;s<this.EVENTS.length;s++)if(null!=this.EVENTS[s]&&this.EVENTS[s].TYPE==t&&this.EVENTS[s].EVENT==i)for(let t=0;t<this.EVENTS[s].CALLBACK.length;t++)if(null!=this.EVENTS[s].CALLBACK[t]){let i=lx.CONTEXT.CONTROLLER.MOUSE.POS;if(null!=this.FOCUS){let t=this.FOCUS.Position(),s=lx.GetDimensions();i=this.TRANSLATE_FROM_FOCUS({X:t.X+i.X-s.width,Y:t.Y+i.Y-s.height})}this.EVENTS[s].CALLBACK[t]({mousePosition:lx.CONTEXT.CONTROLLER.MOUSE.POS,worldPosition:i,state:0})}},CLEAR_EVENT:function(t,i,s){for(let E=0;E<this.EVENTS.length;E++)if(this.EVENTS[E].TYPE==t&&this.EVENTS[E].EVENT==i)return void(null!=s?this.EVENTS[E].CALLBACK[s]=void 0:this.EVENTS.splice(E,1))},ADD_COLLIDER:function(t){for(let i=0;i<this.COLLIDERS.length+1;i++)if(null==this.COLLIDERS[i])return this.COLLIDERS[i]=t,i},ADD_UI_ELEMENT:function(t){for(let i=0;i<this.UI.length+1;i++)if(null==this.UI[i])return this.UI[i]=t,i},FOCUS_GAMEOBJECT:function(t){this.FOCUS=t},TRANSLATE_FROM_FOCUS:function(t){if(null==this.FOCUS)return t;{let i=this.FOCUS.Position(),s=this.FOCUS.SIZE,E=lx.GetDimensions();return null!=s&&null!=s.W&&null!=s.H||(this.FOCUS.SIZE={W:0,H:0}),{X:Math.floor(Math.round(t.X)-Math.round(i.X)+E.width/(2*this.SCALE)-s.W/2)*this.SCALE,Y:Math.floor(Math.round(t.Y)-Math.round(i.Y)+E.height/(2*this.SCALE)-s.H/2)*this.SCALE}}},UNTRANSLATE_FROM_FOCUS:function(t){if(null==this.FOCUS)return t;{let i=this.FOCUS.Position(),s=this.FOCUS.SIZE,E=lx.GetDimensions();return null!=s&&null!=s.W&&null!=s.H||(this.FOCUS.SIZE={W:0,H:0}),{X:Math.floor(Math.round(t.X)+Math.round(i.X)-E.width/2+s.W/2),Y:Math.floor(Math.round(t.Y)+Math.round(i.Y)-E.height/2+s.H/2)}}},ON_SCREEN:function(t,i){let s=lx.GetDimensions();if(null!=this.FOCUS){let E=this.FOCUS.Position(),h=Math.abs(E.X-t.X),e=Math.abs(E.Y-t.Y);return h<=s.width/2+i.W&&e<=s.height/2+i.H}return t.X+i.W>0&&t.Y+i.H>0&&t.X<s.width&&t.Y<s.height},ADD_LAYER_DRAW_EVENT:function(t,i){null==this.BUFFER[t]&&(this.BUFFER[t]=[]),null==this.LAYER_DRAW_EVENTS[t]&&(this.LAYER_DRAW_EVENTS[t]=[]);for(let s=0;s<this.LAYER_DRAW_EVENTS[t].length+1;s++)if(null==this.LAYER_DRAW_EVENTS[t][s])return this.LAYER_DRAW_EVENTS[t][s]=i,s;return-1},CLEAR_LAYER_DRAW_EVENT:function(t){this.LAYER_DRAW_EVENTS[t]=void 0},AUDIO:{CAN_PLAY:!1,SOUNDS:[],CHANNELS:[],SET_CHANNEL_VOLUME:function(t,i){this.CHANNELS[t]=i},GET_CHANNEL_VOLUME:function(t){return null==this.CHANNELS[t]&&this.SET_CHANNEL_VOLUME(t,1),this.CHANNELS[t]},ADD:function(t,i,s,E){if(this.CAN_PLAY&&""!=t){null==this.CHANNELS[i]&&this.SET_CHANNEL_VOLUME(i,1);for(let h=0;h<=this.SOUNDS.length;h++)if(null==this.SOUNDS[h])return this.SOUNDS[h]={CUR:0,SRC:t,CHANNEL:i,SPATIAL:!1,DELAY:s,LOOPS:E,PLAYING:!1},h}},ADD_SPATIAL:function(t,i,s,E,h){if(this.CAN_PLAY&&""!=i){null==this.CHANNELS[s]&&this.SET_CHANNEL_VOLUME(s,1);for(let e=0;e<=this.SOUNDS.length;e++)if(null==this.SOUNDS[e])return this.SOUNDS[e]={CUR:0,POS:t,SRC:i,SPATIAL:!0,CHANNEL:s,DELAY:E,LOOPS:h,PLAYING:!1},e}},CALCULATE_SPATIAL:function(t,i){t=lx.GAME.TRANSLATE_FROM_FOCUS(t);let s=1-Math.abs(t.X-lx.GetDimensions().width/2)/(lx.GetDimensions().width/2),E=1-Math.abs(t.Y-lx.GetDimensions().height/2)/(lx.GetDimensions().height/2),h=this.CHANNELS[i];return((h*=s>=E?s:E)<0||t.X<0||t.Y<0||t.X>lx.GetDimensions().width||t.Y>lx.GetDimensions().height)&&(h=0),h},UPDATE:function(){if(this.CAN_PLAY)for(let t=0;t<this.SOUNDS.length;t++)if(null!=this.SOUNDS[t])if(this.SOUNDS[t].PLAYING)this.SOUNDS[t].SPATIAL&&(this.SOUNDS[t].AUDIO.volume=this.CALCULATE_SPATIAL(this.SOUNDS[t].POS,this.SOUNDS[t].CHANNEL));else if(this.SOUNDS[t].CUR++,null==this.SOUNDS[t].DELAY||this.SOUNDS[t].CUR>=this.SOUNDS[t].DELAY){let i=new Audio;i.type="audio/mpeg",i.src=this.SOUNDS[t].SRC,i.play_id=t,i.onended=function(){lx.GAME.AUDIO.SOUNDS[this.play_id].LOOPS?lx.GAME.AUDIO.SOUNDS[this.play_id].AUDIO.play():lx.GAME.AUDIO.SOUNDS[this.play_id]=void 0},this.SOUNDS[t].SPATIAL?i.volume=this.CALCULATE_SPATIAL(this.SOUNDS[t].POS,this.SOUNDS[t].CHANNEL):i.volume=this.CHANNELS[this.SOUNDS[t].CHANNEL],this.SOUNDS[t].PLAYING=!0,this.SOUNDS[t].AUDIO=i,this.SOUNDS[t].AUDIO.play()}},REMOVE:function(t){null!=t&&null!=this.SOUNDS[t]&&this.SOUNDS[t].PLAYING&&(this.SOUNDS[t].AUDIO.pause(),this.SOUNDS[t].AUDIO.currentTime=0,this.SOUNDS[t]=void 0)}},ADD_GO_MOUSE_EVENT:function(t,i,s){for(let E=0;E<this.GO_MOUSE_EVENTS.length+1;E++)if(null==this.GO_MOUSE_EVENTS[E])return this.GO_MOUSE_EVENTS[E]={GO:t,BUTTON:i,CALLBACK:s},E;return-1},REMOVE_GO_MOUSE_EVENT:function(t){this.GO_MOUSE_EVENTS[t]=void 0},ADD_UI_MOUSE_EVENT:function(t,i,s){for(let E=0;E<this.UI_MOUSE_EVENTS.length+1;E++)if(null==this.UI_MOUSE_EVENTS[E])return this.UI_MOUSE_EVENTS[E]={UI:t,UI:t,BUTTON:i,CALLBACK:s},E;return-1},REMOVE_UI_MOUSE_EVENT:function(t){this.UI_MOUSE_EVENTS[t]=void 0},HANDLE_MOUSE_CLICK:function(t){for(let i=0;i<this.GO_MOUSE_EVENTS.length;i++){let s=this.GO_MOUSE_EVENTS[i];null!=s&&s.BUTTON==t&&(null==s.GO?this.REMOVE_GO_MOUSE_EVENT(i):lx.GAME.GET_MOUSE_IN_BOX(s.GO.POS,s.GO.SIZE)&&s.CALLBACK({mousePosition:lx.CONTEXT.CONTROLLER.MOUSE.POS,state:1}))}for(let i=0;i<this.UI_MOUSE_EVENTS.length;i++){let s=this.UI_MOUSE_EVENTS[i];null!=s&&s.BUTTON==t&&(null==s.UI?this.REMOVE_UI_MOUSE_EVENT(i):lx.GAME.GET_MOUSE_IN_BOX(s.UI.POS,s.UI.SIZE,null!=s.UI.TARGET)&&s.CALLBACK({mousePosition:lx.GetMousePosition(),state:1}))}},GET_MOUSE_IN_BOX:function(t,i,s){null!=this.FOCUS&&(s||null==s)&&(t=this.TRANSLATE_FROM_FOCUS(t)),i={W:i.W*this.SCALE,H:i.H*this.SCALE};let E=lx.GetMousePosition();return t.X<E.X&&t.X+i.W>E.X&&t.Y<E.Y&&t.Y+i.H>E.Y},ADD_ON_RESIZE_EVENT:function(t){for(let i=0;i<this.ON_RESIZE_EVENTS.length+1;i++)if(null==this.ON_RESIZE_EVENTS[i]){this.ON_RESIZE_EVENTS[i]=t;break}},CREATE_SNAPSHOT:function(){return{BUFFER:this.BUFFER,UI:this.UI,COLLIDERS:this.COLLIDERS,FOCUS:this.FOCUS,EVENTS:this.EVENTS,LOOPS:this.LOOPS,GO_MOUSE_EVENTS:this.GO_MOUSE_EVENTS,MOVE_MOUSE_EVENTS:this.MOVE_MOUSE_EVENTS,LAYER_DRAW_EVENTS:this.LAYER_DRAW_EVENTS,AUDIO_CHANNELS:this.AUDIO.CHANNELS,AUDIO_SOUNDS:this.AUDIO.SOUNDS,CONTROLLER_TARGET:lx.CONTEXT.CONTROLLER.TARGET}},RESTORE_SNAPSHOT:function(t){this.BUFFER=t.BUFFER,this.UI=t.UI,this.COLLIDERS=t.COLLIDERS,this.FOCUS=t.FOCUS,this.EVENTS=t.EVENTS,this.LOOPS=t.LOOPS,this.GO_MOUSE_EVENTS=t.GO_MOUSE_EVENTS,this.MOVE_MOUSE_EVENTS=t.MOVE_MOUSE_EVENTS,this.LAYER_DRAW_EVENTS=t.LAYER_DRAW_EVENTS,this.AUDIO.CHANNELS=t.AUDIO_CHANNELS,this.AUDIO.SOUNDS=t.AUDIO_SOUNDS,lx.CONTEXT.CONTROLLER.TARGET=t.CONTROLLER_TARGET}},this.Initialize=function(t){this.CONTEXT.CANVAS=document.createElement("canvas"),this.CONTEXT.CANVAS.id="lynx-canvas",this.CONTEXT.CANVAS.style="background-color: #282828;",this.CONTEXT.CANVAS.innerHTML="HTML5 canvas not supported on this browser.",this.CONTEXT.CANVAS.oncontextmenu=function(t){return t.preventDefault(),!1},this.CONTEXT.GRAPHICS=this.CONTEXT.CANVAS.getContext("2d");let i="string"==typeof t;return(null==t||i)&&(i&&(document.title=t),t=document.body,this.CONTEXT.CANVAS.style="background-color: #282828; position: absolute; top: 0px; left: 0px;"),t.appendChild(this.CONTEXT.CANVAS),window.onresize=function(){let i=t.offsetWidth,s=t.offsetWidth;t==document.body&&(i=self.innerWidth,s=self.innerHeight);let E=i-lx.CONTEXT.CANVAS.width,h=s-lx.CONTEXT.CANVAS.height;lx.GAME.ON_RESIZE_EVENTS.forEach(function(t){t({dx:E,dy:h,oldWidth:lx.CONTEXT.CANVAS.width,oldHeight:lx.CONTEXT.CANVAS.height,width:i,height:s})}),lx.CONTEXT.CANVAS.width=i,lx.CONTEXT.CANVAS.height=s},window.onresize(),null==this.CONTEXT.CONTROLLER&&this.CreateController(),this},this.Start=function(t){return null==t&&(t=60),this.GAME.INIT(t),this},this.Background=function(t){return null==this.CONTEXT.CANVAS?null!=t?this:void 0:null==t?this.CONTEXT.CANVAS.style.backgroundColor:(this.CONTEXT.CANVAS.style.backgroundColor=t,this)},this.Scale=function(t){if(null==t)return this.GAME.SCALE;this.GAME.SCALE=t},this.GetDimensions=function(){return null==this.CONTEXT.CANVAS?(this.GAME.LOG.ERROR("DimensionRetrievalError","Could not get canvas dimensions, Lynx2D is probably not initialized yet."),{width:0,height:0}):{width:this.CONTEXT.CANVAS.width,height:this.CONTEXT.CANVAS.height}},this.LoadScene=function(t){return this.GAME.RESET(),this.CreateController(),t.CALLBACK(),null!=t.ENGINE_ID&&console.log("ENGINE_INTERACTION_LOAD_SCENE("+t.ENGINE_ID+")"),this},this.CreateController=function(){this.CONTEXT.CONTROLLER={KEYS:[],STOPPED_KEYS:[],MOUSE:{POS:{X:0,Y:0},BUTTONS:[],STOPPED_BUTTONS:[]}},this.GAME.EVENTS=[],this.GAME.MOVE_MOUSE_EVENTS=[],document.addEventListener("keydown",function(t){lx.GAME.AUDIO.CAN_PLAY=!0;let i=String.fromCharCode(t.keyCode).toLowerCase();lx.CONTEXT.CONTROLLER.STOPPED_KEYS[i]||(27===t.keyCode&&(lx.CONTEXT.CONTROLLER.KEYS.escape=!0),lx.CONTEXT.CONTROLLER.KEYS[i]=!0,lx.CONTEXT.CONTROLLER.KEYS[t.keyCode]=!0)}),document.addEventListener("keyup",function(t){let i=String.fromCharCode(t.keyCode).toLowerCase();lx.CONTEXT.CONTROLLER.STOPPED_KEYS[i]||lx.GAME.INVALIDATE_EVENT("key",i),lx.CONTEXT.CONTROLLER.STOPPED_KEYS[i]=!1,27===t.keyCode&&(lx.CONTEXT.CONTROLLER.KEYS.escape=!1),lx.CONTEXT.CONTROLLER.KEYS[i]=!1,lx.CONTEXT.CONTROLLER.KEYS[t.keyCode]=!1}),this.CONTEXT.CANVAS.addEventListener("mousedown",function(t){lx.GAME.AUDIO.CAN_PLAY=!0,lx.CONTEXT.CONTROLLER.MOUSE.STOPPED_BUTTONS[t.button]||(lx.CONTEXT.CONTROLLER.MOUSE.BUTTONS[t.button]=!0,lx.GAME.HANDLE_MOUSE_CLICK(t.button))}),this.CONTEXT.CANVAS.addEventListener("mouseup",function(t){lx.CONTEXT.CONTROLLER.MOUSE.STOPPED_BUTTONS[t.button]||lx.GAME.INVALIDATE_EVENT("mousebutton",t.button),lx.CONTEXT.CONTROLLER.MOUSE.STOPPED_BUTTONS[t.button]=!1,lx.CONTEXT.CONTROLLER.MOUSE.BUTTONS[t.button]=!1}),document.addEventListener("mousemove",function(t){lx.CONTEXT.CONTROLLER.MOUSE.POS={X:t.pageX,Y:t.pageY};let i=lx.GetMousePosition(null!=lx.GAME.FOCUS);for(let t=0;t<lx.GAME.MOVE_MOUSE_EVENTS.length;t++)lx.GAME.MOVE_MOUSE_EVENTS[t]({mousePosition:lx.CONTEXT.CONTROLLER.MOUSE.POS,worldPosition:i})});const t={passive:!0};return this.CONTEXT.CANVAS.addEventListener("touchstart",function(t){lx.GAME.AUDIO.CAN_PLAY=!0;let i=t.touches[0];lx.CONTEXT.CONTROLLER.MOUSE.POS={X:i.pageX,Y:i.pageY},lx.CONTEXT.CONTROLLER.MOUSE.STOPPED_BUTTONS[0]||(lx.CONTEXT.CONTROLLER.MOUSE.BUTTONS[0]=!0,lx.GAME.HANDLE_MOUSE_CLICK(0))},t),this.CONTEXT.CANVAS.addEventListener("touchend",function(t){lx.CONTEXT.CONTROLLER.MOUSE.STOPPED_BUTTONS[0]||lx.GAME.INVALIDATE_EVENT("mousebutton",0),lx.CONTEXT.CONTROLLER.MOUSE.STOPPED_BUTTONS[0]=!1,lx.CONTEXT.CONTROLLER.MOUSE.BUTTONS[0]=!1},t),this},this.GetFocus=function(){return this.GAME.FOCUS},this.ResetFocus=function(){return this.GAME.FOCUS=void 0,this},this.ResetCentering=function(){lx.GAME.LOG.ERROR("OldResetFocusError","The ResetCentering method has been renamed to ResetFocus, for now it will work but this should be changed. Please check the documentation for updated objects and methods."),this.ResetFocus()},this.Debugging=function(t){return null==t?this.GAME.DEBUG:(this.GAME.DEBUG=t,this)},this.Smoothing=function(t){return null==t?this.GAME.SETTINGS.AA:(this.GAME.SETTINGS.AA=t,this)},this.Framerate=function(t){return null==t?this.GAME.SETTINGS.FPS:(this.GAME.SETTINGS.FPS=t,this)},this.VerticalSync=function(t){return null==t?this.GAME.SETTINGS.VSYNC:(this.GAME.SETTINGS.VSYNC=t,this)},this.ParticleLimit=function(t){return null==t?this.GAME.SETTINGS.LIMITERS.PARTICLES:(this.GAME.SETTINGS.LIMITERS.PARTICLES=t,this)},this.ChannelVolume=function(t,i){if(null!=t&&null!=i)this.GAME.AUDIO.SET_CHANNEL_VOLUME(t,i);else if(null!=t)return this.GAME.AUDIO.GET_CHANNEL_VOLUME(t);return this},this.FindGameObjectWithCollider=function(t){for(let i=0;i<this.GAME.BUFFER.length;i++)if(null!=this.GAME.BUFFER[i])for(let s=0;s<this.GAME.BUFFER[i].length;s++)if(null!=this.GAME.BUFFER[i][s]&&null!=this.GAME.BUFFER[i][s].COLLIDER&&this.GAME.BUFFER[i][s].COLLIDER.COLLIDER_ID==t.COLLIDER_ID)return this.GAME.BUFFER[i][s]},this.FindGameObjectWithIdentifier=function(t){for(let i=0;i<this.GAME.BUFFER.length;i++)if(null!=this.GAME.BUFFER[i])for(let s=0;s<this.GAME.BUFFER[i].length;s++)if(null!=this.GAME.BUFFER[i][s]&&null!=this.GAME.BUFFER[i][s].Identifier&&this.GAME.BUFFER[i][s].Identifier()===t)return this.GAME.BUFFER[i][s]},this.FindGameObjectsWithIdentifier=function(t){let i=[];for(let s=0;s<this.GAME.BUFFER.length;s++)if(null!=this.GAME.BUFFER[s]){for(let E=0;E<this.GAME.BUFFER[s].length;E++)null!=this.GAME.BUFFER[s][E]&&null!=this.GAME.BUFFER[s][E].Identifier&&this.GAME.BUFFER[s][E].Identifier()===t&&(i[i.length]=this.GAME.BUFFER[s][E]);return i}},this.OnKey=function(t,i){return isNaN(t)?this.GAME.ADD_EVENT("key",t.toLowerCase(),i):this.GAME.ADD_EVENT("key",t,i),this},this.ClearKey=function(t){return this.GAME.CLEAR_EVENT("key",t.toLowerCase()),this},this.StopKey=function(t){return lx.CONTEXT.CONTROLLER.KEYS[t.toLowerCase()]=!1,lx.CONTEXT.CONTROLLER.STOPPED_KEYS[t.toLowerCase()]=!0,this},this.OnMouse=function(t,i){return this.GAME.ADD_EVENT("mousebutton",t,i),this},this.ClearMouse=function(t){return this.GAME.CLEAR_EVENT("mousebutton",t),this},this.StopMouse=function(t){return lx.CONTEXT.CONTROLLER.MOUSE.BUTTONS[t]=!1,lx.CONTEXT.CONTROLLER.MOUSE.STOPPED_BUTTONS[t]=!0,this},this.OnMouseMove=function(t){return lx.GAME.MOVE_MOUSE_EVENTS.push(t),this},this.ClearMouseMove=function(){return lx.GAME.MOVE_MOUSE_EVENTS=[],this},this.GetMousePosition=function(t){let i=lx.CONTEXT.CONTROLLER.MOUSE.POS;if(t)if(null==lx.GAME.FOCUS)lx.GAME.LOG.ERROR("GetMousePositionError","Cannot get the mouse position in world space when there is no focus target.");else{let t=lx.GAME.FOCUS.Position(),s=lx.GetDimensions();i=lx.GAME.TRANSLATE_FROM_FOCUS({X:t.X+i.X-s.width,Y:t.Y+i.Y-s.height})}return i},this.OnResize=function(t){return this.GAME.ADD_ON_RESIZE_EVENT(t),this},this.ClearResize=function(){this.GAME.ON_RESIZE_EVENTS=[]},this.Loops=function(t){return this.GAME.ADD_LOOPS(t),this},this.ClearLoops=function(){return this.GAME.LOOPS=[],this},this.OnLayerDraw=function(t,i){return this.GAME.ADD_LAYER_DRAW_EVENT(t,i),this},this.ClearLayerDraw=function(t){return this.GAME.CLEAR_LAYER_DRAW_EVENT(t),this},this.ResetLayerDraw=function(){return this.GAME.LAYER_DRAW_EVENTS=[],this},this.DrawSprite=function(t,i,s,E,h){if(null==E||null==h){let i=t.Size();E=i.W,h=i.H}if(lx.GAME.ON_SCREEN({X:i,Y:s},{W:E,H:h}))return t.RENDER(this.GAME.TRANSLATE_FROM_FOCUS({X:i,Y:s}),{W:E,H:h}),this},this.Draw=function(t){t(lx.CONTEXT.GRAPHICS)},this.CreateHorizontalTileSheet=function(t,i,s){let E=[],h=Math.round(t.Size().W/i),e=Math.round(t.Size().H/s);for(let l=0;l<e;l++){null==E[l]&&(E[l]=[]);for(let e=0;e<h;e++)E[l][e]=new lx.Sprite(t.IMG,e*i,l*s,i,s)}return E},this.CreateVerticalTileSheet=function(t,i,s){let E=[],h=Math.round(t.Size().W/i),e=Math.round(t.Size().H/s);for(let l=0;l<h;l++){null==E[l]&&(E[l]=[]);for(let h=0;h<e;h++)E[l][h]=new lx.Sprite(t.IMG,l*i,h*s,i,s)}return E},this.MoveToPosition=function(t,i,s,E){if(t.BEING_MOVED)return;t.BEING_MOVED=!0;let h=t.Position(),e=E/1e3*60,l=i-h.X,n=s-h.Y,T=l/e,o=n/e,r=lx.GAME.ADD_LOOPS(function(){t.Move(T,o),--e<=0&&(lx.GAME.LOOPS[r]=void 0,delete t.BEING_MOVED)})},this.ROTATE_AROUND=function(t,i,s){if(0===s||t.X===i.X&&t.Y===i.Y)return t;let E=Math.sin(s),h=Math.cos(s),e=t.X-i.X,l=t.Y-i.Y,n={X:i.X,Y:i.Y};return n.X+=e*h-l*E,n.Y+=e*E+l*h,n},this.NORMALIZE=function(t){let i=Math.sqrt(t.X*t.X+t.Y*t.Y);return{X:t.X/i,Y:t.Y/i}},this.DOT_PRODUCT=function(t,i){return t.X*i.X+t.Y*i.Y},this.HASH_CODE=function(t){let i=0;for(let s=0;s<t.length;s++){i=(i<<5)-i+t.charCodeAt(s),i&=i}return i};class t{constructor(t,i){this.BUFFER_ID=-1,this.POS={X:null==t?0:t,Y:null==i?0:i},this.OFFSET={X:this.POS.X,Y:this.POS.Y}}Show(t){return-1!=this.BUFFER_ID&&this.Hide(),null==t&&(t=0),this.BUFFER_ID=lx.GAME.ADD_TO_BUFFER(this,t),this.BUFFER_LAYER=t,arguments.length>1&&lx.GAME.LOG.ERROR("ShowOverloadError","Too many arguments were supplied to the Show function, this might indicate that older method calls are present that are not being supported anymore (E.G: Animation Show method). Please check the documentation for updated objects and methods."),this}Hide(){if(-1!=this.BUFFER_ID)return null!=lx.GAME.BUFFER[this.BUFFER_LAYER]&&(lx.GAME.BUFFER[this.BUFFER_LAYER][this.BUFFER_ID]=void 0),this.BUFFER_ID=-1,this}Position(t,i){if(null==t||null==i){if(this.TARGET){let t=this.TARGET.Position();return{X:t.X+this.OFFSET.X,Y:t.Y+this.OFFSET.Y}}return this.POS}{let s=this.Position(),E=t-s.X,h=i-s.Y;this.Move(E,h)}return this}ScreenPosition(){return lx.GAME.TRANSLATE_FROM_FOCUS(this.Position())}Offset(t,i){return null==t||null==i?this.OFFSET:(this.OFFSET={X:t,Y:i},this)}Move(t,i){return this.TARGET||(this.POS.X+=t,this.POS.Y+=i),this.OFFSET.X+=t,this.OFFSET.Y+=i,this}Follows(t){return null==t?this.TARGET:(this.TARGET=t,this)}StopFollowing(){return delete this.TARGET,this}Loops(t){return this.LOOPS=t,this}ClearLoops(){return this.LOOPS=void 0,this}IsVisible(){let t=this.Position(),i={X:0,Y:0};return null!=this.Size&&(i=this.Size()),lx.GAME.ON_SCREEN(t,i)}}class s{constructor(t,i,s,E,h){"number"==typeof s||arguments.length>5?lx.GAME.LOG.ERROR("OldColliderError",'The old arguments (x, y, w, h) were supplied to the revised collider class; which now expects (x, y, vertices[]). The base collider class now functions as a polygon collider, to create the "old" rectangular collider use the BoxCollider class. Please check the documentation for updated objects and methods.'):(this.POS={X:t,Y:i},this.OFFSET={X:0,Y:0},this.ROTATION=0,this.VERTICES=s,this.STATIC=E,this.SOLID=!0,this.ENABLED=!1,this.CALCULATE_CENTER(),this.OnCollide=null!=h?h:function(){},E&&this.Enable())}Size(){let t=1/0,i=-1/0,s=1/0,E=-1/0;for(let h=0;h<this.VERTICES.length;h++){let e=lx.ROTATE_AROUND(this.VERTICES[h],this.CENTER,this.ROTATION);e.X<t&&(t=e.X),e.X>i&&(i=e.X),e.Y<s&&(s=e.Y),e.Y>E&&(E=e.Y)}return{W:Math.abs(t)+Math.abs(i),H:Math.abs(s)+Math.abs(E)}}Static(t){return null==t?this.STATIC:(this.STATIC=t,this)}Solid(t){return null==t?this.SOLID:(this.SOLID=t,this)}Position(t,i){return null==t||null==i?this.POS:(this.POS={X:t,Y:i},this)}Move(t,i){return this.POS.X+=t,this.POS.Y+=i,this}ScreenPosition(){return lx.GAME.TRANSLATE_FROM_FOCUS(this.Position())}Rotation(t){return null==t?this.ROTATION:(this.ROTATION=t,this)}Identifier(t){return null==t?this.IDENTIFIER:(this.IDENTIFIER=t,this)}Enable(){if(!this.ENABLED)return this.COLLIDER_ID=lx.GAME.ADD_COLLIDER(this),this.ENABLED=!0,this}Disable(){if(this.ENABLED)return lx.GAME.COLLIDERS[this.COLLIDER_ID]=void 0,this.COLLIDER_ID=void 0,this.ENABLED=!1,this}CALCULATE_CENTER(){if(0===this.VERTICES.length)return void(this.CENTER={X:0,Y:0});let t=0,i=0;for(let s=0;s<this.VERTICES.length;s++)t+=this.VERTICES[s].X,i+=this.VERTICES[s].Y;this.CENTER={X:t/this.VERTICES.length,Y:i/this.VERTICES.length}}GET_POSITIONED_SHAPE(){let t=[];for(let i=0;i<this.VERTICES.length;i++){let s=lx.ROTATE_AROUND(this.VERTICES[i],this.CENTER,this.ROTATION),E=new SAT.Vector(s.X,s.Y);t.push(E)}return new SAT.Polygon(new SAT.Vector(this.POS.X,this.POS.Y),t)}ON_COLLISION(t,i){this.OnCollide({self:this,trigger:t,direction:i,gameObject:lx.FindGameObjectWithCollider(t),static:t.STATIC,solid:t.SOLID})}GET_COLLISION_DIRECTION(t){let i,s=this.Position(),E=t.Position(),h=this.Size(),e=t.Size();return[{tag:"left",actual:Math.abs(s.X-E.X-e.W)},{tag:"right",actual:Math.abs(E.X-s.X-h.W)},{tag:"up",actual:Math.abs(s.Y-E.Y-e.H)},{tag:"down",actual:Math.abs(E.Y-s.Y-h.H)}].forEach(function(t){(null==i||t.actual<i.actual)&&(i=t)}),i.tag}CHECK_COLLISION(t){if(0!=this.POS.X&&0!=this.POS.Y&&this.POS.X==this.OFFSET.X&&this.POS.Y==this.OFFSET.Y)return!1;if(this.STATIC&&t.STATIC)return;let i=this.GET_POSITIONED_SHAPE(),s=t.GET_POSITIONED_SHAPE(),E=new SAT.Response;if(!SAT.testPolygonPolygon(i,s,E))return!1;let h,e=this.GET_COLLISION_DIRECTION(t);switch(e){case"right":h="left";break;case"left":h="right";break;case"down":h="up";break;case"up":h="down"}if(t.SOLID&&this.SOLID&&!t.STATIC){let i=lx.FindGameObjectWithCollider(t);null!=i&&(i.Move(E.overlapV.x,E.overlapV.y),t.Move(E.overlapV.x,E.overlapV.y))}else if(this.SOLID&&t.SOLID&&!this.STATIC){let t=lx.FindGameObjectWithCollider(this);null!=t&&(t.Move(-E.overlapV.x,-E.overlapV.y),this.Move(-E.overlapV.x,-E.overlapV.y))}return this.ON_COLLISION(t,e),t.ON_COLLISION(this,h),!0}RENDER(){let t=this.GET_POSITIONED_SHAPE().calcPoints;for(let i=0;i<t.length;i++){let s=lx.GAME.TRANSLATE_FROM_FOCUS({X:t[i].x,Y:t[i].y}),E=lx.GAME.TRANSLATE_FROM_FOCUS({X:t[(i+1)%t.length].x,Y:t[(i+1)%t.length].y});lx.CONTEXT.GRAPHICS.save(),lx.CONTEXT.GRAPHICS.beginPath(),lx.CONTEXT.GRAPHICS.moveTo(s.X,s.Y),lx.CONTEXT.GRAPHICS.lineTo(E.X,E.Y),lx.CONTEXT.GRAPHICS.stroke(),lx.CONTEXT.GRAPHICS.restore()}}}this.Animation=class extends t{constructor(t,i){super(0,0),this.SIZE={W:0,H:0},this.SPRITES=t,this.FRAME=0,this.ROTATION=0,this.MAX_FRAMES=t.length,this.TIMER={FRAMES:[],STANDARD:i,CURRENT:0}}ShowAmount(t,i){return null!=i&&(this.MAX_AMOUNT=i-1,this.MAX_AMOUNT<0&&(this.MAX_AMOUNT=0)),super.Show(t)}Size(t,i){if(null==t&&null==i){let t=this.SIZE;return 0===t.width&&0===t.height&&(t=this.GET_CURRENT_FRAME().Size()),t}return null==i&&(i=t),this.SIZE={W:t,H:i},this}Speed(t){return null==t?this.TIMER.STANDARD:(this.TIMER.STANDARD=t,this)}Rotation(t){return null==t?this.ROTATION:(this.ROTATION=t,this)}GET_CURRENT_FRAME(){return this.SPRITES[this.FRAME]}RENDER(t,i,s){let E=this.GET_CURRENT_FRAME();null!=E&&(E.ROTATION=this.ROTATION,lx.CONTEXT.GRAPHICS.save(),null==s&&(s=1),lx.CONTEXT.GRAPHICS.globalAlpha=s,-1===this.BUFFER_ID?E.RENDER(t,i,s):(t=this.Position(),i=this.Size(),lx.GAME.ON_SCREEN(t,i)&&E.RENDER(lx.GAME.TRANSLATE_FROM_FOCUS(t),i,s)),lx.CONTEXT.GRAPHICS.restore())}UPDATE(){this.TIMER.FRAMES.length===this.MAX_FRAMES&&(this.TIMER.STANDARD=this.TIMER.FRAMES[this.FRAME]),this.TIMER.CURRENT++,this.TIMER.CURRENT>=this.TIMER.STANDARD&&(this.TIMER.CURRENT=0,this.FRAME++,this.FRAME>=this.MAX_FRAMES&&(this.FRAME=0,null!=this.MAX_AMOUNT&&(0==this.MAX_AMOUNT?(delete this.MAX_AMOUNT,this.Hide()):this.MAX_AMOUNT--))),null!=this.LOOPS&&this.LOOPS()}},this.Canvas=class{constructor(t,i){this.CANVAS=document.createElement("canvas"),this.CANVAS.width=t,this.CANVAS.height=i,this.GRAPHICS=this.CANVAS.getContext("2d")}Size(){return{W:this.CANVAS.width,H:this.CANVAS.height}}DrawSprite(t,i,s,E,h,e){if(null==E&&null==h){let i=t.Size();E=i.W,h=i.H}null==e&&(e=t.Opacity()),t.RENDER({X:i,Y:s},{W:E,H:h},e,this.GRAPHICS)}Draw(t){t(this.GRAPHICS)}},this.Emitter=class extends t{constructor(t,i,s,E,h){super(i,s),this.SPRITE=t,this.MOVEMENT={MIN_VX:-1,MAX_VX:1,MIN_VY:-1,MAX_VY:1,DECELERATES:!0},this.OFFSET={X:i,Y:s},this.SIZE={MIN:8,MAX:16},this.RANGE={X:1,Y:1},this.TIMER={STANDARD:60,CURRENT:60},this.AMOUNT=E,this.DURATION=h,this.PARTICLES=[]}Setup(t,i,s,E,h,e){return this.MOVEMENT.MIN_VX=t,this.MOVEMENT.MAX_VX=i,this.MOVEMENT.MIN_VY=s,this.MOVEMENT.MAX_VY=E,this.SIZE.MIN=h,this.SIZE.MAX=e,this}Range(t,i){return null==t||null==i?this.RANGE:(this.RANGE={X:t,Y:i},this)}Speed(t){return null==t?this.TIMER.STANDARD:(this.TIMER.STANDARD=t,this)}MovementDecelerates(t){return null==t?this.MOVEMENT.DECELERATES:(this.MOVEMENT.DECELERATES=t,this)}Emit(t,i){return this.TIMER.CURRENT=this.TIMER.STANDARD,this.HIDES_AFTER_AMOUNT=i,this.Show(t),this}RENDER(){for(let t=0;t<this.PARTICLES.length;t++)lx.DrawSprite(this.SPRITE.Opacity(this.PARTICLES[t].OPACITY),this.PARTICLES[t].POS.X,this.PARTICLES[t].POS.Y,this.PARTICLES[t].SIZE,this.PARTICLES[t].SIZE),this.SPRITE.Opacity(1)}UPDATE(){let t=this.Position();for(let t=0;t<this.PARTICLES.length;t++)if(this.PARTICLES[t].TIMER.CURRENT>=this.PARTICLES[t].TIMER.STANDARD)this.PARTICLES.splice(t,1);else{if(this.MOVEMENT.DECELERATES){let i=this.PARTICLES[t].MOVEMENT.START_VX/lx.GAME.PHYSICS.STEPS,s=this.PARTICLES[t].MOVEMENT.START_VY/lx.GAME.PHYSICS.STEPS;this.PARTICLES[t].MOVEMENT.VX>0?this.PARTICLES[t].MOVEMENT.VX-i<0?this.PARTICLES[t].MOVEMENT.VX=0:this.PARTICLES[t].MOVEMENT.VX-=i:this.PARTICLES[t].MOVEMENT.VX<0&&(this.PARTICLES[t].MOVEMENT.VX+i>0?this.PARTICLES[t].MOVEMENT.VX=0:this.PARTICLES[t].MOVEMENT.VX+=i),this.PARTICLES[t].MOVEMENT.VY>0?this.PARTICLES[t].MOVEMENT.VY-s<0?this.PARTICLES[t].MOVEMENT.VY=0:this.PARTICLES[t].MOVEMENT.VY-=s:this.PARTICLES[t].MOVEMENT.VY<0&&(this.PARTICLES[t].MOVEMENT.VY+s>0?this.PARTICLES[t].MOVEMENT.VY=0:this.PARTICLES[t].MOVEMENT.VY+=s)}this.PARTICLES[t].POS.X+=this.PARTICLES[t].MOVEMENT.VX,this.PARTICLES[t].POS.Y+=this.PARTICLES[t].MOVEMENT.VY,this.PARTICLES[t].OPACITY>0&&(this.PARTICLES[t].OPACITY-=1/this.PARTICLES[t].TIMER.STANDARD),this.PARTICLES[t].OPACITY<0&&(this.PARTICLES[t].OPACITY=0),this.PARTICLES[t].TIMER.CURRENT++}if(this.TIMER.CURRENT>=this.TIMER.STANDARD){if(null!=this.HIDES_AFTER_AMOUNT)if(this.HIDES_AFTER_AMOUNT<=0){if(0!==this.PARTICLES.length)return;this.Hide(),this.HIDES_AFTER_AMOUNT=void 0}else this.HIDES_AFTER_AMOUNT--;for(let i=0;i<this.AMOUNT&&!(this.PARTICLES.length>=lx.GAME.SETTINGS.LIMITERS.PARTICLES);i++){let i={POS:{X:t.X-this.SIZE.MAX/2+Math.random()*this.RANGE.X-Math.random()*this.RANGE.X,Y:t.Y-this.SIZE.MAX/2+Math.random()*this.RANGE.Y-Math.random()*this.RANGE.Y},MOVEMENT:{VX:Math.random()*this.MOVEMENT.MIN_VX+Math.random()*this.MOVEMENT.MAX_VX,VY:Math.random()*this.MOVEMENT.MIN_VY+Math.random()*this.MOVEMENT.MAX_VY},TIMER:{STANDARD:this.DURATION,CURRENT:0},SIZE:this.SIZE.MIN+Math.random()*(this.SIZE.MAX-this.SIZE.MIN),OPACITY:1};i.MOVEMENT.START_VX=Math.abs(i.MOVEMENT.VX),i.MOVEMENT.START_VY=Math.abs(i.MOVEMENT.VY),this.PARTICLES.unshift(i)}this.TIMER.CURRENT=0}else this.TIMER.CURRENT++}},this.GameObject=class extends t{constructor(t,i,s,E,h){super(i,s),this.SPRITE=t,this.CLICK_ID=[],this.OPACITY=1,this.SIZE={W:0,H:0},null!=E&&null!=h?this.SIZE={W:E,H:h}:null!=t?this.SIZE=t.Size():lx.GAME.LOG.WARNING("GameObjectViolation","Created a GameObject without a proper size."),this.MOVEMENT={VX:0,VY:0,VMAX_X:2,VMAX_Y:2,WEIGHT:1,DECELERATES:!0,UPDATE:function(){if(this.DECELERATES){let t=this.VMAX_X/(lx.GAME.PHYSICS.STEPS*this.WEIGHT),i=this.VMAX_Y/(lx.GAME.PHYSICS.STEPS*this.WEIGHT);this.VX>0&&(this.VX-t<0?this.VX=0:this.VX-=t),this.VY>0&&(this.VY-i<0?this.VY=0:this.VY-=i),this.VX<0&&(this.VX+t>0?this.VX=0:this.VX+=t),this.VY<0&&(this.VY+i>0?this.VY=0:this.VY+=t)}},APPLY:function(t,i){t>0&&this.VX+t<=this.VMAX_X||t<0&&this.VX+t>=-this.VMAX_X?this.VX+=t:0!=t&&(this.VX+t>this.VMAX_X?this.VX=this.VMAX_X:this.VX+t<-this.VMAX_X&&(this.VX=-this.VMAX_X)),i>0&&this.VY+i<=this.VMAX_Y||i<0&&this.VY+i>=-this.VMAX_Y?this.VY+=i:0!=i&&(this.VY+i>this.VMAX_Y?this.VY=this.VMAX_Y:this.VY+i<-this.VMAX_Y&&(this.VY=-this.VMAX_Y))}}}Show(t){return null!=this.COLLIDER&&this.COLLIDER.Enable(),super.Show(t)}Hide(){return null!=this.COLLIDER&&this.COLLIDER.Disable(),super.Hide()}Sprite(t){return null==t?this.SPRITE:(this.SPRITE=t,this)}Identifier(t){return null==t?this.ID:(this.ID=t,this)}Size(t,i){return null==t&&null==i?this.SIZE:(null==i&&(i=t),this.SIZE={W:t,H:i},this)}Rotation(t){if(null==this.SPRITE&&null==this.ANIMATION)return this;if(null==t){if(null!=this.SPRITE&&null==this.ANIMATION)return this.SPRITE.Rotation();if(null!=this.ANIMATION)return this.ANIMATION.Rotation()}else null!=this.SPRITE&&null==this.ANIMATION?this.SPRITE.Rotation(t):null!=this.ANIMATION&&this.ANIMATION.Rotation(t),null!=this.COLLIDER&&this.COLLIDER.Rotation(t);return this}Opacity(t){return null==t?this.OPACITY:(this.OPACITY=t,this)}Clip(t,i,s,E){if(null==this.SPRITE||null==this.SPRITE)return-1;if(null==this.ANIMATION){if(null==t||null==i||null==s||null==E)return this.SPRITE.Clip();this.SPRITE.Clip(t,i,s,E)}else{if(null==t||null==i||null==s||null==E)return this.ANIMATION.GET_CURRENT_FRAME().Clip();lx.GAME.LOG.ERROR("ClippingError","Clipping while an animation is playing is not possible.")}return this}Focus(){return lx.GAME.FOCUS_GAMEOBJECT(this),this}Movement(t,i){return null==t||null==i?{VX:this.MOVEMENT.VX,VY:this.MOVEMENT.VY}:(this.MOVEMENT.VX=t,this.MOVEMENT.VY=i,this)}AddVelocity(t,i){return this.MOVEMENT.APPLY(t,i),this}MaxVelocity(t,i){return null==t&&null==i?{VX:this.MOVEMENT.VMAX_X,VY:this.MOVEMENT.VMAX_Y}:(this.MOVEMENT.VMAX_Y=this.MOVEMENT.VMAX_X=t,null!=i&&(this.MOVEMENT.VMAX_Y=i),this)}MovementDecelerates(t){return null==t?this.MOVEMENT.DECELERATES:(this.MOVEMENT.DECELERATES=t,this)}Weight(t){return null==t?this.MOVEMENT.WEIGHT:(this.MOVEMENT.WEIGHT=t,this)}SetTopDownController(t,i,s,E){return lx.CONTEXT.CONTROLLER.TARGET=this,lx.OnKey("W",function(){lx.CONTEXT.CONTROLLER.TARGET.AddVelocity(0,-i)}),lx.OnKey("A",function(){lx.CONTEXT.CONTROLLER.TARGET.AddVelocity(-t,0)}),lx.OnKey("S",function(){lx.CONTEXT.CONTROLLER.TARGET.AddVelocity(0,i)}),lx.OnKey("D",function(){lx.CONTEXT.CONTROLLER.TARGET.AddVelocity(t,0)}),this.MaxVelocity(s,E),this}SetSideWaysController(t,i){return lx.CONTEXT.CONTROLLER.TARGET=this,lx.OnKey("A",function(){lx.CONTEXT.CONTROLLER.TARGET.AddVelocity(-t,0)}),lx.OnKey("D",function(){lx.CONTEXT.CONTROLLER.TARGET.AddVelocity(t,0)}),this.MaxVelocity(i),this}CreateCollider(t,i){let s=this.Position(),E=this.Size();return this.COLLIDER=new lx.BoxCollider(s.X,s.Y,E.W,E.H,t,i),this.COLLIDER.OFFSET={X:0,Y:0},this.COLLIDER.Enable(),this}ApplyCollider(t){if(null!=t)return t.ENABLED&&t.Disable(),this.COLLIDER=t,this.COLLIDER.OFFSET={X:t.POS.X,Y:t.POS.Y},this.COLLIDER.Enable(),this}ClearCollider(){if(null!=this.COLLIDER)return this.COLLIDER.Disable(),this.COLLIDER=void 0,this}ShowAnimation(t){return this.ANIMATION=t,this}ClearAnimation(){return this.ANIMATION=void 0,this}ShowColorOverlay(t,i){return null!=this.ANIMATION?this.ANIMATION.GET_CURRENT_FRAME().ShowColorOverlay(t,i):this.SPRITE.ShowColorOverlay(t,i),this}HideColorOverlay(){return this.SPRITE.HideColorOverlay(),this}Draws(t){return this.DRAWS=t,this}ClearDraws(){return this.DRAWS=void 0,this}PreDraws(t){return this.PRE_DRAWS=t,this}ClearPreDraws(){return this.PRE_DRAWS=void 0,this}OnMouse(t,i){return null!=this.CLICK_ID[t]?(lx.GAME.LOG.ERROR("GameObjectMouseError","GameObject already has a click handler for button "+t+"."),this):(this.CLICK_ID[t]=lx.GAME.ADD_GO_MOUSE_EVENT(this,t,i),this)}RemoveMouse(t){return null==this.CLICK_ID[t]?this:(lx.GAME.REMOVE_GO_MOUSE_EVENT(this.CLICK_ID[t]),this)}ClearMouse(){for(let t=0;t<this.CLICK_ID.length;t++)this.RemoveMouse(t)}OnHover(t){return this.ON_HOVER=t,this}OnHoverDraw(t){return this.ON_HOVER_DRAW=t,this}RemoveHover(){return this.ON_HOVER=void 0,this}RemoveHoverDraw(){return this.ON_HOVER_DRAW=void 0,this}RENDER(){let t={X:Math.round(this.Position().X),Y:Math.round(this.Position().Y)},i=this.Size();lx.GAME.ON_SCREEN(t,i)&&(null!=this.PRE_DRAWS&&this.PRE_DRAWS({graphics:lx.CONTEXT.GRAPHICS,position:t,size:i}),null==this.ANIMATION?null!=this.SPRITE&&this.SPRITE.RENDER(lx.GAME.TRANSLATE_FROM_FOCUS(t),i,this.OPACITY):this.ANIMATION.RENDER(lx.GAME.TRANSLATE_FROM_FOCUS(t),i,this.OPACITY),null!=this.ON_HOVER_DRAW&&lx.GAME.GET_MOUSE_IN_BOX(t,i)&&this.ON_HOVER_DRAW({graphics:lx.CONTEXT.GRAPHICS,position:t,size:i}),null!=this.DRAWS&&this.DRAWS({graphics:lx.CONTEXT.GRAPHICS,position:t,size:i}))}UPDATE(){let t=this.Position(),i=this.Size();null!=this.ANIMATION&&this.ANIMATION.UPDATE(),null!=this.LOOPS&&this.LOOPS(),null!=this.ON_HOVER&&lx.GAME.GET_MOUSE_IN_BOX(t,i)&&this.ON_HOVER({position:t,size:i}),this.MOVEMENT.UPDATE(),this.Move(this.MOVEMENT.VX,this.MOVEMENT.VY),null!=this.COLLIDER&&(this.COLLIDER.POS={X:t.X+this.COLLIDER.OFFSET.X,Y:t.Y+this.COLLIDER.OFFSET.Y})}},this.Noise=class{constructor(t){null==t&&(t=Math.round(1e4*Math.random())),this.GRAD=[[1,1],[-1,1],[1,-1],[-1,-1],[1,0],[-1,0],[1,0],[-1,0],[0,1],[0,-1],[0,1],[0,-1]],this.RANDOM=function(){let i=1e4*Math.sin(t++);return i-Math.floor(i)},this.P=[];for(let t=0;t<256;t++)this.P[t]=Math.floor(256*this.RANDOM());this.PERM=[];for(var i=0;i<512;i++)this.PERM[i]=this.P[255&i];this.DOT=function(t,i,s){return t[0]*i+t[1]*s},this.MIX=function(t,i,s){return(1-s)*t+s*i},this.FADE=function(t){return t*t*t*(t*(6*t-15)+10)}}Get(t,i){let s=Math.floor(t),E=Math.floor(i);t-=s,i-=E,s&=255,E&=255;let h=this.PERM[s+this.PERM[E]]%12,e=this.PERM[s+this.PERM[E+1]]%12,l=this.PERM[s+1+this.PERM[E]]%12,n=this.PERM[s+1+this.PERM[E+1]]%12,T=this.DOT(this.GRAD[h],t,i),o=this.DOT(this.GRAD[l],t-1,i),r=this.DOT(this.GRAD[e],t,i-1),A=this.DOT(this.GRAD[n],t-1,i-1),S=this.FADE(t),O=this.FADE(i),R=this.MIX(T,o,S),u=this.MIX(r,A,S);return this.MIX(R,u,O)}},this.Ray=class{constructor(t,i){this.POS={X:t,Y:i},this.DIR={X:0,Y:0}}Position(t,i){return null==t||null==i?this.POS:(this.POS={X:t,Y:i},this)}Direction(t,i){if(null==t||null==i)return this.DIR;{this.DIR={X:t-this.POS.X,Y:i-this.POS.Y};let s=Math.sqrt(this.DIR.X*this.DIR.X+this.DIR.Y*this.DIR.Y);this.DIR.X/=s,this.DIR.Y/=s}return this}Cast(t){return-1!==t.BUFFER_ID&&this.CHECK_INTERSECTION(t)}CastClosest(t){let i,s=1/0;for(let E=0;E<t.length;E++){if(-1===target.BUFFER_ID)continue;let h=this.GET_INTERSECTION(t[E]);null==h||h.TMAX<0||h.TMIN>h.TMAX||h.TMIN<s&&(i=t[E],s=h.TMIN)}return i}CHECK_INTERSECTION(t){let i=this.GET_INTERSECTION(t);return!(null==i||i.TMAX<0||i.TMIN>i.TMAX)}GET_INTERSECTION(t){let i=t.POS.X+t.SIZE.W,s=t.POS.Y+t.SIZE.H,E=(t.POS.X-this.POS.X)*(1/this.DIR.X),h=(i-this.POS.X)*(1/this.DIR.X),e=(t.POS.Y-this.POS.Y)*(1/this.DIR.Y),l=(s-this.POS.Y)*(1/this.DIR.Y);return{TMIN:Math.max(Math.min(E,h),Math.min(e,l)),TMAX:Math.min(Math.max(E,h),Math.max(e,l))}}},this.Scene=class{constructor(t){this.SAVED_STATE_AVAILABLE=!1,this.CALLBACK=t}Save(){let t=lx.GAME.CREATE_SNAPSHOT();this.SAVE_DATA=t,this.SAVED_STATE_AVAILABLE=!0}Restore(){return!!this.SAVED_STATE_AVAILABLE&&(lx.GAME.RESET(),lx.GAME.RESTORE_SNAPSHOT(this.SAVE_DATA),!0)}},this.Sound=class{constructor(t,i){this.SRC=t,this.POS={X:0,Y:0},this.PLAY_ID=[],this.CHANNEL=null!=i?i:0}Channel(t){return null==t?this.CHANNEL:(this.CHANNEL=t,this)}Play(t,i){if(null==this.PLAY_ID||null==lx.GAME.AUDIO.SOUNDS[this.PLAY_ID])return this.PLAY_ID=lx.GAME.AUDIO.ADD(this.SRC,this.CHANNEL,i,t),this}PlaySpatial(t,i){if(null==this.PLAY_ID||null==lx.GAME.AUDIO.SOUNDS[this.PLAY_ID])return this.PLAY_ID=lx.GAME.AUDIO.ADD_SPATIAL(this.POS,this.SRC,this.CHANNEL,i,t),this}Stop(){return null!=this.PLAY_ID&&lx.GAME.AUDIO.REMOVE(this.PLAY_ID),this.PLAY_ID=[],this}Position(t,i){return null==t||null==i?this.POS:(this.POS={X:t,Y:i},this)}},this.Sprite=class{constructor(t,i,s,E,h,e){this.CLIPPED_COLOR_OVERLAYS={},this.SPRITE_SIZE={W:0,H:0},this.ROTATION=0,null!=i&&"function"==typeof i&&(e=i,i=void 0),null==i&&null==s&&null==E&&null==h||(this.CLIP={X:i,Y:s,W:E,H:h}),this.CALLBACK=e,this.Source(t)}Size(){return null!=this.CLIP?{W:this.CLIP.W,H:this.CLIP.H}:(0===this.SPRITE_SIZE.W&&0===this.SPRITE_SIZE.H&&lx.GAME.LOG.WARNING("SpriteAccessViolation",'The size was requested of the sprite "'+this.IMG.src+'", which has not fully loaded yet. It is advised to use a callback method to prevent bugs.'),this.SPRITE_SIZE)}Source(t){if(null==t)return null==this.IMG.src?void lx.GAME.LOG.ERROR("SpriteSourceError","Sprite has no available image source."):this.IMG.src;if("string"===typeof t){this.IMG=new Image;let i=this;this.IMG.onload=function(){i.SPRITE_SIZE.W=i.IMG.width,i.SPRITE_SIZE.H=i.IMG.height,null!=i.CALLBACK&&i.CALLBACK(i)},this.IMG.src=t}else null!=t.CANVAS?(this.IMG=t.CANVAS,this.SPRITE_SIZE.W=t.CANVAS.width,this.SPRITE_SIZE.H=t.CANVAS.height):(this.IMG=t,this.SPRITE_SIZE.W=t.width,this.SPRITE_SIZE.H=t.height);return this}Clip(t,i,s,E){return null==t||null==i||null==s||null==E?this.CLIP:(this.CLIP={X:t,Y:i,W:s,H:E},this)}Rotation(t){return null==t?this.ROTATION:(this.ROTATION=t,this)}Opacity(t){return null==t?this.OPACITY:(this.OPACITY=t,this)}ShowColorOverlay(t,i){return null==this.COLOR_OVERLAY&&null==t?this:(this.SET_COLOR_OVERLAY(t),this.SHOW_COLOR_OVERLAY=!0,this.COLOR_OVERLAY_DURATION=i,this)}HideColorOverlay(){return this.SHOW_COLOR_OVERLAY=!1,this}Image(){return this.IMG}SET_COLOR_OVERLAY(t){if(null!=t){let i=t;if(null!=this.CLIP){let s="C"+t+"X"+this.CLIP.X+"Y"+this.CLIP.Y+"W"+this.CLIP.W+"H"+this.CLIP.H;if(null!=this.CLIPPED_COLOR_OVERLAYS[s])return void(this.COLOR_OVERLAY=this.CLIPPED_COLOR_OVERLAYS[s]);i=s}else{if(null!=this.COLOR_OVERLAY&&this.COLOR_OVERLAY._SAVE_ID===t)return;i=t}let s=this.Size(),E=document.createElement("canvas");E.width=s.W,E.height=s.H;let h=E.getContext("2d");h.fillStyle=t,h.fillRect(0,0,s.W,s.H),h.globalCompositeOperation="destination-atop",this.RENDER({X:0,Y:0},s,1,h),null!=i&&null!=this.CLIP&&(this.CLIPPED_COLOR_OVERLAYS[i]=E),E._SAVE_ID=i,this.COLOR_OVERLAY=E}return this}RENDER(t,i,s,E){let h=!1,e=!1;null==i&&(i=this.Size()),null==E?(E=lx.CONTEXT.GRAPHICS,i={W:i.W*lx.GAME.SCALE,H:i.H*lx.GAME.SCALE}):(E.imageSmoothingEnabled=lx.GAME.SETTINGS.AA,e=!0),null==s&&1==this.OPACITY||(null==s&&(s=this.OPACITY),E.save(),h=!0,E.globalAlpha=s);let l=this.IMG;if(this.SHOW_COLOR_OVERLAY&&(l=this.COLOR_OVERLAY),null==this.CLIP||this.SHOW_COLOR_OVERLAY){let s,n=lx.GetDimensions();!e&&i.W>n.width&&i.H>n.height&&(s={X:0,Y:0,W:n.width/lx.GAME.SCALE,H:n.height/lx.GAME.SCALE},t.X<0?(s.X-=t.X/lx.GAME.SCALE,t.X=0):t.X>0&&(s.W-=t.X/lx.GAME.SCALE),t.Y<0?(s.Y-=t.Y/lx.GAME.SCALE,t.Y=0):t.Y>0&&(s.H-=t.Y/lx.GAME.SCALE)),0===this.ROTATION?null==s?E.drawImage(l,t.X,t.Y,i.W,i.H):E.drawImage(l,s.X,s.Y,s.W,s.H,t.X,t.Y,s.W*lx.GAME.SCALE,s.H*lx.GAME.SCALE):(h||(E.save(),h=!0),E.translate(t.X+i.W/2,t.Y+i.H/2),E.rotate(this.ROTATION),null==s?E.drawImage(l,-i.W/2,-i.H/2,i.W,i.H):E.drawImage(l,s.X,s.Y,s.W,s.H,-s.W*lx.GAME.SCALE/2,-s.H*lx.GAME.SCALE/2,s.W*lx.GAME.SCALE,s.H*lx.GAME.SCALE))}else 0===this.ROTATION?E.drawImage(this.IMG,this.CLIP.X,this.CLIP.Y,this.CLIP.W,this.CLIP.H,t.X,t.Y,i.W,i.H):(h||(E.save(),h=!0),E.translate(t.X+i.W/2,t.Y+i.H/2),E.rotate(this.ROTATION),E.drawImage(this.IMG,this.CLIP.X,this.CLIP.Y,this.CLIP.W,this.CLIP.H,-i.W/2,-i.H/2,i.W,i.H));h&&E.restore(),E==lx.CONTEXT.GRAPHICS&&null!=this.COLOR_OVERLAY_DURATION&&(this.COLOR_OVERLAY_DURATION--,this.COLOR_OVERLAY_DURATION<=0&&this.HideColorOverlay())}},this.BoxCollider=class extends s{constructor(t,i,s,E,h,e){super(t,i,[],h,e),this.SIZE={W:s,H:E},this.CREATE_VERTICES()}Size(t,i){return null==t||null==i?this.SIZE:(this.SIZE={W:t,H:i},this.CREATE_VERTICES(),this)}CREATE_VERTICES(){this.VERTICES=[{X:0,Y:0},{X:this.SIZE.W,Y:0},{X:this.SIZE.W,Y:this.SIZE.H},{X:0,Y:this.SIZE.H}],this.CALCULATE_CENTER()}},this.CircleCollider=class extends s{constructor(t,i,s,E,h){super(t,i,[],E,h),this.COMPLEXITY=12,this.RADIUS=s,this.CREATE_VERTICES()}Complexity(t){return null==t?this.COMPLEXITY:(this.COMPLEXITY=t,this.CREATE_VERTICES(),this)}Radius(t){return null==t?this.RADIUS:(this.RADIUS=t,this.CREATE_VERTICES(),this)}CREATE_VERTICES(){let t=[],i=2*Math.PI;for(let s=0;s<this.COMPLEXITY;s++)t[s]={X:this.RADIUS+this.RADIUS*Math.cos(s/this.COMPLEXITY*i),Y:this.RADIUS+this.RADIUS*Math.sin(s/this.COMPLEXITY*i)};this.VERTICES=t,this.CALCULATE_CENTER()}},this.Collider=class extends s{constructor(t,i,s,E,h){if("number"==typeof s||"number"==typeof E)return lx.GAME.LOG.ERROR("OldColliderError",'The old arguments (x, y, w, h, ..) were supplied to the revised collider class; which now expects (x, y, vertices[], ..). The collider class now functions as a polygon collider, to create the "old" rectangular collider use the BoxCollider class. For now a BoxCollider object has been created, but to hide this error you should change this. Please check the documentation for updated objects and methods.'),new lx.BoxCollider(t,i,arguments[2],arguments[3],arguments[4]);super(t,i,s,E,h)}},this.TriangleCollider=class extends s{constructor(t,i,s,E,h,e){super(t,i,[],h,e),this.SIZE={W:s,H:E},this.CREATE_VERTICES()}Size(t,i){return null==t||null==i?this.SIZE:(this.SIZE={W:t,H:i},this.CREATE_VERTICES(),this)}CREATE_VERTICES(){let t=[{X:0,Y:this.SIZE.H},{X:this.SIZE.W/2,Y:0},{X:this.SIZE.W,Y:this.SIZE.H}];this.VERTICES=t,this.CALCULATE_CENTER()}};class E{constructor(t,i){this.POS={X:null==t?0:t,Y:null==i?0:i},this.OFFSET={X:this.POS.X,Y:this.POS.Y}}Show(){return null!=this.UI_ID?this:(this.UI_ID=lx.GAME.ADD_UI_ELEMENT(this),this)}Hide(){return null==this.UI_ID?this:(delete lx.GAME.UI[this.UI_ID],delete this.UI_ID,this)}Position(t,i){if(null==t||null==i){if(this.TARGET){let t=this.TARGET.Position();return{X:t.X+this.OFFSET.X,Y:t.Y+this.OFFSET.Y}}return this.POS}{let s=this.Position(),E=t-s.X,h=i-s.Y;this.Move(E,h)}return this}ScreenPosition(){return lx.GAME.TRANSLATE_FROM_FOCUS(this.Position())}Offset(t,i){return null==t||null==i?this.OFFSET:(this.OFFSET={X:t,Y:i},this)}Move(t,i){return this.TARGET||(this.POS.X+=t,this.POS.Y+=i),this.OFFSET.X+=t,this.OFFSET.Y+=i,this}Follows(t){return null==t?this.TARGET:(this.TARGET=t,this)}StopFollowing(){return delete this.TARGET,this}Loops(t){return this.LOOPS=t,this}ClearLoops(){return this.LOOPS=void 0,this}}this.UIButton=class extends E{constructor(t,i,s,E,h,e){super(s,E),this.SIZE={W:null==h?128:h,H:null==e?32:e},this.CALLBACK=function(){this.ON_CLICK&&(lx.StopMouse(0),this.ON_CLICK())},this.WAS_FOCUSSED=!1,this.OPACITY=1,this.ON_CLICK=(()=>{}),this.ON_MOUSE_OVER=(()=>{}),this.ON_MOUSE_ENTER=(()=>{}),this.ON_MOUSE_LEAVE=(()=>{}),"string"==typeof t&&(t=new lx.UIText(t)),this.Text(t),"string"==typeof i&&(i=new lx.UITexture(i)),this.Texture(i),null==t&&null==i&&lx.GAME.LOG.WARNING("ButtonViolation","Created a button without a text and texture.")}OnClick(t){return t?(this.ON_CLICK=t,this):this.ON_CLICK}OnMouseOver(t){return t?(this.ON_MOUSE_OVER=t,this):this.ON_MOUSE_OVER}OnMouseEnter(t){return t?(this.ON_MOUSE_ENTER=t,this):this.ON_MOUSE_ENTER}OnMouseLeave(t){return t?(this.ON_MOUSE_LEAVE=t,this):this.ON_MOUSE_LEAVE}Text(t){return null==t?this.TEXT:(this.TEXT=t,this.TEXT.Alignment("center"),this)}Texture(t){return null==t?this.TEXTURE:(this.TEXTURE=t,this)}Size(t,i){return null==t&&null==i?this.SIZE:(null==i&&(i=t),this.SIZE={W:t,H:i},this)}RENDER(){let t=this.Position(),i=this.Size();this.TARGET&&(t=lx.GAME.TRANSLATE_FROM_FOCUS(t)),this.TEXTURE&&this.TEXTURE.RENDER(t,i,this.OPACITY),this.TEXT&&this.TEXT.RENDER({X:t.X+i.W/2,Y:t.Y+i.H/2+this.TEXT.SIZE*(1/3)},this.OPACITY)}UPDATE(){this.LOOPS&&this.LOOPS();let t=this.Position(),i=this.Size(),s=null!=this.TARGET;s&&(t=lx.GAME.TRANSLATE_FROM_FOCUS(t)),lx.GAME.GET_MOUSE_IN_BOX(t,i,s)?(this.WAS_FOCUSSED||this.ON_MOUSE_ENTER(),this.OPACITY=.875,this.WAS_FOCUSSED=!0,document.body.style.cursor="pointer",this.ON_MOUSE_OVER(),lx.CONTEXT.CONTROLLER.MOUSE.BUTTONS[0]&&this.CALLBACK()):this.WAS_FOCUSSED&&(this.OPACITY=1,this.WAS_FOCUSSED=!1,document.body.style.cursor="default",this.ON_MOUSE_LEAVE())}},this.UIMultiText=class extends E{constructor(t,i,s,E,h,e){super(i,s),this.SIZE=null==E?14:E,this.COLOR=null==h?"whitesmoke":h,this.FONT=null==e?"Verdana":e,this.TEXT=t,this.ALIGN="left",this.LINE_HEIGHT=this.SIZE/4}Size(t){return null==t?this.SIZE:(this.SIZE=t,this)}LineHeight(t){return null==t?this.LINE_HEIGHT:(this.LINE_HEIGHT=t,this)}Text(t){return null==t?this.TEXT:(this.TEXT=t,this)}TextLine(t,i){if(null!=t&&null!=i)this.TEXT[t]=i;else if(null!=t)return this.TEXT[t];return this}Alignment(t){return null==t?this.ALIGN:(this.ALIGN=t,this)}Color(t){return null==t?this.COLOR:(this.COLOR=t,this)}Font(t){return null==t?this.FONT:(this.FONT=t,this)}SetShadow(t,i,s){return this.SHADOW={C:t,X:i,Y:s},this}ClearShadow(){return this.SHADOW=void 0,this}RENDER(t,s){t||(t={X:0,Y:0}),null==s&&(s=1);let E=1===lx.GAME.SCALE?1:.75*lx.GAME.SCALE,h=lx.CONTEXT.GRAPHICS;h.save(),h.font=this.SIZE*E+"px "+this.FONT,h.fillStyle=this.COLOR,h.textAlign=this.ALIGN,h.globalAlpha=s,null!=this.SHADOW&&(h.shadowColor=this.SHADOW.C,h.shadowOffsetX=this.SHADOW.X,h.shadowOffsetY=this.SHADOW.Y);let e=0;const l=(t,s,l)=>{switch(typeof t){case"object":try{t.RENDER({X:s,Y:l+e},this.OPACITY),e+=this.LINE_HEIGHT+t.SIZE*E}catch{lx.GAME.LOG.ERROR("MultiTextInvalidLineError","The text line #"+i+" is not a valid UIText object.")}break;default:h.fillText(t,s,l+e),e+=this.LINE_HEIGHT+this.SIZE*E}};let n=this.Position();t.X+=n.X,t.Y+=n.Y,this.TARGET&&(t=lx.GAME.TRANSLATE_FROM_FOCUS(t));for(let i=0;i<this.TEXT.length;i++){l(this.TEXT[i],t.X,t.Y)}h.restore()}UPDATE(){this.LOOPS&&this.LOOPS()}},this.UIRichText=class{constructor(t,i,s,E,h,e){return lx.GAME.LOG.ERROR("OldMultiTextError","The RichText user interface object has been renamed to MultiText. For now a MultiText object has been created, but to hide this error you should change this. Please check the documentation for updated objects and methods."),new lx.UIMultiText(t,i,s,E,h,e)}},this.UIProgressBar=class extends E{constructor(t,i,s,E,h,e){super(s,E),this.BACKGROUND=t||"silver",this.FILLING=i||"whitesmoke",this.PROGRESS=0,this.SIZE={W:128,H:24},null!=h&&null!=e&&(this.SIZE={W:h,H:e})}Size(t,i){return null==t||null==i?this.SIZE:(this.SIZE={W:t,H:i},this)}Progress(t){return null==t?this.PROGRESS:(t<0?t=0:t>100&&(t=100),this.PROGRESS=t,this)}Background(t){return null==t?this.BACKGROUND:(this.BACKGROUND=t,this)}Filling(t){return null==t?this.FILLING:(this.FILLING=t,this)}RENDER(t,i,s){t||(t={X:0,Y:0}),i||(i=this.Size()),null==s&&(s=1);let E=this.Position();t.X+=E.X,t.Y+=E.Y;let h=lx.Scale(),e={W:i.W*h,H:i.H*h};this.TARGET&&(t=lx.GAME.TRANSLATE_FROM_FOCUS(t)),"string"==typeof this.BACKGROUND?(lx.CONTEXT.GRAPHICS.save(),lx.CONTEXT.GRAPHICS.fillStyle=this.BACKGROUND,lx.CONTEXT.GRAPHICS.globalAlpha=s,lx.CONTEXT.GRAPHICS.fillRect(t.X,t.Y,e.W,e.H),lx.CONTEXT.GRAPHICS.restore()):this.BACKGROUND.RENDER(t,i,s);let l=this.PROGRESS/100;"string"==typeof this.FILLING?(lx.CONTEXT.GRAPHICS.save(),lx.CONTEXT.GRAPHICS.fillStyle=this.FILLING,lx.CONTEXT.GRAPHICS.globalAlpha=s,lx.CONTEXT.GRAPHICS.fillRect(t.X,t.Y,e.W*l,e.H),lx.CONTEXT.GRAPHICS.restore()):this.FILLING.RENDER(t,{W:i.W*l,H:i.H},s)}UPDATE(){null!=this.LOOPS&&this.LOOPS()}},this.UIText=class extends E{constructor(t,i,s,E,h,e){super(i,s),this.TEXT=t,this.ALIGN="left",this.SIZE=null==E?14:E,this.COLOR=null==h?"whitesmoke":h,this.FONT=null==e?"Verdana":e}Size(t){return null==t?this.SIZE:(this.SIZE=t,this)}Text(t){return null==t?this.TEXT:(this.TEXT=t,this)}Alignment(t){return null==t?this.ALIGN:(this.ALIGN=t,this)}Color(t){return null==t?this.COLOR:(this.COLOR=t,this)}Font(t){return null==t?this.FONT:(this.FONT=t,this)}SetShadow(t,i,s){return this.SHADOW={C:t,X:i,Y:s},this}ClearShadow(){return this.SHADOW=void 0,this}RENDER(t,i){t||(t={X:0,Y:0}),null==i&&(i=1);let s=1===lx.GAME.SCALE?1:.75*lx.GAME.SCALE;lx.CONTEXT.GRAPHICS.save(),lx.CONTEXT.GRAPHICS.font=this.SIZE*s+"px "+this.FONT,lx.CONTEXT.GRAPHICS.fillStyle=this.COLOR,lx.CONTEXT.GRAPHICS.textAlign=this.ALIGN,lx.CONTEXT.GRAPHICS.globalAlpha=i,this.SHADOW&&(lx.CONTEXT.GRAPHICS.shadowColor=this.SHADOW.C,lx.CONTEXT.GRAPHICS.shadowOffsetX=this.SHADOW.X,lx.CONTEXT.GRAPHICS.shadowOffsetY=this.SHADOW.Y);let E=this.Position();t.X+=E.X,t.Y+=E.Y,this.TARGET&&(t=lx.GAME.TRANSLATE_FROM_FOCUS(t)),lx.CONTEXT.GRAPHICS.fillText(this.TEXT,t.X,t.Y),lx.CONTEXT.GRAPHICS.restore()}UPDATE(){this.LOOPS&&this.LOOPS()}},this.UITexture=class extends E{constructor(t,i,s,E,h){super(i,s),this.SPRITE=t,this.SIZE={W:0,H:0},null!=E&&null!=h?this.SIZE={W:E,H:h}:"string"!=typeof t&&(this.SIZE=t.Size())}Size(t,i){return null==t?this.SIZE:(null==i&&(i=t),this.SIZE={W:t,H:i},this)}RENDER(t,i,s){t||(t={X:0,Y:0}),i||(i=this.Size()),null==s&&(s=1);let E=this.Position();t.X+=E.X,t.Y+=E.Y;let h=lx.Scale(),e={W:i.W*h,H:i.H*h};this.TARGET&&(t=lx.GAME.TRANSLATE_FROM_FOCUS(t)),"string"==typeof this.SPRITE?(lx.CONTEXT.GRAPHICS.save(),lx.CONTEXT.GRAPHICS.fillStyle=this.SPRITE,lx.CONTEXT.GRAPHICS.globalAlpha=s,lx.CONTEXT.GRAPHICS.fillRect(t.X,t.Y,e.W,e.H),lx.CONTEXT.GRAPHICS.restore()):this.SPRITE.RENDER(t,i,s)}UPDATE(){this.LOOPS&&this.LOOPS()}}}}!function(t,i){"use strict";"function"==typeof define&&define.amd?define(i):"object"==typeof exports?module.exports=i():t.SAT=i()}(this,function(){"use strict";var t={};function i(t,i){this.x=t||0,this.y=i||0}function s(t,s){this.pos=t||new i,this.r=s||0,this.offset=new i}function E(t,s){this.pos=t||new i,this.angle=0,this.offset=new i,this.setPoints(s||[])}function h(t,s,E){this.pos=t||new i,this.w=s||0,this.h=E||0}function e(){this.a=null,this.b=null,this.overlapN=new i,this.overlapV=new i,this.clear()}t.Vector=i,t.V=i,i.prototype.copy=i.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this},i.prototype.clone=i.prototype.clone=function(){return new i(this.x,this.y)},i.prototype.perp=i.prototype.perp=function(){var t=this.x;return this.x=this.y,this.y=-t,this},i.prototype.rotate=i.prototype.rotate=function(t){var i=this.x,s=this.y;return this.x=i*Math.cos(t)-s*Math.sin(t),this.y=i*Math.sin(t)+s*Math.cos(t),this},i.prototype.reverse=i.prototype.reverse=function(){return this.x=-this.x,this.y=-this.y,this},i.prototype.normalize=i.prototype.normalize=function(){var t=this.len();return t>0&&(this.x=this.x/t,this.y=this.y/t),this},i.prototype.add=i.prototype.add=function(t){return this.x+=t.x,this.y+=t.y,this},i.prototype.sub=i.prototype.sub=function(t){return this.x-=t.x,this.y-=t.y,this},i.prototype.scale=i.prototype.scale=function(t,i){return this.x*=t,this.y*=void 0!==i?i:t,this},i.prototype.project=i.prototype.project=function(t){var i=this.dot(t)/t.len2();return this.x=i*t.x,this.y=i*t.y,this},i.prototype.projectN=i.prototype.projectN=function(t){var i=this.dot(t);return this.x=i*t.x,this.y=i*t.y,this},i.prototype.reflect=i.prototype.reflect=function(t){var i=this.x,s=this.y;return this.project(t).scale(2),this.x-=i,this.y-=s,this},i.prototype.reflectN=i.prototype.reflectN=function(t){var i=this.x,s=this.y;return this.projectN(t).scale(2),this.x-=i,this.y-=s,this},i.prototype.dot=i.prototype.dot=function(t){return this.x*t.x+this.y*t.y},i.prototype.len2=i.prototype.len2=function(){return this.dot(this)},i.prototype.len=i.prototype.len=function(){return Math.sqrt(this.len2())},t.Circle=s,s.prototype.getAABB=s.prototype.getAABB=function(){var t=this.r;return new h(this.pos.clone().add(this.offset).sub(new i(t,t)),2*t,2*t).toPolygon()},s.prototype.setOffset=s.prototype.setOffset=function(t){return this.offset=t,this},t.Polygon=E,E.prototype.setPoints=E.prototype.setPoints=function(t){if(!this.points||this.points.length!==t.length){var s,E=this.calcPoints=[],h=this.edges=[],e=this.normals=[];for(s=0;s<t.length;s++){var l=t[s],n=s<t.length-1?t[s+1]:t[0];l===n||l.x!==n.x||l.y!==n.y?(E.push(new i),h.push(new i),e.push(new i)):(t.splice(s,1),s-=1)}}return this.points=t,this._recalc(),this},E.prototype.setAngle=E.prototype.setAngle=function(t){return this.angle=t,this._recalc(),this},E.prototype.setOffset=E.prototype.setOffset=function(t){return this.offset=t,this._recalc(),this},E.prototype.rotate=E.prototype.rotate=function(t){for(var i=this.points,s=i.length,E=0;E<s;E++)i[E].rotate(t);return this._recalc(),this},E.prototype.translate=E.prototype.translate=function(t,i){for(var s=this.points,E=s.length,h=0;h<E;h++)s[h].x+=t,s[h].y+=i;return this._recalc(),this},E.prototype._recalc=function(){var t,i=this.calcPoints,s=this.edges,E=this.normals,h=this.points,e=this.offset,l=this.angle,n=h.length;for(t=0;t<n;t++){var T=i[t].copy(h[t]);T.x+=e.x,T.y+=e.y,0!==l&&T.rotate(l)}for(t=0;t<n;t++){var o=i[t],r=t<n-1?i[t+1]:i[0],A=s[t].copy(r).sub(o);E[t].copy(A).perp().normalize()}return this},E.prototype.getAABB=E.prototype.getAABB=function(){for(var t=this.calcPoints,s=t.length,E=t[0].x,e=t[0].y,l=t[0].x,n=t[0].y,T=1;T<s;T++){var o=t[T];o.x<E?E=o.x:o.x>l&&(l=o.x),o.y<e?e=o.y:o.y>n&&(n=o.y)}return new h(this.pos.clone().add(new i(E,e)),l-E,n-e).toPolygon()},E.prototype.getCentroid=E.prototype.getCentroid=function(){for(var t=this.calcPoints,s=t.length,E=0,h=0,e=0,l=0;l<s;l++){var n=t[l],T=l===s-1?t[0]:t[l+1],o=n.x*T.y-T.x*n.y;E+=(n.x+T.x)*o,h+=(n.y+T.y)*o,e+=o}return new i(E/=e*=3,h/=e)},t.Box=h,h.prototype.toPolygon=h.prototype.toPolygon=function(){var t=this.pos,s=this.w,h=this.h;return new E(new i(t.x,t.y),[new i,new i(s,0),new i(s,h),new i(0,h)])},t.Response=e,e.prototype.clear=e.prototype.clear=function(){return this.aInB=!0,this.bInA=!0,this.overlap=Number.MAX_VALUE,this};for(var l=[],n=0;n<10;n++)l.push(new i);var T=[];for(n=0;n<5;n++)T.push([]);var o=new e,r=new h(new i,1e-6,1e-6).toPolygon();function A(t,i,s){for(var E=Number.MAX_VALUE,h=-Number.MAX_VALUE,e=t.length,l=0;l<e;l++){var n=t[l].dot(i);n<E&&(E=n),n>h&&(h=n)}s[0]=E,s[1]=h}function S(t,i,s,E,h,e){var n=T.pop(),o=T.pop(),r=l.pop().copy(i).sub(t),S=r.dot(h);if(A(s,h,n),A(E,h,o),o[0]+=S,o[1]+=S,n[0]>o[1]||o[0]>n[1])return l.push(r),T.push(n),T.push(o),!0;if(e){var O,R,u=0;if(n[0]<o[0])if(e.aInB=!1,n[1]<o[1])u=n[1]-o[0],e.bInA=!1;else u=(O=n[1]-o[0])<(R=o[1]-n[0])?O:-R;else if(e.bInA=!1,n[1]>o[1])u=n[0]-o[1],e.aInB=!1;else u=(O=n[1]-o[0])<(R=o[1]-n[0])?O:-R;var C=Math.abs(u);C<e.overlap&&(e.overlap=C,e.overlapN.copy(h),u<0&&e.overlapN.reverse())}return l.push(r),T.push(n),T.push(o),!1}function O(t,i){var s=t.len2(),E=i.dot(t);return E<0?R:E>s?C:u}t.isSeparatingAxis=S;var R=-1,u=0,C=1;function N(t,i,s){for(var E=l.pop().copy(i.pos).add(i.offset).sub(t.pos),h=i.r,e=h*h,n=t.calcPoints,T=n.length,o=l.pop(),r=l.pop(),A=0;A<T;A++){var S=A===T-1?0:A+1,u=0===A?T-1:A-1,N=0,I=null;o.copy(t.edges[A]),r.copy(E).sub(n[A]),s&&r.len2()>e&&(s.aInB=!1);var M=O(o,r);if(M===R){o.copy(t.edges[u]);var L=l.pop().copy(E).sub(n[u]);if((M=O(o,L))===C){if((_=r.len())>h)return l.push(E),l.push(o),l.push(r),l.push(L),!1;s&&(s.bInA=!1,I=r.normalize(),N=h-_)}l.push(L)}else if(M===C){if(o.copy(t.edges[S]),r.copy(E).sub(n[S]),(M=O(o,r))===R){if((_=r.len())>h)return l.push(E),l.push(o),l.push(r),!1;s&&(s.bInA=!1,I=r.normalize(),N=h-_)}}else{var a=o.perp().normalize(),_=r.dot(a),D=Math.abs(_);if(_>0&&D>h)return l.push(E),l.push(a),l.push(r),!1;s&&(I=a,N=h-_,(_>=0||N<2*h)&&(s.bInA=!1))}I&&s&&Math.abs(N)<Math.abs(s.overlap)&&(s.overlap=N,s.overlapN.copy(I))}return s&&(s.a=t,s.b=i,s.overlapV.copy(s.overlapN).scale(s.overlap)),l.push(E),l.push(o),l.push(r),!0}function I(t,i,s){for(var E=t.calcPoints,h=E.length,e=i.calcPoints,l=e.length,n=0;n<h;n++)if(S(t.pos,i.pos,E,e,t.normals[n],s))return!1;for(n=0;n<l;n++)if(S(t.pos,i.pos,E,e,i.normals[n],s))return!1;return s&&(s.a=t,s.b=i,s.overlapV.copy(s.overlapN).scale(s.overlap)),!0}return t.pointInCircle=function(t,i){var s=l.pop().copy(t).sub(i.pos).sub(i.offset),E=i.r*i.r,h=s.len2();return l.push(s),h<=E},t.pointInPolygon=function(t,i){r.pos.copy(t),o.clear();var s=I(r,i,o);return s&&(s=o.aInB),s},t.testCircleCircle=function(t,i,s){var E=l.pop().copy(i.pos).add(i.offset).sub(t.pos).sub(t.offset),h=t.r+i.r,e=h*h,n=E.len2();if(n>e)return l.push(E),!1;if(s){var T=Math.sqrt(n);s.a=t,s.b=i,s.overlap=h-T,s.overlapN.copy(E.normalize()),s.overlapV.copy(E).scale(s.overlap),s.aInB=t.r<=i.r&&T<=i.r-t.r,s.bInA=i.r<=t.r&&T<=t.r-i.r}return l.push(E),!0},t.testPolygonCircle=N,t.testCirclePolygon=function(t,i,s){var E=N(i,t,s);if(E&&s){var h=s.a,e=s.aInB;s.overlapN.reverse(),s.overlapV.reverse(),s.a=s.b,s.b=h,s.aInB=s.bInA,s.bInA=e}return E},t.testPolygonPolygon=I,t});const lx=new Lynx2D;