-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
1 lines (1 loc) · 38.3 KB
/
index.html
1
<html><title>SHUTTLEDECK</title><link rel="shortcut icon" type="image/x-icon" href="images/favicon.ico" sizes="64x64"/><meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0"><style>canvas{width:100%;height:100%;}body{margin:0;background:#000;}</style><canvas><script>const canvas=document.getElementsByTagName("canvas")[0],ctx=canvas.getContext("2d");var w,h;function width(){return w}function height(){return h}function resize(){canvas.width=+window.innerWidth,canvas.height=+window.innerHeight,w=canvas.width,h=canvas.height}ctx.imageSmoothingEnabled=!0,ctx.lineCap="round",ctx.lineJoin="round",resize(),window.addEventListener("resize",resize);var g=[];function get(){return g}function add(e){g.push(e)}function remove(t){g=g.filter(e=>e!=t)}function clear(e){g=[]}function e(){var i={};return{clear:()=>i={},on:(e,t)=>(i[e]||(i[e]=[])).push(t),off:(e,t)=>i[e]=(i[e]||[]).filter(e=>e!=t),emit:(e,t)=>(i[e]||[]).forEach(e=>e(t))}}b=new e;var bus=b;function pulse(t,i,l,a){var r=0;return e=>{r+=e,t((Math.sin(r/a*6.3)+1)/2*(l-i)+i)}}function transition$1(t,a){var r=0;this.update=e=>{1<(r+=e/t)&&a&&(this.destroyed=!0,bus.emit("txn-done"))},this.render=e=>{var t=width(),i=height(),l=0,l=a?Math.max(1-r*r,0):Math.pow(1.3*Math.max(r-.3,0),2);e.save(),e.fillStyle="#443",e.translate(0,.6*-i*l),e.fillRect(0,0,t,i/2),e.strokeStyle="#b94",e.fillStyle="#b94",e.lineWidth=.03*t,e.fillRect(0,i/2,t,.05*i),e.strokeRect(.25*t,.2*i,.5*t,.2*i),e.textAlign="center",e.textBaseline="middle",e.font=`${.06*t}px monospace`,e.fillText("SHUTTLEDECK",.5*t,.3*i),e.restore(),e.save(),e.fillStyle="#443",e.translate(0,.6*i*l),e.fillRect(0,i/2,t,i/2),e.fillStyle="#b94",e.fillRect(0,.55*i,t,.05*-i),e.restore()}}function drawStars(t,i,l,a,r){var n=width(),s=height(),o=Math.sqrt(n*s)/10;t.beginPath(),t.strokeStyle="#aaa",t.fillStyle="#ddd",t.lineWidth=.5;for(let e=0;e<o;e++){var h=1+5*(.5*Math.sin(e*e*1217+e*e*e*983)+.5),f=(1234918*e*e+e*e*e*e*2291722+i*h)%(n+100)-50,c=(3000182*e*e*e*e+e*e*e*e*e*500291+l*h)%(s+100)-50;t.moveTo(f,c),t.lineTo(f+a*h,c+r*h),t.fillRect(f-1,c-1,2,2)}t.stroke()}function drawCard(t,e,i,l,a,r,n){t.save(),r&&(l*=1.04);var s=`rgba(${a.color[0]},${a.color[1]},${a.color[2]},${n})`,o=l/2,h=1.5*o;t.translate(e,i),t.fillStyle=r?`rgb(80,80,80,${.7*n})`:`rgb(50,50,50,${.7*n})`,t.fillRect(-o,-h,2*o,2*h),t.save(),t.beginPath(),t.rect(-o,-h,2*o,2*h),t.clip(),t.fillStyle=`rgba(220,230,250,${.3*n})`,t.rotate(-.3),t.translate(l/2,Date.now()%2e3/1e3*(5*l)-1.2*l),t.fillRect(2*-l,0,4*l,.2*l),t.fillRect(2*-l,.2*-l,4*l,.05*l),t.restore(),t.beginPath(),t.lineWidth=l/20,t.lineJoin="round",t.strokeStyle=s,t.moveTo(-o,-h),t.lineTo(o,-h),t.lineTo(o,h),t.lineTo(-o,h),t.closePath(),t.stroke(),t.save(),t.translate(0,.15*-l),a.glyph(t,l),t.translate(0,.52*-l),t.fillStyle=`rgba(255,255,51,${n})`;var f=.12*l;for(let e=0;e<a.cost;e++)t.fillRect((e-(a.cost-1)/2)*f*1.1-.45*f,0,.9*f,.9*f);t.restore(),t.fillStyle=s,t.textBaseline="middle",t.font=`${l/6}px monospace`,t.textAlign="center";var c=a.title;for(let e=0;e<c.length;e++)t.fillText(c[e],0,.65*h+(e-(c.length-1)/2)*h*.2);t.restore()}function drawMineral(e,t,i,l,a){e.save(),e.translate(t,i),e.fillStyle="#f3f",e.rotate(l),e.fillRect(-a,-a,2*a,2*a),a*=.6,e.fillStyle="#fbf",e.fillRect(-a,-a,2*a,2*a),e.restore()}function drawShield(e,t,i,l,a){e.fillStyle="#333",e.beginPath(),e.arc(t,i,l,0,6.28),e.fill(),a&&(e.fillStyle="#3ff",e.beginPath(),e.arc(t,i,.65*l,0,6.28),e.fill())}function drawEnergy(e,t,i,l,a){e.fillStyle="#333",e.fillRect(t,i,.8*l,l),a&&(e.fillStyle="#ff3",e.fillRect(t+.175*l,i+.175*l,.45*l,.65*l))}function drawDeck(e,t,i,l){e.save(),e.strokeStyle="#ccc",e.fillStyle="#222",e.lineWidth=.1*l;var a=.5*l;e.translate(t-a,i+a),e.fillRect(-l,1.5*-l,2*l,3*l),e.strokeRect(-l,1.5*-l,2*l,3*l),e.translate(a,-a),e.fillRect(-l,1.5*-l,2*l,3*l),e.strokeRect(-l,1.5*-l,2*l,3*l),e.translate(a,-a),e.fillRect(-l,1.5*-l,2*l,3*l),e.strokeRect(-l,1.5*-l,2*l,3*l),e.restore()}function drawCharPlayer(e){var t=width(),i=height(),t=Math.min(.075*i,.1*t);e.save(),e.translate(1.2*t,i+Math.sin(.003*Date.now())*t*.1),e.fillStyle="#bbb",e.beginPath(),e.arc(.1*-t,.1*t,1.4*t,0,6.29),e.fill(),e.fillStyle="#eee",e.beginPath(),e.arc(0,1.9*-t,t,0,6.29),e.fill(),e.fillStyle="#3af",e.fillRect(.1*-t,2.1*-t,t,.4*t),e.restore()}function drawCharZoren(e,t="#3b5"){var i=width(),l=height(),a=Math.min(.075*l,.1*i);e.save(),e.translate(i-1.2*a,l+Math.sin(.0021*Date.now()+3)*a*.1),e.fillStyle=t,e.fillRect(.5*-a,1.5*-a,1.4*a,2*a),e.fillStyle="#666",e.fillRect(.2*-a,1.5*-a,.1*a,2*a),e.fillRect(.35*-a,.8*-a,.1*a,.1*a),e.fillRect(.35*-a,.6*-a,.1*a,.1*a),e.fillStyle="#fdb",e.beginPath(),e.arc(0,1.8*-a,a,0,6.29),e.fill(),e.fillStyle="#333",e.fillRect(-a,1.95*-a,1.6*a,.1*a),e.fillStyle=t,e.beginPath(),e.arc(.8*-a,1.8*-a,.3*a,0,6.29),e.fill(),e.beginPath(),e.arc(.1*-a,1.8*-a,.3*a,0,6.29),e.fill(),e.restore()}function drawCharWeaponTech(e){var t=width(),i=height(),l=Math.min(.075*i,.1*t);e.save(),e.translate(t-1.2*l,i+Math.sin(.0021*Date.now()+3)*l*.1),e.fillStyle="#d72",e.beginPath(),e.ellipse(.1*l,.1*l,+l,1.4*l,0,0,6.29),e.fill(),e.fillStyle="#f94",e.beginPath(),e.arc(0,1.9*-l,l,0,6.29),e.fill(),e.fillRect(.8*-l,2.3*-l,.4*l,-l),e.fillRect(.4*l,2.4*-l,.4*l,-l),e.fillStyle="#fff",e.beginPath(),e.ellipse(.3*-l,2*-l,.5*l,.3*l,0,0,6.29),e.fill(),e.fillStyle="#222",e.beginPath(),e.arc(.4*-l,2*-l,.2*l,0,6.29),e.fill(),e.restore()}function drawCharShipMech(e){var t=width(),i=height(),l=Math.min(.075*i,.1*t);e.save(),e.translate(t-1.2*l,i+Math.sin(.0021*Date.now()+3)*l*.1),e.fillStyle="#77b",e.fillRect(1.1*-l,1.5*-l,2.2*l,2*l),e.fillStyle="#669",e.fillRect(.9*l,1.5*-l,.2*l,2*l),e.fillStyle="#338",e.fillRect(.5*l,2.7*-l,.3*l,1.25*l),e.fillRect(.2*-l,2.7*-l,.1*l,.8*-l),e.fillStyle="#55a",e.fillRect(.8*-l,2.7*-l,1.3*l,1.25*l),e.fillStyle="#ff4",e.fillRect(.25*-l,3.4*-l,.2*l,.2*-l),e.fillRect(.7*-l,2.5*-l,.4*l,.2*l),e.fillRect(.2*-l,2.5*-l,.4*l,.2*l),e.restore()}function drawCharMerchant(e){var t=width(),i=height(),l=Math.min(.075*i,.1*t);e.save(),e.translate(t-1.2*l,i+Math.sin(.0021*Date.now()+3)*l*.1),e.fillStyle="#b31",e.beginPath(),e.ellipse(.4*l,.1*l,.8*l,1.8*l,0,0,6.29),e.fill(),e.fillStyle="#d74",e.beginPath(),e.arc(0,1.6*-l,.6*l,0,6.29),e.fill(),e.strokeStyle="#d74",e.beginPath(),e.lineWidth=.1*l,e.moveTo(.4*-l,2*-l),e.lineTo(.7*-l,3*-l),e.moveTo(.1*-l,2*-l),e.lineTo(.1*-l,3.2*-l),e.moveTo(.2*l,2*-l),e.lineTo(.4*l,3*-l),e.stroke(),e.fillStyle="#eee",e.beginPath(),e.arc(.7*-l,3*-l,.2*l,0,6.29),e.fill(),e.beginPath(),e.arc(.1*-l,3.2*-l,.2*l,0,6.29),e.fill(),e.beginPath(),e.arc(.4*l,3*-l,.2*l,0,6.29),e.fill(),e.fillStyle="#611",e.beginPath(),e.arc(.78*-l,3*-l,.1*l,0,6.29),e.fill(),e.beginPath(),e.arc(.18*-l,3.2*-l,.1*l,0,6.29),e.fill(),e.beginPath(),e.arc(.32*l,3*-l,.1*l,0,6.29),e.fill(),e.restore()}function drawCharSmuggler(e){var t=width(),i=height(),l=Math.min(.075*i,.1*t);e.save(),e.translate(t-1.2*l,i+Math.sin(.0021*Date.now()+3)*l*.1),e.fillStyle="#343",e.beginPath(),e.arc(.2*l,0,.6*l,0,6.29),e.fill(),e.fillStyle="#353",e.beginPath(),e.arc(.5*l,.7*-l,.6*l,0,6.29),e.fill(),e.fillStyle="#363",e.beginPath(),e.arc(.4*l,1.4*-l,.6*l,0,6.29),e.fill(),e.fillStyle="#474",e.beginPath(),e.arc(0,1.9*-l,.8*l,0,6.29),e.fill(),e.fillStyle="#3f3",e.beginPath(),e.arc(.6*-l,2.1*-l,.07*l,0,6.29),e.fill(),e.beginPath(),e.arc(.4*-l,2.08*-l,.07*l,0,6.29),e.fill(),e.beginPath(),e.arc(.65*-l,1.9*-l,.07*l,0,6.29),e.fill(),e.beginPath(),e.arc(.45*-l,1.88*-l,.07*l,0,6.29),e.fill(),e.beginPath(),e.arc(.62*-l,1.7*-l,.07*l,0,6.29),e.fill(),e.beginPath(),e.arc(.42*-l,1.68*-l,.07*l,0,6.29),e.fill(),e.restore()}function drawCharTemplar(e){var t=width(),i=height(),l=Math.min(.075*i,.1*t);e.save(),e.translate(t-1.2*l,i+Math.sin(.0021*Date.now()+3)*l*.1-.5*l),e.fillStyle="#46c",e.beginPath(),e.arc(.2*-l,1.5*-l,.4*l,0,6.29),e.fill(),e.beginPath(),e.arc(.2*l,1.4*-l,.3*l,0,6.29),e.fill(),e.fillStyle="rgba(100,100,255,0.3)",e.beginPath(),e.arc(0,.95*-l,1.1*l,-3.14,0),e.fill(),e.fillStyle="#db3",e.fillRect(1.2*-l,-l,2.4*l,.3*l),e.fillRect(.6*-l,.55*-l,1.2*l,.2*l),e.fillRect(.3*-l,.2*-l,.6*l,.1*l),e.restore()}var lineBreaks=(t,i,l)=>{var a,r,n="",s=[];for(let e=0;e<i.length;e++)n+=i[e],t.measureText(n).width>l&&(a=n.lastIndexOf(" "),r=n.substring(0,a),s.push(r.trim()),n=n.substring(a));return 0<n.trim().length&&s.push(n.trim()),s},getTextLines=(e,t,i,l,a)=>{var r=textLineMap[t];if(r&&r.w==i&&r.h==l)return r.lines;a=lineBreaks(e,t,a);return textLineMap[t]={w:i,h:l,lines:a},a},textLineMap={};function drawDialogBox(t,e,i){var l=width(),a=height(),r=Math.min(.075*a,.1*l),n=Math.max(.09*l,.08*a);t.save(),t.fillStyle="#236",t.strokeStyle="#3af",t.lineWidth=.1*r,t.beginPath(),t.moveTo(2.8*r,.75*a),t.lineTo(l-2.8*r,.75*a),t.lineTo(l-2.8*r,a-1.8*r),t.lineTo(l-2.5*r,a-1.6*r),t.lineTo(l-2.8*r,a-1.4*r),t.lineTo(l-2.8*r,a-.2*r),t.lineTo(2.8*r,a-.2*r),t.closePath(),t.fill(),t.stroke(),t.fillStyle="#ff3",t.textAlign="left",t.font=`${.3*n}px monospace`,t.fillText(e,3*r,.75*a+.25*n),t.fillStyle="#fff",t.textAlign="left",t.font=`${.25*n}px monospace`;var s=getTextLines(t,i,l,a,l-6*r);for(let e=0;e<s.length;e++)t.fillText(s[e],3*r,.75*a+n*(2.1+e)*.3);t.restore()}function drawItemShell(e,t,i,l){e.save(),e.translate(t,i),l/=2,e.fillStyle="#333",e.strokeStyle="#666",e.lineWidth=.1*l,e.beginPath(),e.arc(0,0,l,0,6.29),e.fill(),e.stroke(),e.restore()}function drawItemXeno(e,t,i,l){e.save(),e.translate(t,i),l/=2,e.fillStyle="#ccd",e.fillRect(.07*l,.7*-l,.15*l,.7*l),e.beginPath(),e.arc(.1*l,.54*-l,.24*l,0,6.29),e.fill(),e.fillStyle="#b94",e.fillRect(.6*-l,.1*-l,1.2*l,.7*l),e.fillRect(.3*l,.3*-l,.4*l,.5*l),e.fillStyle="#aaa",e.textAlign="center",e.textBaseline="bottom",e.font=`${.2*l}px monospace`,e.fillText("Xenotransponder",0,1.4*l),e.restore()}function StartButton(r="Liftoff"){var a=({x:e,y:t})=>{var i=width(),l=.1*i;.97*i-2*l<e&&e<.97*i&&0<t&&t<.02*i+.8*l&&(bus.emit("start"),bus.off("tap",a))};bus.on("tap",a),this.render=e=>{var t=width(),i=.1*t;e.save(),e.translate(.97*t-i,.02*t+.4*i);var l=Date.now()%500/500,a=.4*(1-(1-l)*(1-l))+.8;e.scale(a,1.1*a),e.strokeStyle="#0a0",e.lineWidth=.1*i*(1-l),e.strokeRect(-i,.4*-i,2*i,.8*i),e.restore(),e.fillStyle="#0a0",e.fillRect(.97*t,.02*t,2*-i,.8*i),e.fillStyle="#fff",e.font=`${.35*i}px monospace`,e.textAlign="center",e.textBaseline="middle",e.fillText(r,.97*t-i,.02*t+.4*i)}}function Audio(){var s,e,t,i,l,a,r,n,o,h,f,c,d,u,g,p,y=null,m=e=>Math.min(Math.max(Math.sin(e),-1),1),b=e=>(e%6.28-3.14)/6.28,v=e=>Math.min(Math.max(1e3*Math.sin(e),-1),1),S=(e,t,i)=>e<44100*t||44100*i<e?0:1-(e/44100-t)/(i-t),w=(e,t,i,l)=>.01*v(e/(80/Math.pow(2,t/12)))*S(e,i,i+l),x=(e,t)=>.02*Math.random()*S(e,t,t+.06),T=(e,t,i=!0)=>{for(var e=y.createBuffer(1,s*e,s),l=e.getChannelData(0),a=e.length,r=0;r<a;r++){var n=i?1-r/a:1;l[r]=t(44100*r/s)*n}return e};this.init=()=>{y=new(window.AudioContext||window.webkitAudioContext),s=y.sampleRate,e=T(.6,e=>.05*v(e/250)*(m(e/300)+0)),t=T(1,e=>.05*v(e/250)*(m(e/300)+0)+.1*Math.random()*S(e,0,1)),i=T(.7,e=>.07*(b(e/19)*S(e,0,.15)+b(e/11)*S(e,.1,.7))),l=T(.15,e=>.04*m(e/(15-e/2e3))),a=T(.8,e=>.1*Math.random()*S(e,0,.8)*(v(e/200)+1)),r=T(.4,e=>.04*(1+Math.random()/3)*S(e,0,.4)*m(e/50)),n=T(.7,e=>.04*Math.random()*S(e,0,.7)*(v(e/100)+1)),o=T(1.5,e=>.08*(m(e/(30-e/400))*S(e,0,.15)*3+b(e/60)*(v(e/400)+1)/2*S(e,.1,1.5))),h=T(1,e=>.04*m(e/50)*(v(e/800+1)+1)),f=T(.7,e=>.1*(b(e/30)*S(e,0,.1)+b(e/50)*S(e,.1,.2)+b(e/40)*S(e,.2,.3)+b(e/20)*S(e,.3,.4)+b(e/10)*S(e,.4,.5))),c=T(.7,t=>{var i=0;for(let e=0;e<10;e++)i+=m(t/(10+e*e/20))*S(t,e/10,(e+1)/10);return.05*i}),d=T(1.5,t=>{var i=0;for(let e=0;e<13;e++)i+=v(t/(10-e*e/15))*S(t,e/15,(e+1)/15),i+=v(t/(40-e*e/3))*S(t,e/15+.03,(e+1)/15);return.05*i}),u=T(.6,e=>.04*m(e/(50-e/2e3))*(v(e/700+1)+1)),g=T(.2*48,t=>{var i=0;for(let e=0;e<48;e+=8)i+=x(t,.2*(e+0))+x(t,.2*(e+1))+3*x(t,.2*(e+2))+x(t,.2*(e+3))+x(t,.2*(e+4))+3*x(t,.2*(e+6));return i+=w(t,12,1.6,.2)+w(t,7,2.2,.2)+w(t,10,.2*14,.2*1.5)+w(t,9,3.2,.2*1.5)+w(t,3,3.6,.2*1.5)+w(t,6,6.4,.2)+w(t,3,7,.2)+w(t,5,.2*38,.2*1.5)+w(t,3,8,.2*1.5)+w(t,0,8.4,.2*1.5)},!1),p=T(3,e=>.01*(b(e/300)*v(e/130)+1),!1)};var M=e=>{var t=y.createBufferSource();t.buffer=e,t.connect(y.destination),t.start()};this.setup=()=>{null==y&&this.init(),bus.on("txn",()=>{M(e)}),bus.on("txn-done",()=>{M(t)}),bus.on("buy",()=>{M(i)}),bus.on("mineral",()=>{M(l)}),bus.on("mine",()=>{M(l)}),bus.on("hit",()=>{M(a)}),bus.on("boom",()=>{M(a)}),bus.on("lane",()=>{M(r)}),bus.on("hop",()=>{M(f)}),bus.on("dash",()=>{M(c)}),bus.on("hyper",()=>{M(d)}),bus.on("heal",()=>{M(u)}),bus.on("projectile",e=>{1!=e&&4!=e&&5!=e||M(n),2==e&&M(o),3==e&&M(h)})};var P=null;this.music=()=>{null==y&&this.init(),(P=y.createBufferSource()).buffer=g,P.loop=!0,P.connect(y.destination),P.start()},this.bgRocket=()=>{null==y&&this.init(),(P=y.createBufferSource()).buffer=p,P.loop=!0,P.connect(y.destination),P.start()},this.stopMusic=()=>{try{null!=P&&P.stop()}catch(e){}}}var audio=new Audio;function Steam(i,l){var a=.4*Math.random()+.2,r=(Math.random()+1)*width()*.02,t=(Math.random()-.5)*height()*.08*r;this.update=e=>{(a-=e)<0&&(this.destroyed=!1),r+=r*a*e,l+=t*e,t-=t*e*2,i-=(Math.random()-.5)*r*e*5},this.render=e=>{var t=a;e.fillStyle=`rgba(255,255,255,${t})`,e.beginPath(),e.arc(i,l,Math.max(r,1),0,6.29),e.fill()}}function Text(e,t,i,l="#fff",a="1",r="left"){this.str=e,this.x=t,this.y=i,this.color=l,this.size=a,this.render=e=>{var t=.08*width();e.textAlign=r,e.textBaseline="middle",e.fillStyle=this.color,e.font=`${this.size*t}px monospace`,e.fillText(this.str,this.x(),this.y())}}function MainMenu(){this.render=e=>drawStars(e,.03*-Date.now(),0,3,0),add(new Text("SHUTTLEDECK",()=>width()/2,()=>.4*height(),"#fff",1,"center"));var t=new Text("[ Press to start ]",()=>width()/2,()=>.6*height(),"#777",.5,"center");t.ecs=[pulse(e=>{t.size=e},.45,.55,1)],add(t),add(new Text("by Ariel Wexler",()=>width()/2,()=>.8*height(),"#f3f",.35,"center"));var e=()=>{transition(1),bus.off("tap",e)};bus.on("tap",e)}const cards=[{color:[255,51,51],title:["Rho","Channel"],cost:1,price:5,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.beginPath(),e.arc(0,-t/6,t/7,0,6.29),e.stroke(),e.strokeRect(-t/6,t/10,t/3,0),e.strokeRect(-t/6,t/4,t/3,0),e.restore()},use:()=>{bus.emit("lane",0)}},{color:[51,255,51],title:["Gamma","Sector"],cost:1,price:5,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.beginPath(),e.arc(0,0,t/7,0,6.29),e.stroke(),e.strokeRect(-t/6,-t/4,t/3,0),e.strokeRect(-t/6,t/4,t/3,0),e.restore()},use:()=>{bus.emit("lane",1)}},{color:[51,51,255],title:["Beta","Stream"],cost:1,price:5,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.beginPath(),e.arc(0,t/6,t/7,0,6.29),e.stroke(),e.strokeRect(-t/6,-t/10,t/3,0),e.strokeRect(-t/6,-t/4,t/3,0),e.restore()},use:()=>{bus.emit("lane",2)}},{color:[255,160,30],title:["Kepler","Missile"],cost:2,price:10,glyph:function(e,t,i=.05){e.save(),e.translate(t/20,0),e.rotate(.6),e.lineWidth=t*i,e.beginPath(),e.moveTo(-t/18,-t/6),e.lineTo(0,-t/4),e.lineTo(t/18,-t/6),e.lineTo(t/18,t/4),e.lineTo(-t/18,t/4),e.closePath(),e.moveTo(-t/8,t/4),e.lineTo(-t/6,t/4),e.lineTo(-t/8,t/10),e.closePath(),e.moveTo(t/8,t/4),e.lineTo(t/6,t/4),e.lineTo(t/8,t/10),e.closePath(),e.stroke(),e.restore()},use:()=>{bus.emit("projectile",1)}},{color:[255,160,30],title:["Sigma","Cannon"],cost:3,price:15,glyph:function(e,t){e.save(),e.translate(t/12,t/15),e.rotate(.6),e.lineWidth=.05*t,e.lineCap="round",e.beginPath(),e.moveTo(-t/4,-t/4),e.lineTo(-t/14,-t/4),e.lineTo(-t/14,-t/10),e.lineTo(t/10,-t/10),e.lineTo(t/10,t/4),e.lineTo(-t/4,t/4),e.closePath(),e.moveTo(-t/6,0),e.lineTo(0,0),e.lineTo(-t/12,t/12),e.lineTo(0,t/6),e.lineTo(-t/6,t/6),e.stroke(),e.restore()},use:()=>{bus.emit("projectile",2)}},{color:[255,160,30],title:["Pulse","Breaker"],cost:3,price:15,glyph:function(e,t){e.save(),e.translate(-t/30,0),e.lineWidth=.05*t,e.lineCap="round",e.beginPath(),e.arc(0,0,t/16,0,6.29),e.stroke(),e.beginPath(),e.arc(0,0,t/5,-1,1),e.stroke(),e.beginPath(),e.arc(0,0,t/3,-.8,.8),e.stroke(),e.rotate(.5),e.strokeRect(-t/8,-t/30,-t/8,t/15),e.rotate(-1),e.strokeRect(-t/8,-t/30,-t/8,t/15),e.restore()},use:()=>{bus.emit("projectile",3)}},{color:[255,160,30],title:["Crazy","Rockets"],cost:2,price:10,glyph:function(t,i){t.save(),t.lineWidth=.05*i,t.lineCap="round";for(let e=0;e<2;e++)t.beginPath(),t.moveTo(-i/4,i/8),t.lineTo(-i/6,-i/8),t.lineTo(i/14,i/20),t.lineTo(i/8,-i/6),t.stroke(),t.beginPath(),t.moveTo(i/8+i/12,-i/6),t.lineTo(i/8-i/12,-i/6),t.lineTo(i/8,-i/6-i/8),t.closePath(),t.stroke(),t.translate(i/16,i/5),t.rotate(.2);t.restore()},use:()=>{bus.emit("projectile",4)}},{color:[255,160,30],title:["Tactical","Nuke"],cost:4,price:20,glyph:function(t,i){t.save(),t.lineWidth=.05*i,t.lineCap="round",t.beginPath(),t.arc(0,0,i/3,0,6.29),t.stroke(),t.beginPath(),t.arc(0,0,i/20,0,6.29),t.stroke(),t.rotate(.5);for(let e=0;e<3;e++)t.beginPath(),t.arc(0,0,i/4,-.4,.4,!1),t.arc(0,0,i/8,.4,-.4,!0),t.closePath(),t.stroke(),t.rotate(2.1);t.restore()},use:()=>{bus.emit("projectile",5)}},{color:[255,70,255],title:["Quantum","Hopper"],cost:1,price:5,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.lineCap="round",e.beginPath(),e.arc(0,t/5,t/14,0,6.29),e.stroke(),e.beginPath(),e.arc(0,0,t/14,0,6.29),e.stroke(),e.beginPath(),e.arc(0,-t/5,t/14,0,6.29),e.stroke(),e.restore()},use:()=>{bus.emit("hop",2)}},{color:[255,70,255],title:["Shadow","Dash"],cost:2,price:10,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.lineCap="round",e.translate(-t/20,t/10),e.rotate(.6),e.beginPath(),e.arc(0,0,t/10,0,6.29),e.stroke(),e.beginPath(),e.moveTo(0,-t/6),e.lineTo(0,-t/3),e.moveTo(0,t/6),e.lineTo(0,t/4),e.stroke(),e.beginPath(),e.moveTo(-t/12,-t/3),e.lineTo(t/12,-t/3),e.lineTo(0,-t/2),e.closePath(),e.stroke(),e.restore()},use:()=>{bus.emit("dash")}},{color:[255,70,255],title:["Shield","Charger"],cost:3,price:15,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.lineCap="round",e.beginPath(),e.arc(0,0,t/4,0,6.29),e.stroke(),e.beginPath(),e.moveTo(-t/7,0),e.lineTo(t/7,0),e.moveTo(0,-t/7),e.lineTo(0,t/7),e.stroke(),e.restore()},use:()=>{bus.emit("heal")}},{color:[255,70,255],title:["Mineral","Siphon"],cost:3,price:15,glyph:function(t,i){t.save(),t.lineWidth=.05*i,t.lineCap="round";for(let e=0;e<3;e++)t.save(),t.translate((1-(e-1)*(e-1))*i/5,(e-1)*i/5),t.beginPath(),t.moveTo(-i/12,0),t.lineTo(0,-i/10),t.lineTo(i/12,0),t.lineTo(0,i/10),t.closePath(),t.stroke(),t.restore();t.beginPath(),t.moveTo(0,0),t.lineTo(-i/3,0),t.moveTo(-i/8,i/10),t.lineTo(-i/3,0),t.moveTo(-i/8,-i/10),t.lineTo(-i/3,0),t.stroke(),t.restore()},use:()=>{bus.emit("mine")}},{color:[255,70,255],title:["Hyper","Drive"],cost:4,price:20,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.lineCap="round",e.beginPath(),e.moveTo(-t/6,-t/4),e.lineTo(t/6,-t/4),e.lineTo(-t/6,t/4),e.lineTo(t/6,t/4),e.closePath(),e.stroke(),e.restore()},use:()=>{bus.emit("hyper")}},{color:[0,255,255],title:["Defense","Blessing"],cost:0,price:25,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.beginPath(),e.arc(0,0,t/3,0,6.29),e.stroke(),e.beginPath(),e.arc(0,0,t/7,0,6.29),e.stroke(),e.restore()},use:()=>{persist.setMaxShield(persist.getMaxShield()+1)}},{color:[255,255,0],title:["Strength","Blessing"],cost:0,price:25,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.lineCap="round",e.translate(0,-t/10),e.strokeRect(-t/4,-t/6,t/2,.6*t),e.strokeRect(-t/10,-t/4,t/5,-t/8),e.translate(0,t/7),e.beginPath(),e.moveTo(-t/10,-t/6),e.lineTo(t/10,-t/6),e.lineTo(-t/20,0),e.lineTo(t/20,0),e.lineTo(0,t/6),e.stroke(),e.restore()},use:()=>{persist.setMaxEnergy(persist.getMaxEnergy()+1)}},{color:[200,200,200],title:["Vision","Blessing"],cost:0,price:25,glyph:function(e,t){e.save(),e.lineWidth=.05*t,e.lineCap="round",e.strokeRect(.25*-t,0,.2*t,.3*t),e.strokeRect(.05*t,0,.2*t,.3*t),e.strokeRect(.1*-t,.4*-t,.2*t,.3*t),e.restore()},use:()=>{persist.setHandSize(persist.getHandSize()+1)}}];var persist=(()=>{var t=0,i=0,l=3,a=5,r=3,n=[],e={reset:()=>{i=t=0,a=5,r=l=3,n=[cards[0],cards[0],cards[0],cards[1],cards[1],cards[1],cards[2],cards[2],cards[2]]},getMinerals:()=>t,addMineral:e=>t+=e,getLevel:()=>i,setLevel:e=>i=e,getHandSize:()=>l,setHandSize:e=>l=e,getMaxEnergy:()=>a,setMaxEnergy:e=>a=e,getMaxShield:()=>r,setMaxShield:e=>r=e,getDeck:()=>n,addToDeck:e=>n.push(e)};return e.reset(),e})();function Intro(){add(new Text("Professor Zorn's Lab",()=>.03*width(),()=>.05*width(),"#fff",.5,"left")),add(new StartButton),bus.on("start",()=>{persist.reset(),transition(2)}),this.render=e=>{var t=.3*height();drawCharPlayer(e),drawCharZoren(e),drawDialogBox(e,"Professor Zorn","Hey there Courier, I need your help getting this Xenotransponder to Korva-6. It's only a few planets away."),drawItemShell(e,.5*width(),.4*height(),t),drawItemXeno(e,.5*width(),.4*height(),t)}}function PlayedCard(t,i,l,a){var r=0;this.update=e=>{i-=500*(.5-r)*e,a+=3*a*(.5-r)*e,.5<(r+=1.2*e)&&(this.destroyed=!0)},this.render=e=>{drawCard(e,t,i,a,l,!1,2*(.5-r))}}function PullCard(l,a,r,n,s,t){var o=-.5;this.update=e=>{1<(o+=3*e)&&(this.destroyed=!0,bus.emit("place",{slot:t,card:n}))},this.render=e=>{var t=.15;l.hasEnergy(n)&&(t=1);var i=Math.min(Math.max(o,0),1);drawCard(e,a*i*i+width()/2*(1-i*i),r*i*i+height()*(1-i*i),s*i,n,!1,i*t)}}function Asteroid(l,t,i){var a=100*Math.random();this.x=0,this.y=0,this.obstacle=!0,this.update=e=>{a+=.1*e,this.x=l.laneX(t),this.y=l.laneY(i),l.getTick()>t+6&&(this.destroyed=!0),l.closeToShip(l.laneX(t),l.laneY(i),2)&&(this.destroyed=!0,bus.emit("hit",1))},this.render=t=>{t.save(),t.translate(this.x,this.y);var i=+l.laneScale();t.fillStyle="#963";for(let e=0;e<8;e++)t.beginPath(),t.arc((e+.7)*i*.3+Math.sin(3*a+e*e*4)*i*.6,Math.sin(5*a+e*e*4)*i*.7,.6*i/(+e+1),0,6.29),t.fill();t.beginPath(),t.arc(0,0,i,0,6.29),t.fill(),t.restore()}}function Mineral(r,n,s,e){var o=100*Math.random();this.x=0,this.y=0;var h=!1,f=0,c=1;.6<Math.random()&&(c=3,.6<Math.random()&&(c=7));var d=()=>{h=!0,bus.emit("poof",{x:this.x,y:this.y,color:[255,130,255],size:.6,t:.3}),bus.off("mine",d)};bus.on("mine",d),this.update=e=>{var t,i,l,a;o+=+e,h?(t=r.getShipX()-this.x,i=r.getShipY()-this.y,l=Math.sqrt(t*t+i*i),a=width()*f,f+=e,this.x+=t/l*a*e,this.y+=i/l*a*e):(this.x=r.laneX(n),this.y=r.laneY(s)),r.getTick()>n+6&&!h&&(this.destroyed=!0,bus.off("mine",d)),r.closeToShip(this.x,this.y,1.4)&&(this.destroyed=!0,bus.off("mine",d),bus.emit("mineral",c))},this.render=t=>{var i=r.laneScale();if(1==c)drawMineral(t,this.x,this.y,o,.4*i);else if(3==c)drawMineral(t,this.x-i/3,this.y,o,.3*i),drawMineral(t,this.x+i/3,this.y-i/2,o,.3*i),drawMineral(t,this.x+i/3,this.y+i/2,o,.3*i);else if(7==c){for(let e=0;e<6;e++)drawMineral(t,this.x+Math.sin(1.04*e)*i*.8,this.y+Math.cos(1.04*e)*i*.8,o,.25*i);drawMineral(t,this.x,this.y,o,.3*i)}}}function Projectile(o,e,t,i,h){var f=0;this.x=e,this.y=t;var l=[];this.update=e=>{var t,i,l,a;if(f+=+e,5==h){if(this.x+=e*width()*(1-f/.35),.35<f){get().forEach(e=>{e.obstacle&&(e.destroyed=!0,bus.emit("poof",{x:e.x,y:e.y,color:[255,50,50],size:1,t:.5}))});var r=width(),n=height(),s=Math.sqrt(r*n)/20;for(let e=0;e<s;e++)bus.emit("poof",{x:Math.random()*r,y:Math.random()*n,color:[255,244,50],size:+Math.random()+1,t:.4*Math.random()+.4});bus.emit("boom"),this.destroyed=!0}}else 2!=h?(4!=h?this.x+=e*width()/2:(t=.4*Math.sin(Date.now()/30),this.homing&&!this.homing.destroyed&&(t+=Math.atan2(this.homing.y-this.y,this.homing.x-this.x)),this.y+=e*width()*.8*Math.sin(t),this.x+=e*width()*.8*Math.cos(t)),4<f&&(this.destroyed=!0),o.collideTargets(this.x,this.y,1.5)&&(this.destroyed=!0,bus.emit("boom"),1==h&&bus.emit("poof",{x:this.x,y:this.y,color:[255,200,100],size:1,t:.5}),3==h&&bus.emit("poof",{x:this.x,y:this.y,color:[100,255,100],size:1,t:.5}),4==h&&bus.emit("poof",{x:this.x,y:this.y,color:[255,200,140],size:.6,t:.5}))):(i=o.laneScale(),l=o.getShipY(),a=o.getShipX(),get().forEach(e=>{var t;!e.obstacle||(t=l-e.y)*t<i*i&&e.x>a&&!e.destroyed&&(e.destroyed=!0,bus.emit("poof",{x:e.x,y:l,color:[50,130,255],size:.7,t:.5}))}),1<f&&(this.destroyed=!0))},this.render=t=>{t.save();var e=o.laneScale();if(1==h&&(t.fillStyle="#fff",t.translate(this.x,this.y),t.fillRect(.2*-e,.2*-e,1.2*e,.4*e),t.fillRect(.4*-e,.35*-e,.4*e,.2*e),t.fillRect(.4*-e,.15*e,.4*e,.2*e),t.fillStyle="#fa3",0<Math.sin(Date.now()/14)&&t.fillRect(.3*-e,.05*-e,.8*-e,.1*e)),2==h&&(t.translate(o.getShipX(),o.getShipY()),t.fillStyle="#338",t.fillRect(.8*e,.3*-e,.6*e,.6*e),t.fillRect(.9*e,.2*-e,width(),.4*e),t.fillStyle="#3af",0<Math.sin(Date.now()/14)&&(t.fillRect(e,.1*-e,width(),.2*e),t.fillRect(.9*e,.2*-e,.4*e,.4*e))),3==h&&(t.fillStyle="#383",t.translate(this.x,this.y),t.beginPath(),t.arc(0,0,.6*e,0,6.29),t.fill(),0<Math.sin(Date.now()/14)&&(t.fillStyle="#8f8",t.beginPath(),t.arc(0,0,.4*e,0,6.29),t.fill())),4==h){t.fillStyle="#fa4",t.beginPath(),t.arc(this.x,this.y,.3*e,0,6.29),t.fill(),l.unshift({x:this.x,y:this.y}),14<l.length&&l.pop(),t.lineWidth=.1*e,t.strokeStyle="#fa4",t.beginPath(),t.moveTo(this.x,this.y);for(let e=0;e<l.length;e++)t.lineTo(l[e].x,l[e].y);t.stroke()}5==h&&(t.fillStyle="#ff0",t.translate(this.x,this.y),t.beginPath(),t.arc(0,0,.4*e,0,6.29),t.fill(),t.fillStyle="#333",t.fillRect(.2*-e,.2*-e,.4*e,.4*e)),t.restore()}}function Poof(a,r,n,s,o,h){var f=0;this.update=e=>{h<(f+=+e)&&(this.destroyed=!0)},this.render=e=>{e.save();var t=a.laneScale();e.translate(r,n),e.beginPath();var i=1-f/h,l=.5+1.5*(1-Math.exp(-f/h*3));e.fillStyle=`rgba(${s[0]},${s[1]},${s[2]},${i})`,e.arc(0,0,o*t*l,0,6.29),e.fill(),e.restore()}}function Engine(){var l=persist.getLevel(),r=e=>e.sort(()=>Math.random()-.5),a=e=>{var t=parseInt(Math.random()*T.length),i=T[t];T.splice(t,1);var l=width(),a=height(),t=S(l,a);add(new PullCard(this,w(e,t,l),x(a),i,t,e)),0==T.length&&(r(T=n),n=[])},S=(e,t)=>Math.min(e*(.95/(1+s)),.185*t),w=(e,t,i)=>.5*i+(e-(s-1)/2)*t*1.17,x=e=>.735*e,T=persist.getDeck().map(e=>Object.assign({},e)),n=[];r(T);var s=persist.getHandSize(),M=[];for(let e=0;e<s;e++)a(e);var P=-1,o=1,k=1,R=0,C=0,D=0,E=persist.getMaxShield(),W=E,B=persist.getMaxEnergy(),$=B,I=0,z=20+2*l,A=0,L=0,Y=0;const h=e=>{var t=width(),i=height(),l=e.x,a=e.y,r=-1,n=M.length,s=Math.min(t*(.95/(1+n)),.185*i);for(let e=0;e<n;e++){var o=.5*t+(e-(n-1)/2)*s*1.17,h=.735*i;o-s/2<l&&l<o+s/2&&h-3*s/4<a&&a<h+3*s/4&&(r=e)}return r};bus.on("tap",e=>{var t,i,l=h(e);0<=l&&null!=M[l]&&(cost=M[l].cost,$>=cost&&($-=cost,M[l].use(),t=width(),i=height(),e=S(t,i),add(new PlayedCard(w(l,e,t),x(i),M[l],e)),e=l,n.push(M[e]),M[e]=null,a(l)))}),bus.on("move",e=>{P=h(e)}),bus.on("lane",e=>{o=e}),bus.on("hop",()=>{for(var t=o;t==o;)t=parseInt(3*Math.random());var i=this.getShipX(),l=this.laneScale();for(let e=0;e<3;e++){sz=.3;var a=[255,0,255];e==t&&(sz=1,a=[100,255,100]),add(new Poof(this,i+2*l,this.laneY(e),a,sz,.7))}o=t}),bus.on("dash",()=>{C=.5,D=2}),bus.on("hyper",()=>{C=.4,D=10}),bus.on("heal",()=>{W=Math.min(W+1,E),add(new Poof(this,this.getShipX(),this.getShipY(),[0,255,0],1,.5))}),bus.on("poof",({x:e,y:t,color:i,size:l,t:a})=>{add(new Poof(this,e,t,i,l,a))}),bus.on("projectile",e=>{var t,i,l,a;1!=e&&2!=e&&5!=e||add(new Projectile(this,this.getShipX(),this.getShipY(),o,e)),3==e&&(add(new Projectile(this,this.getShipX(),this.laneY(0),0,e)),add(new Projectile(this,this.getShipX(),this.laneY(1),1,e)),add(new Projectile(this,this.getShipX(),this.laneY(2),2,e))),4==e&&(t=this.laneScale(),i=new Projectile(this,this.getShipX(),this.getShipY()-t/2,o,e),l=new Projectile(this,this.getShipX(),this.getShipY()+t/2,o,e),a=get().filter(e=>e.obstacle&&e.x>3*t),e=parseInt(Math.random()*a.length),i.homing=a[e],a.splice(e,1),e=parseInt(Math.random()*a.length),l.homing=a[e],a.splice(e,1),add(i),add(l))}),bus.on("place",({slot:e,card:t})=>{M[e]=t}),bus.on("hit",e=>{(W-=e)<=0&&transition(4),bus.emit("poof",{x:this.getShipX(),y:this.getShipY(),color:[255,255,255],size:1,t:.5})}),bus.on("mineral",e=>{persist.addMineral(e)});var t=()=>{if(!(z-7<A||4<D)){var t,i={};for(let e=0;e<.1+.15*l;e++)Math.random()>.7/(1+.04*l)&&(i[t=parseInt(3*Math.random())]||(i[t]=1,add(new Asteroid(this,A,t))));.6<Math.random()&&(i[t=parseInt(3*Math.random())]||(i[t]=1,add(new Mineral(this,A,t,1))))}};this.hasEnergy=e=>$>=e.cost,this.laneY=e=>{var t=height();return 0==e?.18*t:1==e?.34*t:.5*t},this.laneX=e=>{var t=width(),i=50+t/40+this.laneScale();return i+(1-(A+L-e)/5)*(t+i)},this.laneScale=()=>{var e=width(),t=height();return.3*Math.min(.16*t,e/8)},this.getTick=()=>A,this.getShipX=()=>{return 50+width()/40+this.laneScale()},this.getShipY=()=>{var e=height();return.18*e+k*e*.16},this.closeToShip=(e,t,i)=>{if(0<C)return!1;var l=this.laneScale(),e=e-this.getShipX(),t=t-this.getShipY();return e*e+t*t<l*l*i},this.collideTargets=(i,l,a)=>{var r=this.laneScale(),n=!1;return get().forEach(e=>{var t;!e.obstacle||(t=i-e.x)*t+(t=l-e.y)*t<r*r*a&&(n=!0,e.destroyed=!0)}),n},this.update=e=>{1<(Y+=e)&&(0<C?(C-=e,L+=e*D,Y+=e*D*2):D=0,L+=2*e),1<L&&(L--,A++,t(),z<A&&transition(13==l?5:3)),$<B?1<=(I+=.75*e)&&(--I,$++):I=0,R+=7*(.5*(o-k)-R)*e,k+=5*(o-k)*e},this.render=t=>{var i=width(),l=height(),a=i/40,e=.16*l,r=.1*l,n=r+e,s=n+e,o=.3*Math.min(e,i/8);drawStars(t,20*-Y,0,3+D,0);var h=.3*l;t.fillStyle="#224",t.beginPath(),t.arc(-(A+L)/10*i,.34*l,h,0,6.28),t.fill(),t.beginPath(),t.arc(-(A+L-z)/10*i+.4*i,.34*l,h,0,6.28),t.fill();h=.02*l;t.fillStyle="#446",t.fillRect(15+a,r/2,i-30-2*a,1),t.fillStyle="#446",t.beginPath(),t.arc(15+h,r/2,h,0,6.28),t.fill(),t.fillStyle="#446",t.beginPath(),t.arc(i-15-h,r/2,h,0,6.28),t.fill(),t.fillStyle="#fff";h=15+a+(A+L)/(z+1)*(i-30-2*a);t.beginPath(),t.moveTo(h+a/3,r/2),t.lineTo(h-a/3,r/2-a/3),t.lineTo(h-a/3,r/2+a/3),t.closePath(),t.fill(),t.fillStyle="#f33",t.fillRect(15,r,a,e),t.fillStyle="#3f3",t.fillRect(15,n,a,e),t.fillStyle="#33f",t.fillRect(15,s,a,e),t.fillStyle="#f33",t.fillRect(i-15,r,-a,e),t.fillStyle="#3f3",t.fillRect(i-15,n,-a,e),t.fillStyle="#33f",t.fillRect(i-15,s,-a,e),t.fillStyle="rgba(100,100,100,0.4)",t.fillRect(15,r,i-30,1),t.fillRect(15,n,i-30,1),t.fillRect(15,s,i-30,1),t.fillRect(15,s+e,i-30,1),t.save(),t.translate(50+a+o,r+e/2+k*e),t.rotate(R);for(let e=5;0<=e;e--){e<1?t.fillStyle="#fd6":e<3?t.fillStyle="#fa1":t.fillStyle="#a41",t.beginPath();var f=.2*Math.sin(Y*(e+1)*20)+.5;t.arc(-o-o*e*.1,Math.sin(40*-Y+e)*e*o/30,o*f/(1.5+.3*e),0,6.29),t.fill()}t.translate(Math.sin(30*Y)*o/60,Math.sin(35*Y)*o/40),t.fillStyle="#fff",t.beginPath(),t.moveTo(o,0),t.lineTo(.65*-o,.8*-o),t.lineTo(.65*-o,.3*-o),t.lineTo(-o,.5*-o),t.lineTo(-o,.5*o),t.lineTo(.65*-o,.3*o),t.lineTo(.65*-o,.8*o),t.closePath(),0<C?(t.lineWidth=.1*o,t.strokeStyle="#fff",t.stroke()):t.fill(),t.fillRect(.4*-o,.4*o,o,.15*o),t.fillRect(.4*-o,.4*-o,o,.15*-o),t.restore();var r=Math.min(.025*l,.035*i),c=l-r;t.textBaseline="bottom",t.font=`${r}px monospace`,t.textAlign="right",t.fillStyle="#ff3",t.fillText("Energy",i-a,c),t.textAlign="right",t.fillText($,i-(a+6*r),c),t.textAlign="left",t.fillStyle="#888",t.font=`${.8*r}px monospace`,t.fillText(`/ ${B}`,i-(a+5.7*r),c);var d=1.2*r;for(let e=0;e<B;e++)drawEnergy(t,i-(a+e*(.8*d+4)+d),c-2.4*d,d,e<$);t.fillStyle="#333";e=(.8*d+4)*B;t.fillRect(i-a,c-1.07*d,-e,2),t.fillStyle="#ff3",t.fillRect(i-a,c-1.07*d,-I*e,2);var u=.6*r,g=l-r;t.textBaseline="bottom",t.font=`${r}px monospace`,t.textAlign="left",t.fillStyle="#3ff",t.fillText("Shield",a,g),t.textAlign="right",t.fillText(W,a+5.3*r,g),t.textAlign="left",t.fillStyle="#888",t.font=`${.8*r}px monospace`,t.fillText(`/ ${E}`,a+5.6*r,g);for(let e=0;e<E;e++)drawShield(t,a+e*(2.5*u+4)+u,g-4*u,u,e<W);e=l-r;t.textBaseline="bottom",t.font=`${r}px monospace`,t.textAlign="center",t.fillStyle="#f3f",t.fillText(persist.getMinerals(),.4*i,e),drawMineral(t,.4*i,e-2.1*r,.785,.5*r),t.fillStyle="#aaa",t.fillText(T.length,.6*i,e),drawDeck(t,.6*i,e-2.1*r,.4*r);var p,y,m,b=M.length,v=S(i,l);for(let e=0;e<b;e++)null!=M[e]&&(p=w(e,v,i),y=x(l),m=1,$<M[e].cost&&(m=.15),drawCard(t,p,y,v,M[e],P==e,m))}}function pick(e){return e[parseInt(Math.random()*e.length)]}const planets=["Tenadu","Nurosto Prime","Worlax","Mektrov Zero","Cytoxia","Broggendor","Voitec","Helion","Earth (Remnants)","Yonzi Mata","Streva Gateway","Lumatorr","Desela","Korva-6"];function PlanetEvent(){var e=persist.getLevel();add(new Text(`Planet ${planets[e]}`,()=>.03*width(),()=>.05*width(),"#fff",.5,"left")),add(new StartButton),bus.on("start",()=>{persist.setLevel(persist.getLevel()+1),transition(2)}),onTapCard=({x:t,y:i})=>{var l=width(),a=height(),r=persist.getMinerals(),n=Math.min(.2*a,.25*l);for(let e=0;e<f.length;e++){var s=l/2+(e-(f.length-1)/2)*l*.3;null!=f[e]&&r>=f[e].price&&s-n/2<t&&t<s+n/2&&.4*a-3*n/4<i&&i<.4*a+3*n/4&&(add(new PlayedCard(s,.4*a,f[e],n)),persist.addMineral(-f[e].price),bus.emit("buy"),4==o?f[e].use():persist.addToDeck(f[e]),f[e]=null)}};var o=[],o=pick(0==e?[0,2]:[0,1,2,3,4]),f=[],c="",d=drawCharWeaponTech,u="";if(0==o){var c="Weapon Tech",d=drawCharWeaponTech,u=pick(["Stop staring human! Either buy something or leave.","Rockets! Laser beams! What are you looking for? I've got it all.","Hey hey, don't touch the merchandise! You might hurt yourself..."]),t=[cards[3],cards[4],cards[5],cards[6],cards[7]],i=parseInt(2*Math.random())+2;for(let e=0;e<i;e++)f.push(t[parseInt(Math.random()*t.length)]);bus.on("tap",onTapCard)}if(1==o){c="Ship Mechanic",d=drawCharShipMech,u=pick(["Beep Boop - May I assist you with upgrades for that spacefaring vessel?","Zip Zap - Your shield generator looks a bit flimsy. I can help with that.","Wrrrrr - Do you call that piece of scrap metal a ship?"]);t=[cards[8],cards[9],cards[10],cards[11],cards[12]],i=parseInt(2*Math.random())+2;for(let e=0;e<i;e++)f.push(t[parseInt(Math.random()*t.length)]);bus.on("tap",onTapCard)}if(2==o){c="Street Merchant",d=drawCharMerchant,u=pick(["Pssst. Yeah you. You look like you could use a pumpjack for that ship.","Only the best mechatronics here. Forged from the finest Worlax Steel.","Got this stuff from the Gateway District... You're not a cop right?"]);t=[cards[3],cards[4],cards[8],cards[9]],i=parseInt(2*Math.random())+2;for(let e=0;e<i;e++)f.push(t[parseInt(Math.random()*t.length)]);bus.on("tap",onTapCard)}if(3==o){c="Cytox Smuggler",d=drawCharSmuggler,u=pick(["Sssseems like you need ssssome black market tech. Letssss sssee what I've got...","Elzo Mineralsss are in short sssupply these daysss. My pricing hasss to ssslither up.","This lot isn't my normal sssset of ssssuplies, but itsss much sssafer than the cccytox trade."]);t=[cards[5],cards[6],cards[10],cards[11]],i=parseInt(2*Math.random())+2;for(let e=0;e<i;e++)f.push(t[parseInt(Math.random()*t.length)]);bus.on("tap",onTapCard)}if(4==o){c="Neuro-Templar",d=drawCharTemplar,u=pick(["I sense your journey has experienced rough patches. A blessing will surely aid you.","The Great Consciousness has a gift for you, but an exchange of minerals must be made.","Words from The Cortex will pave your road to enlightenment... for a small fee."]);t=[cards[13],cards[14],cards[15]];for(let e=0;e<2;e++){var l=parseInt(Math.random()*t.length);f.push(t[l]),t.splice(l,1)}bus.on("tap",onTapCard)}this.drawCost=(e,t,i,l,a,r)=>{e.fillStyle="#f3f",e.font=`${.25*a}px monospace`,e.textAlign="left",e.textBaseline="middle";var n=.061*a,s=(e.measureText(t).width+2*n)/2;e.fillText(t,i+3*n-s,l+a),drawMineral(e,i+n/2-s,l+a,.785,.08*a),r||(e.save(),e.fillStyle="rgba(255,0,0,0.7)",e.translate(i,l+a),e.rotate(.1),e.fillRect(.5*-a,-1,a,3),e.rotate(-.2),e.fillRect(.5*-a,-1,a,3),e.restore())},this.render=t=>{var i=width(),l=height(),a=persist.getMinerals(),e=persist.getHandSize(),r=persist.getMaxEnergy(),n=persist.getMaxShield();drawCharPlayer(t),d(t),drawDialogBox(t,c,u);var s=Math.min(.04*l,.04*i);t.textAlign="left",t.textBaseline="middle",t.font=`${s}px monospace`,drawMineral(t,s,.75*l,.785,.3*s),t.fillStyle="#f3f",t.fillText(a,1.7*s,.75*l),drawDeck(t,s,.75*l-s,.2*s),t.fillStyle="#999",t.fillText(e,1.7*s,.75*l-s),drawShield(t,s,.75*l-2*s,.4*s,!0),t.fillStyle="#3ff",t.fillText(n,1.7*s,.75*l-2*s),drawEnergy(t,s-.325*s,.75*l-3.45*s,.8*s,!0),t.fillStyle="#ff3",t.fillText(r,1.7*s,.75*l-3*s);var o,h=Math.min(.2*l,.25*i);for(let e=0;e<f.length;e++)null!=f[e]&&(drawCard(t,o=i/2+(e-(f.length-1)/2)*i*.3,.4*l,h,f[e],!1,1),this.drawCost(t,`${f[e].price}`,o,.4*l,h,a>=f[e].price))}}function GameOver(){var n=persist.getLevel();add(new Text("SHUTTLEDECK",()=>width()/2,()=>.2*height(),"#fff",1,"center")),add(new Text("Game Over",()=>width()/2,()=>.35*height(),"#f55",1,"center")),add(new Text(`Exploded approaching planet ${planets[n]}`,()=>width()/2,()=>.6*height(),"#f55",.4,"center")),add(new Text("[ Press to retry ]",()=>width()/2,()=>.8*height(),"#777",.5,"center"));var e=()=>{transition(1),bus.off("tap",e)};bus.on("tap",e),this.render=t=>{var i=width(),l=height(),a=Math.min(.03*l,.03*i);drawStars(t,.03*-Date.now(),0,3,0),t.lineWidth=.2*a,t.strokeStyle="#555",t.beginPath(),t.moveTo(i/2-14*i/36,l/2),t.lineTo(i/2+14*i/36,l/2),t.stroke();for(let e=0;e<planets.length+1;e++){var r=(e-7)*i/18+i/2;e<=n?(t.beginPath(),t.arc(r,.5*l,.6*a,0,6.29),t.fillStyle="#fff",t.fill()):(t.beginPath(),t.arc(r,.5*l,.5*a,0,6.29),t.fillStyle="#000",t.strokeStyle="#f55",t.fill(),t.stroke())}}}function Win(){add(new Text("Planet Korva-6",()=>.03*width(),()=>.05*width(),"#fff",.5,"left")),add(new Text("Package Delivered!",()=>width()/2,()=>height()/2,"#5f5",.6,"center")),add(new StartButton("Main Menu")),bus.on("start",()=>{transition(0)}),this.render=e=>{drawCharPlayer(e),drawCharZoren(e,"#f55"),drawDialogBox(e,"Professor Quinn","Is that a Xenotransponder?? My brother Zorn must have sent this. Thank you, Courier!")}}function init(){bus.emit("scene",0)}function transition(e){bus.emit("txn"),bus.on("txn-done",()=>{bus.emit("scene",e),add(new transition$1(.9,!1));for(let e=0;e<width();e+=.01*width())add(new Steam(e,height()/2))}),get().forEach(e=>{e.update=void 0}),add(new transition$1(.4,!0))}(()=>{var t,i=e=>{t=e,bus.clear(),bus.on("scene",i),audio.stopMusic(),audio.setup(),clear(),0==t&&add(new MainMenu),1==t&&(add(new Intro),audio.music()),2==t&&(add(new Engine),audio.bgRocket()),3==t&&(add(new PlanetEvent),audio.music()),4==t&&add(new GameOver),5==t&&add(new Win)};bus.on("scene",i)})(),isMobile=()=>/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),window.addEventListener("touchstart",e=>{e.stopPropagation(),bus.emit("tap",{x:e.touches[0].clientX,y:e.touches[0].clientY})}),window.addEventListener("mousedown",e=>{e.preventDefault(),e.stopPropagation(),isMobile()||bus.emit("tap",{x:e.x,y:e.y})}),window.addEventListener("mousemove",e=>{e.preventDefault(),e.stopPropagation(),isMobile()?bus.emit("move",{x:-1,y:-1}):bus.emit("move",{x:e.x,y:e.y})}),init(),(()=>{var e=document.createElement("canvas");e.width=64,e.height=64,document.body.appendChild(e);var t=e.getContext("2d");t.fillStyle="#000",t.fillRect(0,0,64,64),t.strokeStyle="#fa3",t.lineWidth=2,t.lineJoin="round",t.lineCap="round",t.strokeRect(0,0,64,64),t.translate(31,29),cards[3].glyph(t,82,.05),document.querySelector("link[rel~='icon']").href=e.toDataURL(),document.body.removeChild(e)})(),(()=>{var i=Date.now(),l=[],a=()=>{},r=()=>{var e=Date.now(),t=.001*(e-i);.3<t&&(t=.3),ctx.fillStyle="#000",ctx.fillRect(0,0,width(),height()),l.length=0,get().forEach(e=>{(e.ecs||[]).forEach(e=>e(t)),(e.update||a)(t),(e.render||a)(ctx),e.destroyed&&l.push(e)}),l.forEach(e=>remove(e)),i=e,requestAnimationFrame(r)};r()})();</script></html>