/*-----重力設定--------------------------*/
GSet(global.G,global.Gdir,0,1, 0,0,0,1);

with(objEnemyEdit){ if(Edit_Play) exit; }

/*-----キャラクタとの情報の取得---------------*/
playerDistance = point_distance(x,y,objPlayerDoll.x,objPlayerDoll.y);
playerDirection = point_direction(x,y,objPlayerDoll.x,objPlayerDoll.y);

/*-----モーション毎の処理--------------------*/
if(RECV_DAMAGE){
	playEnemySound(SOUND_DAMAGE);
}

if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			/* 相手の方を向く */
			if(objPlayerDoll.x > x) Direction = Right;
			else Direction = Left;

			if(!air && global.PlayerHP>0){
				if(playerDistance<250){
					if(place_free(x-100*Direction,y))	MotionChange(ATTACK_PRE,0,2);
					break;
				}
			}
			break;
		case ATTACK_PRE :
			if(MOTIONEND){
				if(random(100)<50)	MotionChange(ATTACK_LOW,0,1);
				else				MotionChange(ATTACK_HIGH,0,1);
			}
			break;
		case ATTACK_LOW :
			switch(KeyFrmNum){
				case 3 : 
					if(KEYFRAME){
						col = collision_circle( x+Direction*-100 ,y, 64,objPlayerDoll,0,1);
						with( col ){
							if(!INV && !BINDED){
								DamageVoiceRandom_Low();
								addDamage(2, -1, -1, -1, -1, -1, -1);
								sound_play(sndHit00);
								Quake(15,15);
								Direction = other.Direction*-1;
								with(other){
									startBind( col,BIND_ATTACK_LOW_BIND,0,other.BINDED_BITEPLANT_ATTACK_LOW_BIND,0,1 );
									MotionChange(ATTACK_LOW_BIND,0,1);
								}
							}
						}
					}
					break;
			}
			if(MOTIONEND) MotionChange(STAND,0,1);
			break;
		case ATTACK_LOW_BIND :
			DepthSet(objPlayerDoll.depth - 1000);
			if(MOTIONEND){
				with(BindTarget){ MotionChange(BINDED_BITEPLANT_ATTACK_LOW_BINDBITE,0,1); }
				MotionChange(ATTACK_LOW_BINDBITE,0,1);
			}
			break;
		case ATTACK_LOW_BINDBITE :
			DepthSet(objPlayerDoll.depth - 1000);
			switch(KeyFrmNum){
				case 6 : 
				case 9 : 
					if(KEYFRAME){
						DamageVoiceRandom_Mid();
						addDamage(10, -1, -1, -1, -1, -1, -1);
						playEnemySound(SOUND_BITE);
						Fluid(BindTarget.x,BindTarget.y,COLOR_BLOOD,10,2,10,0,180,0.5);
						Flash(c_red,0.7,0.1);
						Quake(10,10);
					}
					break;
			}
			if(BindTarget){
				if(!BindTarget.BINDED){
					MotionChange(STAND,0,5);
					with(BindTarget){ MotionChange(DOWN_0,0,2); }
					endBind();
					break;
				}
			}
			if(MOTIONEND){
				with(BindTarget){ MotionChange(BINDED_BITEPLANT_ATTACK_LOW_BINDBITE,5,1); }
				MotionChange(ATTACK_LOW_BINDBITE,5,1);
			}
			break;
		case ATTACK_HIGH :
			Process[ProcessNum[PARTS_ARM08]].depth		= objPlayerDoll.depth - 1001;
			Process[ProcessNum[PARTS_ARM09]].depth		= objPlayerDoll.depth - 1002;
			Process[ProcessNum[PARTS_ARM10]].depth		= objPlayerDoll.depth - 1003;
			Process[ProcessNum[PARTS_MOUTH02]].depth	= objPlayerDoll.depth - 1004;
			Process[ProcessNum[PARTS_MOUTH01]].depth	= objPlayerDoll.depth - 1005;
			switch(KeyFrmNum){
				case 3 : 
					if(KEYFRAME){
						col = collision_circle( x+Direction*-100 ,y, 64,objPlayerDoll,0,1);
						with( col ){
							if(!INV && !BINDED){
								DamageVoiceRandom_Mid();
								addDamage(2, -1, -1, -1, -1, -1, -1);
								sound_play(sndHit00);
								Quake(15,15);
								Direction = other.Direction*-1;
								with(other){
									startBind( col,BIND_ATTACK_HIGH_BINDBITE,0,other.BINDED_BITEPLANT_ATTACK_HIGH_BINDBITE,0,1 );
									MotionChange(ATTACK_HIGH_BINDBITE,0,1);
								}
							}
						}
					}
					break;
			}
			if(MOTIONEND) MotionChange(STAND,0,1);
			break;
		case ATTACK_HIGH_BINDBITE :
			if(BindTarget){
				if(!BindTarget.BINDED && global.PlayerHP>0){
					with(BindTarget){ MotionChange(STAND_0,0,2); }
					endBind();
					break;
				}else{
					Process[ProcessNum[PARTS_ARM08]].depth		= objPlayerDoll.depth - 1001;
					Process[ProcessNum[PARTS_ARM09]].depth		= objPlayerDoll.depth - 1002;
					Process[ProcessNum[PARTS_ARM10]].depth		= objPlayerDoll.depth - 1003;
					Process[ProcessNum[PARTS_MOUTH01]].depth	= objPlayerDoll.depth - 1005;
				}
				switch(KeyFrmNum){
					case 6 : 
						if(KEYFRAME) FearVoiceRandom_Low();
						break;
					case 9 : 
						if(KEYFRAME){
							addDamage(500, -1, -1, -1, -1, -1, -1);
							playEnemySound(SOUND_BITE);
							Fluid(BindTarget.x,BindTarget.y,COLOR_BLOOD,50,2,10,0,180,0.5);
							Flash(c_red,1,0.05);
							Quake(30,30);
							with(BindTarget){
								HEAD.image_alpha = 0;
								with(objCommon_Head){ image_alpha = 0; }
								with(objCommon_Body){ if(random(100)<50) FluidBreak = true; }
							}
						}
						break;
					case 11 : 
						if(KEYFRAME){
							with(BindTarget){
				                move_outside_solid( 90,-1 );
								MotionChange(DOWN_1,0,1);
							}
							endBind();
						}
						break;
				}
			}
			if(MOTIONEND) MotionChange(STAND,0,1);
			break;
		case DEAD_MOTION :
			if(MOTIONEND){
				effect_create_above(ef_explosion,x,y,1,c_green);
				Flash(c_white,0.1,0.05);
				Fluid(x,y,c_green,5,5,20,0,180,0.5);
				Quake(5,5);
				sound_play(sndFluid);
				instance_destroy();
			}
			break;
	}
}