package objs {
	import flash.display.*;
	import flash.geom.*;
  import flash.events.*;
  import flash.net.*;
	import com.terry.engine.*;
	import com.terry.engine.util.*;
	import gamecontrol.control;
	
	//Note: "player" is special as a rule, with default implementations in several places
	public class ent_otherperson extends ent_generic {
		public function ent_otherperson() {
			name = "person";
		}
		
		override public function create(i:int, xp:Number, yp:Number, para1:String = "0", para2:String = "0", para3:String = "0"):void {
			obj.entities[i].rule = "person";
			obj.entities[i].name = para1;
			if (para1 == "ex") {
				obj.entities[i].tile = 820;	
			}else if (para1 == "girl") {
				obj.entities[i].tile = 540;				
			}else if (para1 == "mum") {
				obj.entities[i].tile = 760;				
			}else if (para1 == "coworker") {
				obj.entities[i].tile = 700;				
			}else if (para1 == "newgirl") {
				obj.entities[i].tile = 940;				
			}
			obj.entities[i].w = 16;
			obj.entities[i].h = 8;
		}
		
		override public function update(i:int):void {
			//Player entity's actual position is usually controlled
			//in the input class: this is for state changes
			if (obj.entities[i].state == 0) {
				
			}
		}
		
		override public function animate(i:int):void {
			if (obj.entities[i].vx < 0) {
				obj.entities[i].dir = 3;
			}else if (obj.entities[i].vx > 0) {
				obj.entities[i].dir = 2;
			}else if (obj.entities[i].vy < 0) {
				obj.entities[i].dir = 1;
			}else if (obj.entities[i].vy > 0) {
				obj.entities[i].dir = 0;
			}
			
			obj.entities[i].drawframe = obj.entities[i].tile + (obj.entities[i].dir * 3);
			
			if (obj.entities[i].vx == 0 && obj.entities[i].vy == 0) {
				//Standing still
			}else {
				//Walking
				obj.entities[i].framedelay--;
				if (obj.entities[i].framedelay <= 0) {
					obj.entities[i].framedelay = 12;
					obj.entities[i].walkingframe = (obj.entities[i].walkingframe+1) % 2;
				}
				obj.entities[i].drawframe = obj.entities[i].drawframe+obj.entities[i].walkingframe+1;
			}
		}
		
		override public function draw(i:int):void {
			var xp:int = 0, yp:int = 0, jpos:int;
			xp = obj.entities[i].xp;
			yp = obj.entities[i].yp - 32;
			if (control.carryingcatcage && obj.entities[i].tile != 940) { //newgirl never carries cat cage
				if (obj.entities[i].dir == 1) {
					//Draw rubbish first
					gfx.drawtile(xp, yp+12, 575);
					
					for (jpos = 0; jpos < 3; jpos++) {
						gfx.drawtile(xp, yp + (jpos * def.TILESIZE), obj.entities[i].drawframe + (jpos * 20));
					}
				}else {
					//Draw player first
					for (jpos = 0; jpos < 3; jpos++) {
						gfx.drawtile(xp, yp + (jpos * def.TILESIZE), obj.entities[i].drawframe + (jpos * 20));
					}
					if (obj.entities[i].dir == 0) {
						gfx.drawtile(xp, yp+12, 575);
					}else if (obj.entities[i].dir == 2) {
						gfx.drawtile(xp+4, yp+12, 575);
					}else if (obj.entities[i].dir == 3) {
						gfx.drawtile(xp-4, yp+12, 575);
					}
					
				}
			}else{
				for (jpos = 0; jpos < 3; jpos++) {
					gfx.drawtile(xp, yp + (jpos * def.TILESIZE), obj.entities[i].drawframe + (jpos * 20));
				}
			}
			//gfx.drawbox(xp, yp+32, obj.entities[i].w, obj.entities[i].h, 255, 255, 0);			
		}
		
		override public function drawinit(i:int, xoff:int, yoff:int, frame:int):void {
			gfx.draw_defaultinit(i, xoff, yoff, frame);
		}
		
		override public function collision(i:int, j:int):void {
			//i is this entity, j is the other
			if (obj.entities[j].rule == "enemy") {
				if (obj.entitycollide(i, j)) {
					//trace("collision");
				}
			}
		}
	}
}