/*-----重力設定--------------------------*/
if( air ){
	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 STAND :
			/* 相手の方を向く */
			if(objPlayerDoll.x > x) Direction = Right;
			else Direction = Left;

			/* 近づいたら歩く */
			if( !air && 200<playerDistance && playerDistance<550){
				MotionChange(WALK,0,5); break;
			}else if( !air && 200>playerDistance ){
				MotionChange(SHOT_YOKO,0,1); break;
			}
			break;
		case WALK :
			if(place_free(x-5*Direction,y)) x -= 5.0*Direction;
			/* 近づきすぎたり離れたりしたら止まる */
			if( 200>playerDistance || playerDistance>550){ MotionChange(STAND,0,5); break; }
			break;
		case SHOT_YOKO :
			/* 弾の作成 */
			for(i=0;i<20;i+=1){
				if(!instance_exists(Bullet[i])){
					playEnemySound(SOUND_FIRE);
					Bullet[i] = createBullet(x-64*Direction,y+32);
					Bullet[i].hspeed			= -(8+random(5))*Direction;
					Bullet[i].image_xscale		= (0.5+random(0.5))*(-1+2*round(random(1)));
					Bullet[i].image_yscale		= Bullet[i].image_xscale;
					Bullet[i].image_angle		= random(360);
					Bullet[i].gravity			= 0.2+random(0.05);
					Bullet[i].gravity_direction	= 90;
					Bullet[i].Picture			= SPRITE_FIRE;
					effect_create_below(ef_smokeup,random(5)+x-64*Direction,random(5)+y+32,0,c_dkgray);
					break;
				}
			}

			switch(KeyFrmNum){
				case 1 : if(place_free(x+3*Direction,y)) x += 2.0*Direction; break;
				case 2 : if(place_free(x+3*Direction,y)) x += 1.0*Direction; break;
				case 3 : if(place_free(x+3*Direction,y)) x += 0.5*Direction; break;
				case 4 : if(place_free(x+3*Direction,y)) x += 0.2*Direction; break;
			}
			if(MOTIONEND){ MotionChange(STAND,0,1); 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;
	}
}

/*-----飛び道具の処理--------------------*/
for(i=0;i<20;i+=1){
	with(Bullet[i]){
		image_angle += hspeed;
		image_xscale *= 1+random(0.2);
		image_yscale = image_xscale;
		image_alpha -= abs(image_xscale*0.05);
		if( checkBlock(x,y) || image_alpha < 0 ) destroyBullet();

		with(checkPlayer(x,y)){
			if(!INV){
				var parts;
				parts = id;
				if(global.config_Effect && instance_number(objFire)<5){
					f = Fire(x,y,90);
					f.attach = true;
					parts = Process[round(random(PARTS_MAX-1))];
					with(objPlayerParts){ if(image_blend > 13421772) image_blend -= 986890; }
					with(objExtParts){ if(image_blend > 8947848) image_blend -= 986895; }
					f.attachTarget = parts;
					f.attachDistance = 0;
					f.attachDirection = 0;
					part_system_depth(f.sys,depth - 1000);
					part_type_alpha2(f.fire,0.1,0);
				}

				with(objExtParts){
					with(DrawTarget){
						PartsDamage(other.id,-random(5),0);
					}
				}
				with(other.parent){ playEnemySound(SOUND_FIRE); }
				effect_create_above(ef_smokeup,parts.x+random(5),parts.y+random(5),1,c_dkgray);
				effect_create_below(ef_smokeup,parts.x+random(5),parts.y+random(5),1,c_dkgray);
				if(BINDED || isGameOver()) addDamage(2, -1, -1, -1, -1, -1, -1);
				else{
					addDamage(2,DAMAGE_0, 0, 1, FINISHED_FIRE_BURN, 0, 2); 
					hspeed = other.hspeed/2;
				}
				if(isGameOver()){
					if(global.voiceInterval < NO_MORE_VOICE_THR){
						global.voiceInterval = 0;
						CryingVoiceRandom_Low();
						global.voiceInterval = NO_MORE_VOICE;
					}
					with(other.parent){ if(!isPlayEnemySound(SOUND_BURN)) playEnemySound(SOUND_BURN); }
				}else{
					DamageVoiceRandom_Mid();
					global.voiceInterval = 15;
				}
				Quake(5,5);
				with(other){ destroyBullet(); }
			}
		}
	}
}