home *** CD-ROM | disk | FTP | other *** search
- package core.bonuses
- {
- import core.BonusesManager;
- import core.CoreEngine;
- import core.events.CoreEvent;
- import flash.events.EventDispatcher;
- import flash.media.Sound;
-
- public class AbstractBonus extends EventDispatcher
- {
-
-
- protected var activateTime:int;
-
- protected var engine:CoreEngine;
-
- public var num:uint;
-
- protected var lifeTime:int;
-
- public var timeLeft:int;
-
- public var isGood:Boolean;
-
- protected var sndActivate:Sound;
-
- public function AbstractBonus(isGood:Boolean)
- {
- super();
- this.isGood = isGood;
- init();
- }
-
- protected function updateHandler(e:CoreEvent) : void
- {
- var time:int = e.data as int;
- timeLeft = lifeTime + activateTime - time;
- if(timeLeft <= 0)
- {
- deactivate();
- }
- }
-
- protected function deactivate() : void
- {
- engine.dispatcher.removeEventListener(CoreEvent.UPDATE,updateHandler);
- dispatchEvent(new CoreEvent(BonusesManager.BONUS_DEACTIVATE,this));
- }
-
- protected function init() : void
- {
- engine = CoreEngine.getInstance();
- lifeTime = 40 * 3;
- num = 1;
- initSounds();
- engine.dispatcher.addEventListener(CoreEvent.DESTROY,destroyHandler);
- }
-
- protected function destroyHandler(e:CoreEvent) : void
- {
- engine.dispatcher.removeEventListener(CoreEvent.UPDATE,updateHandler);
- engine.dispatcher.removeEventListener(CoreEvent.DESTROY,destroyHandler);
- }
-
- public function activate(activateTime:Number) : void
- {
- this.activateTime = activateTime;
- if(sndActivate)
- {
- engine.sndChannel = sndActivate.play(0,0,engine.sndTransform);
- }
- engine.dispatcher.addEventListener(CoreEvent.UPDATE,updateHandler);
- }
-
- protected function initSounds() : void
- {
- sndActivate = null;
- }
- }
- }
-