/*-----重力設定--------------------------*/
if( air ){
	gravity = global.G/5;
	gravity_direction = global.Gdir;
}else{
	gravity = 0;
	gravity_direction = 0;
	hspeed *= 0.5;
}

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

if(!ChangeMotion){
	switch(MotionNum){
		case MOVE :
			ElecCharge += 0.01;
			if(ElecCharge >= 1){
				for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ image_blend = make_color_hsv(0,0,150+random(105)); }
				ElecCharge = 1;
			}else{
				for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ image_blend = c_white; }
			}
			/* 相手の方を向く */
			if(objPlayerDoll.x > x){
				switch(KeyFrmNum){
					case 4 : if(KEYFRAME) hspeed = 4; break;
				}
			}else{
				switch(KeyFrmNum){
					case 4 : if(KEYFRAME) hspeed =-4; break;
				}
			}
			if(objPlayerDoll.y > y){
				switch(KeyFrmNum){
					case 4 : if(KEYFRAME) vspeed = -2; break;
				}
			}else{
				switch(KeyFrmNum){
					case 4 : if(KEYFRAME) vspeed = -10; break;
				}
			}

			if(ElecCharge == 1){
				col = collision_circle( x,y, 32,objPlayerDoll,0,1);
				/* プレーヤが下に居る */
				if(240<playerDirection && playerDirection<300 && objPlayerDoll.HEAD.image_alpha){
					with( col ){
						if(!INV && !BINDED){
							VoreVoiceRandom_Mid();
							Quake(25,25);
							with(other){
								startBind( col,BIND_CATCH,0,other.BINDED_JELLYFISH_CATCH,0,1 );
								MotionChange(CATCH,0,1);
								sound_play(sndVore02);
							}
							with(other){ ElecCharge=0; }
						}
					}
				/* プレーヤが下に居ない */
				}else{
					with( col ){
						if(!INV && !BINDED){
							DamageVoiceRandom_High();
							effect_create_below(ef_smokeup,x,y,2,c_black);
							Flash_Rect(c_white,1.2,0.05);
							Quake(25,25);
							addDamage(20, DOWN_1, 3, 2, DOWN_1, 3, 2);
							with(other){ ElecCharge=0; playEnemySound(SOUND_ELEC01); }
						}
					}
				}
			}

			break;

		/* ============ つかむ ============ */
		case CATCH : 
			gravity = 0;	/* とりあえず重力を切らないと落ちるし */
			vspeed *= 0.8;	/* かといって減速しないといつまでも上がる */

			/* 色を白に */
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ image_blend = c_white; }

			/* キャラより手前に */
			depth = objPlayerDoll.depth - 1000;
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ depth = other.depth - other.i*3; }


			switch(KeyFrmNum){
				/* 0〜3では上がる */
				case 0 : 
				case 1 : 
				case 2 : 
				case 3 : 
					vspeed = -5;
					break;
				/* 4以降はキャラの動きをもがきに変更 */
				case 5 :
					if(KEYFRAME){
						with(BindTarget){ MotionChange(BINDED_RAMDA,0,1); }
					}
					break;
			}

			/* 拘束解除処理 */
			if(BindTarget){
				if(!BindTarget.BINDED){
					ElecCharge = 0;
					MotionChange(MOVE,0,5);
					with(BindTarget){ MotionChange(STAND_0,0,2); }
					endBind();
					break;
				}
			}

			/* モーション終了時に電撃へ移行 */
			if(MOTIONEND){
				SpecialVoice(V_GYA,3);
				startBind( BindTarget,BIND_CATCH,0,BindTarget.BINDED_JELLYFISH_ELECTROSHOCK,0,1 );
				MotionChange(ELECTROSHOCK,0,1);
				loopEnemySound(SOUND_ELEC00);
				playEnemySound(SOUND_ELEC01);
				effect_create_below(ef_smokeup,x,y,2,c_black);
				Flash_Rect(c_white,random(1.1),0.02+random(0.5));
				Flash(c_white,random(1.1),0.02+random(0.5));
				Quake(10,10);
			}
			break;

		/* ============ 電撃 ============ */
		case ELECTROSHOCK : 
			addDamage(1, -1, -1, -1, -1, -1, -1);
			gravity = 0;	/* とりあえず重力を切らないと落ちるし */
			vspeed *= 0.8;	/* かといって減速しないといつまでも上がる */

			with(BindTarget){ MotionChange(BINDED_JELLYFISH_ELECTROSHOCK,round(random(5)),2); }
			if(random(100)<10) effect_create_below(ef_smokeup,x,y,2,c_black);
			if(random(100)<15) Flash_Rect(c_white,random(1.0),0.1+random(0.5));
			if(random(100)<15) Flash(c_white,random(1.0),0.1+random(0.5));
			if(random(100)<10) Quake(10,10);

			/* 色を明滅させる */
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ image_blend = make_color_hsv(0,0,150+random(105)); }

			/* キャラより手前に */
			depth = objPlayerDoll.depth - 1000;
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ depth = other.depth - other.i*3; }

			/* 拘束解除処理 */
			if(BindTarget){
				if(!BindTarget.BINDED){
					ElecCharge = 0;
					MotionChange(MOVE,0,5);
					with(BindTarget){ MotionChange(FLYING_0,0,2); }
					stopEnemySound(SOUND_ELEC00);
					endBind();
					break;
				}
			}

			/* しょうがねーないれてやんよ(*‘ω‘ *) */
			if(isGameOver()){
				if(random(100)<1) objCommon_Body.FluidBreak = true;
			}

			if(global.PlayerHP<-200){ 
				SpecialVoice(V_MUSE,round(random(2)));
				objCommon_Body.FluidBreak = true;
				with(BindTarget){ MotionChange(BINDED_JELLYFISH_ELECTROSHOCK,5,2); }
				MotionChange(FINISH,0,1);
				stopEnemySound(SOUND_ELEC00);
				sound_play(sndSteam);
			}
			break;
		/* ============ 電撃 ============ */
		case FINISH : 
			gravity = 0;	/* とりあえず重力を切らないと落ちるし */
			vspeed *= 0.8;	/* かといって減速しないといつまでも上がる */

			/* 色を白に */
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ image_blend = c_white; }

			/* キャラより手前に */
			depth = objPlayerDoll.depth - 1000;
			for(i=0;i<PARTS_MAX;i+=1) with(Draw[i]){ depth = other.depth - other.i*3; }

			if(random(100)<10) effect_create_below(ef_smokeup,x,y,1,c_black);
			if(random(100)<1){
				with(BindTarget){ if(KeyFrmNum>27) MotionChange(BINDED_JELLYFISH_ELECTROSHOCK,25,2); }
			}
			break;

		/* ============ 死亡モーション ============ */
		case DEAD_MOTION :
			if(MOTIONEND){
				effect_create_above(ef_explosion,x,y,1,c_white);
				Flash(c_white,0.1,0.05);
				Fluid(x,y,c_white,25,5,20,0,180,0.5);
				Quake(5,5);
				sound_play(sndFluid);
				instance_destroy();
			}
			break;
	}
}