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

			/* 場合によっては撃つ */
			if( !objPlayerDoll.HALFBINDED && !air && 350>playerDistance && !instance_exists(Bullet) ){ 
				MotionChange(SHOT_NORMAL,0,10+random(50));
				break;
			}
			break;
		case WALK :
			switch(KeyFrmNum){
				case 1 : if(place_free(x-3*Direction,y)) x -= 0.2*Direction; break;
				case 2 : if(place_free(x-3*Direction,y)) x -= 2.5*Direction; break;
				case 3 : if(place_free(x-3*Direction,y)) x -= 5.5*Direction; break;
				case 4 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						 if(place_free(x-3*Direction,y)) x -= 1.5*Direction; break;
			}
			/* 近づきすぎたり離れたりしたら止まる */
			if( 100>playerDistance || playerDistance>550){ MotionChange(STAND,0,5); break; }

			/* 場合によっては撃つ */
			if( !objPlayerDoll.HALFBINDED && !air && 350>playerDistance && !instance_exists(Bullet) && random(100)<5 ){ 
				MotionChange(SHOT_NORMAL,0,5);
				break;
			}
			break;
		case SHOT_NORMAL :
			switch(KeyFrmNum){
				case 7 : 
					sound_play(sndVore03);
					if(!instance_exists(Bullet)){
						/* 弾の作成 */
						Fluid(x,y,c_white,5,15,10,30,10,0.5);
						Bullet = createBullet(x,y);
						Bullet.vspeed		= -10;
						Bullet.hspeed		= -40*Direction;
						Bullet.Picture		= SPRITE_BULLET;
					}
					break;
			}
			if(MOTIONEND) MotionChange(STAND,0,1);
			break;
		case SHOT_HARD :
			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){
	gravity = 2;
	image_angle = direction;
	image_alpha = 0.4;
	col = checkBlock(x,y);
	if( col ){
		sound_play(sndLotion);
		FluidwithLine(x,y-vspeed,c_white,10,5,10,0,180,0.5,col);
		destroyBullet();
	}
	col = checkPlayer(x,y);
	if( col ){
		with(col){
			if(!INV && !BINDED){
				DamageVoiceRandom_Low();
				sound_play(sndLotion);
				if(BINDED) addDamage(0, -1, -1, -1, -1, -1, -1);
				else{
					if(air){
						hspeed = other.hspeed/2;
						if(Direction){
							if(other.hspeed > 0) addSTDamage(5,20,FLYING_0, 0, 1, FLYING_0, 0, 2);
							else				 addSTDamage(5,20,FLYING_1, 0, 1, FLYING_1, 0, 2);
						}else{
							if(other.hspeed < 0) addSTDamage(5,20,FLYING_0, 0, 1, FLYING_0, 0, 2);
							else				 addSTDamage(5,20,FLYING_1, 0, 1, FLYING_1, 0, 2);
						}
					}else{
						if(!HALFBINDED){
							hspeed = other.hspeed/2;
							if(Direction){
								if(other.hspeed > 0){
									if(random(100)<50) addSTDamage(0,10,BINDED_FLUID_0, 0, 2, DOWN_1, 0, 2);
									else			   addSTDamage(0,10,BINDED_FLUID_1, 0, 2, DOWN_1, 0, 2);
								}else				 addSTDamage(0,10,BINDED_FLUID_2, 0, 2, DOWN_1, 0, 2);
							}else{
								if(other.hspeed < 0){
									if(random(100)<50) addSTDamage(0,10,BINDED_FLUID_0, 0, 2, DOWN_1, 0, 2);
									else			   addSTDamage(0,10,BINDED_FLUID_1, 0, 2, DOWN_1, 0, 2);
								}else				 addSTDamage(0,10,BINDED_FLUID_2, 0, 2, DOWN_1, 0, 2);
							}
						}else addSTDamage(0,10,null, null, null, null, null, null);
						HALFBINDED = true;
					}
				}
				sound_play(sndBulletHit);
				Quake(5,5);
				with(other){
					FluidwithLine(x,y-vspeed,c_white,20,5,10,0,180,0.5,col.Process[round(random(col.PARTS_MAX-1))]);
					destroyBullet();
				}
			}
		}
	}
	if(Time > 150) destroyBullet();
}