/*-----重力設定--------------------------*/
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){
	Fluid(x, y,make_color_rgb(163,73,164),5,0,5,90,360,0.75);
	playEnemySound(SOUND_DAMAGE);
	if(!ChangeMotion){
		/* 相手の方を向く */
		if(objPlayerDoll.x > x) Direction = Right;
		else Direction = Left;
		switch(MotionNum){
			case STAND :
				MotionChange(RUN,0,2);
				break;
			case WALK :
				MotionChange(RUN,0,2);
				break;
		}
	}
}

if(!ChangeMotion){
	switch(MotionNum){
		case STAND :
			/* 相手の方を向く */
			if(objPlayerDoll.x > x) Direction = Right;
			else Direction = Left;

			if(!isGameOver()){
				/* 近づいたら殴る */
				if( 150>playerDistance ){
					if(random(100)<5){ MotionChange(TACKLE,0,2); break; }
					if(random(100)<2){ MotionChange(PUNCH,0,2);  break; }
				}

				/* 近づいたら歩く */
				if( !air && playerDistance<450 && abs(objPlayerDoll.y-y)<200){ MotionChange(WALK,0,5); break; }
			}else{
				if(!objPlayerDoll.BINDED && random(200)<1){
					MotionChange(TACKLE,0,2);
				}
			}
			break;
		case WALK :
			switch(KeyFrmNum){
				case  1 : Move(-1.0*Direction,0); break;
				case  2 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-2.0*Direction,0); break;
				case  3 : Move(-6.5*Direction,0); break;
				case  4 : Move(-1.0*Direction,0); break;
				case  5 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-2.0*Direction,0); break;
				case  6 : Move(-6.5*Direction,0); break;
			}

			if( !objPlayerDoll.BINDED && 250>playerDistance ){
				if(random(100)<2){ MotionChange(RUN,0,2);    break; }
				if(random(100)<4){ MotionChange(TACKLE,0,2); break; }
			}
			/* 近づいたら殴る */
			if( !objPlayerDoll.BINDED && 150>playerDistance ){ MotionChange(PUNCH,2,2); break; }

			/* 相手の方を向く */
			if(objPlayerDoll.x > x){
				if(Direction != Right) MotionChange(STAND,0,5); break;
			}else{
				if(Direction != Left)  MotionChange(STAND,0,5); break;
			}
			break;

		case RUN :
			switch(KeyFrmNum){
				case  1 : Move(-10.0*Direction,0); break;
				case  2 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-15.0*Direction,0); break;
				case  3 : Move(-30.5*Direction,0); break;
				case  4 : Move(-10.0*Direction,0); break;
				case  5 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-15.0*Direction,0); break;
				case  6 : Move(-30.5*Direction,0); break;
			}

			/* 近づいたら殴る */
			if( 100>playerDistance ){ MotionChange(PUNCH,2,2); break; }

			if( 350>playerDistance && 100<playerDistance ){
				if(random(100)<10){ MotionChange(TACKLE,0,2); break; }
			}

			/* 相手の方を向く */
			if(objPlayerDoll.x > x){
				if(Direction != Right) MotionChange(STAND,0,5); break;
			}else{
				if(Direction != Left)  MotionChange(STAND,0,5); break;
			}
			break;

		case PUNCH :
			switch(KeyFrmNum){
				case 3 : HitFlag = 0; break;
				case 4 : Move(-15.0*Direction,0); sound_play(sndSwing00);
				case 5 : Move(-20.0*Direction,0);
					if(KEYFRAME){
						DepthSet(objPlayerDoll.depth - 1000);
						with( collision_circle( Process[PARTS_ATKARM3].x, Process[PARTS_ATKARM3].y, 48,objPlayerDoll,0,1) ){
							if(!INV && !BINDED){
								with(other){
									HitFlag = 1;
									Fluid(Process[PARTS_ATKARM3].x+Direction*64, Process[PARTS_ATKARM3].y,COLOR_BLOOD,35,5,20,90,Direction*-180,1.0);
									sound_play(sndGusha);
								}
								DamageVoiceRandom_High();
								if(BINDED){
									if(Direction!=other.Direction)	addDamage(20, -1, -1, -1, -1, -1, -1);
									else							addDamage(20, -1, -1, -1, -1, -1, -1);
								}else{
									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);
									hspeed = 60*other.Direction*-1;
									vspeed = -6;
								}
								sound_play(sndHit00);
								Quake(30,5);
								HitStop(5,null);
							}
						}
					}
					break;
				case 6 : Move(-10.0*Direction,0); break;
				case 7 : Move(- 5.0*Direction,0); break;
				case 8 : Move(- 2.0*Direction,0); break;
				case 9 : Move(- 1.0*Direction,0); break;
			}
			if(MOTIONEND){
				if(HitFlag) MotionChange(RUN,0,1);
				else        MotionChange(STAND,0,1);
			}
			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-Direction*100,y,48,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(objPlayerDoll.HEAD.image_alpha){
									VoreVoiceRandom_Mid();
									with(other){
										if(Direction!=other.Direction)	startBind( objPlayerDoll,0,BIND_MOUNTPUNCH,other.BINDED_MOUNT_MOUNTPUNCH ,0,1 );
										else							startBind( objPlayerDoll,0,BIND_MOUNTPUNCH,other.BINDED_MOUNT_MOUNTPUNCH2,0,1 );
										MotionChange(MOUNTPUNCH,0,1);
									}
								}else{
									hspeed = 50*other.Direction*-1;
									vspeed = -6;
								}
							}
						}
					}
					break;
			}
			switch(KeyFrmNum){
				case  3 : Move(-60.0*Direction,0); break;
				case  4 : Move(-50.0*Direction,0); break;
				case  5 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-25.0*Direction,0); break;
				case  6 : Move(-15.0*Direction,0); break;
				case  7 : Move(- 5.0*Direction,0); break;
				case  8 : Move(- 2.0*Direction,0); break;
				case  9 : Move(- 1.0*Direction,0); break;
			}
			if(MOTIONEND) MotionChange(STAND,0,2);
			break;

		case MOUNTPUNCH:
			if(BindTarget){
				if(!BindTarget.BINDED){
					MotionChange(STAND,0,5);
					with(BindTarget){ MotionChange(DOWN_0,0,2); }
					endBind();
					break;
				}
			}

			DepthSet(objPlayerDoll.depth - 1000);
			Process[PARTS_FHAND_BELOW ].depth = objPlayerDoll.depth + 1000;
			Process[PARTS_FTHUMB_BELOW].depth = objPlayerDoll.depth + 1001;
			Process[PARTS_FARM2_BELOW ].depth = objPlayerDoll.depth + 1002;
			Process[PARTS_FARM1_BELOW ].depth = objPlayerDoll.depth + 1003;

			switch(KeyFrmNum){
				case 10:
				case 17:
					if(KEYFRAME){
						with(BindTarget){
							with(other){
								Fluid(x-Direction*96,y+48,COLOR_BLOOD,5,5,10,70,40,1.0);
								if(random(100)<10){
									sound_play(sndGusha);
									Fluid(x-Direction*96,y+48,COLOR_BLOOD,25,5,20,70,40,1.0);
									HitStop(12,null);
								}else if(random(100)<50) HitStop(8,null);
							}
							if(global.PlayerHP){
								switch(irandom(2)){
									case 0 : DamageVoiceRandom_Low();  break;
									case 1 : DamageVoiceRandom_Mid();  break;
									case 2 : DamageVoiceRandom_High(); break;
								}
							}else{
								if(random(100)<100+global.PlayerHP*0.25){
									switch(irandom(1)){
										case 0 : DamageVoiceRandom_Low();  break;
										case 1 : DamageVoiceRandom_Mid();  break;
									}
								}
							}
							PartsDamage(objCommon_Head,		-100,0);
							PartsBloodDamage(objCommon_Head,-100,0);
							if(Direction!=other.Direction){
								switch(irandom(6)){
									case 0 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH, 12, 1, BINDED_MOUNT_MOUNTPUNCH, 12, 1); break;
									case 1 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH, 18, 1, BINDED_MOUNT_MOUNTPUNCH, 18, 1); break;
									case 2 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH, 24, 1, BINDED_MOUNT_MOUNTPUNCH, 24, 1); break;
									case 3 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH, 27, 1, BINDED_MOUNT_MOUNTPUNCH, 27, 1); break;
									case 4 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH, 30, 1, BINDED_MOUNT_MOUNTPUNCH, 30, 1); break;
									case 5 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH, 33, 1, BINDED_MOUNT_MOUNTPUNCH, 33, 1); break;
									case 6 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH, 36, 1, BINDED_MOUNT_MOUNTPUNCH, 36, 1); break;
								}
							}else{
								switch(irandom(2)){
									case 0 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH2,  8, 1, BINDED_MOUNT_MOUNTPUNCH2,  8, 1); break;
									case 1 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH2, 11, 1, BINDED_MOUNT_MOUNTPUNCH2, 11, 1); break;
									case 2 : addDamage(6,BINDED_MOUNT_MOUNTPUNCH2, 14, 1, BINDED_MOUNT_MOUNTPUNCH2, 14, 1); break;
								}
							}
							sound_play(sndHit00);
							Quake(20,2);
						}
					}
					break;
			}
			switch(KeyFrmNum){
				case  1 : Move(-30.0*Direction,0); break;
				case  2 : Move(-20.0*Direction,0); break;
				case  3 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  Move(-15.0*Direction,0); break;
				case  4 : Move(- 5.0*Direction,0); break;
				case  5 : Move(- 1.0*Direction,0); break;
			}
			if(MOTIONEND){
				MotionChange(MOUNTPUNCH,5,1+random(2));
				if(global.PlayerHP<0 && random(100)<10){
					MotionChange(STAND,0,5);
					if(Direction!=objPlayerDoll.Direction)	with( objPlayerDoll ){ MotionChange(DEATHPRESS_DOWN_0,0,1); }
					else									with( objPlayerDoll ){ MotionChange(DEATHPRESS_DOWN_1,3,1); }
					endBind();
				}
			}
			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,x,y,1,make_color_rgb(163,73,164));
				Flash(c_white,0.1,0.05);
				Fluid(x,y-64,make_color_rgb(163,73,164),35,5,20,0,180,0.5);
				Quake(5,5);
				sound_play(sndFluid);
				instance_destroy();
			}
			break;
	}
}