/*-----d͐ݒ--------------------------*/
speed = 0; /* ȂI */
gravity = 0;

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̏--------------------*/
Process[ProcessNum[PARTS_GUN]].PartPicture = AnimationIndex;
Process[ProcessNum[PARTS_FIRE]].PartPicture = AnimationIndex;
Process[ProcessNum[PARTS_FIRE]].image_alpha = 0;

if(!ChangeMotion){
	switch(MotionNum){
		/* =========== яǒ =========== */
		case CHECK_DIR :
			FireDirection = 180;
			MotionChange(WAIT,0,1);
			break;
		case WAIT :
			if( 100 < playerDistance && playerDistance < 500){
				if( (x < objPlayerDoll.x && !Direction) || (x > objPlayerDoll.x && Direction) ){
					AnimationIndex = 0;
					playEnemySound(SOUND_MOTOR);
					MotionChange(FIRE,0,5); break;
				}
			}
			break;
		case FIRE :
			AnimationIndex += 1;
			if(AnimationIndex > 50){
				Process[ProcessNum[PARTS_FIRE]].image_alpha = 0.75;
				playEnemySound(SOUND_ATTACK);
				if(AnimationIndex mod 3 == 0){
					/* e̍쐬 */
					for(i=0;i<20;i+=1){
						if(!instance_exists(Bullet[i])){
							Bullet[i] = createBullet(x+lengthdir_x(100,Process[ProcessNum[PARTS_GUN]].image_angle+180),y+lengthdir_y(100,Process[ProcessNum[PARTS_GUN]].image_angle+180));
							Bullet[i].speed		= 60;
							Bullet[i].direction	= Process[ProcessNum[PARTS_GUN]].image_angle+180-random(5);
							Bullet[i].hspeed	*= Direction;
							Bullet[i].Picture	= -1;
							/* 䰂̍쐬 */
							new = instance_create(x,y,objBulletCase);
							new.hspeed = (5+random(5))*Direction;
							new.vspeed = (-10-random(5));
							new.image_index = 1;
							
							break;
						}
					}
				}

				if( AnimationIndex > 120 &&
					!collision_line(x+lengthdir_x(90,Process[ProcessNum[PARTS_GUN]].image_angle+180),y+lengthdir_y(90,Process[ProcessNum[PARTS_GUN]].image_angle+180),
									x+lengthdir_x(550,Process[ProcessNum[PARTS_GUN]].image_angle+180),y+lengthdir_y(550,Process[ProcessNum[PARTS_GUN]].image_angle+180),
									objPlayerDoll,0,1)
				){
					MotionChange(WAIT,0,5); break;
				}
			}
			if( playerDistance>550){ MotionChange(WAIT,0,5); break; }
			break;
	}
}

/*-----ѓ̏--------------------*/
for(i=0;i<20;i+=1){
	with(Bullet[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 && other.Time < 999999){
				DamageVoiceRandom_Low();
				if(BINDED) addDamage(5, -1, -1, -1, -1, -1, -1);
				else{
					addDamage(5,DAMAGE_0, 0, 1, DOWN_1, 0, 2); 
					hspeed = other.hspeed/10;
				}
				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);
				}
				Fluid(x,y,COLOR_BLOOD,20,5,15,direction-5,10,0.5);

				sound_play(sndBulletHit);
				Quake(5,5);
				other.Time = 999999;

				with(objExtParts){
					with(DrawTarget){
						PartsDamage(other.id,-random(15),0);
						PartsBloodDamage(other.id,-random(15),0);
					}
				}

				with(other){ speed *= 0.8+random(0.2);gravity = 0.3; }
			}
		}
		if(Time){
			new = instance_create(x,y,objLine);
			new.xpos = x-hspeed;
			new.ypos = y-vspeed;
		}
	}
}