#TouhouDanmakufu
#Title[Jeromespell]
#Text[Miscria Sign:Forest Attack]
#BackGround[User(.\system\bg0.png, 0, 0)]
#Player[FREE]
#ScriptVersion[2]
//#Image[.\system\image.jpg]
#BGM[.\bgm\lunaticprincess.mp3]

script_enemy_main{
		
		#include_function".\function_cutin.txt";
		#include_function".\Halo.txt";
		
	let CSD = GetCurrentScriptDirectory;

	let imgBoss = CSD ~ "system\kaguyasprite.png";
	let cut = GetCurrentScriptDirectory ~ "system\kaguyacutin.png";
	let bg1 = CSD ~ "system\bg1.png";
	let bg2 = CSD ~ "system\bg2.png";
	let f = 0;
	let f2 = 0;
	let f3 = 0;
	let slide = 0;
	let hover = 0;
	let hovertrue = 0;
		
	@Initialize{
		SetLife(2000);
		SetScore(10000000);
		SetDamageRate(30,10);
		SetTimer(90);		
		SetInvincibility(150);		
		LoadGraphic(imgBoss);
		LoadGraphic(cut);
		LoadGraphic(bg1);
		LoadGraphic(bg2);
		LoadUserShotData(CSD ~ "ZUN's shotdata.txt");
		CreateAura03("ROSE",0,0,1.3,1.3,1.3);
		cutin("NAZRIN","Confusion Sign'Illusion Wave'",cut,0,5,600,439);
		
		mainTask;

	}

	@MainLoop{
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 32);
		
		yield;
	}

	@DrawLoop{
		
		SetTexture(imgBoss);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);		
		
		if(int(GetSpeedX())==0){
			if(f<3){SetGraphicRect(0,0,80,80);}
			f2=0;
			hovertrue=1;
		}
		
		if(GetSpeedX()>0){
			if(f2<3){SetGraphicRect(0,80,80,160);}
			if(f2>=3 && f2<6){SetGraphicRect(80,80,160,160);}
			if(f2>=6){SetGraphicRect(160,80,240,160);}
			f2++;		
			hovertrue=0;
		}
		if(GetSpeedX()<0){
			SetGraphicAngle(180,0,0);
			if(f2<3){SetGraphicRect(0,80,80,160);}
			if(f2>=3 && f2<6){SetGraphicRect(80,80,160,160);}
			if(f2>=6){SetGraphicRect(160,80,240,160);}
			f2++;		
			hovertrue=0;
		}
		if(hovertrue==1){hover++;}
		if(hovertrue==0){hover=0;}
		DrawGraphic(GetX,GetY+(8*sin(hover*3)));
	}

	@BackGround{
		SetTexture(bg2);
		SetGraphicRect(0,0,256,5000+slide);
		SetGraphicScale(1.75,1.75);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetCenterX,GetCenterY-(slide*2));
		
		slide+=0.5;
		SetTexture(bg1);
		SetGraphicRect(0,0,384,448);
		SetGraphicScale(1.5,1.01);
		SetGraphicAngle(0,0,0);
		DrawGraphic(GetCenterX,GetCenterY);		
	}

	@Finalize{
		DeleteGraphic(imgBoss);
		DeleteGraphic(cut);
		DeleteGraphic(bg1);
		DeleteGraphic(bg2);
		PlaySE(CSD ~ "sfx\se_bonus2.wav");
		CreateItem(ITEM_BOMB,GetEnemyX,GetEnemyY);
		PlaySE(CSD ~ "sfx\se_enep00_2.wav");
	}


	task mainTask{
		SetMovePosition03(GetCenterX,GetCenterY-100,10,2);
		wait(120);		
		yield;
		fire;
		//movement;
		wait(7020);
		loop(6){PlaySE(CSD ~ "sfx\se_timeout.wav");
		wait(60);}
		loop(5){PlaySE(CSD ~ "sfx\se_timeout2.wav");
		wait(60);}
	}

	task movement{
		loop{
			wait(180);
			SetMovePosition02(GetCenterX+rand(-120,120),GetCenterY-130,30);
			wait(60);
			yield;
		}
	}
		
	
	task fire{

		let x = 0;
		let dir = 0;
		let frame = 0;
		let aim = 0;
		let aim2 = 0;
		
		Concentration01(90);
		PlaySE(CSD ~ "sfx\charge.wav");
		wait(90);
		while(GetLife>=1200){
			aim = GetCenterX+rand(0,40);
			aim2 = GetCenterY-rand(225,245);
			PlaySE(CSD ~ "sfx\se_boon00.wav");		
		
		          
			ceiling1(aim-21,aim2,8.5,90,14,0);
			
			ceiling1(aim-22,aim2,8.5,90,14,0);
			
			ceiling1(aim-23,aim2,8.5,90,14,0);
		
			ceiling1(aim-24,aim2,8.5,90,14,0);
			
			ceiling1(aim-25,aim2,8.5,90,14,0);
			
			ceiling1(aim-26,aim2,8.5,90,14,0);
			
			ceiling1(aim-27,aim2,8.5,90,14,0);
			
			ceiling1(aim-28,aim2,8.5,90,14,0);
			
			ceiling1(aim-29,aim2,8.5,90,14,0);
			
			ceiling1(aim-210,aim2,8.5,90,14,0);
			
			ceiling1(aim-211,aim2,8.5,90,14,0);
			
			ceiling1(aim-212,aim2,8.5,90,14,0);
			
			ceiling1(aim-213,aim2,8.5,90,14,0);
			
			ceiling1(aim-214,aim2,8.5,90,14,0);
			
			ceiling1(aim-215,aim2,8.5,90,14,0);
			
			ceiling1(aim-216,aim2,8.5,90,14,0);
		
			ceiling1(aim-217,aim2,8.5,90,14,0);
			
			ceiling1(aim-218,aim2,8.5,90,14,0);
			
			ceiling1(aim-219,aim2,8.5,90,14,0);
			
			wait(GetLife/20+10);
			aim = GetCenterX+rand(-40,0);
			aim2 = GetCenterY-rand(225,245);
			PlaySE(CSD ~ "sfx\se_boon00.wav");			
		
			ceiling1(aim+21,aim2,8.5,90,14,0);
			
			ceiling1(aim+22,aim2,8.5,90,14,0);
			
			ceiling1(aim+23,aim2,8.5,90,14,0);
			
			ceiling1(aim+24,aim2,8.5,90,14,0);
			
			ceiling1(aim+25,aim2,8.5,90,14,0);
			
			ceiling1(aim+26,aim2,8.5,90,14,0);
			
			ceiling1(aim+27,aim2,8.5,90,14,0);
			
			ceiling1(aim+28,aim2,8.5,90,14,0);
			
			ceiling1(aim+29,aim2,8.5,90,14,0);
			
			ceiling1(aim+210,aim2,8.5,90,14,0);
			
			ceiling1(aim+211,aim2,8.5,90,14,0);
			
			ceiling1(aim+212,aim2,8.5,90,14,0);
			
			ceiling1(aim+213,aim2,8.5,90,14,0);
			
			ceiling1(aim+214,aim2,8.5,90,14,0);
			
			ceiling1(aim+215,aim2,8.5,90,14,0);
			
			ceiling1(aim+216,aim2,8.5,90,14,0);
			
			ceiling1(aim+217,aim2,8.5,90,14,0);
			
			ceiling1(aim+218,aim2,8.5,90,14,0);
			
			ceiling1(aim+219,aim2,8.5,90,14,0);
			
		
				wait(GetLife/20+10);
		}
		SetInvincibility(560);
		wait(200);
		DeleteEnemyShot(ALL);
		PlaySE(CSD ~ "sfx\se_power0.wav");	
		Concentration01(90);
		wait(90);
		loop{
		aim = GetCenterX-240+rand(0,8);
		aim2 = GetCenterY-rand(220,230);
		ceiling2(aim+16,aim2,1.75,90,46,0);
		ceiling2(aim+16,aim2,1.75,90,46,0);
		ceiling2(aim+32,aim2,1.75,90,46,0);
		ceiling2(aim+32,aim2,1.75,90,46,0);
		ceiling2(aim+48,aim2,1.75,90,46,0);
		ceiling2(aim+48,aim2,1.75,90,46,0);
		ceiling2(aim+64,aim2,1.75,90,46,0);
		ceiling2(aim+64,aim2,1.75,90,46,0);
		ceiling2(aim+80,aim2,1.75,90,46,0);
		ceiling2(aim+80,aim2,1.75,90,46,0);
		ceiling2(aim+96,aim2,1.75,90,46,0);
		ceiling2(aim+96,aim2,1.75,90,46,0);
		ceiling2(aim+112,aim2,1.75,90,46,0);
		ceiling2(aim+112,aim2,1.75,90,46,0);
		ceiling2(aim+128,aim2,1.75,90,46,0);
		ceiling2(aim+128,aim2,1.75,90,46,0);
		ceiling2(aim+144,aim2,1.75,90,46,0);
		ceiling2(aim+144,aim2,1.75,90,46,0);
		ceiling2(aim+160,aim2,1.75,90,46,0);
		ceiling2(aim+160,aim2,1.75,90,46,0);
		ceiling2(aim+176,aim2,1.75,90,46,0);
		ceiling2(aim+176,aim2,1.75,90,46,0);
		ceiling2(aim+192,aim2,1.75,60,46,0);
		ceiling2(aim+192,aim2,1.75,90,46,0);
		ceiling2(aim+208,aim2,1.75,90,46,0);
		ceiling2(aim+208,aim2,1.75,90,46,0);
		ceiling2(aim+224,aim2,1.75,90,46,0);
		ceiling2(aim+224,aim2,1.75,90,46,0);
		ceiling2(aim+240,aim2,1.75,90,46,0);
		ceiling2(aim+240,aim2,1.75,90,46,0);
		ceiling2(aim+256,aim2,1.75,90,46,0);
		ceiling2(aim+256,aim2,1.75,90,46,0);
		ceiling2(aim+272,aim2,1.75,90,46,0);
		ceiling2(aim+272,aim2,1.75,90,46,0);
		ceiling2(aim+288,aim2,1.75,90,46,0);
		ceiling2(aim+288,aim2,1.75,90,46,0);
		ceiling2(aim+304,aim2,1.75,90,46,0);
		ceiling2(aim+304,aim2,1.75,90,46,0);
		ceiling2(aim+320,aim2,1.75,90,46,0);
		ceiling2(aim+320,aim2,1.75,90,46,0);
		ceiling2(aim+336,aim2,1.75,90,46,0);
		ceiling2(aim+336,aim2,1.75,90,46,0);
		ceiling2(aim+352,aim2,1.75,90,46,0);
		ceiling2(aim+352,aim2,1.75,90,46,0);
		ceiling2(aim+368,aim2,1.75,90,46,0);
		ceiling2(aim+368,aim2,1.75,90,46,0);
		ceiling2(aim+384,aim2,1.75,90,46,0);
		ceiling2(aim+384,aim2,1.75,90,46,0);
		ceiling2(aim+400,aim2,1.75,90,46,0);
		ceiling2(aim+400,aim2,1.75,90,46,0);
		ceiling2(aim+416,aim2,1.75,90,46,0);
		ceiling2(aim+416,aim2,1.75,90,46,0);
		ceiling2(aim+432,aim2,1.75,90,46,0);
		ceiling2(aim+432,aim2,1.75,90,46,0);
		ceiling2(aim+448,aim2,1.75,90,46,0);
		ceiling2(aim+448,aim2,1.75,90,46,0);
		ceiling2(aim+464,aim2,1.75,90,46,0);
		ceiling2(aim+464,aim2,1.75,90,46,0);
		ceiling2(aim+480,aim2,1.75,90,46,0);
		ceiling2(aim+480,aim2,1.75,90,46,0);
		ceiling2(aim+496,aim2,1.75,90,46,0);
                                ceiling2(aim+496,aim2,1.75,90,46,0);
		
		wait(GetLife/5+110);}
		yield;
	}		
	
	task ceiling1(x,y,v,dir,graphic,delay){
			let obj = Obj_Create(OBJ_SHOT);
			
			Obj_SetPosition(obj,x,y);
			Obj_SetSpeed(obj,v);
			Obj_SetAngle(obj,dir);
			ObjShot_SetGraphic(obj,graphic);
			ObjShot_SetDelay(obj,delay);
			ObjShot_SetBombResist(obj,true);
						
			while(!Obj_BeDeleted(obj)){
				let color = rand_int(33,48);

			PlaySE(CSD ~ "sfx\se_kira00.wav");
				ceiling12(Obj_GetX(obj),Obj_GetY(obj),1,90+rand(-360,360),color,0);
				wait(12);		
			}
			Obj_Delete(obj);
			yield;			
	}
	
	task ceiling12(x,y,v,dir,graphic,delay){
			let obj = Obj_Create(OBJ_SHOT);
			
			Obj_SetPosition(obj,x,y);
			Obj_SetSpeed(obj,v);
			Obj_SetAngle(obj,dir);
			ObjShot_SetGraphic(obj,graphic);
			ObjShot_SetDelay(obj,delay);
			ObjShot_SetBombResist(obj,false);
						
			wait(175);
			ObjShot_SetDelay(obj,5);
			wait(5);
			Obj_Delete(obj);
			yield;			
	}
	
	task ceiling2(x,y,v,dir,graphic,delay){
			let obj = Obj_Create(OBJ_SHOT);
			
			Obj_SetPosition(obj,x,y);
			Obj_SetSpeed(obj,v);
			Obj_SetAngle(obj,dir);
			ObjShot_SetGraphic(obj,graphic);
			ObjShot_SetDelay(obj,delay);
			ObjShot_SetBombResist(obj,true);
						
			loop(4){
				let color = rand_int(33,48);
				PlaySE(CSD ~ "sfx\se_kira00.wav");
				CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),5);
				// (id,time,speed,dir,dir-velocity,accel,maxspeed,graphic)
				SetShotDataA(1,0,0,60,0,0,0,color);
				SetShotDataA(1,60,0,rand(0,360),0,1.65,1,color);
				FireShot(1);
				wait(15);			
			}
			PlaySE(CSD ~ "sfx\se_ch02.wav");
			loop(1){
				let color = rand_int(33,48);
				
				PlaySE(CSD ~ "sfx\se_kira00.wav");
				CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),5);
				// (id,time,speed,dir,dir-velocity,accel,maxspeed,graphic)
				SetShotDataA(1,0,0,60,0,0,0,color);
				SetShotDataA(1,60,0,rand(0,360),0,1,1.95,color);
				FireShot(1);
				wait(100);			
			}
			PlaySE(CSD ~ "sfx\se_enep02.wav");
			CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),0);
			SetShotDataA_XY(1,0,rand(-5,5),rand(-15,-1.85),0,0.25,0.81,1.5,19);
			FireShot(1);
			Obj_Delete(obj);
			yield;			
	}
	
	function wait(w){
		loop(w){yield;}
	}
}