#TouhouDanmakufu
#Title[Secret Relic 'Inverted Bowl Hat']
#TextSecret Relic 'Inverted Bowl Hat'""]
#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;
	let fam1 = CSD ~ "SC3Familiar1.txt";
	let fam2 = CSD ~ "SC3Familiar2.txt";
	let fam3 = CSD ~ "SC3Familiar3.txt";
	let bgm = CSD ~ "bgm\lunaticprincess.mp3";
		
	@Initialize{
		SetLife(2500);
		SetScore(10000000);
		SetDamageRate(40,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","Secret Relic 'Inverted Bowl Hat'",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);
		FadeOutMusic(bgm,50);
		PlaySE(CSD ~ "sfx\se_bonus2.wav");
		CreateItem(ITEM_1UP,GetEnemyX,GetEnemyY);
		PlaySE(CSD ~ "sfx\se_enep00_2.wav");
	}

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

	task movement{
		wait(240);
		loop{
			wait(300);
			SetMovePosition03(GetCenterX+75,GetCenterY-180,10,2);
			wait(120);
			wait(300);
			SetMovePosition03(GetCenterX-75,GetCenterY-180,10,2);
			wait(120);
			yield;
		}
	}
	
	task lasers{
		let y = 0;
		let dir2 = 0;
		let color2 = 187;
		loop{
		if(GetPlayerY<GetCenterY-30 && GetTimeOfPlayerInvincibility==0){
		PlaySE(CSD ~ "sfx\se_tan00.wav");
		PlaySE(CSD ~ "sfx\se_kira00.wav");
		PlaySE(CSD ~ "sfx\se_lazer00.wav");
		while(y<24){
		CreateLaser01(GetEnemyX,GetEnemyY,4,dir2+GetAngleToPlayer,90,20,color2,1);
                                CreateLaser01(GetEnemyX,GetEnemyY,4,dir2+GetAngleToPlayer,90,20,color2,1);
                                CreateLaser01(GetEnemyX,GetEnemyY,4,dir2+GetAngleToPlayer,90,20,color2,1);
		y++;
		dir2+=360/8;
		color2++;
		if(color2>194){color2=187;}
		}
		y=0;
		dir2=0;
		}
		wait(10);
		}
		yield;
	}
	
	task waterfall{
		loop{
		PlaySE(CSD ~ "sfx\se_tan00_2.wav");
		water(GetCenterX+rand(-15,15),GetCenterY-225,4,90+rand(-0,0),rand_int(33,48),10);
		wait(1);}
		yield;
	}
	
	task toss{
		wait(270);
		loop{
		PlaySE(CSD ~ "sfx\se_boon00.wav");
		splash(GetEnemyX+rand(-25,25),GetEnemyY,1.5,90+rand(-0,0),31,2);
		wait(200);}
		yield;
	}		
	
	task fire{
		let x = 0;
		let dir = 0;
		let frame = 0;
		PlaySE(CSD ~ "sfx\charge.wav");
		Concentration01(90);
		wait(90);
		PlaySE(CSD ~ "sfx\se_option.wav");
		PlaySE(CSD ~ "sfx\se_boon01.wav");
		CreateEnemyFromFile(fam1,GetCenterX-210,GetCenterY-30,0,0,0);
		CreateEnemyFromFile(fam2,GetCenterX,GetCenterY+110,0,0,0);
		CreateEnemyFromFile(fam3,GetCenterX,GetCenterY+110,0,0,0);
		wait(160);
		PlaySE(CSD ~ "sfx\se_ch02.wav");
		SetMovePosition03(GetCenterX-75,GetCenterY-180,10,1);
		Concentration01(60);
		wait(60);
		lasers;
		waterfall;
		wait(10);
		PlaySE(CSD ~ "sfx\se_gosp.wav");
		toss;
		movement;
		loop{
                                 CreateShotA(1,GetCenterX+rand(-255,255),GetCenterY-48,22);
		SetShotDataA_XY(1,125,rand(-0.5,0.5),rand(-0.5,-0.5),0,0.03,0,1.5,rand_int(33,48));
		
		
		FireShot(1);
		wait(1.1);}
		
		yield;
	}		
	
	task water(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);
			
			wait(56);
			Obj_Delete(obj);			
			yield;			
	}
	
	task splash(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)){				
				if(Obj_GetY(obj) > GetCenterY-45){
					PlaySE(CSD ~ "sfx\se_don00.wav");
					PlaySE(CSD ~ "sfx\se_water.wav");
					loop(30){
					CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),0);
					SetShotDataA_XY(1,1,rand(-1.15,1.15),rand(-4,-7),0,0.1,0,1.55,193);
					FireShot(1);}
					Obj_Delete(obj);
				}				
				yield;
			}
	}
	
	
	
	function wait(w){
		loop(w){yield;}
	}
}