/*-----重力設定--------------------------*/
GSet(global.G,global.Gdir,0.1,1,0,0.95,1,1);

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);
}

switch(MotionNum){
	case STAND :
		break;
}

if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			if(playerDistance<80 && !isGameOver()) MotionChange(TOGETTER,0,1);
			if(MOTIONEND){
				if(random(100)<30) MotionChange(ROLLING,0,5);
			}
			break;
		case ROLLING :
			if(playerDistance<80 && !isGameOver()) MotionChange(TOGETTER,0,1);
			switch(KeyFrmNum){
				case 1: if(Move(- 1.0*Direction,0)) Direction = Direction*-1; break;
				case 2: if(Move(- 2.0*Direction,0)) Direction = Direction*-1; break;
				case 3: if(Move(- 4.0*Direction,0)) Direction = Direction*-1; break;
				case 4: if(Move(- 7.0*Direction,0)) Direction = Direction*-1; break;
				case 5: if(Move(- 1.0*Direction,0)) Direction = Direction*-1; break;
				case 6: if(Move(- 0.1*Direction,0)) Direction = Direction*-1; break;
			}
			if(MOTIONEND){
				if(random(100)<30) MotionChange(STAND,0,5);
			}
			break;
		case TOGETTER :
			Process[ProcessNum[PARTS_TOGE0]].depth	= objPlayerDoll.depth + 1000;
			Process[ProcessNum[PARTS_TOGE1]].depth	= objPlayerDoll.depth - 1000;
			Process[ProcessNum[PARTS_BODY ]].depth	= objPlayerDoll.depth - 1001;
			switch(KeyFrmNum){
				case 3:
					if(KEYFRAME){
						with( collision_circle( x,y,80,objPlayerDoll,0,1) ){
							addDamage(25,DOWN_1, 0, 2, DOWN_1, 0, 2);
							PartsDamage(objExtParts,	  -50,0);
							PartsBloodDamage(objExtParts,-100,0);
							Fluid(x-40+random(80),y,COLOR_BLOOD,10,2,20,85,10,0.5);
							Flash(c_red,0.2,0.05);
							sound_play(sndHit02);
							Quake(25,5);
							if(x>other.x) hspeed = 10;
							else		  hspeed =-10;
							if(isGameOver() && !BINDED){
								with(other){
									if(x > other.x){
										if(Direction != other.Direction) startBind( objPlayerDoll,BIND_CATCH,0,other.BINDED_UNIX_FINISH ,0,1 );
										else							 startBind( objPlayerDoll,BIND_CATCH,0,other.BINDED_UNIX_FINISH2,0,1 );
									}else{
										if(Direction != other.Direction) startBind( objPlayerDoll,BIND_CATCH,0,other.BINDED_UNIX_FINISH2,0,1 );
										else							 startBind( objPlayerDoll,BIND_CATCH,0,other.BINDED_UNIX_FINISH ,0,1 );
									}
									MotionChange(TOGETTERFINISH,0,1);
									SpecialVoice(V_OE,irandom(5));
									Quake(35,15);
								}
								break;
							}else DamageVoiceRandom_Low();
						}
					}
			}
			if(MOTIONEND) MotionChange(ROLLING,0,5);
			break;
		case TOGETTERFINISH :
			Process[ProcessNum[PARTS_TOGE0]].depth	= objPlayerDoll.depth + 1000;
			Process[ProcessNum[PARTS_TOGE1]].depth	= objPlayerDoll.depth - 1000;
			Process[ProcessNum[PARTS_BODY ]].depth	= objPlayerDoll.depth - 1001;
			with(BindTarget){
				FluidWithScale(BODY_TOP.x+32,BODY_TOP.y+20,COLOR_BLOOD,irandom(2),0,2,80,20,0.5,1,depth-1);
				FluidWithScale(BODY_TOP.x-16,BODY_TOP.y   ,COLOR_BLOOD,irandom(2),0,2,80,20,0.5,1,depth-1);
			}
			if(MOTIONEND){
				endBind();
				MotionChange(STAND,0,5);
			}
			break;
		case DEAD_MOTION :
			if(KeyFrmNum==1 && KEYFRAME){
				sound_play(sndHit02);
				Fluid(x,y,make_color_rgb(128,128,100),35,5,20,0,180,0.5);
				Quake(5,5);
			}
			if(MOTIONEND){
				effect_create_above(ef_explosion,x,y,1,make_color_rgb(163,73,164));
				Flash(c_white,0.1,0.05);
				Fluid(x,y,make_color_rgb(128,128,100),35,5,20,0,180,0.5);
				Quake(5,5);
				sound_play(sndFluid);
				instance_destroy();
			}
			break;
	}
}