var EHDI = EHDI || Object.create(null); EHDI.scene = EHDI.scene || Object.create(null); EHDI.scene.GameScene = function (){ PIXI.Container.call(this); EHDI.GAME.gameScene = this; this.gameLayer = new EHDI.aka.Container(); this.guiLayer = new EHDI.aka.Container(); this.addChild(this.gameLayer); this.addChild(this.guiLayer); this.isMoving = true; // console.log(this); // this.addChild(bg); }; EHDI.scene.GameScene.prototype = Object.create(EHDI.aka.Container.prototype); EHDI.scene.GameScene.prototype.screenWillAppear = function() { this.bg = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_bg"]); this.gameLayer.addChild(this.bg); } EHDI.scene.GameScene.prototype.screenDidAppear = function() { this.createDragonBones(); EHDI.GAME.scoreManager = new EHDI.components.ScoreManager(this.guiLayer); EHDI.GAME.scoreManager.setXY(EHDI.GAME.sceneManager.getStageWidth() * 0.3, EHDI.GAME.sceneManager.getStageHeight() * 0.015); var pauseButton = new EHDI.components.pauseButton(); this.guiLayer.addChild(pauseButton); var customerLayer = new EHDI.aka.Container(); this.gameLayer.addChild(customerLayer) EHDI.GAME.customerSpawner = new EHDI.components.CustomerSpawner(customerLayer); this.tableLeft = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_table"]); this.gameLayer.addChild(this.tableLeft); this.tableLeft.anchor.y = 1; this.tableLeft.position.y = EHDI.GAME.sceneManager.getStageHeight(); this.tableRight = new EHDI.aka.Sprite(EHDI.Assets.images["fishbread_table"]); this.gameLayer.addChild(this.tableRight); this.tableRight.anchor.y = 1; this.tableRight.anchor.x = 1; this.tableRight.scale.x = -1; this.tableRight.position.y = EHDI.GAME.sceneManager.getStageHeight(); this.tableRight.position.x = this.tableLeft.width; this.bowlShadow = new EHDI.aka.Sprite(EHDI.Assets.images["bowl-shadow"]); this.gameLayer.addChild(this.bowlShadow); this.bowlShadow.anchor.x = 0.5; this.bowlShadow.position.x = this.tableLeft.position.x + this.tableLeft.width; this.bowlShadow.position.y = this.tableLeft.position.y - this.tableLeft.height * 0.95; this.bowlShadow.visible = false; this.tableLeft.interactive = true; this.tableRight.interactive = true; this.breadToggle = new EHDI.components.BreadToggle(); this.breadToggle.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.2, EHDI.GAME.sceneManager.getStageHeight() * 0.82); this.guiLayer.addChild(this.breadToggle); this.fishToggle = new EHDI.components.FishToggle(); this.fishToggle.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.8, EHDI.GAME.sceneManager.getStageHeight() * 0.82); this.guiLayer.addChild(this.fishToggle); this.particleLayer = new EHDI.aka.Container(); this.gameLayer.addChild(this.particleLayer); this.breadGlowTexture = new PIXI.Texture(EHDI.Assets.images["glow2"].baseTexture, new PIXI.Rectangle(0, 0, 158, 157)); this.fishGlowTexture = new PIXI.Texture(EHDI.Assets.images["glow2"].baseTexture, new PIXI.Rectangle(158, 0, 158, 157)); EHDI.GAME.timer = new EHDI.components.Timer(); EHDI.GAME.timer.position.set(EHDI.GAME.sceneManager.getStageWidth() * 0.025, EHDI.GAME.sceneManager.getStageHeight() * 0.015); this.guiLayer.addChild(EHDI.GAME.timer); this.setupKeyboardControls(); var cache = EHDI.GAME.saveData; if(cache.isFirstTimePlay) { EHDI.GAME.pauseButton.isPaused = true; EHDI.GAME.sceneManager.pushPopUp(new EHDI.popup.HTPPopUp(), {y : new EHDI.scene.TransitionParameter(-EHDI.GAME.sceneManager.getStageHeight(), EHDI.GAME.sceneManager.getStageHeight() * 0.5), duration : 0.25}); cache.isFirstTimePlay = false; EHDI.sbGame.saveGameData(EHDI.GAME.saveData, "DEFAULT", function(){ console.log("data saved."); }); } } EHDI.scene.GameScene.prototype.setupKeyboardControls = function () { EHDI.GAME.keyboard = {}; EHDI.GAME.keyboard.leftArrow = EHDI.interactions.Keyboard(37), EHDI.GAME.keyboard.rightArrow = EHDI.interactions.Keyboard(39), EHDI.GAME.keyboard.space = EHDI.interactions.Keyboard(32); var fishToggle = this.fishToggle, breadToggle = this.breadToggle, particleLayer = this.particleLayer, breadGlowTexture = this.breadGlowTexture, fishGlowTexture = this.fishGlowTexture; EHDI.GAME.keyboard.leftArrow.release = function() { breadToggle.toggleBread(); } EHDI.GAME.keyboard.rightArrow.release = function() { fishToggle.toggleFish(); } EHDI.GAME.keyboard.space.release = function() { if(EHDI.GAME.customerSpawner.current) { EHDI.GAME.customerSpawner.current.processCustomer(); } } } EHDI.scene.GameScene.prototype.createDragonBones = function() { EHDI.GAME.dbFactory = new dragonBones.PixiFactory(); for(i = 1; i <= 10; i++) { var textureImage = EHDI.Assets.images["person" + i + "_tex"].baseTexture.source; var textureData = EHDI.Assets.cjAssets.getResult("person" + i + "_tex"); EHDI.GAME.dbFactory.addTextureAtlas(new dragonBones.TextureAtlas(textureImage, textureData)); var skeleton = EHDI.Assets.cjAssets.getResult("person" + i + "_ske"); EHDI.GAME.dbFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(skeleton)); }; var textureImage = EHDI.Assets.images["breadfish_tex"].baseTexture.source; var textureData = EHDI.Assets.cjAssets.getResult("breadfish_tex"); EHDI.GAME.dbFactory.addTextureAtlas(new dragonBones.TextureAtlas(textureImage, textureData)); var skeleton = EHDI.Assets.cjAssets.getResult("breadfish_ske"); EHDI.GAME.dbFactory.addDragonBonesData(dragonBones.DataParser.parseDragonBonesData(skeleton)); EHDI.GAME.updateManager.addFrameListener(this.animateAnimations); }; EHDI.scene.GameScene.prototype.animateAnimations = function(dt) { if(EHDI.GAME.pauseButton.isPaused || EHDI.GAME.pauseButton.isEndGame) return; dragonBones.WorldClock.clock.advanceTime(dt * 0.001); } EHDI.scene.GameScene.prototype.endGame = function() { var score = EHDI.GAME.scoreManager.getScore(), star = 0; if(score > 0) star++; if(score > 150) star++; if(score >= 300) star++; EHDI.GAME.pauseButton.endGame(); //EHDI.GAME.sceneManager.pushPopUp(new EHDI.popup.PostGamePopUp(star, score), {y : new EHDI.scene.TransitionParameter(-EHDI.GAME.sceneManager.getStageHeight(), EHDI.GAME.sceneManager.getStageHeight() * 0.5), duration : 0.5}); if(score > EHDI.GAME.saveData.highScore) { EHDI.GAME.saveData.highScore = score; EHDI.sbGame.saveGameData(EHDI.GAME.saveData, "DEFAULT", function(){ console.log("data saved."); }); } EHDI.sbGame.end(score); } EHDI.scene.GameScene.prototype.popUpWillAppear = function() { EHDI.GAME.customerSpawner.pause(); EHDI.GAME.soundManager.pauseBGM(); } EHDI.scene.GameScene.prototype.popUpDidDisappear = function() { if(!EHDI.GAME.pauseButton.isEndGame) { EHDI.GAME.customerSpawner.resume(); EHDI.GAME.soundManager.resumeBGM(); } } EHDI.scene.GameScene.prototype.screenDidDisappear = function() { EHDI.GAME.updateManager.removeFrameListener(this.animateAnimations); EHDI.GAME.timer.dispose(); EHDI.GAME.pauseButton.endGame(); dragonBones.WorldClock.clock.clear(); EHDI.GAME.keyboard.leftArrow.dispose(); EHDI.GAME.keyboard.rightArrow.dispose(); EHDI.GAME.keyboard.space.dispose(); delete EHDI.GAME.keyboard; this.destroy({children : true}); } EHDI.scene.GameScene.prototype.onPauseClick = function() { EHDI.GAME.sceneManager.pushPopUp(new EHDI.popup.PauseScene(), {y : new EHDI.scene.TransitionParameter(-EHDI.GAME.sceneManager.getStageHeight(),0), duration : 0.2}); };