//Augment Module var ITW = (function(itw){ "use strict"; //aliases var components, protot; itw.components = itw.components || Object.create(null); components = itw.components; components.Anchor = function(){ this.super.call(this); var _init = function(){ // init stuff here this._speed = 0; this._moveDown = false; this._sprMain = new EHDI.aka.Sprite( EHDI.Assets.images[ "anchor" ] ); //this._sprMain.scale.set( 0.75 ); this._sprMain.x = this._sprMain.width * -0.5; this._sprMain.y = this._sprMain.height * -0.5; var texLine = EHDI.Assets.images[ "anchor_rope_tile" ]; var lineSize = new EHDI.aka.Sprite( texLine ); //this._lineHeight = lineSize.height; this._lineHeight = ITW.SceneMgr.getStageHeight() * 0.5; this._sprLine = new PIXI.extras.TilingSprite( texLine, lineSize.width, lineSize.height ); this._sprLine.anchor.y = 1.0; this._sprLine.height = this._lineHeight; this._sprLine.x = lineSize.width * -0.5; this._sprLine.y = this._sprMain.y - ( this._lineHeight * 0.95 ); this._sprHole = new EHDI.aka.Sprite( EHDI.Assets.images[ "anchor_hole" ] ); this._sprHole.x = this._sprHole.width * -0.5; this._sprHole.y = this._sprLine.y - this._lineHeight - this._sprHole.height * 0.5; this.addChild( this._sprHole ); this.addChild( this._sprMain ); this.addChild( this._sprLine ); this.x = -( this._sprMain.width * 0.5 ); this._active = false; this._bindedfunction = this.loop.bind(this); ITW.UpdateMgr.addFrameListener( this._bindedfunction ); }.bind(this); _init(); } protot = components.Anchor.prototype = Object.create(EHDI.aka.Container.prototype); protot.constructor = components.Anchor; protot.super = EHDI.aka.Container; protot.loop = function( dt ){ if( ITW.GameMgr.getPaused() === true ) return; if( ITW.GameMgr.getGameOver() === true ){ if( typeof this._bindedfunction === 'function' ) ITW.UpdateMgr.removeFrameListener( this._bindedfunction ); return; } if( this._active === false ) return; dt *= 0.001; if( this.x > ITW.SceneMgr.getStageWidth() * 0.85 ){ this._sprMain.x = ( this._sprMain.width * -0.5 ) + Math.floor( EHDI.NumberUtil.randomRange(-4, 5) ); return; } if( this._sprMain.x !== this._sprMain.width * -0.5 ) this._sprMain.x - this._sprMain.width * -0.5 if( this._moveDown === false ){ if( this._sprLine.height <= this._lineHeight * 0.15 ){ this._sprLine.height = this._lineHeight * 0.15; this._active = false; } else{ this._sprMain.y -= dt * this._speed; this._sprLine.height -= dt * this._speed; this._sprLine.y -= dt * this._speed; } } else{ if( this._sprLine.height >= this._lineHeight ){ this._sprLine.height = this._lineHeight; this._active = false; } else{ this._sprMain.y += dt * this._speed; this._sprLine.height += dt * this._speed; this._sprLine.y += dt * this._speed; } } } protot.getCollisionArea = function(){ return { //x: ( ( this.toGlobal( this._sprMain.position ).x / ITW.ScaleMgr.getScale() ) + ( this._sprMain.width * 0.49 ) ), //y: ( ( this.toGlobal( this._sprMain.position ).y / ITW.ScaleMgr.getScale() ) + ( this._sprMain.height * 0.55 ) ), x: ( ( this.toGlobal( this._sprMain.position ).x / ITW.scaleRatio ) + ( this._sprMain.width * 0.49 ) ), y: ( ( this.toGlobal( this._sprMain.position ).y / ITW.scaleRatio ) + ( this._sprMain.height * 0.55 ) ), r: ( this._sprMain.width * 0.41 ) }; } protot.resetState = function(){ var startHeight = ( EHDI.NumberUtil.randomRange(0.0, 1.0) > 0.5 ) ? 0.15 : 1.0; this._sprLine.height = this._lineHeight * startHeight; //this._sprLine.y -= this._lineHeight * ( 1.0 - startHeight ); this._sprLine.y = this._sprHole.y + ( this._sprHole.height * 0.5 ) + this._sprLine.height; this._sprMain.y = this._sprLine.y; if( ITW.GameMgr.getScore() > 24 ){ if( EHDI.NumberUtil.randomRange(0.0, 1.0) > 0.45 ) return; this._speed = ITW.GameMgr.getSpeed() * 0.325; if( startHeight > 0.5 ){ this._moveDown = false; } else{ this._moveDown = true; } this._active = true; var snd = ITW.SoundMgr.playSFX("anchor_move"); snd.stop(); snd.play(null, 800); } if( ITW.GameMgr.getDebug() === true ){ if( typeof this.pixiCircle !== "undefined" ){ if( this.pixiCircle.parent !== null ) this.removeChild( this.pixiCircle ); } this.pixiCircle = new EHDI.aka.Graphics(); this.pixiCircle.beginFill( 0xFF00FF, 0.5 ); this.pixiCircle.drawCircle( ( this._sprMain.x + ( this._sprMain.width * 0.49 ) ), ( this._sprMain.y + ( this._sprMain.height * 0.55 ) ), ( this._sprMain.width * 0.41 ) ); //(x,y,radius) this.pixiCircle.endFill(); this.addChild( this.pixiCircle ); } } protot.destroy = function(){ if( typeof this._bindedfunction === 'function' ) ITW.UpdateMgr.removeFrameListener( this._bindedfunction ); this.super.prototype.destroy.call( this, {children: true} ); } return itw; }(ITW || Object.create(null)));