(function() { "use strict"; var LevelScene = function() { this.initialize(); } var p = LevelScene.prototype = new creatine.Scene(); p.Scene_initialize = p.initialize; // INITIALIZATION ========================================================= p.initialize = function() { this.Scene_initialize(); // layers this.layerParent = new createjs.Container(); this.layerBackground1 = new createjs.Container(); // sun this.layerBackground2 = new createjs.Container(); // level static this.layerBackground3 = new createjs.Container(); // clouds and dynamics this.layerObjects = new createjs.Container(); // chibis, dialogos, cupido this.layerForeground = new createjs.Container(); // fontes, chuva, passaros this.layerUI = new createjs.Container(); // ui // objects this.chibis = []; this.staticLevel = null; this.clouds = null; this.sun = null; this.cupid = null; this.rains = null; this.birds = null; this.dialogs = null; this.aitree = null; // initialize this.initializeLevel(); this.initializeAi(); this.initializeUI(); // add children this.layerParent.addChild(this.layerBackground1); this.layerParent.addChild(this.layerBackground2); this.layerParent.addChild(this.layerBackground3); this.layerParent.addChild(this.layerObjects); this.layerParent.addChild(this.layerForeground); this.addChild(this.layerParent); this.addChild(this.layerUI); // register events this.on('sceneenter', this.onSceneEnter); this.on('sceneresume', this.onSceneResume); this.on('scenepause', this.onScenePause); this.on('sceneexit', this.onSceneExit); } p.initializeUI = function() { this.buttonBack = createButton(140, 40, 'Back'); this.buttonBack.x = 90; this.buttonBack.y = 556; this.layerUI.addChild(this.buttonBack); this.pointBox = createBox(150, 70); this.pointBox.x = 710; this.pointBox.y = 550; this.layerUI.addChild(this.pointBox); this.heartIndicator = new createjs.Sprite(ssicon); this.heartIndicator.gotoAndStop(13); var bounds = this.heartIndicator.getBounds(); this.heartIndicator.regX = bounds.width/2; this.heartIndicator.regY = bounds.height/2; this.heartIndicator.x = 680; this.heartIndicator.y = 550; this.layerUI.addChild(this.heartIndicator); this.pointIndicator = new createjs.Text('0', '72px sweetlove', '#6D4419'); this.pointIndicator.textAlign = 'center'; this.pointIndicator.x = 715; this.pointIndicator.y = 510; this.layerUI.addChild(this.pointIndicator); } p.initializeLevel = function() { this.ended = false; this.levelData = LEVELS[registry.currentLevel]; CONST.RELATIONSHIP_SUCCESS_RATE = this.levelData.relationSuccessRate; // Set up the camera configuration this.layerParent.regX = canvas.width/2; this.layerParent.regY = 500; this.layerParent.scaleX = this.levelData.scale; this.layerParent.scaleY = this.levelData.scale; this.layerParent.x = canvas.width/2; this.layerParent.y = 500; // Set up the level elements // ground this.staticLevel = LevelFactory.createGround(this.levelData); this.layerBackground2.addChild(this.staticLevel); // sun if (this.levelData.sunPosition) { this.sun = EventFactory.createSun(this.levelData); this.layerBackground1.addChild(this.sun); } if (this.levelData.rainFrequency > 0) { this.rain = EventFactory.createRain(this.levelData); this.layerForeground.addChild(this.rain); } if (this.levelData.birdFrequency > 0) { this.bird = EventFactory.createBird(this.levelData); this.layerForeground.addChild(this.bird); } // ================================ registry.levelWidth = this.levelData.width registry.points = 0; this.chibis = [] for (var i=0; i= this.levelData.maxPoints && !this.ended) { this.unregisterEvents(); registry.currentLevel++; localStorage['loveCraft.bestLevel']= Math.max( registry.currentLevel, localStorage['loveCraft.bestLevel'] ); createjs.Tween.get({}) .wait(2000) .call(function() { director.push( new WinScene(LevelScene), new creatine.transitions.MoveIn( creatine.TOP, createjs.Ease.bounceOut, 800 ) ) }); this.ended = true; } } p.__beginDrag = function(x, y, object) { var point = object.globalToLocal(x, y); if (object.hitTest(point.x, point.y)) { UserControl.beginDrag(x, y, object); return true; } return false; } // EVENTS ================================================================= p.registerEvents = function(event) { var this_ = this; stage.on('stagemousedown', function(event) {this_.onMouseDown(event);}); stage.on('stagemouseup', function(event) {this_.onMouseUp(event);}); stage.on('stagemousemove', function(event) {this_.onMouseMove(event);}); this.buttonBack.on('click', this.onButtonBack, this); } p.unregisterEvents = function(event) { stage.removeAllEventListeners('stagemousedown'); stage.removeAllEventListeners('stagemouseup'); stage.removeAllEventListeners('stagemousemove'); this.buttonBack.removeAllEventListeners('click'); } p.onMouseDown = function(event) { // console.log(this); var x = event.stageX; var y = event.stageY; // var cp = this.layerParent.globalToLocal(x, y); // x = cp.x; // y = cp.y; for (var i=DragComponent.children.length-1; i>=0; i--) { if (this.__beginDrag(x, y, DragComponent.children[i])) { return; } } } p.onMouseMove = function(event) { // console.log(this); var x = event.stageX; var y = event.stageY; UserControl.updateDrag(x, y, this.levelData); } p.onMouseUp = function(event) { // console.log(this); var x = event.stageX; var y = event.stageY; UserControl.endDrag(x, y); } p.onUpdate = function(event) { this.updateLevel(event.fdelta); // this.camera.apply(this); } p.onSceneEnter = function(event) { this.registerEvents(); } p.onSceneExit = function(event) { AiComponent.children = []; DragComponent.children = []; MoveComponent.children = []; RelationComponent.children = []; } p.onSceneResume = function(event) { this.registerEvents(); } p.onScenePause = function(event) { this.unregisterEvents(); } p.onButtonBack = function(event) { director.replace( new MenuScene(), new creatine.transitions.FadeInOut()//creatine.BOTTOM) ); } window.LevelScene = LevelScene; }());