-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
1 lines (1 loc) · 34.8 KB
/
bundle.js
1
(()=>{"use strict";var t={732:(t,e,n)=>{n.d(e,{A:()=>o});var r=n(314),i=n.n(r)()((function(t){return t[1]}));i.push([t.id,"/* ******************** */\n/* Reset */\n/* ******************** */\n* {\n margin: 0;\n padding: 0;\n}\n\nbody, main, div {\n margin: 0 auto;\n}\n\na {\n text-decoration: none;\n color: lightblue;\n}\n\na:hover {\n text-decoration: underline;\n}\n\np {\n font-size: 1rem;\n}\n\nh1 {\n font-size: 3rem;\n}\n\nul {\n list-style: none;\n text-align: left;\n margin-bottom: 15px;\n}\n\nli {\n text-align: left;\n font-size: 1rem;\n}\n\nbutton {\n border-radius: 4px;\n padding: 10px 10px;\n cursor: pointer;\n}\n\n/* ******************** */\n/* Game */\n/* ******************** */\n\n.canvas-width {\n max-width: 720px;\n width: 100%;\n}\n\n#canvas {\n display: block;\n border: 3px solid orange;\n background: transparent;\n background-image: linear-gradient(0deg, transparent 24%,\n rgba(255, 255, 255, .05) 25%,\n rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent),\n linear-gradient(90deg, transparent 24%, rgba(255, 255, 255, .05) 25%,\n rgba(255, 255, 255, .05) 26%, transparent 27%, transparent 74%, rgba(255, 255, 255, .05) 75%, rgba(255, 255, 255, .05) 76%, transparent 77%, transparent);\n background-size: 50px 50px;\n}\n\n#startGame {\n top: 45%;\n left: 45%;\n}\n\n/* ******************** */\n/* Display */\n/* ******************** */\n\n.d-none {\n display: none !important;\n}\n\n.d-block {\n display: block !important;\n}\n\n.position-relative {\n position: relative;\n}\n\n.position-absolute {\n position: absolute;\n}\n\n.overlay {\n position: absolute;\n display: block;\n top: 0;\n left: 0;\n right: 0;\n bottom: 0;\n background-color: rgba(0,0,0,0.5);\n z-index: 2;\n cursor: pointer;\n}\n\n/* ******************** */\n/* Flex */\n/* ******************** */\n\n.d-flex {\n display: flex;\n}\n\n.justify-content-between {\n justify-content: space-between;\n}\n\n.justify-content-center {\n justify-content: center;\n}\n\n.justify-content-end {\n justify-content: end;\n}\n\n.align-items-center {\n align-items: center;\n}\n\n.flex-column {\n flex-direction: column;\n}\n\n/* ******************** */\n/* Text */\n/* ******************** */\n\n.color-white {\n color: white;\n}\n\n.color-green {\n color: lightgreen;\n}\n\n.color-orange {\n color: orange;\n}\n\n.color-black {\n color: black;\n}\n\n.bold {\n font-weight: bold;\n}\n\n.font-size-small {\n font-size: .75rem;\n}\n\n.font-size-large {\n font-size: 1.5rem;\n}\n\n.text-center {\n text-align: center;\n}\n\n/* ******************** */\n/* Margin */\n/* ******************** */\n\n.mb-30 {\n margin-bottom: 30px;\n}\n\n.mb-25 {\n margin-bottom: 25px;\n}\n\n.mb-10 {\n margin-bottom: 10px;\n}\n\n.mb-6 {\n margin-bottom: 6px;\n}\n\n.ml-8 {\n margin-left: 8px;\n}\n\n.ml-0 {\n margin-left: 0;\n}\n\n.mr-4 {\n margin-right: 4px;\n}\n\n.mr-6 {\n margin-right: 6px;\n}\n\n.mr-8 {\n margin-right: 8px;\n}\n\n.mr-10 {\n margin-right: 10px;\n}\n\n.mr-15 {\n margin-right: 15px;\n}\n\n.mr-25 {\n margin-right: 25px;\n}\n\n.mt-25 {\n margin-top: 25px;\n}\n\n.mt-10 {\n margin-top: 10px;\n}\n\n.mx-8 {\n margin-left: 8px;\n margin-right: 8px;\n}\n\n.my-10 {\n margin-top: 10px;\n margin-bottom: 10px;\n}\n\n.mx-0 {\n margin-left: 0;\n margin-right: 0;\n}\n\n/* ******************** */\n/* Padding */\n/* ******************** */\n\n.p-15 {\n padding: 15px;\n}\n\n/* ******************** */\n/* Backgrounds & Borders */\n/* ******************** */\n\n.bg-white {\n background-color: white;\n}\n\n.bg-black {\n background-color: black;\n}\n\n.btn-orange {\n background-color: orange;\n border: 2px solid orange;\n}\n\n/* ******************** */\n/* Utils */\n/* ******************** */\n\n.vw-100 {\n width: 100vw;\n}\n\n.vh-100 {\n height: 100vh;\n}\n",""]);const o=i},314:t=>{t.exports=function(t){var e=[];return e.toString=function(){return this.map((function(e){var n=t(e);return e[2]?"@media ".concat(e[2]," {").concat(n,"}"):n})).join("")},e.i=function(t,n,r){"string"==typeof t&&(t=[[null,t,""]]);var i={};if(r)for(var o=0;o<this.length;o++){var s=this[o][0];null!=s&&(i[s]=!0)}for(var a=0;a<t.length;a++){var u=[].concat(t[a]);r&&i[u[0]]||(n&&(u[2]?u[2]="".concat(n," and ").concat(u[2]):u[2]=n),e.push(u))}},e}},72:(t,e,n)=>{var r,i=function(){var t={};return function(e){if(void 0===t[e]){var n=document.querySelector(e);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(t){n=null}t[e]=n}return t[e]}}(),o=[];function s(t){for(var e=-1,n=0;n<o.length;n++)if(o[n].identifier===t){e=n;break}return e}function a(t,e){for(var n={},r=[],i=0;i<t.length;i++){var a=t[i],u=e.base?a[0]+e.base:a[0],c=n[u]||0,l="".concat(u," ").concat(c);n[u]=c+1;var f=s(l),h={css:a[1],media:a[2],sourceMap:a[3]};-1!==f?(o[f].references++,o[f].updater(h)):o.push({identifier:l,updater:d(h,e),references:1}),r.push(l)}return r}function u(t){var e=document.createElement("style"),r=t.attributes||{};if(void 0===r.nonce){var o=n.nc;o&&(r.nonce=o)}if(Object.keys(r).forEach((function(t){e.setAttribute(t,r[t])})),"function"==typeof t.insert)t.insert(e);else{var s=i(t.insert||"head");if(!s)throw new Error("Couldn't find a style target. This probably means that the value for the 'insert' parameter is invalid.");s.appendChild(e)}return e}var c,l=(c=[],function(t,e){return c[t]=e,c.filter(Boolean).join("\n")});function f(t,e,n,r){var i=n?"":r.media?"@media ".concat(r.media," {").concat(r.css,"}"):r.css;if(t.styleSheet)t.styleSheet.cssText=l(e,i);else{var o=document.createTextNode(i),s=t.childNodes;s[e]&&t.removeChild(s[e]),s.length?t.insertBefore(o,s[e]):t.appendChild(o)}}function h(t,e,n){var r=n.css,i=n.media,o=n.sourceMap;if(i?t.setAttribute("media",i):t.removeAttribute("media"),o&&"undefined"!=typeof btoa&&(r+="\n/*# sourceMappingURL=data:application/json;base64,".concat(btoa(unescape(encodeURIComponent(JSON.stringify(o))))," */")),t.styleSheet)t.styleSheet.cssText=r;else{for(;t.firstChild;)t.removeChild(t.firstChild);t.appendChild(document.createTextNode(r))}}var p=null,y=0;function d(t,e){var n,r,i;if(e.singleton){var o=y++;n=p||(p=u(e)),r=f.bind(null,n,o,!1),i=f.bind(null,n,o,!0)}else n=u(e),r=h.bind(null,n,e),i=function(){!function(t){if(null===t.parentNode)return!1;t.parentNode.removeChild(t)}(n)};return r(t),function(e){if(e){if(e.css===t.css&&e.media===t.media&&e.sourceMap===t.sourceMap)return;r(t=e)}else i()}}t.exports=function(t,e){(e=e||{}).singleton||"boolean"==typeof e.singleton||(e.singleton=(void 0===r&&(r=Boolean(window&&document&&document.all&&!window.atob)),r));var n=a(t=t||[],e);return function(t){if(t=t||[],"[object Array]"===Object.prototype.toString.call(t)){for(var r=0;r<n.length;r++){var i=s(n[r]);o[i].references--}for(var u=a(t,e),c=0;c<n.length;c++){var l=s(n[c]);0===o[l].references&&(o[l].updater(),o.splice(l,1))}n=u}}}}},e={};function n(r){var i=e[r];if(void 0!==i)return i.exports;var o=e[r]={id:r,exports:{}};return t[r](o,o.exports,n),o.exports}n.n=t=>{var e=t&&t.__esModule?()=>t.default:()=>t;return n.d(e,{a:e}),e},n.d=(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},n.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),n.nc=void 0,(()=>{var t=n(72),e=n.n(t),r=n(732);function i(t){return i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},i(t)}function o(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,s(r.key),r)}}function s(t){var e=function(t,e){if("object"!=i(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=i(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==i(e)?e:e+""}e()(r.A,{insert:"head",singleton:!1}),r.A.locals;var a=function(){return t=function t(e,n,r,i,o,s){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.x=e,this.y=n,this.size=r,this.color=i,this.dx=o,this.dy=s,this.width=r/2},(e=[{key:"move",value:function(t){this.checkBounds(t.ship),this.x+=this.dx,this.y+=this.dy,this.updatePosition(t)}},{key:"checkBounds",value:function(t){if(this.x>720){var e=0;e===t.x&&(e+=30),this.x=e,this.y=Math.floor(540*Math.random())}else this.x+this.size<=0&&(this.x=720-this.size,this.y=Math.floor(540*Math.random()));if(this.y>540){var n=0;n===t.y&&(n+=30),this.y=n,this.x=Math.floor(720*Math.random())}else this.y<=0&&(this.y=540-this.size,this.x=Math.floor(720*Math.random()))}}])&&o(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function u(t){return u="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},u(t)}function c(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,l(r.key),r)}}function l(t){var e=function(t,e){if("object"!=u(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=u(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==u(e)?e:e+""}function f(t,e,n){return e=p(e),function(t,e){if(e&&("object"===u(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,h()?Reflect.construct(e,n||[],p(t).constructor):e.apply(t,n))}function h(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(h=function(){return!!t})()}function p(t){return p=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},p(t)}function y(t,e){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},y(t,e)}var d=function(t){function e(t,n){var r;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(r=f(this,e,[t,n,10,"white",0,0])).angle=0,r.lives=2,r.bombs=2,r}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&y(t,e)}(e,t),n=e,(r=[{key:"draw",value:function(t){t.save(),t.translate(this.x,this.y),t.rotate(this.angle),t.beginPath(),t.moveTo(-this.size/2,this.size/2),t.lineTo(this.size,0),t.lineTo(-this.size/2,-this.size/2),t.fillStyle=this.color,t.fill(),t.restore(),t.closePath()}},{key:"updatePosition",value:function(t){this.dx+=this.dx>0?-.01:.01,this.dy+=this.dy>0?-.01:.01,t.input.pressed.left&&(this.dx-=.1),t.input.pressed.right&&(this.dx+=.1),t.input.pressed.up&&(this.dy-=.1),t.input.pressed.down&&(this.dy+=.1),t.input.pressed.rotateLeft&&(this.angle-=.1),t.input.pressed.rotateRight&&(this.angle+=.1)}},{key:"checkBounds",value:function(t){t.x>720-t.size&&(this.dx=0,this.x=720-this.size),this.y>540-this.size&&(this.dy=0,this.y=540-this.size),this.y<this.size&&(this.dy=0,this.y=this.size),this.x<this.size&&(this.dx=0,this.x=this.size)}}])&&c(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r}(a);function m(t){return m="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},m(t)}function b(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,v(r.key),r)}}function v(t){var e=function(t,e){if("object"!=m(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=m(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==m(e)?e:e+""}function g(t,e,n){return e=x(e),function(t,e){if(e&&("object"===m(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,w()?Reflect.construct(e,n||[],x(t).constructor):e.apply(t,n))}function w(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(w=function(){return!!t})()}function x(t){return x=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},x(t)}function k(t,e){return k=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},k(t,e)}var P=function(t){function e(t){var n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var r=Math.floor(720*Math.random());return r>=t.ship.x-100&&r<=t.ship.x+100&&(r+=200),(n=g(this,e,[r,Math.floor(720*Math.random()),20,"purple",Math.random()<.5?-.5:.5,Math.random()<.5?-.5:.5])).points=10,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&k(t,e)}(e,t),n=e,(r=[{key:"draw",value:function(t){var e=this.size/2;t.beginPath(),t.moveTo(this.x,this.y),t.lineTo(this.x+e,this.y),t.lineTo(this.x,this.y+e),t.lineTo(this.x-e,this.y),t.lineTo(this.x,this.y),t.lineWidth=3,t.strokeStyle="purple",t.stroke(),t.closePath()}},{key:"updatePosition",value:function(t){}}])&&b(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r}(a);function O(t){return O="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},O(t)}function j(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,E(r.key),r)}}function E(t){var e=function(t,e){if("object"!=O(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=O(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==O(e)?e:e+""}function S(t,e,n){return e=_(e),function(t,e){if(e&&("object"===O(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,T()?Reflect.construct(e,n||[],_(t).constructor):e.apply(t,n))}function T(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(T=function(){return!!t})()}function _(t){return _=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},_(t)}function I(t,e){return I=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},I(t,e)}var M=function(t){function e(t){var n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var r=Math.floor(720*Math.random());return r>=t.ship.x-100&&r<=t.ship.x+100&&(r+=200),(n=S(this,e,[r,Math.floor(720*Math.random()),20,"green",0,0])).speed=.7,n.points=30,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&I(t,e)}(e,t),n=e,(r=[{key:"draw",value:function(t){var e=this.size/2,n=e/2,r=n/2+n;t.beginPath(),t.moveTo(this.x,this.y-e),t.lineTo(this.x+n,this.y-r),t.lineTo(this.x+n,this.y+r),t.lineTo(this.x,this.y+e),t.lineTo(this.x-n,this.y+r),t.lineTo(this.x-n,this.y-r),t.lineTo(this.x,this.y-e),t.lineWidth=3,t.strokeStyle=this.color,t.stroke(),t.closePath()}},{key:"updatePosition",value:function(t){var e=this,n=!1;t.bullets.forEach((function(t){var r=Math.abs(t.x-e.x)<75,i=Math.abs(t.y-e.y)<75,o=Math.abs(t.dx+e.dx)<Math.abs(t.dx),s=Math.abs(t.dy+e.dy)<Math.abs(t.dy);r&&i&&o&&s&&(e.dx<10?(e.dx=t.dx<0?5:-5,e.dy=t.dy<0?-5:5):e.dy<10?(e.dx=t.dx<0?-5:5,e.dy=t.dy<0?5:-5):(e.dx=t.dx<0?5:-5,e.dy=t.dy<0?-5:5),n=!0)})),n||(this.dx=t.ship.x-this.x<0?-this.speed:this.speed,this.dy=t.ship.y-this.y<0?-this.speed:this.speed)}}])&&j(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r}(a);function L(t){return L="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},L(t)}function C(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,B(r.key),r)}}function B(t){var e=function(t,e){if("object"!=L(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=L(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==L(e)?e:e+""}function H(t,e,n){return e=D(e),function(t,e){if(e&&("object"===L(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,z()?Reflect.construct(e,n||[],D(t).constructor):e.apply(t,n))}function z(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(z=function(){return!!t})()}function D(t){return D=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},D(t)}function R(t,e){return R=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},R(t,e)}var A=function(t){function e(t){var n;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var r=Math.floor(720*Math.random());return r>=t.ship.x-100&&r<=t.ship.x+100&&(r+=200),(n=H(this,e,[r,Math.floor(720*Math.random()),20,"blue",0,0])).speed=.8,n.points=20,n}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&R(t,e)}(e,t),n=e,(r=[{key:"draw",value:function(t){var e=this.size/2;t.beginPath(),t.moveTo(this.x,this.y-e),t.lineTo(this.x+e,this.y),t.lineTo(this.x,this.y+e),t.lineTo(this.x-e,this.y),t.lineTo(this.x,this.y-e),t.lineWidth=3,t.strokeStyle=this.color,t.stroke(),t.closePath()}},{key:"updatePosition",value:function(t){this.dx=t.ship.x-this.x<0?-this.speed:this.speed,this.dy=t.ship.y-this.y<0?-this.speed:this.speed}}])&&C(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r}(a);function F(t){return F="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},F(t)}function G(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,U(r.key),r)}}function U(t){var e=function(t,e){if("object"!=F(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=F(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==F(e)?e:e+""}function N(t,e,n){return e=Y(e),function(t,e){if(e&&("object"===F(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,W()?Reflect.construct(e,n||[],Y(t).constructor):e.apply(t,n))}function W(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(W=function(){return!!t})()}function Y(t){return Y=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},Y(t)}function q(t,e){return q=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},q(t,e)}var V=function(t){function e(t,n,r){var i;return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),(i=N(this,e,[t,n,3,"yellow",0,0])).angle=r,i}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&q(t,e)}(e,t),n=e,(r=[{key:"draw",value:function(t){t.beginPath(),t.arc(this.x,this.y,this.size,0,2*Math.PI),t.fillStyle=this.color,t.fill(),t.closePath()}},{key:"move",value:function(t,e){this.checkBounds(t.ship),this.dx=(e+4)*Math.cos(this.angle),this.dy=(e+4)*Math.sin(this.angle),this.x+=this.dx,this.y+=this.dy}},{key:"checkBounds",value:function(t){(this.x>720-t.size||this.x<t.size)&&(this.x=t.x,this.y=t.y,this.angle=t.angle),(this.y>540-t.size||this.y<t.size)&&(this.y=t.y,this.x=t.x,this.angle=t.angle)}}])&&G(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r}(a);function X(t){return X="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},X(t)}function J(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,K(r.key),r)}}function K(t){var e=function(t,e){if("object"!=X(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=X(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==X(e)?e:e+""}function Q(t,e,n){return e=$(e),function(t,e){if(e&&("object"===X(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t)}(t,Z()?Reflect.construct(e,n||[],$(t).constructor):e.apply(t,n))}function Z(){try{var t=!Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){})))}catch(t){}return(Z=function(){return!!t})()}function $(t){return $=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(t){return t.__proto__||Object.getPrototypeOf(t)},$(t)}function tt(t,e){return tt=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t},tt(t,e)}var et=function(t){function e(t,n,r,i){var o;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e);var s=Math.random();s=s>.5?-s:s;var a=Math.random();return(o=Q(this,e,[t,n,1,r,s,a=a>.5?-a:a])).life=0,o.maxLife=i,o}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&tt(t,e)}(e,t),n=e,(r=[{key:"draw",value:function(t){this.life++,t.beginPath(),t.arc(this.x,this.y,this.size,0,2*Math.PI),t.fillStyle=this.color,t.fill(),t.closePath()}},{key:"updatePosition",value:function(){}}])&&J(n.prototype,r),Object.defineProperty(n,"prototype",{writable:!1}),n;var n,r}(a);function nt(t){return nt="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},nt(t)}function rt(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,it(r.key),r)}}function it(t){var e=function(t,e){if("object"!=nt(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=nt(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==nt(e)?e:e+""}var ot=function(){function t(e,n,r){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.ctx=e,this.input=n,this.sound=r,this.newFrame=this.newFrame.bind(this),this.resume=this.resume.bind(this),this.restart=this.restart.bind(this),this.ship=new d(t.WIDTH/2,t.HEIGHT/2),this.points=0,this.highscore=t.BASE_HIGHSCORE,this.difficulty=t.INITIAL_DIFFICULTY,this.bullets=[],this.message="",this.enemyInfo={wander:{spawn_rate:2500,last_spawn:null},follow:{spawn_rate:5e3,last_spawn:null},avoider:{spawn_rate:8e3,last_spawn:null}},this.gameInfo={points:document.getElementById("points"),lives:document.getElementById("lives"),bombs:document.getElementById("bombs"),highscore:document.getElementById("highscore"),message:document.getElementById("message"),overlay:document.getElementById("canvas-overlay")},this.input.attachHandlers(this),this.updateGameInfoDisplay()}return e=t,(n=[{key:"start",value:function(){this.enemies=[],this.bullets=[],this.fillBullets(),this.particles=[],this.sound.play("background"),this.playing=!0,requestAnimationFrame(this.newFrame)}},{key:"pause",value:function(){this.playing=!1,this.sound.pause(),this.message="Paused. Click to resume.",this.gameInfo.overlay.classList.remove("d-none"),this.gameInfo.overlay.addEventListener("click",this.resume),this.updateGameInfoDisplay()}},{key:"resume",value:function(){this.playing=!0,this.sound.play("background"),this.message="",this.gameInfo.overlay.classList.add("d-none"),this.gameInfo.overlay.removeEventListener("click",this.resume),requestAnimationFrame(this.newFrame),this.updateGameInfoDisplay()}},{key:"restart",value:function(){this.gameInfo.overlay.classList.add("d-none"),this.gameInfo.overlay.removeEventListener("click",this.restart),this.message="",this.points=0,this.ship.color="white",this.ship.lives=2,this.ship.bombs=2,this.difficulty=t.INITIAL_DIFFICULTY,this.updateGameInfoDisplay(),this.start()}},{key:"bomb",value:function(){var t=this;this.ship.bombs>0&&(this.sound.play("bomb"),this.ship.bombs-=1,this.createParticles(this.ship.x,this.ship.y,this.ship.color),this.points+=100,this.enemies.forEach((function(e){t.createParticles(e.x,e.y,e.color),t.points+=e.points})),this.enemies=[],this.updateGameInfoDisplay())}},{key:"newFrame",value:function(e){this.difficulty+=t.DIFFICULTY_DELTA,this.addEnemies(e),this.move(),this.checkShipCollision(),this.checkBulletCollision(),this.draw(),this.checkParticleLife(),this.playing&&requestAnimationFrame(this.newFrame)}},{key:"move",value:function(){var t=this;this.ship.move(this),this.bullets.forEach((function(e,n){e.move(t,n)})),this.enemies.forEach((function(e){e.move(t)})),this.particles.forEach((function(e){e.move(t)}))}},{key:"addEnemies",value:function(t){if(null===this.enemyInfo.wander.last_spawn)return this.enemies.push(new P(this)),this.enemies.push(new P(this)),this.enemies.push(new P(this)),this.enemies.push(new P(this)),this.enemyInfo.wander.last_spawn=t,this.enemyInfo.follow.last_spawn=t,void(this.enemyInfo.avoider.last_spawn=t);t-this.enemyInfo.wander.last_spawn>=this.enemyInfo.wander.spawn_rate-this.difficulty&&(this.enemies.push(new P(this)),this.enemies.push(new P(this)),this.enemyInfo.wander.last_spawn=t),t-this.enemyInfo.follow.last_spawn>=this.enemyInfo.follow.spawn_rate-this.difficulty&&(this.enemies.push(new A(this)),this.enemyInfo.follow.last_spawn=t),t-this.enemyInfo.avoider.last_spawn>=this.enemyInfo.avoider.spawn_rate-this.difficulty&&(this.enemies.push(new M(this)),this.enemyInfo.avoider.last_spawn=t)}},{key:"checkShipCollision",value:function(){var e=this;this.enemies.forEach((function(n){e.ship.x>=n.x-n.width&&e.ship.x<=n.x+n.width&&e.ship.y>=n.y-n.width&&e.ship.y<=n.y+n.width&&(e.ship.color="black",e.sound.play("death"),e.ship.lives-=1,e.createParticles(e.ship.x,e.ship.y,"red"),e.ship.lives>0?(e.enemies=[],e.ship.x=t.WIDTH/2,e.ship.y=t.HEIGHT/2,e.ship.color="white",e.enemies.push(new A(e)),e.enemies.push(new A(e)),e.enemies.push(new A(e))):(e.bullets=[],e.sound.pause(),e.playing=!1,e.message="Game Over. Click to Play Again.",e.points>e.highscore&&(e.highscore=e.points,e.message="New High Score! Click to Play Again."),e.gameInfo.overlay.classList.remove("d-none"),e.gameInfo.overlay.addEventListener("click",e.restart)),e.updateGameInfoDisplay())}))}},{key:"checkBulletCollision",value:function(){var t=this;this.bullets.forEach((function(e){t.enemies.forEach((function(n,r){e.x>=n.x-n.width&&e.x<=n.x+n.width&&e.y>=n.y-n.width&&e.y<=n.y+n.width&&(t.createParticles(n.x,n.y,n.color),t.points+=n.points,t.enemies.splice(r,1),t.sound.play("kill"),t.updateGameInfoDisplay())}))}))}},{key:"updateGameInfoDisplay",value:function(){this.gameInfo.points.innerHTML=this.points,this.gameInfo.lives.innerHTML=this.ship.lives,this.gameInfo.bombs.innerHTML=this.ship.bombs,this.gameInfo.highscore.innerHTML=this.highscore,this.gameInfo.message.innerHTML=this.message}},{key:"fillBullets",value:function(){for(var e=0;e<t.BULLET_COUNT;e++)this.bullets.push(new V(this.ship.x,this.ship.y,this.ship.angle))}},{key:"checkParticleLife",value:function(){var t=this;this.particles.forEach((function(e,n){e.life>=e.maxLife&&t.particles.splice(n,1)}))}},{key:"createParticles",value:function(e,n,r){for(var i=0;i<t.NUM_PARTICLES;i++)this.particles.push(new et(e,n,r,t.PARTICLE_MAX_LIFE))}},{key:"draw",value:function(){var e=this;this.ctx.clearRect(0,0,t.WIDTH,t.HEIGHT),this.ship.draw(this.ctx),this.bullets.forEach((function(t){t.draw(e.ctx)})),this.enemies.forEach((function(t){t.draw(e.ctx)})),this.particles.forEach((function(t){t.draw(e.ctx)}))}}])&&rt(e.prototype,n),Object.defineProperty(e,"prototype",{writable:!1}),e;var e,n}();ot.WIDTH=720,ot.HEIGHT=540,ot.PARTICLE_MAX_LIFE=40,ot.NUM_PARTICLES=30,ot.BULLET_COUNT=10,ot.INITIAL_DIFFICULTY=.001,ot.DIFFICULTY_DELTA=.003,ot.BASE_HIGHSCORE=1e3;const st=ot;function at(t){return at="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},at(t)}function ut(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,ct(r.key),r)}}function ct(t){var e=function(t,e){if("object"!=at(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=at(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==at(e)?e:e+""}var lt=function(){return t=function t(e){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.background=new Audio("../public/audio/rolemusicPirateAndDancer.mp3"),this.bomb=new Audio("../public/audio/cat.wav"),this.death=new Audio("../public/audio/death-scream.wav"),this.kill=new Audio("../public/audio/enemy-destroy.wav"),this.star=new Audio("../public/audio/hadokowa_get_a_dog_pet_a_dog.mp3"),this.background.loop=!0,this.elements={volume:document.getElementById("volume"),mute:document.getElementById("mute")},this.updateVolume(this.elements.volume.value)},(e=[{key:"attachHandlers",value:function(){var t=this;this.elements.mute.addEventListener("change",(function(){t.elements.mute.checked?t.mute():t.unmute()})),this.elements.volume.addEventListener("change",(function(){t.updateVolume(t.elements.volume.value)}))}},{key:"play",value:function(t){this[t].play()}},{key:"all",value:function(){return[this.background,this.bomb,this.death,this.kill,this.star]}},{key:"updateVolume",value:function(t){this.all().forEach((function(e){e.volume=t}))}},{key:"mute",value:function(){this.all().forEach((function(t){t.muted=!0}))}},{key:"unmute",value:function(){this.all().forEach((function(t){t.muted=!1}))}},{key:"pause",value:function(){this.background.pause()}}])&&ut(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();function ft(t){return ft="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},ft(t)}function ht(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,pt(r.key),r)}}function pt(t){var e=function(t,e){if("object"!=ft(t)||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=ft(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==ft(e)?e:e+""}var yt=function(){return t=function t(){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.keyDownHandler=this.keyDownHandler.bind(this),this.keyUpHandler=this.keyUpHandler.bind(this),this.pressed={right:!1,left:!1,up:!1,down:!1,rotateLeft:!1,rotateRight:!1}},(e=[{key:"attachHandlers",value:function(t){this.game=t,document.addEventListener("keydown",this.keyDownHandler,!1),document.addEventListener("keyup",this.keyUpHandler,!1)}},{key:"keyDownHandler",value:function(t){switch(t.keyCode){case 65:this.pressed.left=!0;break;case 37:this.pressed.rotateLeft=!0;break;case 87:this.pressed.up=!0;break;case 68:this.pressed.right=!0;break;case 39:this.pressed.rotateRight=!0;break;case 83:this.pressed.down=!0;break;case 80:this.game.pause();break;case 82:this.game.playing=!1,this.game.bullets=[];break;case 32:t.preventDefault(),this.game.playing&&this.game.bomb()}}},{key:"keyUpHandler",value:function(t){switch(t.keyCode){case 65:this.pressed.left=!1;break;case 37:this.pressed.rotateLeft=!1;case 87:this.pressed.up=!1;break;case 68:this.pressed.right=!1;break;case 39:this.pressed.rotateRight=!1;break;case 83:this.pressed.down=!1;break;case 82:this.game.restart()}}}])&&ht(t.prototype,e),Object.defineProperty(t,"prototype",{writable:!1}),t;var t,e}();document.addEventListener("DOMContentLoaded",(function(){var t=document.getElementById("canvas");t.width=st.WIDTH,t.height=st.HEIGHT;var e=t.getContext("2d"),n=new yt,r=new lt;r.attachHandlers();var i=new st(e,n,r);document.getElementById("startGame").addEventListener("click",(function(){this.classList.add("d-none"),i.start()}))}))})()})();