/*-----重力設定--------------------------*/
if( place_free(x,y+1) ){
	air = true;
	gravity = 0.9;
	gravity_direction = 270;
}else{
	air = false;
	speed = 0;
	gravity = 0;
	gravity_direction = 0;
}

/*-----拘束解除時-------------------------*/
BIND_CHECK(0,0,2);

/*-----パーツサイズ初期化-------------------*/
for(p=0;p<partsize;p+=1) with(Parts[p]){
	image_xscale=1;image_yscale=1;
};

/*-----キャラクタとの情報の取得---------------*/
distance = point_distance(x,y,objPlayer.x,objPlayer.y);
dir = point_direction(x,y,objPlayer.x,objPlayer.y);
/*-----モーション毎の処理--------------------*/
image_xscale =  1;
Parts[1].image_index =  PLUG_ANIMATION;
Parts[2].image_index =  ELEC_ANIMATION;
switch(motion){
	case 0 :	/* ----------通常待機---------- */
	case 1 :	/* ----------通常待機---------- */
	case 2 :	/* ----------通常待機---------- */
	case 3 :	/* ----------通常待機---------- */
	case 4 :	/* ----------通常待機---------- */
	case 5 :	/* ----------通常待機---------- */
	case 6 :	/* ----------通常待機---------- */
		switch(round(dir/30)){
			case 0 : if(motion!=0) force_motion(0,0,5);break;
			case 1 : if(motion!=1) force_motion(1,0,5);break;
			case 2 : if(motion!=2) force_motion(2,0,5);break;
			case 3 : if(motion!=3) force_motion(3,0,5);break;
			case 4 : if(motion!=4) force_motion(4,0,5);break;
			case 5 : if(motion!=5) force_motion(5,0,5);break;
			case 6 : if(motion!=6) force_motion(6,0,5);break;
		}

		switch(MOVE_MODE){
			case TARGET : 
				/* 近づいたら歩く */
				if( 100 < distance && distance<400 ){
					if(!SOUND_FLAG) sound_play(sndMecha);
					SOUND_FLAG = 1;
					/* 相手の方を向く */
					if(objPlayer.x > x){
						MOVE((distance-100)/20 );
					}else{
						MOVE((-distance+100)/20 );
					}
				}else SOUND_FLAG = 0;
				break;
			case RUNAWAY : 
				/* 遠くまで逃げる */
				if( distance<300 ){
					if(!SOUND_FLAG) sound_play(sndMecha);
					SOUND_FLAG = 1;
					/* 相手の方を向く */
					if(objPlayer.x < x){
						MOVE((300-distance)/20 );
					}else{
						MOVE((-300+distance)/20 );
					}
				}else SOUND_FLAG = 0;
				break;
		}
		if(per(1)){
			SOUND_FLAG = 0;
			switch(MOVE_MODE){
				case TARGET : MOVE_MODE = RUNAWAY; break;
				case RUNAWAY : MOVE_MODE = TARGET; break;
			}
		}

		ELEC_ANIMATION = 0;
		if(distance <120 && !force_change ) PLUG_ANIMATION+=0.5;
		else PLUG_ANIMATION-=0.3;
		if(PLUG_ANIMATION<0) PLUG_ANIMATION = 0;
		if(PLUG_ANIMATION>=9){
			PLUG_ANIMATION = 9;
			ELEC_ANIMATION = random(5);
			if(BIND_ABLE()){
				check = collision_enemy(x+lengthdir_x(128,Parts[1].angle),y+lengthdir_y(128,Parts[1].angle),40,20,0,-1,2,5,150);
				if(check){
					if(per(50)) sound_play(sndHit07);
					else sound_play(sndHit08);
					quake(20,5);
					flash(c_white,0.5,0.01);
				}
			}
		}
		break;
}