Source

ld3k / hurts / HLine.as

Full commit
package hurts
{
	import net.flashpunk.Entity;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Emitter;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.graphics.PreRotation;
	import net.flashpunk.masks.Pixelmask;
	import net.flashpunk.utils.Draw;
	
	import objs.Line;
	
	
	public class HLine extends Entity
	{
		[Embed(source = 'data/line.png')]
		private static const ImgLine:Class;
		
//		private static const _imline:PreRotation;
//		_imline = new PreRotation(ImgLine, 80);
		// TODO maybe should use Image not PreRotation
		
		/////////////////////////////////////
		private var _imline:Image;
		private var _vec:Vector2D;
		private var _emitx:Number;
		private var _emity:Number;
		private var _pemit:Emitter;
		
		public function  HLine()
		{
			_imline = new Image(ImgLine);
			_vec = new Vector2D(0, 0);
			super(0, 0, _imline);	
			active = false;
			visible = false;
			type = "hurtline";
		}
		
		public function reset(Lin:Line):void {
			_emitx = x = Lin.startx; _emity = y = Lin.starty;
			_vec.set(Lin.endx - Lin.startx, Lin.endy - Lin.starty);
			_vec.magnitude = 2; // TODO remove this
			_imline.angle = -_vec.angle; // MUST get reverse cause
			// game coordinates are reverse
			// use rotated image to get a pixelperfect mask
			mask = new Linemask(0, 0, _vec); 
			
			// REMEMBER TO ACTIVE
			active = true;
			visible = true;
		}
		
		override public function update():void {
			// glow effects
			Indicator.pemit.emit("glow", _emitx, _emity);
			_emitx += _vec.x; _emity += _vec.y;
			
			var _player:Player = GameWorld.player;
			// collide when active
			if (_player.active && collideWithEx(_player)) { 
				// TODO die/hurt here
				FP.console.log(Au._cnter++);
				_player.kill();
				GameWorld.gworld.quake(15);
				GameWorld.gworld.showPanel(7 - _player.deathcount);
			}
			super.update();
		}
		
//		override public function render():void {
//			var lm:Linemask = mask as Linemask;
//			Draw.line(0, _player.y-_player.originY, 100, _player.y-_player.originY, 0x0000FF);
//			Draw.line(0, _player.y+_player.height-_player.originY, 100, _player.y+_player.height-_player.originY, 0xFF00FF);
//			Draw.line(lm.ccx1, 0, lm.ccx1, 100, 0x00FF00);
//			Draw.line(lm.ccx2, 0, lm.ccx2, 100, 0xFF0000);
//			Draw.hitbox(_player);
//			super.render();
//		}
		
	}
}