(function() { "use strict"; var TutorialScene = function() { this.initialize(); } var p = TutorialScene.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 var text1 = 'Chibis are autonomous'; var text2 = ' Just wait and they\'ll talk'; var text3 = ' You can drag meddler chibis\n and other problems'; var text4 = 'Help them to find love'; this.text1 = new createjs.Text(text1, '48px sweetlove', '#6D4419'); this.text2 = new createjs.Text(text2, '48px sweetlove', '#6D4419'); this.text3 = new createjs.Text(text3, '48px sweetlove', '#6D4419'); this.text4 = new createjs.Text(text4, '48px sweetlove', '#6D4419'); this.text1.alpha = 1; this.text1.textAlign = 'center'; this.text1.x = canvas.width/2; this.text1.y = 180; this.text2.alpha = 0; this.text2.textAlign = 'center'; this.text2.x = canvas.width/2; this.text2.y = 180; this.text3.alpha = 0; this.text3.textAlign = 'center'; this.text3.x = canvas.width/2; this.text3.y = 180; this.text4.alpha = 0; this.text4.textAlign = 'center'; this.text4.x = canvas.width/2; this.text4.y = 180; var this_ = this; createjs.Tween.get(this.text1) .to({alpha:1, y:150}, 3000, createjs.Tween.cubicOut) .to({alpha:0, y:100}, 3000, createjs.Tween.cubicIn) createjs.Tween.get(this.text2) .wait(5000) .to({alpha:1, y:150}, 3000, createjs.Tween.cubicOut) .to({alpha:0, y:100}, 3000, createjs.Tween.cubicIn) createjs.Tween.get(this.text3) .wait(20000) .call(function() { var chibi = new ChibiFactory.createChibi(this_.levelData, MALE); this_.chibis.push(chibi); this_.layerObjects.addChild(chibi); }) .to({alpha:1, y:150}, 3000, createjs.Tween.cubicOut) .to({alpha:0, y:100}, 3000, createjs.Tween.cubicIn) createjs.Tween.get(this.text4) .wait(28000) .to({alpha:1, y:150}, 3000, createjs.Tween.cubicOut) .to({alpha:0, y:100}, 3000, createjs.Tween.cubicIn) // 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); this.layerUI.addChild(this.text1); this.layerUI.addChild(this.text2); this.layerUI.addChild(this.text3); this.layerUI.addChild(this.text4); // 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 = TUTORIAL; 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); registry.levelWidth = this.levelData.width registry.points = 0; this.chibis = [] var chibi = new ChibiFactory.createChibiOnScreen(this.levelData, MALE); this.chibis.push(chibi); this.layerObjects.addChild(chibi); var chibi = new ChibiFactory.createChibiOnScreen(this.levelData, FEMALE); this.chibis.push(chibi); this.layerObjects.addChild(chibi); registry.chibis = this.chibis; registry.chatQueue = []; } p.initializeAi = function() { this.aitree = new AIBehaviorTree(); var root = new AIPriority( // MARRY new AIMemSequence( new AIChibiConditions.CanMarry(), new AIChibiActions.Wait(3, 3), new AIChibiActions.Marry() ), // RUN new AIPriority( new AISequence( new AIChibiConditions.IsRunning(), new AIChibiActions.Wait(20, 20) ), new AIPriority( new AISequence( new AIPriority( new AIChibiConditions.IsWet(), new AIChibiConditions.IsShitted() ), new AIChibiActions.Stop(), new AIChibiActions.EndConversation(), new AIChibiActions.Wait(2, 3), new AIChibiActions.RunAway() ), new AISequence( new AIChibiConditions.IsMaxTocos(), new AIChibiActions.EndConversation(), new AIChibiActions.RunAway() ) ) ), // BORED new AIMemSequence( new AIChibiConditions.IsBored(), new AIChibiActions.SetRandomPosition(), new AIChibiActions.GoToRandomPosition(), new AIChibiActions.Wait(3, 5), new AIChibiActions.GoSingle() ), // REQUESTING TALK new AIPriority( new AIMemSequence( new AIChibiConditions.AnyConversationRequest(), new AIChibiDecorators.Inverter( new AISequence( new AIChibiConditions.InConversation(), new AIChibiConditions.IsConversationGood(), new AIChibiActions.DenyConversationInvite() ) ), new AIChibiActions.EndPartnerConversation(), new AIChibiActions.AcceptConversationInvite(), new AIChibiActions.Stop() ), new AIMemSequence( new AIChibiConditions.AnyTargetToConversation(), new AIChibiActions.SendConversationInvite(), new AIChibiActions.Stop(), new AIChibiDecorators.MaxTimeRunning(5, new AIChibiActions.WaitForConversationResponse() ) ) ), // TALK new AISequence( new AIChibiConditions.InConversation(), new AIChibiActions.Stop(), new AIChibiDecorators.Inverter( new AISequence( new AIChibiConditions.IsPartnerDistant(), new AIChibiActions.EndConversationWell() ) ), new AIChibiDecorators.Inverter( new AIMemSequence( new AIChibiConditions.IsLoserConversation(), new AIChibiActions.Wait(3, 5), new AIChibiActions.Angry(), new AIChibiActions.Wait(2, 4), new AIChibiActions.EndConversation() ) ), new AIPriority( new AIMemSequence( new AIChibiConditions.PartnerAskedSomething(), new AIChibiActions.Wait(3, 4), new AIChibiActions.AnswerQuestion() ), new AIMemSequence( new AIChibiConditions.IsMyTurnInChat(), new AIChibiActions.Wait(3, 5), new AIChibiActions.AskQuestion(), new AIChibiActions.WaitAnswer() ), new AIChibiActions.WaitQuestion() ) ), // IDLE new AIMemPriority( new AIMemSequence( new AIChibiConditions.IsWalkingForced(), new AIMemSequence ( new AIChibiActions.SetRandomPosition(), new AIChibiActions.GoToRandomPosition() ), new AIChibiActions.Wait(1, 3) ), new AIMemRandom( new AIMemSequence( new AIMemSequence ( new AIChibiActions.SetRandomPosition(), new AIChibiActions.GoToRandomPosition() ), new AIChibiActions.Wait(1, 3) ), new AIMemSequence( new AIMemSequence ( new AIChibiActions.SetRandomPosition(), new AIChibiActions.GoToRandomPosition() ), new AIChibiActions.Wait(1, 3) ), new AIMemPriority( new AIChibiActions.GoToNearestSingleChibi(), new AIMemSequence( new AIChibiActions.Stop(), new AIChibiActions.Wait(1, 3) ) ), new AIMemPriority( new AIChibiActions.GoToNearestChattingChibi(), new AIMemSequence( new AIChibiActions.Stop(), new AIChibiActions.Wait(1, 3) ) ) ) ) ); this.aitree.root = root; } p.updateLevel = function(fdelta) { PhysicsControl.applyGravity(this.chibis, fdelta); PhysicsControl.applyDragForce(DragComponent.children, fdelta); MoveSystem.updateMovement(MoveComponent.children, fdelta); ChibiControl.updateChibisTree(AiComponent.children, this.aitree, fdelta) ChibiControl.updateChibis(AiComponent.children, fdelta, this); if (this.pointIndicator.points != ''+registry.points) { this.pointIndicator.points = registry.points; this.pointIndicator.text = registry.points+'/'+this.levelData.maxPoints; } 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.TutorialScene = TutorialScene; }());