/*-----d͐ݒ--------------------------*/
GSet(global.G,global.Gdir,0.3,1, 0,0,0.3,1);

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

/*-----LN^Ƃ̏̎擾---------------*/
playerDistance = point_distance(x,y,objPlayerDoll.x,objPlayerDoll.y);
playerDirection = point_direction(x,y,objPlayerDoll.x,objPlayerDoll.y);

/*-----[V̏--------------------*/
if(RECV_DAMAGE){
	if(INV){ /* ĜƂ */
		playEnemySound(SOUND_NODAMAGE);
		switch(MotionNum){
			case STAND : /* Gőҋ@ */
				var self_id;
				self_id = id; /* ̃CX^XIDۑ */
				/* UĂz͈͓ɂ */
				if( !air && collision_line(x,y,x-500*Direction,y,objPlayerDoll,0,1)){
					with(objPlayerDoll){
						with(objNana_Gun){
							if(Bullet<=1){ /* eꔭȂȂ */
								/* ˌ */
								with(self_id){MotionChange(WALK,0,1);}
							}
						}
					}
				}
				break;
		}
	}
	else playEnemySound(SOUND_DAMAGE);
}

INV = 0;
WEAK = 0;
if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			INV = 2;
			/* ̕ */
			if(objPlayerDoll.x > x){
				if(Direction){ MotionChange(RETURN,0,2); break; }
				/* Direction = Right; */
			}else{
				if(!Direction){ MotionChange(RETURN,0,2); break; }
				/* Direction = Left; */
			}

			/* ߂Â */
			if( collision_line(x,y,x-100*Direction,y,objPlayerDoll,0,1) ){ MotionChange(ATTACK,0,1); break; }
			else if( collision_line(x,y,x-250*Direction,y,objPlayerDoll,0,1) ){ MotionChange(WALK,0,1); break; }
			else if( isPlayerDown() && collision_line(x,y,x-600*Direction,y,objPlayerDoll,0,1) ){ MotionChange(WALK,0,1); break; }
			break;
		case WALK :
			INV = 2;
			switch(KeyFrmNum){
				case  1 : Move(-24.0*Direction,0); break;
				case  2 : Move(-12.0*Direction,0); break;
				case  3 : Move(- 6.0*Direction,0); break;
				case  4 : Move(-24.0*Direction,0); break;
				case  5 : Move(-12.0*Direction,0); break;
				case  6 : Move(- 6.0*Direction,0); break;
			}

			if( collision_line(x,y,x-100*Direction,y,objPlayerDoll,0,1) ){ MotionChange(ATTACK,0,1); break; }

			/* ǂɂԂ藣ꂽ肵~܂ */
			if( !place_free(x-24*Direction,y) && !collision_line(x,y,x-600*Direction,y,objPlayerDoll,0,1) ){ MotionChange(STAND,0,5); break; }
			break;
		case RETURN :
			INV = 2;
			switch(KeyFrmNum){
				case  1 : Move(- 8.0*Direction,0); break;
				case  2 : Move(-16.0*Direction,0); break;
				case  3 :
						if(KEYFRAME) Direction = -Direction;
						Move(-32.0*Direction,0);
						break;
				case  4 : Move(+10.0*Direction,0); break;
				case  5 : Move(+ 8.0*Direction,0); break;
				case  6 : Move(+ 4.0*Direction,0); break;
				case  7 : Move(+ 2.0*Direction,0); break;
				case  8 : Move(+ 1.0*Direction,0); break;
			}
			if(MOTIONEND){ MotionChange(STAND,0,5); break; }
			break;
		case ATTACK :
			/* {Iɂ͖G */
			INV = 2;
			switch(KeyFrmNum){
				case  1 :
					WEAK = 1;
				case  2 :
				case  3 :
					/* ̊ԂUʂ */
					if(Direction){ /*  */
						if(135<playerDirection && playerDirection<225) INV = 0;
						else INV = 2;
					}else{ /* E */
						if(45<playerDirection && playerDirection<315) INV = 2;
						else INV = 0;
					}
					Move(- 1.0*Direction,0); break;
				case  4 : 
					/* ̊ԂUʂ */
					if(Direction){ /*  */
						if(135<playerDirection && playerDirection<225) INV = 0;
						else INV = 2;
					}else{ /* E */
						if(45<playerDirection && playerDirection<315) INV = 2;
						else INV = 0;
					}
					Move(-16.0*Direction,0);
					if(KEYFRAME){
						sound_play(sndHit00);
						col = collision_circle( x-64*Direction,y, 80,objPlayerDoll,0,1)
						with( col ){
							if(!INV){
								DamageVoiceRandom_High();
								with(other){ playEnemySound(SOUND_BITE); }
								Fluid(x,y,COLOR_BLOOD,15,2,20, 80,20,0.5);
								Fluid(x,y,COLOR_BLOOD,15,2,20,260,20,0.5);
								Flash(c_red,0.2,0.05);
								Quake(15,15);

								if(BINDED){
									addDamage(80, -1, -1, -1, -1, -1, -1);
								}else{
									addDamage(80,DAMAGE_0, 0, 1, DOWN_1, 0, 2);

									if(random(100)<50){
										Fluid(x,y,c_red,15,5,20,0,180,0.5);
										if(Direction != other.Direction){
											with(other){
												startBind( col,BIND_CATCH_FLOOR,0,other.BINDED_WANIO_CATCH_FLOOR,0,1 );
												MotionChange(CATCH_FLOOR,0,1);
												Quake(15,15);
											}
										}else{
											addDamage(80,DAMAGE_0, 0, 1, DOWN_1, 0, 2);
											with(other){
												startBind( col,BIND_CATCH_FLOOR,0,other.BINDED_WANIO_CATCH_CUT,0,1 );
												MotionChange(CATCH_CUT,0,1);
												Quake(15,15);
											}
										}
									}
								}
							}
						}
					}
					break;
			}
			if(MOTIONEND){ MotionChange(STAND,0,5); break; }
			break;
		case CATCH_CUT :
			/* LO */
			DepthSet(objPlayerDoll.depth - 1000);
			Process[ProcessNum[SPRITE_HEAD02]].depth	= objPlayerDoll.depth + 1000;

			with(BindTarget){
				if(0<KeyFrmNum && KeyFrmNum<22) Fluid(FOOT2_ABOVE.x,FOOT2_ABOVE.y,COLOR_BLOOD,2+random(5),0,5,0,360,0.5);
				FOOT2_ABOVE.image_alpha = 0;
				FOOT3_ABOVE.image_alpha = 0;
				with(objCommon_Foot_Above){ image_alpha = 0; }
			}

			switch(KeyFrmNum){
				case  1 : 
					if(KEYFRAME){
						addDamage(150,-1, -1, -1, -1, -1, -1);
						Quake(15,15);
						if(BindTarget) Fluid(BindTarget.FOOT2_ABOVE.x,BindTarget.FOOT2_ABOVE.y,COLOR_BLOOD,50,0,20,0,360,0.5);
						Flash(c_red,1.0,0.1);
					}
					break;
				case  6 : 
				case  7 : 
				case  8 : 
				case 12 : 
				case 13 : 
				case 17 : 
				case 18 : 
				case 19 : 
					if(BindTarget) Fluid(BindTarget.BODY_TOP.x,BindTarget.BODY_TOP.y,COLOR_BLOOD,3,0,5,0,360,0.5);
					break;
				case  5 : 
				case 11 : 
				case 16 : 
				case 22 : 
					if(KEYFRAME){
						DamageVoiceRandom_Mid();
						addDamage(20,-1, -1, -1, -1, -1, -1);
						Quake(15,15);
						if(BindTarget) Fluid(BindTarget.BODY_TOP.x,BindTarget.BODY_TOP.y,COLOR_BLOOD,20,0,20,0,360,0.5);
						Flash(c_red,0.5,0.1);
						playEnemySound(SOUND_BITE);
					}
					break;
			}
			if(MOTIONEND){
				startBind( BindTarget,BIND_CATCH_FLOOR,0,BindTarget.BINDED_WANIO_CATCH_CUT,49,1 );
				MotionChange(CATCH_CUT,25,1);
			}
			break;
		case CATCH_FLOOR :
			/* LO */
			DepthSet(objPlayerDoll.depth - 1000);
			Process[ProcessNum[SPRITE_HEAD02]].depth	= objPlayerDoll.depth + 1000;

			switch(KeyFrmNum){
				case  4 : 
				case  6 : 
				case  8 : 
					if(BindTarget) Fluid(BindTarget.FOOT2_ABOVE.x,BindTarget.FOOT2_ABOVE.y,COLOR_BLOOD,3,0,5,0,360,0.5);
					break;
				case  10 : 
					if(KEYFRAME){
						DamageVoiceRandom_Low();
						addDamage(500,-1, -1, -1, -1, -1, -1);
						Quake(15,15);
						Flash(c_red,0.5,0.1);
						playEnemySound(SOUND_CLASH);
					}
					break;
			}
			if(MOTIONEND){
				if(isGameOver()){
					startBind( BindTarget,BIND_CATCH_FLOOR,0,BindTarget.BINDED_WANIO_CATCH_FLOOR_FINISH,0,1 );
					MotionChange(CATCH_FLOOR_FINISH,0,1);
				}
			}
			break;
		case CATCH_FLOOR_FINISH :
			/* LO */
			DepthSet(objPlayerDoll.depth - 1000);
			Process[ProcessNum[SPRITE_HEAD02]].depth	= objPlayerDoll.depth + 1000;

			switch(KeyFrmNum){
				case  18 : 
					if(KEYFRAME){
						Macro_CutHand1_Above();
					}
				case  2 : 
				case  8 : 
				case  12 : 
				case  23 : 
					if(KEYFRAME){
						Quake(15,15);
						Flash(c_red,1.0,0.1);
						playEnemySound(SOUND_BITE);
						if(BindTarget) Fluid(BindTarget.x,BindTarget.y,COLOR_BLOOD,30,0,25,0,360,0.5);
					}
					break;
			}
			if(MOTIONEND){
				startBind( BindTarget,BIND_CATCH_FLOOR,0,BindTarget.BINDED_WANIO_CATCH_FLOOR_FINISH,19,1 );
				MotionChange(CATCH_FLOOR_FINISH,28,1);
			}
			break;
		case DEAD_MOTION :
			if(KeyFrmNum==1 && KEYFRAME){
				sound_play(sndHit02);
				Fluid(x,y,COLOR_BLOOD,35,5,20,0,180,0.5);
				Quake(5,5);
			}
			if(MOTIONEND){
				effect_create_above(ef_explosion,x,y,1,COLOR_BLOOD);
				Flash(c_white,0.1,0.05);
				Fluid(x,y,COLOR_BLOOD,5,5,20,0,180,0.5);
				Quake(5,5);
				sound_play(sndFluid);
				instance_destroy();
			}
			break;
	}
}