/*-----重力設定--------------------------*/
if( HP < 0 ){
	gravity = global.G;
	gravity_direction = global.Gdir;
}else{
	gravity = 0;
	gravity_direction = 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);
}

if(!ChangeMotion){
	switch(MotionNum){
		case WAIT :
			speed *= 0.5;
			/* 相手の方を向く */
			if(objPlayerDoll.x > x){
				if(Direction){ MotionChange(TURN,0,2); break; }
			}else{
				if(!Direction){ MotionChange(TURN,0,2); break; }
			}
			if(playerDistance<300){ MotionChange(RUNAFTER,0,2); break; }
			break;
		case TURN :
			speed *= 0.5;
			switch(KeyFrmNum){
				case 4 : 
					if(KEYFRAME) 	Direction = -Direction;
					break;
			}
			if(MOTIONEND){
				MotionChange(WAIT,0,1);
			}
			break;
		case RUNAFTER :
			motion_set(playerDirection,10);
			if(playerDistance<64){ MotionChange(KAMIKAZE,0,2); break; }
			if(playerDistance>500){ MotionChange(WAIT,0,2); break; }
			if(objPlayerDoll.x > x){
				if(Direction){ MotionChange(TURN,0,2); break; }
			}else{
				if(!Direction){ MotionChange(TURN,0,2); break; }
			}
			if(MOTIONEND){
				MotionChange(RUNAFTER,0,1);
			}
			break;
		case KAMIKAZE :
			speed *= 0.25;
			switch(KeyFrmNum){
				case 1 : 
					if(KEYFRAME) playEnemySound(SOUND_BEEP);
					break;
			}
			if(MOTIONEND){
				with( collision_circle( x,y,128,objPlayerDoll,0,1) ){
					if(BINDED){
						addDamage(30, -1, -1, -1, -1, -1, -1,);
					}else{
						if(!INV){
							DamageVoiceRandom_Mid();
							if(Direction){
								if(x > other.x)	addDamage(30,FLYING_0, 0, 1, FLYING_0, 0, 2);
								else			addDamage(30,FLYING_1, 0, 1, FLYING_1, 0, 2);
							}else{
								if(x < other.x)	addDamage(30,FLYING_0, 0, 1, FLYING_0, 0, 2);
								else			addDamage(30,FLYING_1, 0, 1, FLYING_1, 0, 2);
							}
							motion_set(other.playerDirection,30);
						}
					}
					sound_play(sndHit00);
					Quake(15,15);
				}

				instance_create(x,y,objExplosionSmall);
				Flash(c_white,0.1,0.05);

				Quake(5,5);
				sound_play(sndBomb);
				instance_destroy();
			}
			break;
		case DEAD_MOTION :
			switch(KeyFrmNum){
				case 1 : 
					if(KEYFRAME) effect_create_above(ef_smokeup,x,y,0,c_black);
					break;
			}
			if(MOTIONEND){
				instance_create(x,y,objExplosionSmall);
				Flash(c_white,0.1,0.05);

				Quake(5,5);
				sound_play(sndBomb);
				instance_destroy();
			}
			break;
	}
}