package  
{
	import flash.display.Sprite;
	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 LazorBeam extends Projectile
	{
		[Embed(source = 'gfx/lazor.png')]
		private const LAZOR:Class;
		
		public var lazor:Spritemap;
		//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 csin:Number=0;
		
		public function LazorBeam()
		{
			vy = 0;
			vx = 16;
			if (Bazaar.player.pedd.flipped) vx *= -1;
			lazor = new Spritemap(LAZOR,32, 16);
			graphic = lazor;
			lazor.add("burn", [0, 1], 20, true);
			//lazor.flipped += Bazaar.player.pedd.flipped;
			lazor.play("burn");
			setHitbox(32, 16, 0, 0);
			type = "bullet";
			damage = 10;
			killonhit = false;
			
		}
		
		override public function update():void
		{
			//csin += vx * vx + vy * vy;
			//lazor.scale = (Math.sin(csin) * .5) + 1;
			//lazor.angle+=vx+vy;
			//vy += Bazaar.player.vfall;
			y += vy;
			x += vx;
			if (
				x < 0 || y < 0 || 
				x > Bazaar.level.tilemap.sw || y > Bazaar.level.tilemap.sh)  FP.world.remove(this);
			if (collide("level", x, y))
			{
				var lvl_x:uint;
				var lvl_y:uint;
				lvl_x = x / Bazaar.level.tilemap.s;
				lvl_y = y / Bazaar.level.tilemap.s;
				if (lvl_x < Bazaar.level.tilemap.w-1 && lvl_y < Bazaar.level.tilemap.h-1 && lvl_x>0 && lvl_y>0) 
				{
					trace(Bazaar.level.tilemap.getTile(lvl_x, lvl_y));
					if (Bazaar.level.tilemap.getTile(lvl_x,lvl_y)==22) Bazaar.level.tilemap.setTile2(lvl_x, lvl_y, false);
					if (Bazaar.level.tilemap.getTile(lvl_x+1,lvl_y)==22) Bazaar.level.tilemap.setTile2(lvl_x+1, lvl_y, false);
					if (lvl_y + 1 < Bazaar.level.tilemap.h - 1) 
					if (Bazaar.level.tilemap.getTile(lvl_x,lvl_y+1)==22) Bazaar.level.tilemap.setTile2(lvl_x, lvl_y + 1, false);
					if (Bazaar.level.tilemap.getTile(lvl_x-1,lvl_y)==22) Bazaar.level.tilemap.setTile2(lvl_x-1, lvl_y, false);
					if (Bazaar.level.tilemap.getTile(lvl_x,lvl_y-1)==22) Bazaar.level.tilemap.setTile2(lvl_x, lvl_y-1, false);
					//Bazaar.level.tilemap.grid.setTile(lvl_x + 1, lvl_y + 1, false);
					
				}
				FP.world.remove(this);
			}
			kill();
		}
		
	}
}