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

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 STAND :
				MotionChange(RUN,0,2);
				break;
			case WALK :
				MotionChange(RUN,KeyFrmNum,2);
				break;
		}
	}
}

if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			/* 相手の方を向く */
			if(objPlayerDoll.x > x) Direction = Right;
			else Direction = Left;

			/* 近づいたら歩く */
			if( !air && 100<playerDistance && playerDistance<400){ MotionChange(WALK,0,5); break; }
			if(80>playerDistance){ MotionChange(PUNCH,0,2); break; }
			break;
		case WALK :
			switch(KeyFrmNum){
				case  1 : Move(-2.0*Direction,0); break;
				case  2 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-0.5*Direction,0); break;
				case  5 : Move(-2.0*Direction,0); break;

				case  6 : Move(-2.0*Direction,0); break;
				case  7 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-0.5*Direction,0); break;
				case 10 : Move(-2.0*Direction,0); break;
			}

			/* 急接近 */
			if( 200>playerDistance ){ MotionChange(RUN,KeyFrmNum,2); break; }

			/* 近づきすぎたり離れたりしたら止まる */
			if( 100>playerDistance || playerDistance>500){ MotionChange(STAND,0,5); break; }
			break;
		case RUN :
			/* 相手の方を向く */
			if(objPlayerDoll.x > x) Direction = Right;
			else Direction = Left;

			switch(KeyFrmNum){
				case  1 : Move(-10.0*Direction,0); break;
				case  2 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-1.5*Direction,0); break;
				case  5 : Move(-10.0*Direction,0); break;

				case  6 : Move(-10.0*Direction,0); break;
				case  7 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-1.5*Direction,0); break;
				case 10 : Move(-10.0*Direction,0); break;
			}
			/* 近づきすぎたり離れたりしたら止まる */
			if(playerDistance>600){ MotionChange(WALK,0,5); break; }
			if(80>playerDistance){ MotionChange(PUNCH,0,2); break; }
			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;
		case PUNCH :
			switch(KeyFrmNum){
				case 6 : 
					if(KEYFRAME){
						with( collision_circle( Process[PARTS_ARM3_ABOVE].x+40*Direction*-1, Process[PARTS_ARM3_ABOVE].y, 64,objPlayerDoll,0,1) ){
							if(!INV && !BINDED){
								DamageVoiceRandom_Mid();
								if(Direction!=other.Direction)	addDamage(30,FLYING_0, 0, 1, FLYING_0, 0, 2);
								else							addDamage(30,FLYING_1, 0, 1, FLYING_1, 0, 2);
								hspeed = 30*other.Direction*-1;
								vspeed = -6;
								sound_play(sndHit00);
								Quake(15,15);
							}
						}
					}
					break;
			}

			if(MOTIONEND){
				MotionChange(STAND,0,1);
			}
			break;
	}
}
