/*-----重力設定--------------------------*/
GSet(global.G,global.Gdir,1,1, 0,0,0.3,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){
	if(!ChangeMotion){
		switch(MotionNum){
			case STAND :
			case DODGE :
				MotionChange(DODGE,1,2);
				break;
			default :
				Fluid(x, y,make_color_rgb(163,73,164),5,0,5,90,360,0.75);
				playEnemySound(SOUND_DAMAGE);
				break;
		}
	}
}

INV = 0;
if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			INV = 1;

			/* 相手の方を向く */
			if(objPlayerDoll.x > x) Direction = Right;
			else Direction = Left;

			/* 近づいたら歩く */
			if( !air && 100<playerDistance && playerDistance<350){
				switch(irandom(1)){
					case 0: MotionChange(JUMPATTACK,0,5); break;
					case 1: MotionChange(TACKLE,0,5);     break;
				}
			}
			break;

		case JUMPATTACK:
			switch(KeyFrmNum){
				case  1 : HitFlag = 0; break;
				case  5 : 
				case  6 : 
					if(HitFlag) Fluid(Process[PARTS_HAND_ABOVE].x, Process[PARTS_HAND_ABOVE].y-24,COLOR_BLOOD,15,0,5,90,Direction*-180,1.0);
					if(KEYFRAME && !HitFlag){
						with( collision_circle( Process[PARTS_HAND_ABOVE].x, Process[PARTS_HAND_ABOVE].y+64, 64,objPlayerDoll,0,1) ){
							if(!INV && !BINDED){
								with(other){ HitFlag = 1; }
								if(Direction!=other.Direction)	addDamage(30,DOWN_1, 0, 2, DOWN_1, 0, 2);
								else							addDamage(30,DOWN_1, 0, 2, DOWN_1, 0, 2);
								hspeed = -10*other.Direction*-1;
								sound_play(sndHit02);
								Quake(15,15);

								if(global.PlayerHP>0) DamageVoiceRandom_Mid();
								else{
									Macro_CutHead();
									with(other){ playEnemySound(SOUND_HEAD); }
								}
							}
						}
					}
					break;
			}

			switch(KeyFrmNum){
				case  3 : Move(-30.0*Direction,0); break;
				case  4 : Move(-30.0*Direction,0); break;
				case  5 : if(KEYFRAME){ playEnemySound(SOUND_STEP); sound_play(sndSwing01); }
						  Move(-15.5*Direction,0);
				case  6 : Move(-10.5*Direction,0); break;
				case  7 : Move(- 8.5*Direction,0); break;
				case  8 : Move(- 6.5*Direction,0); break;
				case  9 : Move(- 4.5*Direction,0); break;
			}
			if(MOTIONEND) MotionChange(STAND,0,5);
			break;
		case TACKLE:
			switch(KeyFrmNum){
				case 1 : HitFlag = 0; break;
				case 3 : 
				case 4 : 
				case 5 : 
					if(!HitFlag){
						DepthSet(objPlayerDoll.depth - 1000);
						with( collision_circle( x,y+48, 24,objPlayerDoll,0,1) ){
							other.HitFlag = 1;
							if(!INV && !BINDED){
								sound_play(sndHit00);
								Quake(15,15);
								HitStop(5,null);
								if(Direction!=other.Direction)	addDamage(20,FLYING_0, 0, 1, FLYING_0, 0, 2);
								else							addDamage(20,FLYING_1, 0, 1, FLYING_1, 0, 2);
								if(global.PlayerHP<0 && objPlayerDoll.HEAD.image_alpha){
									VoreVoiceRandom_Mid();
									with(other){
										if(Direction!=other.Direction)	startBind( objPlayerDoll,0,BIND_TACKLE_FINISH,other.BINDED_SLIME_MEDIUM_ATTACKHIT,0,1 );
										else							startBind( objPlayerDoll,0,BIND_TACKLE_FINISH,other.BINDED_SLIME_MEDIUM_ATTACKHIT2,3,1 );
										MotionChange(TACKLE_FINISH,0,1);
									}
								}else{
									DamageVoiceRandom_High();
									hspeed = 50*other.Direction*-1;
									vspeed = -6;
								}
							}
						}
					}
					break;
			}
			switch(KeyFrmNum){
				case  3 : Move(-50.0*Direction,0); break;
				case  4 : Move(-40.0*Direction,0); break;
				case  5 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-15.5*Direction,0); break;
				case  6 : Move(-10.5*Direction,0); break;
				case  7 : Move(- 8.5*Direction,0); break;
				case  8 : Move(- 6.5*Direction,0); break;
				case  9 : Move(- 4.5*Direction,0); break;
			}
			if(MOTIONEND) MotionChange(STAND,0,5);
			break;
		case TACKLE_FINISH:
			DepthSet(objPlayerDoll.depth + 1000);
			Process[PARTS_BODYTOP    ].depth = objPlayerDoll.depth - 1000;
			Process[PARTS_BODYBOTTOM ].depth = objPlayerDoll.depth - 1001;
			Process[PARTS_ARM1_ABOVE ].depth = objPlayerDoll.depth - 1006;
			Process[PARTS_ARM2_ABOVE ].depth = objPlayerDoll.depth - 1007;
			Process[PARTS_HAND_ABOVE ].depth = objPlayerDoll.depth - 1008;
			Process[PARTS_LEG1_ABOVE ].depth = objPlayerDoll.depth - 1002;
			Process[PARTS_LEG2_ABOVE ].depth = objPlayerDoll.depth - 1003;
			Process[PARTS_FOOT1_ABOVE].depth = objPlayerDoll.depth - 1004;
			Process[PARTS_FOOT2_ABOVE].depth = objPlayerDoll.depth - 1005;

			switch(KeyFrmNum){
				case 1 :Move(-20.0*Direction,0); break;
				case 2 :Move(-10.0*Direction,0); break;
				case 3 :Move(- 5.0*Direction,0); break;
				case 4 :Move(- 2.0*Direction,0); break;
				case 7 :
					Flash(c_red,0.7,0.1);
					Quake(10,10);
					if(KEYFRAME){
						DamageVoiceRandom_High();
						SpecialVoice(V_MUSE,0);
						with( objPlayerDoll ){
							PartsDamage(objCommon_Body,-100,0);
							PartsBloodDamage(objCommon_Body,-100,0);
							PartsBloodDamage(objCommon_Head,-100,0);
						}
						sound_play(sndGusha);
						if(Direction!=objPlayerDoll.Direction)	with( objPlayerDoll ){ MotionChange(DEATHPRESS_DOWN_0,0,1); }
						else									with( objPlayerDoll ){ MotionChange(DEATHPRESS_DOWN_1,3,1); }
					}
					break;
				case 8 : Fluid(Process[PARTS_HAND_BELOW].x, Process[PARTS_HAND_BELOW].y-24,COLOR_BLOOD,15,5,15,70,40,1.0);
				case 12 :
					Quake(10,10);
					if(KEYFRAME){
						with( objPlayerDoll ){
							DamageVoiceRandom_Low();
							PartsDamage(objCommon_Body,-100,0);
							PartsBloodDamage(objCommon_Body,-100,0);
							PartsBloodDamage(objCommon_Head,-100,0);
						}
						playEnemySound(SOUND_HEAD);
						if(Direction!=objPlayerDoll.Direction)	with( objPlayerDoll ){ MotionChange(DEATHPRESS_DOWN_0,0,1); }
						else									with( objPlayerDoll ){ MotionChange(DEATHPRESS_DOWN_1,3,1); }
					}
					break;
				case 13 :
				case 14 :
					Fluid(Process[PARTS_HAND_BELOW].x-32*Direction,Process[PARTS_HAND_BELOW].y,COLOR_BLOOD,5,0,5,0,360,0.5);
					break;
			}
			if(MOTIONEND) MotionChange(STAND_WAIT,0,5);
			break;
		case DODGE:
			INV = 1;
			switch(KeyFrmNum){
				case  1 : Move(-60.0*Direction,0); break;
				case  2 : Move(-50.0*Direction,0); if(KEYFRAME) playEnemySound(SOUND_STEP); break;
				case  3 : Move(-40.0*Direction,0); break;
				case  4 : Move(-10.0*Direction,0); break;
			}

			if(Direction!=objPlayerDoll.Direction){
				if( (Direction && objPlayerDoll.x>x+16) || (!Direction && objPlayerDoll.x<x-16) ){
					Direction = objPlayerDoll.Direction;
					MotionChange(TACKLE,0,1);     break;
				}
			}

			if(MOTIONEND) MotionChange(STAND,0,1);
			break;
		case DEAD_MOTION :
			if(KeyFrmNum==1 && KEYFRAME){
				sound_play(sndHit02);
				Fluid(x,y,make_color_rgb(163,73,164),35,5,20,0,180,0.5);
				Quake(5,5);
			}
			if(MOTIONEND){
				effect_create_above(ef_explosion,Process[PARTS_BODYTOP].x,Process[PARTS_BODYTOP].y,1,make_color_rgb(163,73,164));
				Flash(c_white,0.1,0.05);
				Fluid(Process[PARTS_BODYTOP].x,Process[PARTS_BODYTOP].y-64,make_color_rgb(163,73,164),35,5,20,0,180,0.5);
				Quake(5,5);
				sound_play(sndFluid);
				instance_destroy();
			}
			break;
	}
}