-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1 lines (1 loc) · 3.41 KB
/
index.js
1
!function(){return function e(t,o,r){function i(l,a){if(!o[l]){if(!t[l]){var c="function"==typeof require&&require;if(!a&&c)return c(l,!0);if(n)return n(l,!0);var h=new Error("Cannot find module '"+l+"'");throw h.code="MODULE_NOT_FOUND",h}var d=o[l]={exports:{}};t[l][0].call(d.exports,function(e){return i(t[l][1][e]||e)},d,d.exports,e,t,o,r)}return o[l].exports}for(var n="function"==typeof require&&require,l=0;l<r.length;l++)i(r[l]);return i}}()({1:[function(e,t,o){const{Sprite:r,GameLoop:i,initPointer:n,onPointerDown:l,setStoreItem:a,getStoreItem:c,load:h,init:d}=kontra,{canvas:s,context:u}=d(),f=s.width,x=s.height,y=f/2,p=x/2;let g,b,A,k,m,w,T,S=2,M=c("luon_hi_score")?c("luon_hi_score"):0,_="menu";const D={game:{init:()=>{const e=e=>r({x:0,y:e,width:f,height:64,color:"#010A43",type:"bar"});g=r({width:26,height:26,anchor:{x:.5,y:.5},x:80,y:p,dy:2.5,color:"#EDA593",border:"#FF3F98",face:"#010A43",type:"luon",render:function(){this.draw(),u.beginPath(),u.fillStyle=this.color,u.strokeStyle=this.border,u.lineWidth=4,u.arc(this.x,this.y,14,0,2*Math.PI),u.fill(),u.stroke(),u.beginPath(),u.strokeStyle=this.face,u.lineWidth=2,u.arc(this.x,this.y-4,4,0,2*Math.PI),u.stroke(),u.moveTo(this.x,this.y-1),u.lineTo(this.x,this.y+10),u.stroke()}}),b=e(0),A=e(x-64),w=r({color:"#EDA593",render:function(){u.fillStyle=this.color,u.font="bold 40px Arial",u.textAlign="center",u.fillText(`${m}`,y,50)}}),k=[],m=0},update:e=>{(S-=e)<0&&(S=2,k=k.concat(v())),g.update(),b.update(),A.update(),w.update();for(let e of k)e.update(),e.x+64===g.x&&(e.type.includes("double")||m++),(e.collidesWith(A)||e.collidesWith(b))&&(e.dy=-e.dy),e.collidesWith(g)&&(m>M&&a("luon_hi_score",M=m),_="menu",q.play());(g.collidesWith(A)||g.collidesWith(b))&&(m>M&&a("luon_hi_score",M=m),_="menu",q.play())},render:()=>{g.render(),b.render(),A.render(),w.render();for(let e of k)e.render()},click:()=>{g.dy=-g.dy}},menu:{init:()=>{T=r({color:"#FF3F98",border:"#010A43",render:function(){u.fillStyle=this.color,u.textAlign="center",u.font="bold 55px Arial",u.strokeStyle=this.border,u.lineWidth=3,u.fillText("LUON",y,50),u.strokeText("LUON",y,50),u.fillStyle=this.border,u.font="bold 40px Arial",u.fillText(`High score: ${M}`,y,110),u.font="28px Arial",u.fillText("RULES",y,180),u.font="24px Arial",u.fillText("Click to play",y,220),u.fillText("Avoid dark blocks",y,260),u.font="28px Arial",u.fillText("CREDITS",y,320),u.font="24px Arial",u.fillText("Design & code: Phong Duong",y,360)}})},update:()=>{T.update()},render:()=>{T.render()},click:()=>{D[_="game"].init()}}},v=()=>{const e=500,t=[];switch(Math.floor(3*Math.random()+1)){case 1:const o=Math.floor(4*Math.random()+1);t.push(r({x:e,y:64*o,width:64,height:64,anchor:{x:.5,y:0},dy:3,dx:-2,color:"#010A43",type:"bar"}));break;case 2:const i=1===Math.floor(2*Math.random()+1)?64:96,n=i+160;t.push(r({x:e,y:i,width:64,height:64,anchor:{x:.5,y:0},dx:-2,color:"#010A43",type:["bar","double"]})),t.push(r({x:e,y:n,width:64,height:64,anchor:{x:.5,y:0},dx:-2,color:"#010A43",type:"bar"}));break;default:const l=1===Math.floor(2*Math.random()+1)?64:160;t.push(r({x:e,y:l,width:64,height:160,anchor:{x:.5,y:0},dx:-2,color:"#010A43",type:"bar"}))}return t},F=i({update:function(e){(0,D[_].update)(e)},render:function(){(0,D[_].render)()}}),W=new AudioContext,P=new TinyMusic.Sequence(W,120,["D4 es"]);P.loop=!1,P.gain.gain.value=.5;const q=new TinyMusic.Sequence(W,120,["C3 es","F0 es"]);q.loop=!1,D.menu.init(),n(),F.start(),l(()=>{P.play(),D[_].click()})},{}]},{},[1]);