var EHDI = EHDI || Object.create(null); EHDI.components = EHDI.components || Object.create(null); EHDI.components.NoteManager = function(stage) { this.notespeed = EHDI.GAME.sceneManager.getStageHeight () * 0.45; this.spawnOffset = 0.85 / 0.45; this.noteSheet = EHDI.Assets.cjAssets.getResult("notesheet")["notesheet"]; this.notes = new Array(5); for(var i = 0; i < 5; i++) { this.notes[i] = []; } this.stage = stage; this.hasSpawned = false; this.noteIndex = 0; this.miss = 0; this.songTimer = 0; this.recoveryCounter = 0; this.songDuration = EHDI.GAME.gameScene.song.duration; this.updateFunction = this.updateNotes.bind(this); EHDI.GAME.updateManager.addFrameListener(this.updateFunction); }; EHDI.components.prototype = Object.create(null); EHDI.components.NoteManager.prototype.updateNotes = function(dt) { if(this.isEndGame) return; if(EHDI.GAME.pauseButton.isPaused || EHDI.GAME.pauseButton.isEndGame) return; this.updateSongTimer(dt); var time = this.songTimer / this.songDuration, initial = 1 + this.miss * 0.3; EHDI.GAME.gameScene.atmosphere.alpha = (1 - time) * initial; if(this.noteIndex < this.noteSheet.length && this.noteSheet[this.noteIndex].time - this.spawnOffset <= Math.round(this.songTimer / 10) / 100) { this.spawnNotes(this.noteSheet[this.noteIndex].button, this.noteSheet.length && this.noteSheet[this.noteIndex].time - this.spawnOffset); this.noteIndex++; } /*if(!this.hasSpawned && Math.round(EHDI.GAME.gameScene.bgm.position / 10) / 100 >= 0.5) { this.spawnNotes(); this.hasSpawned = true; }*/ for(var i = 0; i < this.notes.length; i++) { for(var j = 0; j < this.notes[i].length; j++) { this.notes[i][j].y = (this.songTimer / 1000 - this.notes[i][j].spawnTime) * this.notespeed; } if(j === 4 && this.notes[i][0].y > EHDI.GAME.sceneManager.getStageHeight) { this.stage.removeChild(this.notes[4][0]); this.notes[4].splice(0,1); } else if(this.notes[i].length > 0 && this.notes[i][0].y > EHDI.GAME.sceneManager.getStageHeight() * 0.89 && this.notes[i][0].state === "default") { this.notes[i][0].miss(); EHDI.GAME.gameScene.buttons[i].error(); this.miss++; EHDI.GAME.gameScene.smoke.animation.timeScale = 0.5 + this.miss * 0.15; if(this.miss === 3) EHDI.GAME.gameScene.atmosphere.alpha = 1; EHDI.GAME.gameScene.kingSaul.animation.gotoAndPlay("saul_hiterror" + this.miss, -1, -1, 1); EHDI.GAME.gameScene.kingSaul.number = this.miss; if(this.miss >= 3) { EHDI.GAME.gameScene.song.stop(); EHDI.GAME.pauseButton.isEndGame = true; EHDI.GAME.pauseButton.hidePauseButton(); setTimeout(EHDI.GAME.gameScene.goToEndScreen.bind(EHDI.GAME.gameScene), 500); } this.notes[4].push(this.notes[i].splice(0, 1)[0]); } } }; EHDI.components.NoteManager.prototype.spawnNotes = function(index, time) { var note = new EHDI.components.Note(index, time); this.stage.addChild(note); this.notes[index].push(note); }; EHDI.components.NoteManager.prototype.hitNote = function(index) { var stageHeight = EHDI.GAME.sceneManager.getStageHeight(); if(this.notes[index].length > 0 && this.notes[index][0].y > stageHeight * 0.73 && this.notes[index][0].y <= stageHeight * 0.89 && this.notes[index][0].state === "default") { this.notes[index][0].hit(); if(this.miss > 0) this.recoveryCounter++; if(this.recoveryCounter === 3) { this.recoveryCounter = 0; this.miss--; EHDI.GAME.gameScene.smoke.animation.timeScale = 0.5 + this.miss * 0.15; if(this.miss <= 0) { this.miss = 0; EHDI.GAME.gameScene.kingSaul.animation.gotoAndPlay("saul_default", -1, -1, 0); } else { EHDI.GAME.gameScene.kingSaul.animation.gotoAndPlay("saul_hiterror" + this.miss, -1, -1, 1); EHDI.GAME.gameScene.kingSaul.number = this.miss; } } if(this.notes[index][0].y > stageHeight * 0.84 && this.notes[index][0].y <= stageHeight * 0.89) { this.stage.removeChild(this.notes[index][0]); this.notes[index].splice(0, 1); EHDI.GAME.scoreManager.addScore(10); return "perfect"; } else { this.stage.removeChild(this.notes[index][0]); this.notes[index].splice(0, 1); EHDI.GAME.scoreManager.addScore(5); return "good"; } } else { EHDI.GAME.gameScene.buttons[index].error(); this.miss++; EHDI.GAME.gameScene.smoke.animation.timeScale = 0.5 + this.miss * 0.15; if(this.miss === 3) EHDI.GAME.gameScene.atmosphere.alpha = 1; EHDI.GAME.gameScene.kingSaul.animation.gotoAndPlay("saul_hiterror" + this.miss, -1, -1, 1); EHDI.GAME.gameScene.kingSaul.number = this.miss; if(this.miss >= 3) { EHDI.GAME.gameScene.song.stop(); EHDI.GAME.pauseButton.isEndGame = true; EHDI.GAME.pauseButton.hidePauseButton(); setTimeout(EHDI.GAME.gameScene.goToEndScreen.bind(EHDI.GAME.gameScene), 500); } } return false; }; EHDI.components.NoteManager.prototype.updateSongTimer = function(dt) { this.songTimer += dt; if(EHDI.GAME.gameScene.song.position !== this.lastPlayHeadPosition) { this.songTimer = (this.songTimer + EHDI.GAME.gameScene.song.position) / 2; this.lastPlayHeadPosition = EHDI.GAME.gameScene.song.position; if(EHDI.GAME.gameScene.song.position === 0) { this.songTimer = 0; } } } EHDI.components.NoteManager.prototype.dispose = function() { EHDI.GAME.updateManager.removeFrameListener(this.updateFunction); }