/** * See LICENSE file. * * Play scene.. */ (function() { HN.BrickActor= function() { HN.BrickActor.superclass.constructor.call(this); this.sb= new CAAT.ScaleBehavior(). setFrameTime(-1,0). setValues(1,1); this.addBehavior(this.sb); this.rb= new CAAT.RotateBehavior(). setFrameTime(-1,0). setValues(0,0) this.addBehavior(this.rb); this.pb= new CAAT.PathBehavior(). setFrameTime(-1,0) this.addBehavior(this.pb); this.ab= new CAAT.AlphaBehavior(). setFrameTime(-1,0). setValues(1) this.addBehavior(this.ab); return this; }; HN.BrickActor.status= { REGULAR: 0, // en tablero. FALLING: 1, // cayendo. (rearrange) CLEARED: 2 // eliminado, no disponible (cayendo y eliminado) } HN.BrickActor.prototype= { timeOver: 250, timeSelection: 1000, timeRespawn: 1500, timeRearrange: 1500, timeOverflow: 200, timeCleared: 800, brick: null, status: 0, // 0: regular state, 1: falling, 2: cleared. ab: null, sb: null, rb: null, pb: null, /** * * @param numberImage * @param brick a HN.Brick instance. */ initialize : function( numberImage, brick ) { var tw= numberImage.singleWidth; var th= numberImage.singleHeight; this.setSize(tw,th); this.setBackgroundImage(numberImage.getRef(),true); this.brick= brick; var me= this; brick.delegate = function() { me.setSpriteIndex( me.brick.value + numberImage.columns*me.brick.color ); } return this; }, /** * Make initialize animation. * @param brickPosition */ initializeForPlay: function( brickPosition, animationStartTime, animationDuration ) { var brickActor= this; brickActor. setLocation( brickPosition.x, brickPosition.y ). setScale( .01, .01 ); brickActor.sb. setValues( .01,1, .01, 1). setInterpolator( new CAAT.Interpolator().createElasticOutInterpolator(1.1, 0.1, false) ). setFrameTime(animationStartTime, animationDuration ); }, setStatus : function(st) { this.status= st; return this; }, mouseEnter : function(mouseEvent) { if ( this.brick.selected ) { return; } this.parent.setZOrder( this, Number.MAX_VALUE ); this.sb.setFrameTime( this.time, this.timeOver ). setValues( 1, 1.2, 1, 1.2 ). setPingPong(); if ( CAAT.browser!=='iOS' ) { CAAT.setCursor('pointer'); } }, mouseExit : function(mouseEvent) { if ( CAAT.browser!=='iOS' ) { CAAT.setCursor('default'); } }, mouseDown : function(mouseEvent) { this.brick.changeSelection(); }, toString : function() { return 'HN.Brick '+this.brick.row+','+this.brick.column; }, /** * brick deselected. */ reset : function() { this.resetAlpha(). resetRotate(). resetScale(). resetTransform(); this.alpha=1; return this; }, resetBehavior : function(b,p1,p2) { b.emptyListenerList(); b.setCycle(false); b.setInterpolator( new CAAT.Interpolator().createLinearInterpolator() ); b.setFrameTime(-1,0); if ( p1&& p2 ) { b.setValues(p1,p2); } }, resetAlpha: function() { this.resetBehavior(this.ab,1,1); return this; }, resetScale: function() { this.resetBehavior(this.sb,1,1); return this; }, resetRotate: function() { this.resetBehavior(this.rb,0,2*Math.PI); return this; }, resetPath : function() { this.resetBehavior(this.pb); return this; }, resetBehaviors : function() { this.resetAlpha(); this.resetScale(); this.resetRotate(); this.resetPath(); return this; }, /** * brick selected. */ setSelected : function() { this.sb. setValues( 1, .65, 1, .65 ). setFrameTime( this.time, this.timeSelection ). setPingPong(). setCycle(true); this.ab. setValues( .75, .25 ). setFrameTime( this.time, this.timeSelection ). setPingPong(). setCycle(true); }, /** * game just started. */ set: function() { this.status= HN.BrickActor.status.REGULAR; this.enableEvents(true); this.reset(); }, /** * actors entering game upon respawn timeout. * @param x * @param y */ respawn: function(x,y) { this. reset(). enableEvents(true). setFrameTime(this.time,Number.MAX_VALUE). resetTransform(). setAlpha(1). setStatus(HN.BrickActor.status.FALLING) ; this.pb. emptyListenerList(). setFrameTime(this.time, this.timeRespawn+this.brick.row*50). setPath( new CAAT.LinearPath(). setInitialPosition(x, -this.height-((Math.random()*100)>>0) ). setFinalPosition(x, y)). setInterpolator( new CAAT.Interpolator().createBounceOutInterpolator() ). addListener( { behaviorApplied : function() { }, // re-enable events on actor after moving to rearrange position. behaviorExpired : function(behavior, time, actor) { actor.setStatus(HN.BrickActor.status.REGULAR); } } ); }, /** * brick's been rearranged, i.e. moved position in context. * @param x * @param y */ rearrange: function(x,y) { if ( this.status===HN.BrickActor.status.CLEARED ) { return; } this.setStatus(HN.BrickActor.status.FALLING); this.pb. emptyListenerList(). setFrameTime(this.time + this.brick.column*50, this.timeRearrange). setPath( new CAAT.LinearPath(). setInitialPosition(this.x, this.y). setFinalPosition(x, y)). setInterpolator( new CAAT.Interpolator().createBounceOutInterpolator() ). addListener({ behaviorApplied : function() { }, // re-enable events on actor after moving to rearrange position. behaviorExpired : function(behavior, time, actor) { actor.setStatus(HN.BrickActor.status.REGULAR); } }); }, /** * selection excedes suggested number. * @param callback */ selectionOverflow : function() { // ladrillos que estn cayendo, no hacen el path de error. //if ( !this.falling ) { if ( this.status===HN.BrickActor.status.REGULAR ) { var signo= Math.random()<.5 ? 1: -1; this.pb. emptyListenerList(). setFrameTime(this.time, this.timeOverflow). setPath( new CAAT.Path(). beginPath(this.x,this.y). addLineTo(this.x + signo*(5+5*Math.random()),this.y). addLineTo(this.x - signo*(5+5*Math.random()),this.y). endPath() ). setPingPong(); } }, /** * this brick belongs to valid selection which sums up the suggested number. * @param scene * @param maxHeight */ selectionCleared : function(scene, maxHeight) { this.setStatus(HN.BrickActor.status.CLEARED); var signo= Math.random()<.5 ? 1 : -1; var offset= 50+Math.random()*30; var actor= this; this.enableEvents(false).setScale( 1.5, 1.5 ); this.pb. emptyListenerList(). setFrameTime( this.time, this.timeCleared ). setPath( new CAAT.Path(). beginPath( this.x, this.y ). addQuadricTo( this.x+offset*signo, this.y-300, this.x+offset*signo*2, this.y+maxHeight+20). endPath() ); if ( !HN.LOWQUALITY ) { this.pb.addListener( { behaviorExpired : function(behavior, time, actor) { actor.setExpired(true); }, behaviorApplied : function(behavior, time, normalizedTime, actor, value) { for( var i=0; i< (CAAT.browser==='iOS' ? 1 : 3); i++ ) { var offset0= Math.random()*10*(Math.random()<.5?1:-1); var offset1= Math.random()*10*(Math.random()<.5?1:-1); if ( scene.fallingStarCache.length>0 ) { var actor2= scene.fallingStarCache.shift(); // check for no parent, that is, no active actor. if ( !actor2.domParent ) { actor2. setAnimationImageIndex( [(Math.random()*6)>>0] ). setFrameTime(actor.time, 400). setLocation( offset0+actor.x+actor.width/2, offset1+actor.y); actor2.__parent.addChild(actor2); actor2.getBehavior( '__alpha' ).setFrameTime( actor.time, 400 ); } } } } }); } this.pb.setInterpolator( new CAAT.Interpolator().createLinearInterpolator(false,false) ); this.rb. setFrameTime( this.time, this.timeCleared ). setValues( 0, (Math.PI + Math.random()*Math.PI*2)*(Math.random()<.5?1:-1) ); this.ab. setFrameTime( this.time, this.timeCleared ). setValues( 1, .25 ); } }; extend( HN.BrickActor, CAAT.Actor); })(); (function() { HN.RespawnClockActor= function() { HN.RespawnClockActor.superclass.constructor.call(this); this.ticks= []; return this; }; HN.RespawnClockActor.prototype= { ticks: null, respawnTime: 10000, scene: null, context: null, arrow: null, enabled: false, initialize: function(director, scene, context) { this.scene= scene; this.context= context; var itick= director.getImage('rclock-tick'); var itickci; itickci= new CAAT.SpriteImage().initialize( itick, 16, 1 ); var ibg= director.getImage('rclock-bg'); var iarrow= director.getImage('rclock-arrow'); var me= this; this.setSize(64,64); var bg= new CAAT.Actor(). setBackgroundImage( ibg, true ). setLocation((this.width-ibg.width)/2, (this.height-ibg.height)/2); this.addChild(bg); var NTicks= 12; for( var i=0; i>0)] ); }) ); tick.addBehavior(cb); } var flecha= new CAAT.Actor().setBackgroundImage(iarrow, true); flecha.setLocation( (this.width-flecha.width)/2, this.height/2-23-.5 ); this.addChild(flecha); flecha.addBehavior( new CAAT.RotateBehavior(). setOutOfFrameTime(). setValues(0, 2*Math.PI, .50, (23/flecha.height*100)/100 ). addListener({ behaviorExpired : function(behavior, time, actor) { me.resetTimer(); me.context.respawn(); }, behaviorApplied : function(behavior, time, normalizedTime, actor, value) {} }) ); this.arrow= flecha; return this; }, resetTimer : function() { var NTicks= this.ticks.length; for( var i=0; i expectedParticleCount ) { this.particles.splice( expectedParticleCount, this.particles.length-expectedParticleCount ); } else { while( this.particles.length1 ) { this.setupPath(); if ( null===this.coords || 0===this.coords.length ) { return; } director.glFlush(); var i, pos=0, z= 0, point= new CAAT.Point(), m= this.worldModelViewMatrix, cc= director.coords, ccthis= this.coords, pa= this.particles; for( i=0; i>0) + (i*this.font.singleWidth*this.FONT_CORRECTION) - 5, 12 ). setScale( this.FONT_CORRECTION, this.FONT_CORRECTION ); this.addChild(actor); } return this; }, contextEvent : function( event ) { if ( event.source=='context' ) { if ( event.event=='score' ) { this.maxScore= event.params.score; this.minScore= this.currentScore; this.incrementScore= this.maxScore- this.minScore; window.score=this.maxScore; this.startTime= this.time; } else if ( event.event=='status') { if ( event.params==HN.Context.prototype.ST_STARTGAME ) { this.reset(); } } } }, setScore: function(director) { this.currentScore>>=0; var str= ''+this.currentScore; while( str.length<6 ) { str='0'+str; } this.numbers= []; var i=0; for( i=0; i= this.startTime && time0 ) { me.currentAltitude=0; } me.setBackgroundImageOffset( 0, me.currentAltitude ); timerTask.reset( me.scene.time ); me.context.incrementAltitude( me.altitudeMeterByIncrement ); }, null, null ); } }, setInitialOffset : function( offset ) { this.setBackgroundImageOffset( 0, offset ); this.initialOffset= offset; this.currentAltitude= offset; return this; }, caer : function(time) { this.setBackgroundImageOffset( 0, this.currentOffset + (this.initialOffset-this.currentOffset)*time ); } }; extend( HN.AnimatedBackground, CAAT.Actor); })(); (function() { HN.BackgroundImage= function() { HN.BackgroundImage.superclass.constructor.call(this); return this; }; HN.BackgroundImage.prototype= { setupBehavior : function(director, bFirstTime) { var is_bg= Math.random()<.4; this.setBackgroundImage( director.getImage('cloud'+(is_bg ? 'b' : '')+ ((4*Math.random())>>0) ), true ); var t= (30000*(is_bg?1.5:1) + 5000*Math.random()*2); var me= this; var ix0, ix1, iy0, iy1; var dw= director.width; var dh= director.height-200; var ih= this.backgroundImage.height; var iw= this.backgroundImage.width; if ( bFirstTime ) { ix0= dw*Math.random(); iy0= dh*Math.random(); t= (dw-ix0)/dw*t; } else { ix0= -iw-iw*Math.random(); iy0= dh*Math.random(); } ix1= dw+iw*Math.random(); iy1= iy0 + Math.random()*30; this.emptyBehaviorList(); this.addBehavior( new CAAT.PathBehavior(). setFrameTime( this.time, t ). setPath( new CAAT.Path().setLinear(ix0, iy0, ix1, iy1) ). addListener( { behaviorExpired : function(behavior, time, actor) { me.setupBehavior(director, false); }, behaviorApplied : function(actor,time,normalizedTime,value) { } }) ); return this; } }; extend( HN.BackgroundImage, CAAT.Actor); })(); (function() { HN.LevelActor= function() { HN.LevelActor.superclass.constructor.call(this); this.numbers= []; return this; }; HN.LevelActor.prototype= { font: null, numbers: null, initialize : function(font, background) { this.font= font; for( var i=0; i<2; i++ ) { var digit= new CAAT.Actor(). setBackgroundImage(font.getRef(), true). setVisible(false); this.numbers.push(digit); this.addChild(digit); } this.setBackgroundImage(background, true); return this; }, contextEvent : function(event) { if ( event.source=='context' ) { if ( event.event=='levelchange') { this.level= event.params; var snumber= this.level.toString(); var i, number; var correction= this.font.singleWidth*.8; for( i=0; i1 ) { this.multiplier = event.params.multiplier; this.actornum.setVisible(true).setAnimationImageIndex([this.multiplier]); this.actorx.setVisible(true); this.emptyBehaviorList(); this.addBehavior( new CAAT.ScaleBehavior(). setFrameTime(this.time,1000). setValues(.9, 1.1, .9, 1.1 ). setPingPong(). setCycle(true)); this.b1(this.actorx); this.b1(this.actornum); } else { this.emptyBehaviorList(); this.b2(this.actorx); this.b2(this.actornum); } } else if ( event.event=='status') { if ( event.params==HN.Context.prototype.ST_ENDGAME ) { this.hideMultiplier(); } } } } }; extend( HN.MultiplierActor, CAAT.ActorContainer); })(); (function() { HN.MultiplierActorS= function() { HN.MultiplierActorS.superclass.constructor.call(this); this.star= new CAAT.Actor(); this.container= new CAAT.ActorContainer(); this.actorx= new CAAT.Actor(); this.actornum= new CAAT.Actor(); this.addChild(this.star); this.addChild(this.container); this.container.addChild(this.actorx); this.container.addChild(this.actornum); this.container.setGlobalAlpha(true); return this; }; HN.MultiplierActorS.prototype= { actorx: null, actornum: null, star: null, multiplier: 0, setImages : function( font, x, star, scene ) { this.scene= scene; this.setOutOfFrameTime(); this.star.setBackgroundImage(star); var S= this.star.width/2; this.actorx.setBackgroundImage(x,false). setBounds(0, (this.star.height-S)/2, S, S). setImageTransformation( CAAT.SpriteImage.prototype.TR_FIXED_TO_SIZE ); this.actornum.setBackgroundImage(font,true). setScale( .4,.4 ). setLocation( 0, -20 ); this.setSize( this.star.width, this.star.height); this.container.setSize( this.star.width, this.star.height); this.container.setRotation( Math.PI/16 ); this.star.setLocation( 0,0 ); return this; }, hideMultiplier : function() { this.multiplier=0; this.setOutOfFrameTime(); }, b1 : function(actor) { actor.emptyBehaviorList(); var cb= new CAAT.ContainerBehavior(). setFrameTime(this.scene.time,1000). setCycle(true); var ab= new CAAT.AlphaBehavior(). setFrameTime(0,1000). setValues(.8,1). setPingPong(); var sb= new CAAT.ScaleBehavior(). setFrameTime(0,1000). setValues(.8, 1, .8, 1). setPingPong(); cb.addBehavior(ab); cb.addBehavior(sb); actor.addBehavior(cb); }, b2 : function(actor) { var me= this; actor.emptyBehaviorList(); var ab= new CAAT.AlphaBehavior(). setFrameTime(this.time,300). setValues( this.alpha, 0 ). addListener( { behaviorExpired : function(behavior, time, actor) { me.hideMultiplier(); }, behaviorApplied : function(actor,time,normalizedTime,value) {} }); actor.addBehavior(ab); }, contextEvent : function( event ) { if ( event.source == 'context' ) { if ( event.event=='multiplier' ) { if ( event.params.multiplier>1 ) { this.multiplier = event.params.multiplier; this.actornum.setAnimationImageIndex([this.multiplier]); this.setFrameTime(0, Number.MAX_VALUE); this.emptyBehaviorList(); this.star.addBehavior( new CAAT.RotateBehavior(). setFrameTime(this.time,1000). setValues(0, Math.PI*2 ). setCycle(true)); this.b1(this.container); } else { this.emptyBehaviorList(); this.b2(this.container); } } else if ( event.event=='status') { if ( event.params==HN.Context.prototype.ST_ENDGAME ) { this.hideMultiplier(); } } } } }; extend( HN.MultiplierActorS, CAAT.ActorContainer); })(); (function() { HN.GameScene= function() { this.gameListener= []; return this; }; HN.GameScene.prototype= { gameRows: 15, gameColumns: 20, context: null, directorScene: null, selectionPath: null, bricksContainer: null, brickActors: null, particleContainer: null, selectionStarCache: null, fallingStarCache: null, brickWidth: 0, brickHeight: 0, buttonImage: null, starsImage: null, numbersImage: null, numbersImageSmall: null, levelActor: null, chronoActor: null, timer: null, scrollTimer: null, scoreActor: null, respawnClock: null, scoreActorEG: null, levelActorEG: null, endGameActor: null, endLevelActor: null, endLevelMessage: null, director: null, actorInitializationCount: 0, // flag indicating how many actors have finished initializing. backgroundContainer: null, music: null, sound: null, gameListener: null, /** * Creates the main game Scene. * @param director a CAAT.Director instance. */ create : function(director, gameMode ) { var me= this; var i,j; this.director= director; this.bricksImageAll= new CAAT.SpriteImage().initialize( director.getImage('bricks'), 9, 10 ); this.brickWidth= this.bricksImageAll.singleWidth; this.brickHeight= this.bricksImageAll.singleHeight; this.buttonImage= new CAAT.SpriteImage().initialize( director.getImage('buttons'), 7,3 ); this.starsImage= new CAAT.SpriteImage().initialize( director.getImage('stars'), 24,6 ); this.numbersImage= new CAAT.SpriteImage().initialize( director.getImage('numbers'), 1,10 ); this.numbersImageSmall= new CAAT.SpriteImage().initialize( director.getImage('numberssmall'), 1,10 ); this.context= new HN.Context(). create( 8,8, 9 ). addContextListener(this); this.gameRows= this.context.rows; this.gameColumns= this.context.columns; this.directorScene= director.createScene(); this.directorScene.activated= function() { // cada vez que la escena se prepare para empezar partida, inicializar el contexto. //me.context.initialize(); me.context.setGameMode(me.gameMode); me.prepareSound(); }; var dw= director.width; var dh= director.height; //////////////////////// animated background this.backgroundContainer= new HN.AnimatedBackground(). setBounds(0,0,dw,dh). setBackgroundImage( director.getImage('background-1') ). setInitialOffset( -director.getImage('background-1').height+dh ). setData(this.directorScene, this.context); this.directorScene.addChild( this.backgroundContainer ); this.context.addContextListener(this.backgroundContainer); this.brickActors= []; ///////////// some clouds for( i=0; i<4; i++ ) { var cl= new HN.BackgroundImage().setupBehavior(director,true); this.directorScene.addChild(cl); } //////////////////////// Number Bricks this.bricksContainer= new CAAT.ActorContainer(). create(). setSize( this.gameColumns*this.brickWidth, this.gameRows*this.brickHeight ) ; var TT= 15; var bricksCY= dw>dh ? 10: (dh-this.brickHeight*this.gameRows) - 105; // vertically set space for banner. var bricksCX= dw>dh ? bricksCY + TT : (dw - (this.gameColumns * this.brickWidth )) / 2; // center horizontally this.bricksContainer.setLocation( bricksCX, bricksCY ); this.directorScene.addChild(this.bricksContainer); for( i=0; idh ) { controls.setBounds( this.bricksContainer.x + this.bricksContainer.width + bricksCX + 10 , -15, dw - bricksCX - (this.bricksContainer.x + this.bricksContainer.width) - bricksCX, this.director.height-40 ); } else { controls.setBounds(0,0,dw, this.bricksContainer.y-5); } this.directorScene.addChild( controls ); /////////////////////// initialize button var restart= new CAAT.Actor(); if ( dw>dh ) { restart.setAsButton( this.buttonImage.getRef(), 9,10,11,9, function(button) { me.context.timeUp(); }). setLocation( (controls.width-this.buttonImage.singleWidth)/2 - 15, controls.height - this.buttonImage.singleHeight - 15 ); } else { restart. setAsButton( new CAAT.SpriteImage().initialize(director.getImage('boton-salir'), 1, 3), 0,2,0,0, function(button) { me.context.timeUp(); }). setLocation( 0,0 ); } restart.contextEvent= function(event) { if ( event.source=='context' ) { if ( event.event=='levelchange') { restart.enableEvents(true); } else if ( event.event=='status') { if ( event.params==HN.Context.prototype.ST_STARTGAME ) { restart.enableEvents(true); } else if ( event.params==HN.Context.prototype.ST_ENDGAME || event.params==HN.Context.prototype.ST_LEVEL_RESULT ) { restart.enableEvents(false); } } } }; this.context.addContextListener(restart); controls.addChild(restart); ///////////////////// Guess Number var guess= new HN.GuessNumberActor(). setNumbersImage( this.numbersImage, director.getImage('target-number') ); if ( dw>dh ) { guess.setLocation( -15, 20, controls.width, 70 ); } else { guess.setLocation( WW, HH, controls.width, 70 ); } this.context.addContextListener(guess); controls.addChild(guess); ///////////////////// score this.scoreActor= new HN.ScoreActor(). initialize( this.numbersImageSmall, director.getImage('points') ); if ( dw>dh ) { this.scoreActor.setLocation( 0, 250 ); } else { this.scoreActor.setLocation( dw-this.scoreActor.width-WW, HH ); } controls.addChild( this.scoreActor ); this.context.addContextListener(this.scoreActor); ///////////////////// chronometer this.chronoActor= new HN.Chrono(). setImages( director.getImage('time'), director.getImage('timeprogress')); if ( dw>dh ) { this.chronoActor.setLocation( 0, 310 ); } else { this.chronoActor.setLocation( dw-this.chronoActor.width-WW, guess.y+guess.height-this.chronoActor.height-15 ); } this.context.addContextListener(this.chronoActor); controls.addChild(this.chronoActor); ///////////////////// Level indicator this.levelActor= new HN.LevelActor(). initialize( this.numbersImageSmall, dw>dh ? director.getImage('level') : director.getImage('level-small') ); if ( dw>dh ) { this.levelActor.setLocation( 0, 170 ); } else { this.levelActor.setLocation( // espacio entre target number y score actor ((this.scoreActor.x- (guess.x+guess.width)) - this.levelActor.width)/2 + (guess.x+guess.width), guess.y+guess.height - this.levelActor.height - 10 ); } this.context.addContextListener(this.levelActor); controls.addChild(this.levelActor); ////////////////////// Multiplier var multiplier; var star= director.getImage('multiplier-star'); multiplier= new HN.MultiplierActorS(). setLocation( this.scoreActor.x + this.scoreActor.width - star.width*.8, this.scoreActor.y - star.height*.3 ). setImages( this.numbersImage, director.getImage('multiplier'), star, this.directorScene ); controls.addChild( multiplier ); this.context.addContextListener(multiplier); var sitelogo= new CAAT.Actor(). setBackgroundImage( director.getImage('sitelogo'), true). enableEvents(true); sitelogo.setLocation( (director.width-sitelogo.width)/2, 10 ); this.directorScene.addChild(sitelogo); sitelogo.mouseClick= function( e ) { CreateLinksInGame('Math-Plus','game','logo'); }; /////////////////////// particle container // just to accelerate events delivery if ( !HN.LOWQUALITY ) { this.particleContainer= new CAAT.ActorContainer(). create(). //setBounds(0,0,dw,dh). setBounds( this.bricksContainer.x, this.bricksContainer.y, dw, dh ). enableEvents(false); this.directorScene.addChild( this.particleContainer ); this.create_cache(); } /////////////////////// initialize selection path /// create this one as the last actor so when gl active, no extra drawtris call needed. this.selectionPath= new HN.SelectionPath(director). setBounds( this.bricksContainer.x, this.bricksContainer.y, this.gameColumns*this.brickWidth, this.gameRows*this.brickHeight); this.selectionPath.enableEvents(false); this.directorScene.addChild(this.selectionPath); this.context.addContextListener(this.selectionPath); ////////////// respawn this.create_respawntimer(director); if ( dw>dh ) { this.respawnClock.setLocation(2,2); } else { this.respawnClock.setLocation( this.levelActor.x + (this.levelActor.width - this.respawnClock.width)/2, this.levelActor.y - this.respawnClock.height ); } //////////////////////////////////////////////// this.create_EndGame(director); this.create_EndLevel(director); this.soundControls( director ); return this; }, createCachedStar : function(director) { var iindex= (Math.random()*this.starsImage.columns)>>0; var actor= new CAAT.Actor(); actor.__imageIndex= iindex; actor. setBackgroundImage( this.starsImage.getRef().setAnimationImageIndex( [iindex] ), true ). enableEvents(false). setDiscardable(true). setOutOfFrameTime(). addBehavior( this.director.getRenderType()==='CSS' ? new CAAT.AlphaBehavior(). setValues( 1, .1 ). setId('__alpha'): new CAAT.GenericBehavior(). setValues( 1, .1, null, null, function(value,target,actor) { actor.backgroundImage.setAnimationImageIndex( [ actor.__imageIndex+(23-((23*value)>>0))*actor.backgroundImage.getColumns() ] ); }). setId('__alpha') ); return actor; }, create_cache: function() { this.selectionStarCache= []; this.fallingStarCache= []; var i,actor,me; me= this; for( i=0; i<16*4; i++ ) { actor= this.createSelectionStarCache(); actor.addListener( { actorLifeCycleEvent : function(actor, event, time) { if (event === 'destroyed') { me.selectionStarCache.push(actor); } } }); actor.__parent= this.particleContainer; this.selectionStarCache.push(actor); } for( i=0; i<384; i++ ) { var actor= this.createCachedStar(); actor.addListener( { actorLifeCycleEvent : function(actor, event, time) { if (event === 'destroyed') { me.fallingStarCache.push(actor); } } }); actor.__parent= this.particleContainer; this.fallingStarCache.push(actor); } }, createSelectionStarCache : function() { var actor= this.createCachedStar(); var trb= new CAAT.PathBehavior(). setFrameTime(this.directorScene.time,0). setPath( new CAAT.LinearPath(). setInitialPosition(0,0). setFinalPosition(0,0) ). setInterpolator( new CAAT.Interpolator().createExponentialOutInterpolator( 2, false) ); actor.__trb= trb; actor.addBehavior(trb); var ab= null; if ( this.director.getRenderType()==='CSS' ) { ab= new CAAT.AlphaBehavior().setValues( 1, .1 ); } else { ab= new CAAT.GenericBehavior(). setValues( 1, .1, null, null, function(value,target,actor) { actor.backgroundImage.setAnimationImageIndex( [ actor.__imageIndex+(23-((23*value)>>0))*actor.backgroundImage.getColumns() ] ); }); } actor.__ab= ab; actor.addBehavior(ab); return actor; }, create_respawntimer: function(director) { var clock= new HN.RespawnClockActor().create().initialize(director, this.directorScene, this.context); this.directorScene.addChild( clock ); this.context.addContextListener(clock); this.respawnClock= clock; this.respawnClock.setOutOfFrameTime(); }, create_EndLevel : function( director ) { this.endLevelActor= new CAAT.ActorContainer(). setBackgroundImage( director.getImage('levelclear'), true); var me= this; var me_endLevel= this.endLevelActor; var continueButton= new CAAT.Actor(). setAsButton( this.buttonImage.getRef(), 12,13,14,12, function(button) { director.audioPlay('11'); me.removeGameEvent( me.endLevelActor, function() { me.context.nextLevel(); }); }); continueButton.setLocation( (this.endLevelActor.width-continueButton.width)/2, this.endLevelActor.height-continueButton.height-50 ); this.endLevelMessage= new CAAT.Actor(). setBackgroundImage( director.getImage('msg1'), true ); this.endLevelActor.addChild(continueButton); this.endLevelActor.addChild(this.endLevelMessage); this.endLevelActor.setOutOfFrameTime(); this.directorScene.addChild(this.endLevelActor); }, create_EndGame : function(director, go_to_menu_callback ) { var me= this; this.endGameActor= new CAAT.ActorContainer(). setBackgroundImage( director.getImage('background_op'), true ); var menu= new CAAT.Actor(). setAsButton( this.buttonImage.getRef(), 0,1,2,0, function(button) { director.audioPlay('11'); me.endGameActor.enableEvents(false); var a0; var a1; a0= CAAT.Actor.prototype.ANCHOR_BOTTOM; a1= CAAT.Actor.prototype.ANCHOR_TOP; director.easeInOut( 0, CAAT.Scene.EASE_TRANSLATE, a0, 1, CAAT.Scene.EASE_TRANSLATE, a1, 1000, false, new CAAT.Interpolator().createExponentialInOutInterpolator(3,false), new CAAT.Interpolator().createExponentialInOutInterpolator(3,false) ); }); var me_endGame= this.endGameActor; var restart= new CAAT.Actor(). setAsButton( this.buttonImage.getRef(), 3,4,5,3, function(button) { director.audioPlay('11'); me.removeGameEvent( me.endGameActor, function() { me.prepareSceneIn(me.context.gameMode); me.context.initialize(); }) }); var x= 45; var y= this.endGameActor.height-35-menu.height; menu.setLocation( x, y ); restart.setLocation( x+menu.width+10, y ); this.endGameActor.addChild(menu); this.endGameActor.addChild(restart); var __buttons= [ menu, restart ]; CAAT.modules.LayoutUtils.row( this.endGameActor, __buttons, { padding_left: 50, padding_right: 50, top: y }); //////////////////////// info de partida this.levelActorEG= new HN.LevelActor(). initialize(this.numbersImageSmall, director.getImage('level')); this.levelActorEG. setBounds( (this.endGameActor.width-this.levelActorEG.width)/2, 265, this.levelActorEG.width, this.levelActorEG.height ); this.endGameActor.addChild(this.levelActorEG); this.context.addContextListener(this.levelActorEG); console.log( this.levelActorEG); ///////////////////// score this.scoreActorEG= new HN.ScoreActor(). create(). setBounds( ((this.endGameActor.width-this.scoreActor.width)/2)|0, 335, this.scoreActor.width, this.scoreActor.height ). initialize( this.numbersImageSmall, director.getImage('points') ); this.endGameActor.addChild( this.scoreActorEG ); this.context.addContextListener(this.scoreActorEG); this.endGameActor.setOutOfFrameTime(); this.directorScene.addChild(this.endGameActor); console.log(this.scoreActorEG); }, getBrickPosition : function(row,column) { return { x: (this.context.columns-this.context.currentColumns)/2*this.brickWidth+ column*this.brickWidth, y: (this.context.rows-this.context.currentRows)/2*this.brickHeight+ row*this.brickHeight }; }, uninitializeActors : function() { this.selectionPath.initialize(); var i, j; var radius= Math.max(this.director.width,this.director.height ); var angle= Math.PI*2*Math.random(); var me= this; var p0= Math.random()*this.director.width; var p1= Math.random()*this.director.height; var p2= Math.random()*this.director.width; var p3= Math.random()*this.director.height; for( i=0; i>0; var brickPosition= this.getBrickPosition(i,j); brickActor.pb. emptyListenerList(). setPath( new CAAT.CurvePath(). setCubic( radius/2 + Math.cos(angle)*radius, radius/2 + Math.sin(angle)*radius, p0, p1, p2, p3, brickPosition.x, brickPosition.y) ). setInterpolator( new CAAT.Interpolator().createExponentialInOutInterpolator(3,false) ). setFrameTime(this.directorScene.time, 1000+random); brickActor.sb. emptyListenerList(). setValues( .1, 1, .1 , 1). setInterpolator( new CAAT.Interpolator().createExponentialInOutInterpolator(3,false) ). setFrameTime(this.directorScene.time , 1000+random); brickActor. enableEvents(false); var actorCount=0; brickActor.pb.addListener( { behaviorExpired : function( behavior, time, actor ) { actorCount++; if ( actorCount==me.context.getLevelActiveBricks() ) { brickActor.pb.emptyListenerList(); if ( me.context.status==me.context.ST_INITIALIZING ) { me.context.setStatus( me.context.ST_RUNNNING ); } } } }); } } } context= this.context; this.directorScene.createTimer( this.directorScene.time, maxt, function timeout() { if ( context.status==context.ST_INITIALIZING ) { context.setStatus( context.ST_RUNNNING ); } } ); this.actorInitializationCount=0; }, contextEvent : function( event ) { var i, j; var brickActor; var me= this; if ( event.source=='context' ) { if ( event.event=='levelchange') { this.bricksContainer.enableEvents(true); } else if ( event.event=='status') { if ( event.params==this.context.ST_INITIALIZING ) { this.director.audioPlay( 'mostrarpanel' ); this.initializeActors(); } else if ( event.params==this.context.ST_RUNNNING) { for( i=0; i>0] ); actor.__trb.setFrameTime(this.directorScene.time, T); actor.__trb.path.setInitialPosition(x0,y0).setFinalPosition(x1,y1); actor.__ab.setFrameTime(this.directorScene.time, T); actor.__parent.addChild(actor); } } } brickActor.setSelected(); } else { brickActor.reset(); } }, selectionOverflowEvent : function(event) { var i,j; var selectedContextBricks= event.params; var actor; for( i=0; i7 ) { level=7; } var image= this.director.getImage( 'msg'+level); if ( null!=image ) { this.endLevelMessage.setBackgroundImage( image, true ); this.endLevelMessage.setLocation( (this.endLevelMessage.parent.width-image.width)/2, this.endLevelMessage.parent.height/2 - 65 ); } this.showGameEvent( this.endLevelActor ); window.level=level; //updateShare(window.level,window.score); //Play68.setRankingLevelScoreDesc(window.level,window.score); console.log('level:'+window.level+'score:'+window.score); }, removeGameEvent : function( actor, callback ) { actor.enableEvents(false); this.uninitializeActors(); var me= this; actor.emptyBehaviorList(); actor.addBehavior( new CAAT.PathBehavior(). setFrameTime( actor.time, 2000 ). setPath( new CAAT.LinearPath(). setInitialPosition( actor.x, actor.y ). setFinalPosition( actor.x, -actor.height ) ). setInterpolator( new CAAT.Interpolator().createExponentialInInterpolator(2,false) ). addListener( { behaviorExpired : function(behavior, time, actor) { actor.setOutOfFrameTime(); callback(); } } ) ); }, showGameEvent : function(actor) { // parar y eliminar cronometro. this.cancelTimer(); // quitar contorl de mouse. this.bricksContainer.enableEvents(false); // mostrar endgameactor. var x= (this.directorScene.width - actor.width)/2; var y= (this.directorScene.height - actor.height)/2 - 100; var me_endGameActor= actor; actor.emptyBehaviorList(). setFrameTime(this.directorScene.time, Number.MAX_VALUE). enableEvents(false). addBehavior( new CAAT.PathBehavior(). setFrameTime( this.directorScene.time, 2000 ). setPath( new CAAT.LinearPath(). setInitialPosition( x, this.directorScene.height ). setFinalPosition( x, y ) ). setInterpolator( new CAAT.Interpolator().createExponentialInOutInterpolator(3,false) ). addListener( { behaviorExpired : function(behavior, time, actor) { me_endGameActor.enableEvents(true); me_endGameActor.emptyBehaviorList(); }, behaviorApplied : function(behavior, time, normalizedTime, actor, value) { } } ) ); }, soundControls : function(director) { var ci= new CAAT.SpriteImage().initialize( director.getImage('sound'), 2,3 ); var dw= director.width; var dh= director.height; var music= new CAAT.Actor(). setAsButton( ci.getRef(),0,1,0,0, function(button) { director.audioManager.setMusicEnabled( !director.audioManager.isMusicEnabled() ); if ( director.audioManager.isMusicEnabled() ) { button.setButtonImageIndex(0,1,0,0); } else { button.setButtonImageIndex(2,2,2,2); } }). setBounds( dw-ci.singleWidth-2, 2, ci.singleWidth, ci.singleHeight ); var sound= new CAAT.Actor(). setAsButton( ci.getRef(),3,4,3,3, function(button) { director.audioManager.setSoundEffectsEnabled( !director.audioManager.isSoundEffectsEnabled() ); if ( director.audioManager.isSoundEffectsEnabled() ) { button.setButtonImageIndex(3,4,3,3); } else { button.setButtonImageIndex(5,5,5,5); } }); if ( director.width>director.height ) { sound.setBounds( dw-ci.singleWidth-2, 2+2+ci.singleHeight, ci.singleWidth, ci.singleHeight ); } else { sound.setBounds( dw-ci.singleWidth*2-2, 2+2, ci.singleWidth, ci.singleHeight ); } music.prepare= function() { if ( director.audioManager.isMusicEnabled() ) { this.setButtonImageIndex(0,1,0,0); } else { this.setButtonImageIndex(2,2,2,2); } } sound.prepare= function() { if ( director.audioManager.isSoundEffectsEnabled() ) { this.setButtonImageIndex(3,4,3,3); } else { this.setButtonImageIndex(5,5,5,5); } } this.directorScene.addChild(sound); this.directorScene.addChild(music); this.music= music; this.sound= sound; }, prepareSound : function() { try { this.sound.prepare(); this.music.prepare(); } catch(e) { } } }; })();