MMI.Util.ns( 'Osg.RiverBloat' ); Osg.RiverBloat = MMI.stdClass.extend({ _reefEntryPoint: [ 180, 110 ], _currentDropSpeed: 3000, __construct: function( options ) { options = jQuery.extend({ isGood: false, listKey: 0, destructorCallback: function(){} }, options); this._isGood = options.isGood; this._listKey = options.listKey; this._destructorCallback = options.destructorCallback; this._jqelRiverBloat = jQuery( 'River bloat' ); if( this._isGood ){ this._jqelRiverBloat.addClass( 'good' ) } else { this._jqelRiverBloat.addClass( 'bad' ) } jQuery( '#gameScreen' ).append( this._jqelRiverBloat ); this._animateIn(); }, _getImageSrc: function(){ var imageUrlBase = 'images/'; var randomizedNumber = Math.round( Math.random() * 10 ); var completedImageUrl; if ( this.isGood() ) { completedImageUrl = imageUrlBase + 'good-bloat' + ( randomizedNumber % 3 + 1 ) + '.png'; } else { completedImageUrl = imageUrlBase + 'bad-bloat' + ( randomizedNumber % 5 + 1 ) + '.png'; } return completedImageUrl; }, isGood: function(){ return this._isGood; }, isBad: function(){ return !this._isGood; }, _animateIn: function(){ this._jqelRiverBloat.addClass( 'visibleBlock' ).animate( { left: this._reefEntryPoint[ 0 ], top: this._reefEntryPoint[ 1 ] },{ duration: 700, easing: 'linear', complete: MMI.Util.bind( this._moveToDropPoint, this ) } ); }, _moveToDropPoint: function(){ this._bob(); var dropPoint = Math.round( Math.random() * ( 550 - this._jqelRiverBloat.width() )); this._jqelRiverBloat.animate( { left: dropPoint }, { duration: 500, complete: MMI.Util.bind( this._drop, this ) } ); }, _bob: function(){ var offset = 10; var direction = this._jqelRiverBloat.data( 'direction' ); if( direction != 1 ){ direction = -1; } var coords = { top: ( this._jqelRiverBloat.position().top + ( direction * offset )) + 'px' }; this._jqelRiverBloat.data( 'direction', -1 * direction ); this._jqelRiverBloat.animate( coords, { duration: 500, easing: 'linear', queue: false } ); }, _drop: function(){ this._jqelRiverBloat.animate( { top: this._jqelRiverBloat.parent().height() }, { duration: this._currentDropSpeed, complete: MMI.Util.bind( this.__destruct, this ) } ); }, getListKey: function(){ return this._listKey; }, eject: function(){ this._jqelRiverBloat.stop(); this._jqelRiverBloat.animate( { top: 0 - this._jqelRiverBloat.height(), left: Math.random() * 400 }, { duration: 250, easing: 'linear', complete: MMI.Util.bind( this.__destruct, this ) } ); }, __destruct: function(){ var app = MMI.App.getInstance(); if( this.isBad() && this._jqelRiverBloat.position().top >= 400 ){ app.player1.decreaseScore(); app.chumWater(); } else if ( this.isGood() && this._jqelRiverBloat.position().top >= 400 ) { app.player1.increaseScore( 'saved' ); app.player1.increaseScore( 'score' ); } this._jqelRiverBloat.remove(); this._destructorCallback( this ); } });