/*-----d͐ݒ--------------------------*/
if( air ){
	gravity = global.G;
	gravity_direction = global.Gdir;
}else{
	gravity = 0;
	gravity_direction = 0;
	hspeed *= 0.3;
}

with(objEnemyEdit){ if(Edit_Play) exit; }

/*-----LN^Ƃ̏̎擾---------------*/
playerDistance = point_distance(x,y,objPlayerDoll.x,objPlayerDoll.y);
playerDirection = point_direction(x,y,objPlayerDoll.x,objPlayerDoll.y);

/*-----[V̏--------------------*/
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( !place_free(x-96*Direction,y)) MotionChange(TACKLE,0,2);
					else MotionChange(PUNCH,0,2);
				}

				/* ߂Â */
				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 : if(place_free(x-7*Direction,y)) x -= 1.0*Direction; break;
				case  2 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  if(place_free(x-7*Direction,y)) x -= 2.0*Direction; break;
				case  3 : if(place_free(x-7*Direction,y)) x -= 6.5*Direction; break;
				case  4 : if(place_free(x-7*Direction,y)) x -= 1.0*Direction; break;
				case  5 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  if(place_free(x-7*Direction,y)) x -= 2.0*Direction; break;
				case  6 : if(place_free(x-7*Direction,y)) x -= 6.5*Direction; break;
			}

			/* ߂Â牣 */
			if( !objPlayerDoll.BINDED && 150>playerDistance ){ MotionChange(PUNCH,2,2); break; }

			if( !objPlayerDoll.BINDED && 250>playerDistance ){
				if(random(100)<2){ MotionChange(RUN,0,2);    break; }
				if(random(100)<2){ 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 RUN :
			switch(KeyFrmNum){
				case  1 : if(place_free(x-30*Direction,y)) x -= 10.0*Direction; break;
				case  2 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  if(place_free(x-30*Direction,y)) x -= 15.0*Direction; break;
				case  3 : if(place_free(x-30*Direction,y)) x -= 30.5*Direction; break;
				case  4 : if(place_free(x-30*Direction,y)) x -= 10.0*Direction; break;
				case  5 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  if(place_free(x-30*Direction,y)) x -= 15.0*Direction; break;
				case  6 : if(place_free(x-30*Direction,y)) x -= 30.5*Direction; 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 : if(place_free(x-30*Direction,y)) x -= 15.0*Direction; sound_play(sndSwing00);
				case 5 : if(place_free(x-30*Direction,y)) x -= 20.0*Direction;
					if(KEYFRAME){
						depth = objPlayerDoll.depth - 1000;
						for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ depth = other.depth - other.i*3; }
						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 : if(place_free(x-30*Direction,y)) x -= 10.0*Direction; break;
				case 7 : if(place_free(x-30*Direction,y)) x -=  5.0*Direction; break;
				case 8 : if(place_free(x-30*Direction,y)) x -=  2.0*Direction; break;
				case 9 : if(place_free(x-30*Direction,y)) x -=  1.0*Direction; 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){
						depth = objPlayerDoll.depth - 1000;
						for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ depth = other.depth - other.i*3; }
						with( collision_circle( x,y+48, 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 : if(place_free(x-50*Direction,y)) x -= 60.0*Direction; break;
				case  4 : if(place_free(x-50*Direction,y)) x -= 50.0*Direction; break;
				case  5 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  if(place_free(x-50*Direction,y)) x -= 25.0*Direction; break;
				case  6 : if(place_free(x-50*Direction,y)) x -= 15.0*Direction; break;
				case  7 : if(place_free(x-50*Direction,y)) x -=  5.0*Direction; break;
				case  8 : if(place_free(x-50*Direction,y)) x -=  2.0*Direction; break;
				case  9 : if(place_free(x-50*Direction,y)) x -=  1.0*Direction; 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;
				}
			}

			depth = objPlayerDoll.depth - 1000;
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ depth = other.depth - other.i*3; }
			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(10,null);
								}else if(random(100)<50) HitStop(6,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 : if(place_free(x-50*Direction,y)) x -= 30.0*Direction; break;
				case  2 : if(place_free(x-50*Direction,y)) x -= 20.0*Direction; break;
				case  3 : if(KEYFRAME) playEnemySound(SOUND_STEP);
						  if(place_free(x-50*Direction,y)) x -= 15.0*Direction; break;
				case  4 : if(place_free(x-50*Direction,y)) x -=  5.0*Direction; break;
				case  5 : if(place_free(x-50*Direction,y)) x -=  1.0*Direction; break;
			}
			if(MOTIONEND){
				MotionChange(MOUNTPUNCH,5,1);
				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;
	}
}