/*-----重力設定--------------------------*/
if( place_free(x,y+1) ){
	air = true;
	gravity = 10;
	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);

/*-----モーション毎の処理--------------------*/
switch(motion){
	case 0 :	/* ----------通常待機---------- */
		/* 相手の方を向く */
		if(objPlayer.x > x) image_xscale = -1;
		else image_xscale =  1;

		/* 近づいたら歩く */
		if( 10<distance && distance<400 ){ force_motion(4,0,5); break; }

		/* 攻撃遷移 */
		if( distance<150 && per(10) ){ force_motion(7,0,3); break; }
		if( distance<200 && per(10) ){ force_motion(6,0,5); break; }
		if( distance<200 && per(1) ){ force_motion(5,0,5); break; }
		break;
	case 1 :	/* ----------弱ダメージ---------- */
		break;
	case 2 :	/* ----------中ダメージ---------- */
		break;
	case 3 :	/* ----------強ダメージ---------- */
		/* ノックバック */
		switch(number){
			case 1 : 
			case 2 : 
				if( KEYFRAME && per(30) ) force_motion(5,4,5);
				MOVE(image_xscale*3,0);
				break;
			case 3 : 
			case 4 : 
				MOVE(image_xscale*2,0);
				break;
			case 4 : 
			case 5 : 
				MOVE(image_xscale*1,0);
				break;
		}
		break;
	case 4 :	/* ----------歩き---------- */
		/* 近づきすぎたり離れたりしたら止まる */
		if( 10>distance || distance>400){ force_motion(0,0,5); break; }

		/* 攻撃遷移 */
		if( distance<150 && per(10) ){ force_motion(7,0,3); break; }
		if( distance<200 && per(10) ){ force_motion(6,0,5); break; }
		if( distance<200 && per(1) ){ force_motion(5,0,5); break; }

		switch(number){
			case 1 : 
			case 2 : 
				MOVE(-image_xscale*3,0);
				break;
			case 5 : 
			case 6 : 
				MOVE(-image_xscale*2,0);
				break;
			case 0 : 
			case 4 :
				MOVE(-image_xscale*1,0);
				break;
		}
		break;
	case 5 :	/* ----------鞭A---------- */
		switch(number){
			case 6 : 
			case 7 : MOVE(-image_xscale*5,0); break;
			case 8 : MOVE(-image_xscale*10,0); break;
			case 9 : 
				if(KEYFRAME){
					sound_play(sndHit06);
					if( BIND_ABLE() ){
						check = collision_enemy(Parts[11].x,Parts[11].y,96,15,rev_angle(image_xscale,0),-1,2,40,5);
						if(check){
							sound_play(sndHit04);
							quake(20,5);
							flash(c_red,0.5,0.1);
						}
					}
				}
				break;
		}
		break;
	case 6 :	/* ----------鞭B---------- */
		switch(number){
			case 2 : MOVE(-image_xscale*5,0); break;
			case 3 : MOVE(-image_xscale*10,0); break;
			case 4 :
				if(KEYFRAME){
					sound_play(sndHit06);
					if( BIND_ABLE() ){
						check = collision_enemy(Parts[11].x,Parts[11].y,96,15,rev_angle(image_xscale,0),-1,1,10,5);
						if(check){
							sound_play(sndHit04);
							quake(20,5);
							flash(c_red,0.5,0.1);
						}
					}
				}
				break;
		}
		break;
	case 7 :	/* ----------叩きつけつかみ---------- */
		switch(number){
			case 4 :
				if(KEYFRAME){
					sound_play(sndHit06);
					if( BIND_ABLE() ){
						tmp = objPlayer.image_xscale;
						check = collision_enemy(Parts[11].x,Parts[11].y,96,15,rev_angle(image_xscale,0),-1,1,10,5);
						if(check){
							sound_play(sndHit03);
							quake(20,5);
							flash(c_red,0.5,0.1);
							BIND_ON();
							switch(floor(random(2))){
								case 1 :
									force_other_motion(objPlayer,DAMAGE_PLANT[2],0,1);
									force_motion(10,0,1);
									objPlayer.image_xscale = tmp;
									break;
								default : 
									force_other_motion(objPlayer,DAMAGE_PLANT[0],0,1);
									force_motion(8,0,1);
									objPlayer.image_xscale = image_xscale;
									break;
							}
						}
					}
				}
				break;
		}
		break;
	case 8 :	/* ----------叩きつけ---------- */
		BIND_POSITION(12);
		switch(number){
			case  7 :
				if(KEYFRAME && per(50) ){
					force_other_motion(objPlayer,DAMAGE_PLANT[1],0,1);
					force_motion(9,0,1);
				}
				break;
			case 14 :
				if(KEYFRAME){
					collision_enemy(x,y,500,0,0,NULL,0,10,0);
					if( per(30) ){
						with(objHead){ Blood(x,y,5,0.2,0.1,250,40,0,5,c_red); }
						with(objBody_Bottom){ event_user(0); }
					}
					sound_play(sndHit04);
					quake(40,10);
					flash(c_red,0.2,0.1);
					if(per(10)){
						BIND_OFF();
						collision_enemy(x,y,1000,15,rev_angle(image_xscale,90),-2,0,10,10);
						force_motion(0,0,3);
					}
				}
				break;
		}
		break;
	case 9 :	/* ----------叩きつけ---------- */
		BIND_POSITION(12);
		switch(number){
			case 3 :
				if(KEYFRAME){
					collision_enemy(x,y,500,0,0,NULL,0,10,0);
					if( per(30) ){
						with(objHead){ Blood(x,y,5,0.2,0.1,250,40,0,5,c_red); }
						with(objBody_Bottom){ event_user(0); }
					}
					sound_play(sndHit04);
					quake(40,10);
					flash(c_red,0.2,0.1);
					if(per(10)){
						BIND_OFF();
						collision_enemy(x,y,1000,15,rev_angle(image_xscale,90),-2,0,10,10);
						force_motion(0,0,3);
					}
				}
				break;
		}
		break;
	case 10 :	/* ----------締め上げ---------- */
		if(number == 6 && KEYFRAME && objPlayer.image_xscale == image_xscale && per(80)){
			force_other_motion(objPlayer,DAMAGE_PLANT[4],0,1);
			force_motion(12,0,1);
			break;
		}

		BIND_POSITION(12,0,-38);
		Parts[10].depth_mode = true; Parts[10].depth = objPlayer.depth+1;
		Parts[11].depth_mode = true; Parts[11].depth = objPlayer.depth+1;
		with(objPlayer){
			Parts[4].depth_mode = true; Parts[4].depth = other.depth-1;
			Parts[5].depth_mode = true; Parts[5].depth = other.depth-1;
			Parts[8].depth_mode = true; Parts[8].depth = other.depth-1;
		}
		Parts[12].image_xscale= 1 + 0.2*random(1);

		if( random(100)<1 ){
			switch(floor(random(4))){
				case 0 : force_other_motion(objPlayer,DAMAGE_PLANT[2],10,1);break;
				case 1 : force_other_motion(objPlayer,DAMAGE_PLANT[2],15,1);break;
				case 2 : force_other_motion(objPlayer,DAMAGE_PLANT[2],17,1);break;
				case 3 : force_other_motion(objPlayer,DAMAGE_PLANT[2],20,1);break;
			}
			quake(20,5);
			with(objBody_Top){ event_user(0); }
			with(objHead){ Blood(x,y,15,0.01,0.1,80,20,2,2,c_white); }
			if(objPlayer.HP<0) with(objHead){ Blood(x,y,5,0.1,0.1,80,20,3,2,c_red); }
		}
		if(number>7) quake(1,5);
		objPlayer.HP -= 1.075;
		if(objPlayer.HP<0){
			objPlayer.HP = -100;
			force_motion(11,0,2);
			force_other_motion(objPlayer,DAMAGE_PLANT[3],0,2);
			quake(60,20);
			flash(c_red,0.5,0.1);
			with(objBody_Bottom){ event_user(0); }
		}
		break;
	case 11 : /* ----------締め上げフィニッシュ---------- */
		objPlayer.RECOVER = 0;
		objPlayer.HP = -100;
		BIND_POSITION(12,0,-45);
		Parts[10].depth_mode = true; Parts[10].depth = objPlayer.depth+1;
		Parts[11].depth_mode = true; Parts[11].depth = objPlayer.depth+1;
		with(objPlayer){
			Parts[4].depth_mode = true; Parts[4].depth = other.depth-1;
			Parts[5].depth_mode = true; Parts[5].depth = other.depth-1;
			Parts[8].depth_mode = true; Parts[8].depth = other.depth-1;
		}
		if(number < 12) Parts[12].image_xscale= 1 + 0.1*random(1);
		else Parts[12].image_xscale= 1;
		switch(number){
			case  1 :
			case  2 :
			case  3 :
			case  4 :
				if( per(5) ) with(objBody_Bottom){ event_user(0); }
				break;
			case 12 :
			case 13 :
			case 14 :
				if( per(2) ) force_other_motion(objPlayer,DAMAGE_PLANT[3],20,1);
				break;
			case 17 :
				if(KEYFRAME){
					BIND_OFF();
					collision_enemy(x,y,1000,30,rev_angle(image_xscale,250),-2,0,10,10);
				}
				break;
		}
		break;
	case 12 :	/* ----------吸血---------- */
		BIND_POSITION(12,0,-38);
		Parts[10].depth_mode = true; Parts[10].depth = objPlayer.depth+1;
		Parts[11].depth_mode = true; Parts[11].depth = objPlayer.depth+1;
		with(objPlayer){
			Parts[4].depth_mode = true; Parts[4].depth = other.depth-1;
			Parts[5].depth_mode = true; Parts[5].depth = other.depth-1;
			Parts[8].depth_mode = true; Parts[8].depth = other.depth-1;
		}
		Parts[12].image_xscale= 1 + 0.2*random(1);

		switch(number){
			case  5 :
				if(KEYFRAME){
					flash(c_red,0.2,0.01);
					quake(20,5);
					sound_play(sndGoku01);
				}
				break;
			case 10 :
				if(KEYFRAME){
					flash(c_red,0.5,0.1);
					with(objHead){ Blood(x,y,15,0.1,0.1,80,20,3,2,c_red); }
					objPlayer.HP -= 15;
					quake(20,5);
					sound_play(sndGoku03);
				}
				break;
		}

		objPlayer.RECOVER = 0;
		if(objPlayer.HP<0){
			objPlayer.HP = -100;
			sound_play(sndFluid);
			sound_play(sndGoku01);
			force_motion(13,0,2);
			force_other_motion(objPlayer,DAMAGE_PLANT[3],15,2);
			quake(60,20);
			flash(c_red,0.5,0.05);
		}
		break;
	case 13 :	/* ----------吸血抜き---------- */
		BIND_POSITION(12,0,-38);
		with(objHead){ Blood(x,y,2,0.1,0.3,80,20,3,2,c_red); }
		Parts[10].depth_mode = true; Parts[10].depth = objPlayer.depth+1;
		Parts[11].depth_mode = true; Parts[11].depth = objPlayer.depth+1;
		break;
}