package Game.Objects
{
	import flash.events.MouseEvent;
	import flinjin.Flinjin;
	import flinjin.graphics.Sprite;
	import flinjin.sound.FlinjinSound;
	import Game.GameMain;
	import Game.Sun;
	
	/**
	 * ...
	 * @author Michael Miriti
	 */
	public class WeaponBonus extends Sprite
	{
		[Embed(source="../../bmp/weaponbonus.png")]
		private static var _bonusBitmap:Class;
		
		[Embed(source="../../snd/bonus.mp3")]
		private static var _sndTake:Class;
		
		[Embed(source="../../snd/bonus-fall.mp3")]
		private static var _sndFall:Class;
		
		private var _takeSound:FlinjinSound = new FlinjinSound(new _sndTake());
		
		private var _fallSound:FlinjinSound = new FlinjinSound(new _sndFall());
		
		private var _fallSpeed:Number = 0;
		
		public function WeaponBonus()
		{
			super(new _bonusBitmap());
			
			addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
		}
		
		private function onMouseDown(e:MouseEvent):void
		{
			Visible = false;
			Delete();
			(parent as GameMain).sun.currentWeapon = (parent as GameMain).sun.currentWeapon == Sun.WEAPON_LASER ? Sun.WEAPON_ROCKET : Sun.WEAPON_LASER;
			_takeSound.play();
		}
		
		override public function Move():void 
		{
			if (y >= Flinjin.sceneHeight - 100) {
				_fallSpeed = -_fallSpeed * 0.8;
				_fallSound.play();
				
				if (Math.abs(_fallSpeed) < 1) {
					_fallSpeed = 0;
				}
			}
			
			y += _fallSpeed;
			_fallSpeed += 0.1;
			
			super.Move();
		}
	
	}

}