package  
{
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.utils.Input;
	import net.flashpunk.utils.Key;
	import net.flashpunk.FP;
	
	public class BounceBall extends Projectile
	{
		[Embed(source = 'gfx/bouncer.png')]
		private const BOUNCER:Class;
		
		//public var damage:Number = 0;
		public var range:Number = 0;
		public var blast_radius:Number = 0;
		public var wallbreak:uint = 0;
		public var vx:Number;
		public var vy:Number;
		public var life:uint = 300;
		
		public function BounceBall(angle:Number, velocity:Number = 20)
		{
			//vy = 0;// (1 - 2 * Math.random()) * accuracy;
			//vx = velocity;
			vx = Math.cos(angle) * velocity;
			vy = Math.sin(angle) * velocity;
			if (Bazaar.player.pedd.flipped) vx *= -1;
			graphic = new Image(BOUNCER);
			//(graphic as Image).flipped+=Bazaar.player.pedd.flipped;
			(graphic as Image).angle = -angle*180/Math.PI;
			setHitbox(16, 16, 0, 0);
			type = "bullet";
			damage = 100;
			
			
		}
		
		override public function update():void
		{
			life--;
			if (!life) 
			{
				FP.world.remove(this);
				return;
			}
			(graphic as Image).angle+=vx+vy;
			//vy += Bazaar.player.vfall;
			y += vy;
			x += vx;
			if (collide("level", x, y))
			{
				if (!collide("level", x - vx, y))
				{
					y -= vy;
					x -= vx;
					vx = -vx;
					
				} else if (!collide("level", x, y-vy))
				{
					y -= vy;
					x -= vx;
					
					vy = -vy;
				} else {
					y -= vy;
					x -= vx;
					vx = -vx;
					vy = -vy;
				}
			} else if (	x < 0)
			{
				y -= vy;
					x -= vx;
				vx = -vx;
				
			}else if (	y < 0)
			{
				y -= vy;
					x -= vx;
				
				vy = -vy;
			}else if (	x > Bazaar.level.tilemap.sw)
			{
				y -= vy;
					x -= vx;
				vx = -vx;
				
			}else if (	y > Bazaar.level.tilemap.sh) 
				{
					y -= vy;
					x -= vx;
				
				vy = -vy;
					
					
					
					
				}
			
		}
		
	}
}