/*-----d͐ݒ--------------------------*/
GSet(global.G,global.Gdir,1,1, 0,0,1,1);

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

/*-----LN^Ƃ̏̎擾---------------*/
playerDistance = point_distance(x,y,objPlayerDoll.x,objPlayerDoll.y);
playerDirection = point_direction(x,y,objPlayerDoll.x,objPlayerDoll.y);

/*-----[V̏--------------------*/
if(RECV_DAMAGE) playEnemySound(SOUND_DAMAGE);

if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			/* ̕ */
			if(objPlayerDoll.x > x) Direction = Right;
			else Direction = Left;

			/* ߂Â */
			if( !air && 100<playerDistance && playerDistance<350){ MotionChange(WALK,0,5); break; }

			/* ꍇɂĂ͌ */
			if( !air && 200>playerDistance && !instance_exists(BulletEffect) ){ 
				if( 10 < playerDirection && playerDirection < 170){
					MotionChange(SHOT_UE,0,3);
				}else{
					MotionChange(SHOT_YOKO,0,5);
				}
				break;
			}
			break;
		case WALK :
			switch(KeyFrmNum){
				case 0 : Move(-0.2*Direction,0); break;
				case 1 : Move(-1.5*Direction,0); break;
				case 2 : Move(-0.5*Direction,0); break;
				case 3 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						 Move(-2.5*Direction,0); break;
				case 6 : Move(-1.5*Direction,0); break;
				case 7 : Move(-0.5*Direction,0); break;
				case 8 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						 Move(-1.0*Direction,0); break;
				case 9 : Move(-0.5*Direction,0); break;
			}
			/* ߂Â藣ꂽ肵~܂ */
			if( 100>playerDistance || playerDistance>350){ MotionChange(STAND,0,5); break; }

			/* ꍇɂĂ͌ */
			if( !air && 200>playerDistance && !instance_exists(BulletEffect) ){ 
				if( 10 < playerDirection && playerDirection < 170){
					MotionChange(SHOT_UE,0,3);
				}else{
					MotionChange(SHOT_YOKO,0,5);
				}
				break;
			}
			break;
		case SHOT_YOKO :
			switch(KeyFrmNum){
				case 4 : 
					if(KEYFRAME){
						Quake(5,5);
						sound_play(sndBullet3);

						/* CGtFNg̍쐬 */
						BulletEffect = createBullet(Process[PARTS_CANON].x+20*Direction*-1,Process[PARTS_CANON].y);
						BulletEffect.speed		= 1;
						BulletEffect.direction	= Process[PARTS_CANON].image_angle+180;
						BulletEffect.hspeed		*= Direction;
						BulletEffect.Picture	= SPRITE_BULLET;

						/* ߋ_[W */
						with( collision_circle( Process[PARTS_CANON].x+10*Direction*-1, Process[PARTS_CANON].y, 64,objPlayerDoll,0,1) ){
							if(!INV && !BINDED){
								if(Direction!=other.Direction)	addDamage(20,FLYING_0, 0, 1, DOWN_1, 0, 2);
								else							addDamage(20,FLYING_1, 0, 1, DOWN_0, 0, 2);
								hspeed = 30*other.Direction*-1;
							}
							sound_play(sndBulletHit);
							Quake(15,5);
							other.SpecialAttack = 1;
						}

						/* e̍쐬 */
						for(i=0;i<5;i+=1){
							ShotGunBullet[i] = createBullet(Process[PARTS_CANON].x+20*Direction*-1,Process[PARTS_CANON].y);
							ShotGunBullet[i].speed		= 30+random(10);
							ShotGunBullet[i].direction	= Process[PARTS_CANON].image_angle+180 -10+random(20);
							ShotGunBullet[i].hspeed	*= Direction;
							ShotGunBullet[i].Picture	= -1;
							with(ShotGunBullet[i]){ SpecialAttack = other.SpecialAttack; }
						}
						SpecialAttack = 0;

						/* 䰂̍쐬 */
						new = instance_create(x,y,objBulletCase);
						new.hspeed = (5+random(5))*Direction;
						new.vspeed = (-10-random(5));
						new.image_index = 2;
					}
					break;
			}
			if(MOTIONEND){ MotionChange(STAND,0,5); break; }
			break;
		case SHOT_UE :
			switch(KeyFrmNum){
				case 4 : 
					if(KEYFRAME){
						Quake(5,5);
						sound_play(sndBullet3);

						/* CGtFNg̍쐬 */
						BulletEffect = createBullet(Process[PARTS_CANON].x+15*Direction*-1,Process[PARTS_CANON].y+20);
						BulletEffect.speed		= 1;
						BulletEffect.direction	= Process[PARTS_CANON].image_angle+180;
						BulletEffect.hspeed		*= Direction;
						BulletEffect.Picture	= SPRITE_BULLET;

						/* ߋ_[W */
						with( collision_circle( Process[PARTS_CANON].x+10*Direction*-1, Process[PARTS_CANON].y+20, 64,objPlayerDoll,0,1) ){
							DamageVoiceRandom_Mid();
							if(BINDED) addDamage(30, -1, -1, -1, DOWN_1, 0, 2);
							else{
								addDamage(30,FLYING_0, 0, 1, DOWN_1, 0, 2);
								hspeed = 30*other.Direction*-1;
							}
							sound_play(sndBulletHit);
							Quake(15,5);
							other.SpecialAttack = 1;
						}

						/* e̍쐬 */
						for(i=0;i<5;i+=1){
							ShotGunBullet[i] = createBullet(Process[PARTS_CANON].x+20*Direction*-1,Process[PARTS_CANON].y);
							ShotGunBullet[i].speed		= 30+random(10);;
							ShotGunBullet[i].direction	= Process[PARTS_CANON].image_angle+180 -10+random(20);
							ShotGunBullet[i].hspeed	*= Direction;
							ShotGunBullet[i].Picture	= -1;
							with(ShotGunBullet[i]){ SpecialAttack = other.SpecialAttack; }
						}
						SpecialAttack = 0;

						/* 䰂̍쐬 */
						new = instance_create(x,y,objBulletCase);
						new.hspeed = (5+random(5))*Direction;
						new.vspeed = (-10-random(5));
						new.image_index = 2;
					}
					break;
			}
			if(MOTIONEND){ MotionChange(STAND,0,5); 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;
	}
}

/*-----ѓ̏--------------------*/
with(BulletEffect){
	image_angle = direction;
	image_speed = 0.8;
	if(image_index > 6 ) destroyBullet();
}

for(i=0;i<5;i+=1){
	with(ShotGunBullet[i]){
		image_angle = direction;
		if( checkBlock(x,y) ){
			var Num,VarianceX,VarianceY,Gravity,AngleMin,AngleRange,SpeedMin,SpeedRange,TimeMin,TimeRange;
			Num = 10+random(20);
			Gravity		= 1;
			VarianceX	= 8;
			VarianceY	= 8;
			AngleMin	= 180+direction-10;
			AngleRange	= 20;
			SpeedMin	= 0;
			SpeedRange	= 5;
			TimeMin		= 5;
			TimeRange	= 5;
			Spark(Num,VarianceX,VarianceY,Gravity,AngleMin,AngleRange,SpeedMin,SpeedRange,TimeMin,TimeRange);
			destroyBullet();
		}
		with(checkPlayer(x,y)){
			if(!INV && !BINDED){
				if(!other.SpecialAttack){
					DamageVoiceRandom_Mid();
					global.voiceInterval = 10;
					addDamage(2,DAMAGE_0, 0, 1, DOWN_1, 0, 2); 
					hspeed = other.hspeed/2;
				}
				if(other.hspeed>0) 	Fluid(x,y,COLOR_BLOOD,10,2,10,90, 180,0.5);
				else				Fluid(x,y,COLOR_BLOOD,10,2,10,90,-180,0.5);
				sound_play(sndBulletHit);
				Quake(5,5);
				with(other){ destroyBullet(); }
			}
		}
		if(Time){
			new = instance_create(x,y,objLine);
			new.xpos = x-hspeed;
			new.ypos = y-vspeed;
			if(Time > 5) destroyBullet();
		}
	}
}