/*-----重力設定--------------------------*/
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_TOGE1 ]].depth	= objPlayerDoll.depth - 1001;
			Process[ProcessNum[PARTS_TOGE3 ]].depth	= objPlayerDoll.depth - 1002;
			Process[ProcessNum[PARTS_TOGE5 ]].depth	= objPlayerDoll.depth - 1003;
			Process[ProcessNum[PARTS_TOGE7 ]].depth	= objPlayerDoll.depth - 1004;
			Process[ProcessNum[PARTS_TOGE9]].depth	= objPlayerDoll.depth - 1005;
			Process[ProcessNum[PARTS_TOGE13]].depth	= objPlayerDoll.depth - 1006;
			Process[ProcessNum[PARTS_TOGE15]].depth	= objPlayerDoll.depth - 1007;
			Process[ProcessNum[PARTS_BODY  ]].depth	= objPlayerDoll.depth - 1008;
			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()){
								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 :
			with(BindTarget){
				Fluid(BODY_TOP.x+32,BODY_TOP.y+20,COLOR_BLOOD,irandom(2),0,2,80,20,0.5);
				Fluid(BODY_TOP.x-16,BODY_TOP.y   ,COLOR_BLOOD,irandom(2),0,2,80,20,0.5);
			}
			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;
	}
}