/*-----d͐ݒ--------------------------*/
if( air ){
	gravity = global.G;
	gravity_direction = global.Gdir;
}else{
	gravity = 0;
	gravity_direction = 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̏--------------------*/
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(Bullet) ){ 
				if( 10 < playerDirection && playerDirection < 170){
					MotionChange(SHOT_UE,0,3);
				}else{
					MotionChange(SHOT_YOKO,0,5);
				}
				break;
			}
			break;
		case WALK :
			switch(KeyFrmNum){
				case 0 : if(place_free(x-3*Direction,y)) x -= 0.2*Direction; break;
				case 1 : if(place_free(x-3*Direction,y)) x -= 1.5*Direction; break;
				case 2 : if(place_free(x-3*Direction,y)) x -= 0.5*Direction; break;
				case 3 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						 if(place_free(x-3*Direction,y)) x -= 2.5*Direction; break;
				case 6 : if(place_free(x-3*Direction,y)) x -= 1.5*Direction; break;
				case 7 : if(place_free(x-3*Direction,y)) x -= 0.5*Direction; break;
				case 8 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						 if(place_free(x-3*Direction,y)) x -= 1.0*Direction; break;
				case 9 : if(place_free(x-3*Direction,y)) x -= 0.5*Direction; break;
			}
			/* ߂Â藣ꂽ肵~܂ */
			if( 100>playerDistance || playerDistance>350){ MotionChange(STAND,0,5); break; }

			/* ꍇɂĂ͌ */
			if( !air && 200>playerDistance && !instance_exists(Bullet) ){ 
				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(sndBullet2);

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

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

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

						/* 䰂̍쐬 */
						new = instance_create(x,y,objBulletCase);
						new.hspeed = (5+random(5))*Direction;
						new.vspeed = (-10-random(5));
						new.image_index = 1;
					}
					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(Bullet){
	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){
			DamageVoiceRandom_Low();
			if(BINDED) addDamage(10, -1, -1, -1, -1, -1, -1);
			else{
				addDamage(10,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;
	}
}