/*-----重力設定--------------------------*/
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 && 320>playerDistance ){
				MotionChange(SHOT_YOKO,0,5); 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; }

			if( !air && 320>playerDistance ){
				MotionChange(SHOT_YOKO,0,5); break;
			}
			break;
		case SHOT_YOKO :
			/* 弾の作成 */
			switch(KeyFrmNum){
				case 2 : 
				case 4 : 
				case 6 : 
				case 8 : 
					if(KEYFRAME){
						for(i=0;i<10;i+=1){
							if(!instance_exists(Bullet[i])){
								playEnemySound(SOUND_PILESHOT);
								Bullet[i] = createBullet(x-64*Direction,y+32-8*KeyFrmNum);
								Bullet[i].hspeed			= -50*Direction;
								Bullet[i].image_angle		= Bullet[i].direction;
								Bullet[i].preAngle			= Bullet[i].direction;
								Bullet[i].Picture			= SPRITE_PILE;
								Bullet[i].gravity			= 0.2;
								with(Bullet[i]){
									CollisionWidth  = 64;
									CollisionHeight = 8;
									attachObj = noone;
									attachDirection = 0;
									attachDistance = 0;
									adjustDirection = 0;
									Todome = other.KeyFrmNum;
									hitFlag= 0;
								}
								break;
							}
						}
					}
					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);
				for(i=0;i<10;i+=1){
					with(Bullet[i]){ instance_destroy(); }
				}
				instance_destroy();
			}
			break;
	}
}

/*-----飛び道具の処理--------------------*/
for(i=0;i<10;i+=1){
	with(Bullet[i]){
		if(attachObj == noone){
			image_angle = direction;
			with(checkBlock(x,y)){
				other.attachObj = id;
				other.attachDirection = point_direction(other.x,other.y,x,y);
				other.attachDistance  = random(16);
			};
			with(checkPlayer(x,y)){
				if(!INV){
					with(objExtParts){
						with(DrawTarget){
							PartsDamage(other.id,-random(5),0);
							PartsBloodDamage(other.id,-random(25),0);
						}
					}
					other.attachObj = Process[round(random(1))];
					other.attachDirection = point_direction(other.x,other.y,x,y);
					other.attachDistance  = random(24);
					other.adjustDirection = true;

					Fluid(x,y,COLOR_BLOOD,15,2,10,direction+90,180,0.5);
					Fluid(x,y,COLOR_BLOOD,20,5,15,direction-10,20,0.5);
					if(BINDED) addSTDamage(5,5, -1, -1, -1, -1, -1, -1);
					else{
						if(other.Todome>6){
							DamageVoiceRandom_Mid();
							addSTDamage(10,5,DOWN_0, 0, 1, DOWN_0, 0, 2); 
						}else{
							DamageVoiceRandom_Low();
							addSTDamage(10,20,DAMAGE_0, 0, 1, DOWN_0, 0, 2); 
						}
						hspeed = other.hspeed/2;
					}
					Quake(5,5);
				}
			}
		}else{
			hitFlag += 1;
			if(hitFlag>120) destroyBullet();
		}
	}
}