/*-----重力設定--------------------------*/
if( air ){
	gravity = global.G;
	gravity_direction = global.Gdir;
}else{
	gravity = 0;
	gravity_direction = 0;
	hspeed *= 0.5;
}

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

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

/*-----モーション毎の処理--------------------*/
if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			/* 相手の方を向く */
			if(PlayerNext_x > x) Direction = Right;
			else Direction = Left;

			/* 飲み込む */
			if( !air && 96>playerDistance){ MotionChange(ATTACK,1,2); break; }

			/* 近づいたら歩く */
			if( !air && playerDistance<400){ MotionChange(WALK,0,3); break; }
			break;
		case WALK :
			/* 相手の方を向く */
			if(PlayerNext_x > x) Direction = Right;
			else Direction = Left;

			switch(KeyFrmNum){
				case 1 : if(place_free(x-4*Direction,y)) x -= 0.3*Direction; break;
				case 2 : if(place_free(x-4*Direction,y)) x -= 3.5*Direction; break;
				case 3 : if(place_free(x-4*Direction,y)) x -= 12.0*Direction; break;
				case 4 : if(place_free(x-4*Direction,y)) x -= 0.2*Direction; break;
				case 5 : if(place_free(x-4*Direction,y)) x -= 2.5*Direction; break;
				case 6 : if(place_free(x-4*Direction,y)) x -= 6.0*Direction; break;
			}

			/* 飲み込む */
			if( !air && 200>playerDistance){ MotionChange(ATTACK,1,2); break; }

			/* 近づきすぎたり離れたりしたら止まる */
			if( 100>playerDistance || playerDistance>400){ MotionChange(STAND,0,3); break; }
			break;
		case ATTACK :
			switch(KeyFrmNum){
				case 3 : if(place_free(x-5*Direction,y)) x -= 2.0*Direction; break;
				case 4 : if(place_free(x-5*Direction,y)) x -= 4.0*Direction; break;
				case 5 : if(place_free(x-5*Direction,y)) x -= 6.0*Direction; break;
				case 6 : if(place_free(x-5*Direction,y)) x -= 25.5*Direction; break;
				case 7 : if(place_free(x-5*Direction,y)) x -= 15.5*Direction; break;
				case 8 : 
						if(place_free(x-5*Direction,y)) x -= 1.5*Direction;
						if(KEYFRAME){
							col = collision_circle(Process[PARTS_MOUTH].x-32*Direction,Process[PARTS_MOUTH].y,64,objPlayerDoll,0,0);
							with(col){
								if(!INV && !BINDED){
									VoreVoiceRandom_Mid();
									with(other){
										MotionChange( VORE , 0 , 1 );
										startBind( col,BIND_VORE,1,other.BINDED_RAMDA,0,1 );
									}
									addDamage(10,-1, -1, -1, -1, -1, -1);
									sound_play(sndLotion);
									sound_play(sndVore03);
									Quake(5,5);
									hspeed = other.Direction*-10;
								}
							}
						}
						break;
			}
			if(MOTIONEND){ MotionChange(STAND,0,5); }
			break;
		case VORE : 
			addDamage(0.2,-1, -1, -1, -1, -1, -1);
			depth = objPlayerDoll.depth - 1000;
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ depth = other.depth - other.i*3; }

			if(global.PlayerHP<=0){
				VoreVoiceRandom_High();
				Flash(c_red,1,0.01);
				sound_play(sndVore02);
				MotionChange(VORE_FINISH,0,2);
				startBind( col,BIND_VORE_FINISH,0,objPlayerDoll.BINDED_RAMDA_FINISH,0,1);
			}
			if(MOTIONEND){
				VoreVoiceRandom_Low();
				Quake(5,5);
				sound_play(sndVore03);
				addDamage(1,-1, -1, -1, -1, -1, -1);
				MotionChange(VORE,9,1);
				startBind( col,BIND_VORE,9,-1,-1,-1);
			}
			if(BindTarget){
				if(!BindTarget.BINDED){
					MotionChange(STAND,0,10);
					with(BindTarget){
						HEAD.visible = 1;
						with(objCommon_Head){ visible = 1; }
						MotionChange(RISE_1_DAMAGE_BACK,5,2);
					}
					endBind();
				}
			}
			with(BindTarget){
				HEAD.visible = 0;
				with(objCommon_Head){ visible = 0; }
			}
			break;
		case VORE_FINISH : 
			if(BindTarget) BindTarget.Direction = Direction*-1;
			depth = objPlayerDoll.depth - 1000;
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ depth = other.depth - other.i*3; }

			with(BindTarget){
				HEAD.visible = 1;
				with(objCommon_Head){ visible = 1; }
			}
			switch(KeyFrmNum){
				case 10 :	case 11 :	case 12 :	
					if(DrawAlpha>0.4) DrawAlpha -= 0.03;	break;
				case 13 :	case 14 :	case 15 :	case 16 :	case 17 :	
					DrawAlpha = 0.4;			break;
				case 18 :	case 19 :	case 20 :	
					if(DrawAlpha<1.0) DrawAlpha += 0.02;	break;
				default : 
					with(BindTarget){
						HEAD.visible = 0;
						with(objCommon_Head){ visible = 0; }
					}
					break;
			}
			if(KEYFRAME){
				switch(KeyFrmNum){
					case 6 : sound_play(sndVore01);Quake(15,15);Flash(c_red,1,0.05);	break;
					case 13 : sound_play(sndVore04);Quake(25,15);Flash(c_red,3,0.01);	break;
				}
			}
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ image_alpha=other.DrawAlpha ; }

			if(MOTIONEND){
				Quake(5,5);
				with(BindTarget){ MotionChange(BINDED_RAMDA_FINISH,19,1); }
				MotionChange(VORE_FINISH,19,1);
				startBind( BindTarget,BIND_VORE_FINISH,19,-1,-1,-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_lime,25,5,20,0,180,0.5);

				Quake(5,5);
				sound_play(sndFluid);
				playEnemySound(SOUND_DEATH);
				instance_destroy();
			}
			break;
	}
}