1 |
- window.astro=(()=>{"use strict";var e={86:function(e,t){var s,i=this&&this.__awaiter||function(e,t,s,i){return new(s||(s=Promise))((function(a,o){function r(e){try{l(i.next(e))}catch(e){o(e)}}function n(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,n)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.BackendClient=t.RequestMetod=void 0,function(e){e.Post="post",e.Get="get"}(s=t.RequestMetod||(t.RequestMetod={})),t.BackendClient=class{constructor(e=window.location.host){this.host=e,this.apiEndpoint=`https://${e}/db/ecal`,this.sockEndpoint=`wss://${e}/db/sock`}message(e){const t=JSON.parse(e.data);"init_success"==t.type?console.log("New ECAL websocket established"):"data"==t.type&&this.update(t.payload)}createSock(e,t,s){return i(this,void 0,void 0,(function*(){const i=Object.keys(t).map((e=>{const s=t[e];return`${e}=${encodeURIComponent(s)}`})).join("&"),a=`${this.sockEndpoint}${e}?${i}`,o=this.message.bind({update:s});return new Promise((function(e,t){try{const t=new WebSocket(a);t.onmessage=o,t.onopen=()=>{e(t)}}catch(e){t(e)}}))}))}sendSockData(e,t){e.send(JSON.stringify(t))}req(e,t,i=s.Post){const a=new XMLHttpRequest;if(i===s.Post)a.open(i,`${this.apiEndpoint}${e}`,!0);else{const s=Object.keys(t).map((e=>{const s=t[e];return`${e}=${encodeURIComponent(s)}`})).join("&"),o=`${this.apiEndpoint}${e}?${s}`;a.open(i,o,!0)}return a.setRequestHeader("content-type","application/json"),new Promise((function(e,o){a.onload=function(){try{if(200===a.status)e(JSON.parse(a.response));else{let e;try{e=JSON.parse(a.responseText).error||a.responseText.trim()}catch(t){e=a.responseText.trim()}o(e)}}catch(e){o(e)}},i===s.Post?a.send(JSON.stringify(t)):a.send()}))}}},262:function(e,t){var s,i=this&&this.__awaiter||function(e,t,s,i){return new(s||(s=Promise))((function(a,o){function r(e){try{l(i.next(e))}catch(e){o(e)}}function n(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,n)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.AssetLoader=t.AssetType=void 0,function(e){e.ImageAsset="image",e.SoundAsset="sound"}(s=t.AssetType||(t.AssetType={})),t.AssetLoader=class{constructor(e=window.location.host,t="assets"){this.loadedAssets={},this.host=e,this.assetURLPrefix=`https://${e}/${t}/`}preload(e,t){return i(this,void 0,void 0,(function*(){let i=0,a=()=>{i++,console.log(`Asset ${i} of ${e.length} loaded.`),i===e.length&&t(this.loadedAssets)};for(let t of e)if(t.type===s.ImageAsset){var o=new Image;o.src=`${this.assetURLPrefix}${t.file}`,o.onload=a,t.image=o,this.loadedAssets[t.id]=t}else if(t.type===s.SoundAsset){(r=new Audio).src=`${this.assetURLPrefix}${t.file}`,r.oncanplaythrough=a,t.audio=[r];for(let e=0;e<6;e++){var r;(r=new Audio).src=`${this.assetURLPrefix}${t.file}`,t.audio.push(r)}this.loadedAssets[t.id]=t}}))}}},382:(e,t)=>{var s;Object.defineProperty(t,"__esModule",{value:!0}),t.EliasDBGraphQLClient=t.RequestMetod=void 0,function(e){e.Post="post",e.Get="get"}(s=t.RequestMetod||(t.RequestMetod={})),t.EliasDBGraphQLClient=class{constructor(e=window.location.host,t="main"){this.delayedOperations=[],this.subscriptionQueue=[],this.subscriptionCallbacks={},this.host=e,this.partition=t,this.graphQLEndpoint=`https://${e}/db/v1/graphql/${t}`,this.graphQLReadOnlyEndpoint=`https://${e}/db/v1/graphql-query/${t}`}initWebsocket(){const e=`wss://${this.host}/db/v1/graphql-subscriptions/${this.partition}`;this.ws=new WebSocket(e),this.ws.onmessage=this.message.bind(this),this.ws.onopen=()=>{this.ws&&this.ws.send(JSON.stringify({type:"init",payload:{}}))}}req(e,t={},i="",a=s.Post){const o=new XMLHttpRequest,r={operationName:i,variables:t,query:e};if(a===s.Post)o.open(a,this.graphQLEndpoint,!0);else{const e=Object.keys(r).map((e=>{const t="variables"!==e?r[e]:JSON.stringify(r[e]);return`${e}=${encodeURIComponent(t)}`})).join("&"),t=`${this.graphQLReadOnlyEndpoint}?${e}`;o.open(a,t,!0)}return o.setRequestHeader("content-type","application/json"),new Promise((function(e,t){o.onload=function(){try{if(200===o.status)e(JSON.parse(o.response));else{let e;try{e=JSON.parse(o.responseText).errors}catch(t){e=o.responseText.trim()}t(e)}}catch(e){t(e)}},a===s.Post?o.send(JSON.stringify(r)):o.send()}))}subscribe(e,t,s=null){if(this.ws||this.initWebsocket(),this.ws){const i=this,a=function(){i.ws&&(i.ws.send(JSON.stringify({id:i.subscriptionQueue.length,query:e,type:"subscription_start",variables:s})),i.subscriptionQueue.push(t))};this.ws.readyState!==WebSocket.OPEN?this.delayedOperations.push(a):a()}}message(e){const t=JSON.parse(e.data);if("init_success"==t.type)this.delayedOperations.forEach((e=>e())),this.delayedOperations=[];else if("subscription_success"==t.type){const e=this.subscriptionQueue.shift();if(e){const s=t.id;this.subscriptionCallbacks[s]=e}}else if("subscription_data"==t.type){const e=this.subscriptionCallbacks[t.id];e&&e(t.payload)}else"subscription_fail"==t.type&&console.error("Subscription failed: ",t.payload.errors.join("; "))}}},386:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.DefaultPlayerState=t.DefaultSpriteState=t.DefaultEngineOptions=t.DefaultEngineEventHandler=void 0,t.DefaultEngineEventHandler=class{onkeydown(e,t){let s="move";switch((t=t||window.event).code){case"ControlLeft":case"Space":e.stateUpdate("fire",[]);break;case"ArrowUp":e.speed+=.006,e.stateUpdate(s,["speed"]);break;case"ArrowDown":e.speed+=-.008,e.stateUpdate(s,["speed"]);break;case"ArrowRight":t.ctrlKey||t.shiftKey?(e.strafe=1,e.stateUpdate(s,["strafe"])):(e.dir=1,e.rotSpeed<e.maxRotSpeed?(e.rotSpeed=e.deltaRotSpeed(e.rotSpeed),e.stateUpdate(s,["dir","rotSpeed"])):e.stateUpdate(s,["dir"]));break;case"ArrowLeft":t.ctrlKey||t.shiftKey?(e.strafe=-1,e.stateUpdate(s,["strafe"])):(e.dir=-1,e.rotSpeed<e.maxRotSpeed?(e.rotSpeed=e.deltaRotSpeed(e.rotSpeed),e.stateUpdate(s,["dir","rotSpeed"])):e.stateUpdate(s,["dir"]))}this.stopBubbleEvent(t)}onkeyup(e,t){t=t||window.event,e.dir=0,e.strafe=0,e.rotSpeed=e.minRotSpeed,e.stateUpdate("stop move",["dir","strafe","rotSpeed"]),this.stopBubbleEvent(t)}stopBubbleEvent(e){(e=e||window.event).stopPropagation&&e.stopPropagation(),null!==e.cancelBubble&&(e.cancelBubble=!0)}},t.DefaultEngineOptions=class{constructor(){this.backdrop=null,this.assets={},this.screenWidth=640,this.screenHeight=480,this.screenElementWidth=640,this.screenElementHeight=480}};class s{constructor(){this.id="",this.x=20,this.y=20,this.kind="",this.owner="",this.dim=20,this.isMoving=!0,this.displayLoop=!0,this.dir=0,this.rot=0,this.rotSpeed=9e-5,this.speed=0,this.strafe=0,this.moveSpeed=0,this.animation=null}setState(e){this.id=e.id||this.id,this.x=e.x||this.x,this.y=e.y||this.y,this.kind=e.kind||this.kind,this.owner=e.owner||this.owner,this.dim=e.dim||this.dim,this.isMoving=e.isMoving||this.isMoving,this.displayLoop=e.displayLoop||this.displayLoop,this.dir=e.dir||this.dir,this.rot=e.rot||this.rot,this.rotSpeed=e.rotSpeed||this.rotSpeed,this.speed=e.speed||this.speed,this.strafe=e.strafe||this.strafe,this.moveSpeed=e.moveSpeed||this.moveSpeed}}t.DefaultSpriteState=s,t.DefaultPlayerState=class extends s{constructor(){super(...arguments),this.maxRotSpeed=9e-4,this.minRotSpeed=1e-4}stateUpdate(e,t){}deltaRotSpeed(e){return 1.000001*e}}},216:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MainDisplayController=void 0,t.MainDisplayController=class{constructor(e,t){this.running=!1,this.debugOutputElement=null,this.player={},this.sprites=[],this.overlayData=[],this.animationFrame=0,this.isSpectatorMode=!1,this.showHelp=!1,this.lastRenderCycleTime=0,this.options=t;const s=document.getElementById(e);if(null===s)throw Error("Canvas element not found");this.canvas=s;const i=s.getContext("2d");if(null===i)throw Error("Could not get canvas rendering context");this.ctx=i,this.debugOutputElement=document.getElementById("game-debug-out"),this.canvas.width=this.options.screenWidth,this.canvas.height=this.options.screenHeight,this.canvas.style.width=this.options.screenElementWidth+"px",this.canvas.style.height=this.options.screenElementHeight+"px"}registerEventHandlers(){document.onkeydown=e=>{"F1"==e.code&&(this.showHelp=!this.showHelp),this.options.eventHandler.onkeydown(this.player,e)},document.onkeyup=e=>{this.options.eventHandler.onkeyup(this.player,e)}}deRegisterEventHandlers(){document.onkeydown=null,document.onkeyup=null}start(e){this.player=e,this.registerEventHandlers(),this.isSpectatorMode=!1,this.running||(this.running=!0,this.drawLoop())}stop(){this.running=!1,this.deRegisterEventHandlers(),this.options.stopHandler()}spectatorMode(){this.isSpectatorMode=!0,this.deRegisterEventHandlers()}addSprite(e){this.sprites.push(e)}removeSprite(e){if(!e)throw new Error("Trying to remove non-existing sprite state");this.sprites.splice(this.sprites.indexOf(e),1)}setOverlayData(e){this.overlayData=e}printDebug(e){null!==this.debugOutputElement&&(this.debugOutputElement.innerHTML+=e+"<br>")}drawLoop(){this.animationFrame++,this.animationFrame=this.animationFrame%1e3,null===this.options.backdrop?this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height):(this.ctx.drawImage(this.options.backdrop,0,0,this.canvas.width,this.canvas.height),this.ctx.save(),this.ctx.globalAlpha=.5,this.ctx.fillRect(0,0,this.canvas.width,this.canvas.height),this.ctx.restore()),null!==this.debugOutputElement&&(this.debugOutputElement.innerHTML="");let e=(new Date).getTime();if(this.drawSprites(),this.isSpectatorMode||this.drawPlayer(),this.options.drawHandler(this.ctx,this.player,this.sprites),0!==e){let e=(new Date).getTime();const t=e-this.lastRenderCycleTime,s=Math.floor(1e3/t);this.lastRenderCycleTime=e,this.printDebug("FPS: "+s)}this.drawInfoOverlay(),this.running&&setTimeout((()=>{this.drawLoop()}),20)}drawInfoOverlay(){this.ctx.save(),this.ctx.font="10px Arial bold",this.ctx.globalAlpha=.6;let e="#000000";if(this.ctx.fillStyle="#ffbf00",this.ctx.strokeStyle="#ff8000",this.isSpectatorMode){let t=[`Player: ${this.player.id}`,...this.overlayData,""],s=Math.floor(this.options.screenWidth/2),i=Math.floor(this.options.screenHeight/3),a=Math.floor(12*t.length/2);this.drawRoundRect(s-200,i-a,400,2*a+40,10,!0,!0),this.ctx.fillStyle=e,this.ctx.font="20px Arial";let o="Game Over";this.ctx.fillText(o,s-Math.floor(this.ctx.measureText(o).width/2),i-a+30),this.ctx.font="10px Arial bold";for(let e=0;e<t.length;e++){let o=t[e].trim(),r=this.ctx.measureText(o).width;this.ctx.fillText(o,s-Math.floor(r/2),i-a+50+12*e)}}else{let t=[`Player: ${this.player.id}`,...this.overlayData,""];this.showHelp?(t.push("Controls:"),t.push(""),t.push("<cursor left/right>"),t.push(" Rotate"),t.push(""),t.push("<cursor up/down>"),t.push(" Accelerate/Decelerate"),t.push(""),t.push("<space / ctrl>"),t.push(" Shoot"),t.push(""),t.push("<shift>"),t.push(" Strafe")):t.push("Press F1 for help ..."),this.drawRoundRect(this.options.screenWidth-170,10,160,13+10*t.length,10,!0,!0),this.ctx.fillStyle=e;for(let e=0;e<t.length;e++)this.ctx.fillText(t[e],this.options.screenWidth-165,25+10*e)}this.ctx.restore()}drawPlayer(){try{return void this.player.draw(this.ctx,this.player,this.options.assets)}catch(e){}this.ctx.beginPath(),this.ctx.arc(this.player.x,this.player.y,this.player.dim/2,0,2*Math.PI),this.ctx.moveTo(this.player.x,this.player.y),this.ctx.lineTo(this.player.x+20*Math.cos(this.player.rot),this.player.y+20*Math.sin(this.player.rot)),this.ctx.closePath(),this.ctx.stroke();let e=this.ctx.strokeStyle,t=this.player.dim/2;this.ctx.strokeStyle="red",this.ctx.rect(this.player.x-t,this.player.y-t,this.player.dim,this.player.dim),this.ctx.stroke(),this.ctx.strokeStyle=e}drawSprites(){for(let e of this.sprites){try{e.draw(this.ctx,e,this.options.assets);continue}catch(e){}this.ctx.beginPath(),this.ctx.arc(e.x,e.y,e.dim/2,0,2*Math.PI),this.ctx.moveTo(e.x,e.y),this.ctx.lineTo(e.x+20*Math.cos(e.rot),e.y+20*Math.sin(e.rot)),this.ctx.closePath(),this.ctx.stroke();let t=this.ctx.strokeStyle,s=e.dim/2;this.ctx.strokeStyle="red",this.ctx.rect(e.x-s,e.y-s,e.dim,e.dim),this.ctx.stroke(),this.ctx.strokeStyle=t}}drawRoundRect(e,t,s,i,a=5,o=!0,r=!0){let n=a,l=a,d=a,h=a;this.ctx.beginPath(),this.ctx.moveTo(e+n,t),this.ctx.lineTo(e+s-l,t),this.ctx.quadraticCurveTo(e+s,t,e+s,t+l),this.ctx.lineTo(e+s,t+i-d),this.ctx.quadraticCurveTo(e+s,t+i,e+s-d,t+i),this.ctx.lineTo(e+h,t+i),this.ctx.quadraticCurveTo(e,t+i,e,t+i-h),this.ctx.lineTo(e,t+n),this.ctx.quadraticCurveTo(e,t,e+n,t),this.ctx.closePath(),o&&this.ctx.fill(),r&&this.ctx.stroke()}}},263:function(e,t,s){var i=this&&this.__awaiter||function(e,t,s,i){return new(s||(s=Promise))((function(a,o){function r(e){try{l(i.next(e))}catch(e){o(e)}}function n(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,n)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0});const a=s(47),o=s(216),r=s(86),n=s(382),l=s(983),d=s(949),h=s(262),p=s(321);t.default={generatePlayerName:function(){return d.generateRandomName()},start:function(e){return i(this,void 0,void 0,(function*(){const t=`${window.location.hostname}:${window.location.port}`;new h.AssetLoader(t).preload([{id:"background_nebular",type:h.AssetType.ImageAsset,file:"background_nebular.jpg"},{id:"spaceShips_001",type:h.AssetType.ImageAsset,file:"spaceShips_001.png"},{id:"spaceShips_002",type:h.AssetType.ImageAsset,file:"spaceShips_002.png"},{id:"spaceShips_003",type:h.AssetType.ImageAsset,file:"spaceShips_003.png"},{id:"spaceShips_004",type:h.AssetType.ImageAsset,file:"spaceShips_004.png"},{id:"spaceShips_005",type:h.AssetType.ImageAsset,file:"spaceShips_005.png"},{id:"spaceShips_006",type:h.AssetType.ImageAsset,file:"spaceShips_006.png"},{id:"spaceShips_007",type:h.AssetType.ImageAsset,file:"spaceShips_007.png"},{id:"spaceShips_008",type:h.AssetType.ImageAsset,file:"spaceShips_008.png"},{id:"spaceShips_009",type:h.AssetType.ImageAsset,file:"spaceShips_009.png"},{id:"asteroid_001",type:h.AssetType.ImageAsset,file:"asteroid_001.png"},{id:"asteroid_002",type:h.AssetType.ImageAsset,file:"asteroid_002.png"},{id:"shot_001",type:h.AssetType.ImageAsset,file:"shot_001.png"},{id:"shot_002",type:h.AssetType.ImageAsset,file:"shot_002.png"},{id:"shot_003",type:h.AssetType.ImageAsset,file:"shot_003.png"},{id:"explosion_001",type:h.AssetType.SoundAsset,file:"explosion_001.mp3"},{id:"explosion_002",type:h.AssetType.SoundAsset,file:"explosion_002.mp3"},{id:"explosion_003",type:h.AssetType.SoundAsset,file:"explosion_003.mp3"},{id:"explosion_004",type:h.AssetType.SoundAsset,file:"explosion_004.mp3"},{id:"explosion_005",type:h.AssetType.SoundAsset,file:"explosion_005.mp3"},{id:"vanish_001",type:h.AssetType.SoundAsset,file:"vanish_001.mp3"},{id:"shotfired_001",type:h.AssetType.SoundAsset,file:"shot_001.mp3"},{id:"shotfired_002",type:h.AssetType.SoundAsset,file:"shot_002.mp3"},{id:"shotfired_003",type:h.AssetType.SoundAsset,file:"shot_003.mp3"},{id:"shotfired_004",type:h.AssetType.SoundAsset,file:"shot_004.mp3"},{id:"shotfired_005",type:h.AssetType.SoundAsset,file:"shot_005.mp3"},{id:"shotfired_006",type:h.AssetType.SoundAsset,file:"shot_006.mp3"},{id:"shotfired_007",type:h.AssetType.SoundAsset,file:"shot_007.mp3"},{id:"shotfired_008",type:h.AssetType.SoundAsset,file:"shot_008.mp3"},{id:"shotfired_009",type:h.AssetType.SoundAsset,file:"shot_009.mp3"},{id:"ship_explosion_ani_001",type:h.AssetType.ImageAsset,file:"ship_explosion_001.png"},{id:"ship_explosion_snd_001",type:h.AssetType.SoundAsset,file:"ship_explosion_001.mp3"},{id:"background_sound",type:h.AssetType.SoundAsset,file:"background-sound.mp3"}],(t=>{this.startGame(e,t)}))}))},startGame:function(e,t){return i(this,void 0,void 0,(function*(){let s=d.getURLParams();s.player||(d.setURLParam("player",d.generateRandomName()),s=d.getURLParams()),s.game||(d.setURLParam("game","main"),s=d.getURLParams());const i=`${window.location.hostname}:${window.location.port}`,h=s.game,c=s.player,u=new r.BackendClient(i),y=new n.EliasDBGraphQLClient(i),m=new a.GameOptions;try{const e=(yield u.req("/game",{gameName:h},r.RequestMetod.Get)).gameworld;m.backdrop=null;let s=t[e.backdrop||""];s&&(m.backdrop=s.image),m.assets=t,m.screenWidth=e.screenWidth,m.screenHeight=e.screenHeight,m.screenElementWidth=e.screenElementWidth,m.screenElementHeight=e.screenElementHeight}catch(e){throw new Error(`Could not get game world information: ${e}`)}const f=new o.MainDisplayController(e,m);try{let e=new l.MainGameController(h,c,t,f,u,y);this.GameController=e;const s=yield u.createSock("/gamestate",{gameName:h,playerName:c},e.updatePushHandler.bind(e));e.setPlayerWebsocket(s),yield u.req("/player",{player:c,gameName:h}),p.playLoop(t.background_sound.audio)}catch(e){throw new Error(`Could not register: ${e}`)}}))}}},983:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.MainGameController=void 0;const i=s(949),a=s(321),o=s(47);t.MainGameController=class{constructor(e,t,s,i,a,r){this.gameName=e,this.assets=s,this.display=i,this.backedClient=a,this.graphQLClient=r,this.playerState=new o.Player(e,a),this.playerState.id=t,this.spriteMap={},this.graphQLClient.subscribe("\n subscription {\n score(ascending:score) {\n key,\n score,\n }\n }",(e=>{let t=[],s=e.data.score.reverse().slice(0,10),i=0;t.push(""),t.push("Highscores:"),t.push("");for(let e of s)t.push(` ${e.key}`),t.push(` ${e.score}`),e.key==this.playerState.id&&(i=e.score);t.unshift(`Score: ${i}`),this.display.setOverlayData(t)}))}setPlayerWebsocket(e){this.playerState.setWebsocket(e)}updatePushHandler(e){if(e.payload.audioEvent){let t=e.payload.audioEvent;if("explosion"===t){let e=Math.floor(5*Math.random())+1;a.playOneSound(this.assets[`explosion_00${e}`].audio)}else if("vanish"===t)a.playOneSound(this.assets.vanish_001.audio);else if("shot"===t){let t=e.payload.player,s=i.stringToNumber(t,1,9);a.playOneSound(this.assets[`shotfired_00${s}`].audio)}return}if(e.payload.toRemovePlayerIds){for(let t of e.payload.toRemovePlayerIds){let e,s=this.playerState;if(t===this.playerState.id)console.log("Sorry",this.playerState.id,"but you are gone ..."),e=()=>{this.display.spectatorMode()};else{if(s=this.spriteMap[t],!s)continue;e=()=>{delete this.spriteMap[t],this.display.removeSprite(s)}}s.animation=new a.AnimationController(this.assets.ship_explosion_ani_001.image,24,24,a.AnimationStyle.ForwardAndBackward,3,100,e),a.playOneSound(this.assets.ship_explosion_snd_001.audio)}return}if(e.payload.toRemoveSpriteIds){for(let t of e.payload.toRemoveSpriteIds){let e=this.spriteMap[t];e&&(delete this.spriteMap[t],this.display.removeSprite(e))}return}let t=e.payload.state;if(t.id===this.playerState.id)this.playerState.setState(t);else{let e=this.spriteMap[t.id];e||(e=new o.Sprite,e.setState(t),this.spriteMap[e.id]=e,this.display.addSprite(e)),e.setState(t)}this.display.running||this.display.start(this.playerState)}}},321:function(e,t){var s,i=this&&this.__awaiter||function(e,t,s,i){return new(s||(s=Promise))((function(a,o){function r(e){try{l(i.next(e))}catch(e){o(e)}}function n(e){try{l(i.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?a(e.value):(t=e.value,t instanceof s?t:new s((function(e){e(t)}))).then(r,n)}l((i=i.apply(e,t||[])).next())}))};Object.defineProperty(t,"__esModule",{value:!0}),t.playLoop=t.playOneSound=t.AnimationController=t.AnimationStyle=void 0,function(e){e.Forward="forward",e.ForwardAndBackward="forwardandbackward"}(s=t.AnimationStyle||(t.AnimationStyle={})),t.AnimationController=class{constructor(e,t,i,a=s.Forward,o=-1,r=100,n=(()=>{})){this.direction=!0,this.currentFrame=-1,this.currentFrameStartTime=0,this.framesImage=e,this.frameWidth=t,this.frameHeight=i,this.style=a,this.sequences=o,this.tickTime=r,this.callback=n,this.totalFrames=Math.floor(e.width/this.frameWidth)}tick(e,t,i,a,o){if(0==this.sequences)return;let r=Date.now();r-this.currentFrameStartTime>this.tickTime&&(this.currentFrameStartTime=r,this.direction?this.currentFrame++:this.currentFrame--,(this.currentFrame>=this.totalFrames-1||this.currentFrame<=-1)&&(this.currentFrame>=this.totalFrames-1?this.style===s.ForwardAndBackward?this.direction=!this.direction:this.currentFrame=0:this.currentFrame<0&&(this.style===s.ForwardAndBackward?(this.direction=!this.direction,this.currentFrame=0):this.currentFrame=this.totalFrames-1),this.sequences>0&&(this.sequences--,0==this.sequences)))?this.callback():e.drawImage(this.framesImage,this.currentFrame*this.frameWidth,0,this.frameWidth,this.frameHeight,t,i,a,o)}},t.playOneSound=function(e){for(var t=0;t<e.length;t++)if(e[t].paused){e[t].play();break}},t.playLoop=function e(t){return i(this,void 0,void 0,(function*(){try{t[0].loop=!0,yield t[0].play(),console.log("Background!")}catch(s){setTimeout((()=>{e(t)}),100)}}))}},47:(e,t,s)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.Sprite=t.Player=t.GameOptions=t.GameEventHandler=void 0;const i=s(386),a=s(949);class o extends i.DefaultEngineEventHandler{}t.GameEventHandler=o;class r extends i.DefaultEngineOptions{constructor(){super(),this.eventHandler=new o}drawHandler(){}stopHandler(){}}t.GameOptions=r;class n extends i.DefaultPlayerState{constructor(e,t){super(),this.websocket=null,this.gameName=e,this.backedClient=t}setWebsocket(e){this.websocket=e}stateUpdate(e,t){super.stateUpdate(e,t),null!=this.websocket&&this.backedClient.sendSockData(this.websocket,{player:this.id,gameName:this.gameName,action:e,state:{dir:this.dir,rotSpeed:this.rotSpeed,speed:this.speed,strafe:this.strafe}})}draw(e,t,s){d(e,t,s)}}t.Player=n;class l extends i.DefaultSpriteState{draw(e,t,s){if("asteroid"===t.kind)return e.save(),e.translate(t.x,t.y),e.rotate(t.rot+Math.PI/2*3),e.drawImage(s.asteroid_001.image,-t.dim/2,-t.dim/2,t.dim,t.dim),void e.restore();if("shot"===t.kind){let i=a.stringToNumber(t.owner,1,3),o=38;return e.save(),e.translate(t.x,t.y),e.rotate(t.rot+2*Math.PI),e.drawImage(s[`shot_00${i}`].image,-o/2,-o/2,o,o),void e.restore()}if("player"!==t.kind)throw console.log("Could not draw: ",t.kind),new Error(`Method not implemented. ${e}, ${t}`);d(e,t,s)}}function d(e,t,s){let i=a.stringToNumber(t.id,1,9);e.save(),e.translate(t.x,t.y),e.rotate(t.rot+Math.PI/2*3),t.animation?t.animation.tick(e,-t.dim/2,-t.dim/2,t.dim,t.dim):e.drawImage(s[`spaceShips_00${i}`].image,-t.dim/2,-t.dim/2,t.dim,t.dim),e.restore(),e.save(),e.font="10px Arial",e.fillStyle="#ffbf00",e.fillText(t.id,t.x-Math.floor(e.measureText(t.id).width/2),t.y+t.dim+5),e.restore()}t.Sprite=l},949:(e,t)=>{Object.defineProperty(t,"__esModule",{value:!0}),t.generateRandomName=t.removeURLParam=t.setURLParam=t.getURLParams=t.stringToNumber=void 0,t.stringToNumber=function(e,t,s){let i=0,a=s-t+1;for(var o=0;o<e.length;o++)i+=e.charCodeAt(o);return i%a+t},t.getURLParams=function(){const e=/[?&]?([^=]+)=([^&]*)/g,t=document.location.search.split("+").join(" ");let s,i={};for(;s=e.exec(t);)i[decodeURIComponent(s[1])]=decodeURIComponent(s[2]);return i},t.setURLParam=function(e,t){let s=window.location.href;if(s.indexOf(e+"=")>=0){var i=s.substring(0,s.indexOf(e)),a=s.substring(s.indexOf(e));s=i+e+"="+t+(a=(a=a.substring(a.indexOf("=")+1)).indexOf("&")>=0?a.substring(a.indexOf("&")):"")}else s.indexOf("?")<0?s+="?"+e+"="+t:s+="&"+e+"="+t;window.history.pushState(null,document.title,s)},t.removeURLParam=function(e){let t=window.location.href,s=t.split("?");if(s.length>=2){for(var i=e+"=",a=s[1].split(/[&;]/g),o=a.length-1;o>=0;o--)-1!==a[o].lastIndexOf(i,0)&&a.splice(o,1);t=s[0]+(a.length>0?"?"+a.join("&"):""),window.history.pushState(null,document.title,t)}};const s=["adorable","adventurous","aggressive","agreeable","alert","alive","amused","angry","annoyed","annoying","anxious","arrogant","ashamed","attractive","average","awful","bad","beautiful","better","bewildered","black","bloody","blue","blue-eyed","blushing","bored","brainy","brave","breakable","bright","busy","calm","careful","cautious","charming","cheerful","clean","clear","clever","cloudy","clumsy","colorful","combative","comfortable","concerned","condemned","confused","cooperative","courageous","crazy","creepy","crowded","cruel","curious","cute","dangerous","dark","dead","defeated","defiant","delightful","depressed","determined","different","difficult","disgusted","distinct","disturbed","dizzy","doubtful","drab","dull","eager","easy","elated","elegant","embarrassed","enchanting","encouraging","energetic","enthusiastic","envious","evil","excited","expensive","exuberant","fair","faithful","famous","fancy","fantastic","fierce","filthy","fine","foolish","fragile","frail","frantic","friendly","frightened","funny","gentle","gifted","glamorous","gleaming","glorious","good","gorgeous","graceful","grieving","grotesque","grumpy","handsome","happy","healthy","helpful","helpless","hilarious","homeless","homely","horrible","hungry","hurt","ill","important","impossible","inexpensive","innocent","inquisitive","itchy","jealous","jittery","jolly","joyous","kind","lazy","light","lively","lonely","long","lovely","lucky","magnificent","misty","modern","motionless","muddy","mushy","mysterious","nasty","naughty","nervous","nice","nutty","obedient","obnoxious","odd","old-fashioned","open","outrageous","outstanding","panicky","perfect","plain","pleasant","poised","poor","powerful","precious","prickly","proud","putrid","puzzled","quaint","real","relieved","repulsive","rich","scary","selfish","shiny","shy","silly","sleepy","smiling","smoggy","sore","sparkling","splendid","spotless","stormy","strange","stupid","successful","super","talented","tame","tasty","tender","tense","terrible","thankful","thoughtful","thoughtless","tired","tough","troubled","ugliest","ugly","uninterested","unsightly","unusual","upset","uptight","vast","victorious","vivacious","wandering","weary","wicked","wide-eyed","wild","witty","worried","worrisome","wrong","zany","zealous"],i=["Aardvark","Albatross","Alligator","Alpaca","Anole","Ant","Anteater","Antelope","Ape","Armadillo","Baboon","Badger","Barracuda","Bat","Bear","Beaver","Bee","Binturong","Bird","Bison","Bluebird","Boar","Bobcat","Budgerigar","Buffalo","Butterfly","Camel","Capybara","Caracal","Caribou","Cassowary","Cat","Caterpillar","Cattle","Chamois","Cheetah","Chicken","Chimpanzee","Chinchilla","Chough","Coati","Cobra","Cockroach","Cod","Cormorant","Cougar","Coyote","Crab","Crane","Cricket","Crocodile","Crow","Cuckoo","Curlew","Deer","Dhole","Dingo","Dinosaur","Dog","Dogfish","Dolphin","Donkey","Dove","Dragonfly","Duck","Dugong","Dunlin","Eagle","Echidna","Eel","Eland","Elephant","Elk","Emu","Falcon","Ferret","Finch","Fish","Fisher","Flamingo","Fly","Flycatcher","Fox","Frog","Gaur","Gazelle","Gecko","Genet","Gerbil","Giant","Giraffe","Gnat","Gnu","Goat","Goldfinch","Goosander","Goose","Gorilla","Goshawk","Grasshopper","Grouse","Guanaco","Guinea","Guinea","Gull","Hamster","Hare","Hawk","Hedgehog","Hermit","Heron","Herring","Hippopotamus","Hoatzin","Hoopoe","Hornet","Horse","Human","Hummingbird","Hyena","Ibex","Ibis","Iguana","Impala","Jackal","Jaguar","Jay","Jellyfish","Jerboa","Kangaroo","Kingbird","Kingfisher","Kinkajou","Kite","Koala","Kodkod","Komodo","Kookaburra","Kouprey","Kudu","Langur","Lapwing","Lark","Lechwe","Lemur","Leopard","Lion","Lizard","Llama","Lobster","Locust","Loris","Louse","Lynx","Lyrebird","Macaque","Macaw","Magpie","Mallard","Mammoth","Manatee","Mandrill","Margay","Marmoset","Marmot","Meerkat","Mink","Mole","Mongoose","Monkey","Moose","Mosquito","Mouse","Myna","Narwhal","Newt","Nightingale","Nilgai","Ocelot","Octopus","Okapi","Oncilla","Opossum","Orangutan","Oryx","Ostrich","Otter","Ox","Owl","Oyster","Panther","Parrot","Panda","Partridge","Peafowl","Penguin","Pheasant","Pig","Pigeon","Pika","Polar bear","Pony","Porcupine","Porpoise","Prairie","Pug","Quail","Quelea","Quetzal","Rabbit","Raccoon","Ram","Rat","Raven","Red deer","Red panda","Reindeer","Rhea","Rhinoceros","Rook","Saki","Salamander","Salmon","Sand dollar","Sandpiper","Sardine","Sassaby","Sea lion","Seahorse","Seal","Serval","Shark","Sheep","Shrew","Shrike","Siamang","Skink","Skipper","Skunk","Sloth","Snail","Snake ","Spider ","Spoonbill","Squid","Squirrel","Starling","Stilt","Swan","Tamarin","Tapir","Tarsier","Termite","Thrush","Tiger","Toad","Topi","Toucan","Turaco","Turkey","Turtle","Vicuña","Vinegaroon","Viper","Vulture","Wallaby","Walrus","Wasp","Water buffalo","Waxwing","Weasel","Whale","Wobbegong","Wolf","Wolverine","Wombat","Woodpecker","Worm","Wren","Yak","Zebra"];t.generateRandomName=function(){let e=s[Math.floor(Math.random()*s.length)],t=i[Math.floor(Math.random()*i.length)];return e=e.charAt(0).toUpperCase()+e.slice(1),`${e}${t}`}}},t={};return function s(i){if(t[i])return t[i].exports;var a=t[i]={exports:{}};return e[i].call(a.exports,a,a.exports,s),a.exports}(263)})().default;
|