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

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);
}


switch(MotionNum){
	case CATCH :
		with(objController){
			if( global.PlayerHP && (left==2 || right==2 || up==2 || down==2 || b1==2 || b2==2 || b3==2) ) other.Mogaki = 1;
			with(CtrlTarget){
				if( other.BindCounter>20+0.1*(100-global.PlayerHP) ){
					other.BindCounter = 0;
					move_outside_afterBind();
					BINDED = 0;
				}
			}
		}
		break;
}

CountDown -= 1;
DepthSet(objPlayerDoll.depth - 1000);
INV = 1;
if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			if(!isGameOver()){
				if(270-30<playerDirection && playerDirection<270+30 ){
					if( 250>playerDistance ) MotionChange(ATTACK,0,2);
				}
			}
			switch(KeyFrmNum){
				case 2 : 
				case 3 : 
				case 4 : 
				case 5 : 
					INV = 0;
					break;
			}
			break;
		case ATTACK :
			INV = 0;
			if(KEYFRAME){
				switch(KeyFrmNum){
					case 3:
						with( collision_circle( Process[ProcessNum[PARTS_HEAD]].x,Process[ProcessNum[PARTS_HEAD]].y+96, 40,objPlayerDoll,0,1) ){
							if(!INV && !BINDED){
								DamageVoiceRandom_Mid();
								addDamage(3,-1,-1,-1,-1,-1,-1);
								sound_play(sndHit00);
								Quake(15,15);
								other.Direction = Direction*-1;
								with(other){
									CountDown = 60;
									startBind( objPlayerDoll,BIND_CATCH,0,other.BINDED_VIX_CATCH,0,1 );
									MotionChange(CATCH,0,1);
								}
							}
						}
						break;
				}
			}
			if(MOTIONEND) MotionChange(INTO,0,2);
			break;
		case INTO :
			if(MOTIONEND) MotionChange(STAND,0,1);
			break;
		case CATCH :
			if(KeyFrmNum<13){
				if(BindTarget){
					if(!BindTarget.BINDED && !isGameOver()){
							DamageVoiceRandom_Low();
							with(BindTarget){ MotionChange(STAND_0,0,2); }
							endBind();
							MotionChange(INTO,0,2);
							break;
					}
				}
			}
			if(KEYFRAME){
				switch(KeyFrmNum){
					case  3: 
						if(Mogaki){	Mogaki = 0; MotionChange(CATCH,4,2);with(BindTarget){MotionChange(BINDED_VIX_CATCH,4,2)}; break; }
					case  4: 
						if(CountDown){ MotionChange(CATCH, 2,5);with(BindTarget){ MotionChange(BINDED_VIX_CATCH, 2,5);} };
						else		 { MotionChange(CATCH,13,5);with(BindTarget){ MotionChange(BINDED_VIX_CATCH,13,5);} };
						break;
					case 12:
						if(!CountDown)  {             MotionChange(CATCH,13,5);with(BindTarget){ MotionChange(BINDED_VIX_CATCH,13,5);}}
						else if(Mogaki)	{ Mogaki = 0; MotionChange(CATCH, 4,2);with(BindTarget){ MotionChange(BINDED_VIX_CATCH, 4,2);}}
						else {            Mogaki = 0; MotionChange(CATCH, 2,2);with(BindTarget){ MotionChange(BINDED_VIX_CATCH, 2,2);}}
						break;
					case 16: 
						PartsBloodDamage(objCommon_Head,-100,0);
						with(BindTarget){ FluidWithScale(HEAD.x,HEAD.y-8,COLOR_BLOOD,35,5,10,70,40,0.3,0.3,HEAD.depth-1000); }
						FearVoiceRandom_Mid();
						playEnemySound(SOUND_BITE);
						global.GameOver = true;
						Flash(c_red,0.5,0.01);
						addDamage(3,-1,-1,-1,-1,-1,-1);
						Quake(10,5);
						break;
					case 20: 
						if(random(100)<10) objCommon_Body.FluidBreak = true;
						with(BindTarget){ FluidWithScale(HEAD.x,HEAD.y-8,COLOR_BLOOD,35,0,5,0,360,0.3,0.3,HEAD.depth-1000); }
						if(random(100)<200+global.PlayerHP) SpecialVoice(V_OE,irandom(5));
						Quake(3,3);
						if(random(100)<50) sound_play(sndLotion);
						Flash(random(c_red),0.8,0.01);
						switch(irandom(5)){
							case 0:playEnemySound(SOUND_BRAIN0);break;
							case 1:playEnemySound(SOUND_BRAIN1);break;
							case 2:sound_play(sndVore01);break;
							case 3:sound_play(sndVore02);break;
							case 4:sound_play(sndVore03);break;
							case 5:sound_play(sndVore04);break;
						}
						addDamage(10,-1,-1,-1,-1,-1,-1);
						break;
					case 24:
						MotionChange(CATCH,18,10);
						with(BindTarget){ MotionChange(BINDED_VIX_CATCH,18,10);}
						break;
				}
			}
			break;
		/*-----------------------------*/
		case DEAD_MOTION :
			if(KeyFrmNum==1 && KEYFRAME){
				sound_play(sndHit02);
				Fluid(x,y,make_color_rgb(163,73,164),35,5,20,0,180,0.5);
				Quake(5,5);
			}
			if(MOTIONEND){
				effect_create_above(ef_explosion,x,y,1,make_color_rgb(163,73,164));
				Flash(c_white,0.1,0.05);
				Fluid(x,y-64,make_color_rgb(163,73,164),35,5,20,0,180,0.5);
				Quake(5,5);
				sound_play(sndFluid);
				instance_destroy();
			}
			break;
	}
}