-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.min.js
1 lines (1 loc) · 3.33 KB
/
main.min.js
1
class Main extends Phaser.Scene{constructor(){super("Main")}preload(){this.load.image("monitor0","monitor0.png"),this.load.image("monitor1","monitor1.png"),this.load.image("monitor2","monitor2.png"),this.load.image("monitor3","monitor3.png"),this.load.audio("pulse0","pulse0.wav"),this.load.audio("pulse1","pulse1.wav"),this.load.audio("pulse2","pulse2.wav"),this.load.audio("pulse3","pulse3.wav")}generate(){gameState.a=Math.ceil(100*Math.random()),gameState.b=Math.ceil(100*Math.random()),gameState.c=gameState.a*gameState.b,gameState.button=Math.floor(4*Math.random()),gameState.aText.setText(`${Math.ceil(100*Math.random())}`),gameState.bText.setText(`${Math.ceil(100*Math.random())}`),gameState.cText.setText(`${Math.ceil(100*Math.random())}`),gameState.dText.setText(`${Math.ceil(100*Math.random())}`),0==gameState.button&&gameState.aText.setText(`${gameState.a}`),1==gameState.button&&gameState.bText.setText(`${gameState.a}`),2==gameState.button&&gameState.cText.setText(`${gameState.a}`),3==gameState.button&&gameState.dText.setText(`${gameState.a}`),gameState.mainText.setText(`${gameState.c}/${gameState.b}=?`)}answer(t){console.log(t),console.log(gameState.errors),this.generate(),t==gameState.button?this.generate():(gameState.errors+=1,gameState.errors<3?(this.generate(),1==gameState.errors&&(this.add.image(100,50,"monitor2").setOrigin(0,0),gameState.music1.stop(),gameState.music2=this.sound.add("pulse2"),gameState.music2.loop=!0,gameState.music2.play()),2==gameState.errors&&(this.add.image(100,50,"monitor3").setOrigin(0,0),gameState.music2.stop(),gameState.music3=this.sound.add("pulse3"),gameState.music3.loop=!0,gameState.music3.play())):(console.log("a"),this.setDeath())),clearTimeout(gameState.timer),gameState.timer=setTimeout(()=>{this.setDeath()},3e3)}setDeath(){console.log("dead"),gameState.mainText.setText("You died"),this.add.image(100,50,"monitor0").setOrigin(0,0),0==gameState.errors&&gameState.music1.stop(),1==gameState.errors&&gameState.music2.stop(),2==gameState.errors&&gameState.music3.stop(),gameState.errors=3,gameState.music0=this.sound.add("pulse0"),gameState.music0.loop=!0,gameState.music0.play(),gameState.timer=setTimeout(()=>{this.setReset()},1e3)}setReset(){this.input.on("pointerdown",()=>{gameState.errors=0,gameState.music0.stop(),this.scene.stop("Main"),this.scene.start("Menu")})}create(){gameState.music1=this.sound.add("pulse1"),gameState.music1.loop=!0,gameState.music1.play(),gameState.errors=0,this.add.image(100,50,"monitor1").setOrigin(0,0),gameState.mainText=this.add.text(100,300,"text",{fill:"#000000",fontSize:"40px"});let t=this.add.rectangle(100,400,250,50,8947848);t.setOrigin(0,0),gameState.aText=this.add.text(100,400,"a",{fill:"#000000",fontSize:"30px"}),t.setInteractive(),t.on("pointerdown",()=>{this.answer(0)});let e=this.add.rectangle(450,400,250,50,8947848);e.setOrigin(0,0),gameState.bText=this.add.text(450,400,"b",{fill:"#000000",fontSize:"30px"}),e.setInteractive(),e.on("pointerdown",()=>{this.answer(1)});let a=this.add.rectangle(100,500,250,50,8947848);a.setOrigin(0,0),gameState.cText=this.add.text(100,500,"c",{fill:"#000000",fontSize:"30px"}),a.setInteractive(),a.on("pointerdown",()=>{this.answer(2)});let s=this.add.rectangle(450,500,250,50,8947848);s.setOrigin(0,0),gameState.dText=this.add.text(450,500,"d",{fill:"#000000",fontSize:"30px"}),s.setInteractive(),s.on("pointerdown",()=>{this.answer(3)}),this.generate()}}