#TouhouDanmakufu
#Title[Morinku1]
#Text[Nonspell 1]
#BackGround[User(.\system\bg0.png, 0, 0)]
#Player[FREE]
#ScriptVersion[2]
//#Image[.\system\image.jpg]

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 time = 120;
	let bgm = CSD ~ "bgm\lunaticprincess.mp3";
		
	@Initialize{
		SetLife(2500);
		//SetScore(10000000);
		SetDamageRate(80,50);
		SetTimer(65);		
		SetInvincibility(90);		
		LoadGraphic(imgBoss);
		LoadGraphic(cut);
		LoadGraphic(bg1);
		LoadGraphic(bg2);
		PlayMusic(bgm);
		LoadUserShotData(CSD ~ "ZUN's shotdata.txt");
		//CreateAura03(color,style,effect,flameX,flameY,originScale)
		CreateAura03("ROSE",0,1,1.3,1.3,1.3);
		//cutin("NAZRIN","New Impossible Request 'Precious Hourai Jewel'",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_enep00_2.wav");
	}


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

	task movement{
		loop{
			
			wait(50);
			SetMovePositionRandom01(30,10,1.5,GetPlayerX-30,GetCenterY-130,GetPlayerX+30,GetCenterY-110);
			wait(50);
			yield;
		}
	}	
		
	task fire{

		let x = 0;
		let dir = 0;
		let frame = 0;
		let speed = 4;
		let lowspeed = 2;
		
		Concentration01(60);
		PlaySE(CSD ~ "sfx\se_ch02.wav");			
		wait(60);
		//SetPlayerInvincibility(100000);
		loop{						
			loop(6){
			loop(7){
			PlaySE(CSD ~ "sfx\se_tan00_2.wav");
			while(x<10){
				CreateShotA(1,GetEnemyX,GetEnemyY,20);
				// (id,time,speed,dir,dir-velocity,accel,maxspeed,graphic)				
				SetShotDataA(1,0,2,dir,1.5,-0.04,0,148);
				SetShotDataA(1,0,2,dir,1.5,-0.04,0,148);
				SetShotDataA(1,90,NULL,NULL,0,0.1,1.75,148);
                                                               SetShotDataA(1,0,2,dir,1.5,-0.04,0,148);
				SetShotDataA(1,0,2,dir,1.5,-0.04,0,148);
				SetShotDataA(1,90,NULL,NULL,0,0.1,1.75,148);
				FireShot(1);				
				dir+=360/9;
				x++;				
			}
			x = 0;
			while(x<10){
				CreateShotA(1,GetEnemyX,GetEnemyY,20);
				// (id,time,speed,dir,dir-velocity,accel,maxspeed,graphic)				
				SetShotDataA(1,0,2,-dir,-1.5,-0.04,0,149);
				SetShotDataA(1,0,2,-dir,-1.5,-0.04,0,149);
				SetShotDataA(1,90,NULL,NULL,0,0.1,1.75,149);
                                                                SetShotDataA(1,0,2,-dir,-1.5,-0.04,0,149);
				SetShotDataA(1,0,2,-dir,-1.5,-0.04,0,149);
				SetShotDataA(1,90,NULL,NULL,0,0.1,1.75,149);
				FireShot(1);				
				dir+=360/9;
				x++;	
					
			}
			x = 0;
			dir += 1;
			wait(4);}
			dir += rand(10,30);}
			PlaySE(CSD ~ "sfx\se_tan00.wav");
			while(speed>lowspeed){
				CreateShot01(GetEnemyX,GetEnemyY,speed,GetAngleToPlayer-0,151,30);
				CreateShot01(GetEnemyX,GetEnemyY,speed,GetAngleToPlayer-1,151,30);
                                                                CreateShot01(GetEnemyX,GetEnemyY,speed,GetAngleToPlayer-0,151,30);
				CreateShot01(GetEnemyX,GetEnemyY,speed,GetAngleToPlayer-1,151,30);
                                                                CreateShot01(GetEnemyX,GetEnemyY,speed,GetAngleToPlayer-0,151,30);
				CreateShot01(GetEnemyX,GetEnemyY,speed,GetAngleToPlayer-1,151,30);
                                                                CreateShot01(GetEnemyX,GetEnemyY,speed,GetAngleToPlayer-0,151,30);
				CreateShot01(GetEnemyX,GetEnemyY,speed,GetAngleToPlayer-1,151,30);
				speed+= -0.3;
			}
			speed = 4;
			lowspeed += -0.04;
		}
		yield;
	}		
	
	//object bullet task
	task reflect(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) < GetClipMinY){
					PlaySE(CSD ~ "sfx\se_kira00.wav");
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,-dir,139,30);
					Obj_Delete(obj);
				}
				
				if(Obj_GetY(obj) > GetClipMaxY){
					PlaySE(CSD ~ "sfx\se_kira00.wav");
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,-dir,139,30);
					Obj_Delete(obj);
				}
				
				
				if(Obj_GetX(obj) > GetClipMaxX){
					PlaySE(CSD ~ "sfx\se_kira00.wav");
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,-dir+180,139,30);
					Obj_Delete(obj);
				}
				
				if(Obj_GetX(obj) < GetClipMinX){
					PlaySE(CSD ~ "sfx\se_kira00.wav");
					CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2,-dir-180,139,30);
					Obj_Delete(obj);
				}
				
				yield;
			}
			
			
	}
	
	function wait(w){
		loop(w){yield;}
	}
}