/*-----重力設定--------------------------*/
GSet(global.G,global.Gdir,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 :
		DepthSet(objPlayerDoll.depth - 1000);
		with(objController){
			with(CtrlTarget){
				if( other.BindCounter>30+0.1*(100-global.PlayerHP) ){
					other.BindCounter = 0;
					move_outside_afterBind();
					BINDED = 0;
				}
			}
		}
		break;
	case CATCH_FINISH :
		DepthSet(objPlayerDoll.depth - 1000);
		break;
	/*-----------------------------*/
	case CATCHAIR :
		DepthSet(objPlayerDoll.depth - 1000);
		if(KeyFrmNum<18){
			with(objController){
				with(CtrlTarget){
					if( other.BindCounter>30+0.1*(100-global.PlayerHP) ){
						other.BindCounter = 0;
						move_outside_afterBind();
						BINDED = 0;
					}
				}
			}
		}
		break;
	/*-----------------------------*/
	case CATCHNEAR :
	case CATCHNEAR_FINISH :
		DepthSet(objPlayerDoll.depth - 1000);
		Process[ProcessNum[PARTS_BODY0]].depth = objPlayerDoll.depth + 1001;
		Process[ProcessNum[PARTS_BODY1]].depth = objPlayerDoll.depth + 1000;
		if(KeyFrmNum<18){
			with(objController){
				with(CtrlTarget){
					if( other.BindCounter>30+0.1*(100-global.PlayerHP) ){
						other.BindCounter = 0;
						move_outside_afterBind();
						BINDED = 0;
					}
				}
			}
		}
		break;
}

if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			/* 相手の方を向く */
			if( (objPlayerDoll.x > x && Direction != Right) || 
				(objPlayerDoll.x < x && Direction != Left ) ) MotionChange(TURN,0,1);
			
			if(!isGameOver()){
				if(!objPlayerDoll.air){
					if( 120>playerDistance )      MotionChange(ATTACKNEAR,0,1);
					else if( 250>playerDistance ) MotionChange(ATTACK,0,1);
				}else{
					if( 250>playerDistance ) MotionChange(ATTACKAIR,0,1);
				}
			}else{
				if(BindTarget){
					addDamage(0.1,-1,-1,-1,-1,-1,-1);
				}
			}
			break;
		case TURN :
			if(KeyFrmNum==3){
				if(KEYFRAME) Direction = Direction*-1;
			}
			if(MOTIONEND) MotionChange(STAND,0,1);
			break;

		/*-----------------------------*/
		case ATTACK:
			switch(KeyFrmNum){
				case 5 : 
					if(KEYFRAME) sound_play(sndSwing00);
				case 6 : 
					if(KEYFRAME){
						with( collision_circle( Process[ProcessNum[PARTS_BODY3]].x-Direction*96,Process[ProcessNum[PARTS_BODY3]].y, 40,objPlayerDoll,0,1) ){
							if(!INV && !BINDED){
								addDamage(3,-1,-1,-1,-1,-1,-1);
								sound_play(sndHit00);
								Quake(15,15);
								Direction = other.Direction*-1;
								with(other){
									startBind( objPlayerDoll,BIND_CATCH,0,other.BINDED_WORM_CATCH,0,1 );
									MotionChange(CATCH,0,1);
								}
							}
						}
					}
					break;
			}
			if(MOTIONEND){
				/* 相手の方を向く */
				if( (objPlayerDoll.x > x && Direction != Right) || 
					(objPlayerDoll.x < x && Direction != Left ) ) MotionChange(TURN,0,1);
				else MotionChange(STAND,0,1);
			}
			break;
		case CATCH:
			if(BindTarget){
				if(!BindTarget.BINDED && !isGameOver()){
						DamageVoiceRandom_Low();
						with(BindTarget){ MotionChange(STAND_0,0,2); }
						endBind();
						MotionChange(STAND,0,20);
						break;
				}
			}
			switch(KeyFrmNum){
				case  2 :
				case  8 :
				case 14 :
				case 20 :
					if(KEYFRAME){
						addDamage(3,-1,-1,-1,-1,-1,-1);
						VoreVoiceRandom_Mid();
						Quake(5,15);
					}
					break;
				case 6:
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x-90*Direction,Process[ProcessNum[PARTS_BODY3]].y,c_white,10,5,10,90,90*Direction,0.25,1.5,BindTarget.depth);
						if(global.PlayerHP/global.PlayerHPMAX > 0.75){
							startBind( objPlayerDoll,BIND_CATCH,0,objPlayerDoll.BINDED_WORM_CATCH,0,1 );
							MotionChange(CATCH,0,1);
						}
					}
					break;
				case 12:
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x-90*Direction,Process[ProcessNum[PARTS_BODY3]].y,c_white,10,5,10,90,90*Direction,0.25,1.5,BindTarget.depth);
						if(global.PlayerHP/global.PlayerHPMAX > 0.5){
							startBind( objPlayerDoll,BIND_CATCH,0,objPlayerDoll.BINDED_WORM_CATCH,7,1 );
							MotionChange(CATCH,7,1);
						}
					}
					break;
				case 18:
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x-90*Direction,Process[ProcessNum[PARTS_BODY3]].y,c_white,10,5,10,90,90*Direction,0.25,1.5,BindTarget.depth);
						if(global.PlayerHP/global.PlayerHPMAX > 0.25){
							startBind( objPlayerDoll,BIND_CATCH,0,objPlayerDoll.BINDED_WORM_CATCH,13,1 );
							MotionChange(CATCH,13,1);
						}
					}
					break;
			}
			if(MOTIONEND){
				with(BindTarget){MotionChange(BINDED_WORM_CATCH_FINISH,0,1);}
				MotionChange(CATCH_FINISH,0,1);
			}
			break;
		case CATCH_FINISH:
			switch(KeyFrmNum){
				case  1 :
				case  4 :
				case  7 :
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x-90*Direction,Process[ProcessNum[PARTS_BODY3]].y,c_white,10,5,10,90,90*Direction,0.25,1.5,BindTarget.depth);
						addDamage(3,-1,-1,-1,-1,-1,-1);
						VoreVoiceRandom_Mid();
						Quake(5,15);
						switch(irandom(2)){
							case 0: sound_play(sndVore01);break;
							case 1: sound_play(sndVore02);break;
							case 2: sound_play(sndVore03);break;
						}
					}
					break;
				case 10 :
					if(KEYFRAME){
						addDamage(3,-1,-1,-1,-1,-1,-1);
						VoreVoiceRandom_High();
						Quake(5,15);
					}
					break;
				case 11 :
				case 17 :
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y,c_white,20,5,10,70,20,0.25,1.5,BindTarget.depth);
						addDamage(3,-1,-1,-1,-1,-1,-1);
						Quake(5,15);
						switch(irandom(2)){
							case 0: sound_play(sndVore01);break;
							case 1: sound_play(sndVore02);break;
							case 2: sound_play(sndVore03);break;
						}
					}
					break;
			}
			if(MOTIONEND){
				Flash(c_red,0.8,0.01);
				global.GameOver = true;
				sound_play(sndVore04);
				Quake(15,15);
				with(objPlayerParts){visible = 0;}
				with(objExtParts){visible = 0;}
				MotionChange(STAND,0,10);
			}
			break;
		/*-----------------------------*/
		case ATTACKAIR:
			switch(KeyFrmNum){
				case 5 : 
					if(KEYFRAME) sound_play(sndSwing00);
				case 6 : 
					if(KEYFRAME){
						with( collision_circle( Process[ProcessNum[PARTS_BODY3]].x-Direction*96, Process[ProcessNum[PARTS_BODY3]].y, 40,objPlayerDoll,0,1) ){
							if(air && !INV && !BINDED){
								addDamage(3,-1,-1,-1,-1,-1,-1);
								sound_play(sndHit00);
								Quake(15,15);
								Direction = other.Direction*-1;
								with(other){
									startBind( objPlayerDoll,BIND_CATCHAIR,0,objPlayerDoll.BINDED_WORM_CATCHAIR,0,1 );
									MotionChange(CATCHAIR,0,1);
								}
							}
						}
					}
					break;
			}
			if(MOTIONEND){
				/* 相手の方を向く */
				if( (objPlayerDoll.x > x && Direction != Right) || 
					(objPlayerDoll.x < x && Direction != Left ) ) MotionChange(TURN,0,1);
				else MotionChange(STAND,0,1);
			}
			break;
		case CATCHAIR:
			if(BindTarget){
				if(!BindTarget.BINDED && !isGameOver()){
						DamageVoiceRandom_Low();
						with(BindTarget){ MotionChange(STAND_0,0,2); }
						endBind();
						MotionChange(STAND,0,20);
						break;
				}
			}
			switch(KeyFrmNum){
				case  3 :
				case  8 :
				case 16 :
					if(KEYFRAME){
						addDamage(3,-1,-1,-1,-1,-1,-1);
						DamageVoiceRandom_Low();
						Quake(5,15);
						switch(irandom(2)){
							case 0: sound_play(sndVore01);break;
							case 1: sound_play(sndVore02);break;
							case 2: sound_play(sndVore03);break;
						}
					}
					break;
				case 25 :
				case 34 :
					if(KEYFRAME){
						addDamage(3,-1,-1,-1,-1,-1,-1);
						VoreVoiceRandom_Mid();
						Quake(5,15);
						switch(irandom(2)){
							case 0: sound_play(sndVore01);break;
							case 1: sound_play(sndVore02);break;
							case 2: sound_play(sndVore03);break;
						}
					}
					break;
				case 10 :
				case 13 :
				case 22 :
				case 31 :
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y-100,c_white,10,5,10,45,90,0.25,1.5,BindTarget.depth);
						switch(irandom(2)){
							case 0: sound_play(sndVore01);break;
							case 1: sound_play(sndVore02);break;
							case 2: sound_play(sndVore03);break;
						}
					}
					break;
				case 12:
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y-100,c_white,10,5,10,45,90,0.25,1.5,BindTarget.depth);
						if(global.PlayerHP/global.PlayerHPMAX > 0.75){
							startBind( objPlayerDoll,BIND_CATCHAIR,0,objPlayerDoll.BINDED_WORM_CATCHAIR,9,1 );
							MotionChange(CATCHAIR,9,1);
						}
						addDamage(3,-1,-1,-1,-1,-1,-1);
						Quake(5,15);
					}
					break;
				case 21:
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y-100,c_white,10,5,10,45,90,0.25,1.5,BindTarget.depth);
						if(global.PlayerHP/global.PlayerHPMAX > 0.50){
							startBind( objPlayerDoll,BIND_CATCHAIR,0,objPlayerDoll.BINDED_WORM_CATCHAIR,13,1 );
							MotionChange(CATCHAIR,13,1);
						}
						addDamage(3,-1,-1,-1,-1,-1,-1);
						Quake(5,15);
					}
					break;
				case 30:
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y-100,c_white,10,5,10,45,90,0.25,1.5,BindTarget.depth);
						if(global.PlayerHP/global.PlayerHPMAX > 0.25){
							startBind( objPlayerDoll,BIND_CATCHAIR,0,objPlayerDoll.BINDED_WORM_CATCHAIR,22,1 );
							MotionChange(CATCHAIR,22,1);
						}
						addDamage(3,-1,-1,-1,-1,-1,-1);
						Quake(5,15);
					}
					break;
			}
			if(MOTIONEND){
				VoreVoiceRandom_High();
				Flash(c_red,0.8,0.01);
				FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y-100,c_white,25,5,10,70,20,0.25,1.5,BindTarget.depth);
				global.GameOver = true;
				sound_play(sndVore04);
				Quake(15,15);
				with(objPlayerParts){visible = 0;}
				with(objExtParts){visible = 0;}
				MotionChange(STAND,0,40);
			}
			break;
		/*-----------------------------*/
		case ATTACKNEAR:
			switch(KeyFrmNum){
				case 5 : 
					if(KEYFRAME) sound_play(sndSwing00);
				case 6 : 
					if(KEYFRAME){
						with( collision_circle( Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y, 40,objPlayerDoll,0,1) ){
							if(!INV && !BINDED){
								addDamage(3,-1,-1,-1,-1,-1,-1);
								sound_play(sndHit00);
								Quake(15,15);
								Direction = other.Direction*-1;
								with(other){
									startBind( objPlayerDoll,BIND_CATCHNEAR,0,other.BINDED_WORM_CATCHNEAR,0,1 );
									MotionChange(CATCHNEAR,0,1);
								}
							}
						}
					}
					break;
			}
			if(MOTIONEND){
				/* 相手の方を向く */
				if( (objPlayerDoll.x > x && Direction != Right) || 
					(objPlayerDoll.x < x && Direction != Left ) ) MotionChange(TURN,0,1);
				else MotionChange(STAND,0,1);
			}
			break;
		case CATCHNEAR:
			if(BindTarget){
				if(!BindTarget.BINDED && !isGameOver()){
						DamageVoiceRandom_Low();
						with(BindTarget){ MotionChange(STAND_0,0,2); }
						endBind();
						MotionChange(STAND,0,20);
						break;
				}
			}
			switch(KeyFrmNum){
				case 6:
					if(KEYFRAME){
						addDamage(3,-1,-1,-1,-1,-1,-1);
						VoreVoiceRandom_Mid();
						Quake(5,15);
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y-100,c_white,10,5,10,45,90,0.25,1.5,BindTarget.depth);
						if(global.PlayerHP/global.PlayerHPMAX > 0.75){
							startBind( objPlayerDoll,BIND_CATCHNEAR,0,objPlayerDoll.BINDED_WORM_CATCHNEAR,0,1 );
							MotionChange(CATCHNEAR,0,1);
						}
					}
					break;
			}
			if(MOTIONEND){
				with(BindTarget){MotionChange(BINDED_WORM_CATCHNEAR_FINISH,0,1);}
				MotionChange(CATCHNEAR_FINISH,0,1);
			}
			break;
		case CATCHNEAR_FINISH:
			switch(KeyFrmNum){
				case  18 :
					if(KEYFRAME){
						if(global.PlayerHP/global.PlayerHPMAX > 0.5){
							with(BindTarget){MotionChange(BINDED_WORM_CATCHNEAR_FINISH,10,2);}
							MotionChange(CATCHNEAR_FINISH,10,2);
						}
					}
					break;
				case  27 :
					if(KEYFRAME){
						if(global.PlayerHP/global.PlayerHPMAX > 0.25){
							with(BindTarget){MotionChange(BINDED_WORM_CATCHNEAR_FINISH,19,2);}
							MotionChange(CATCHNEAR_FINISH,19,2);
						}
					}
					break;
				case  5 :
				case 13 :
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y-100,c_white,10,5,10,70,20,0.25,1.5,BindTarget.depth);
						addDamage(5,-1,-1,-1,-1,-1,-1);
						DamageVoiceRandom_Low();
						Quake(5,15);
						switch(irandom(2)){
							case 0: sound_play(sndVore01);break;
							case 1: sound_play(sndVore02);break;
							case 2: sound_play(sndVore03);break;
						}
					}
					break;
				case 22 :
				case 31 :
					if(KEYFRAME){
						FluidWithScale(Process[ProcessNum[PARTS_BODY3]].x,Process[ProcessNum[PARTS_BODY3]].y-100,c_white,10,5,10,70,20,0.25,1.5,BindTarget.depth);
						addDamage(5,-1,-1,-1,-1,-1,-1);
						VoreVoiceRandom_Low();
						Quake(5,15);
						switch(irandom(2)){
							case 0: sound_play(sndVore01);break;
							case 1: sound_play(sndVore02);break;
							case 2: sound_play(sndVore03);break;
						}
					}
					break;
			}
			if(MOTIONEND){
				Flash(c_red,0.8,0.01);
				global.GameOver = true;
				sound_play(sndVore04);
				Quake(15,15);
				with(objPlayerParts){visible = 0;}
				with(objExtParts){visible = 0;}
				MotionChange(STAND,0,10);
			}
			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;
	}
}