#TouhouDanmakufu
#Title[Non Spell 3 - Easy]

#Text[Non Spell 3]

#Player[REIMU]
#PlayLevel[Easy]

#ScriptVersion[2]


script_enemy_main{


	let D = GetCurrentScriptDirectory;


	let imgBoss = D ~ "system\Youmu.png";
	let bg = D ~ "system\trees nighttime.png";

	let shot = D ~ "ZUN's shotdata.txt";
	let s1 = D ~ "sfx\Shot.wav";
	let s2 = D ~ "sfx\Wave.wav";
	let d1 = D ~ "sfx\Damage00.wav";
	let d2 = D ~ "sfx\Damage01.wav";
	let t1 = D ~ "sfx\t1.wav";
	let t2 = D ~ "sfx\t2.wav";
	let c1 = D ~ "sfx\Power0.wav";
	let alph1 = 255;
	let slide = 0;
	let slide2 = 0;

	let f = 0;
	let f2 = 0;
	@Initialize{

		SetLife(4000);

		SetTimer(40);
		SetEnemyMarker(true);
		SetInvincibility(140);
		LoadGraphic(bg);

		LoadGraphic(imgBoss);
   		LoadUserShotData(shot);
		LoadSE(s1);
		LoadSE(s2);
		LoadSE(d1);
		LoadSE(d2);
		LoadSE(t1);
		LoadSE(t2);
		LoadSE(c1);
		damage;
		timeout;
		maintask;
	}


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

	@DrawLoop{
		SetTexture(imgBoss);
		SetRenderState(ALPHA);
		SetAlpha(255);
		SetGraphicScale(1,1);
		SetGraphicAngle(0,0,0);
		if(int(GetSpeedX())==0){
			if(f<10){ SetGraphicRect(256,100,304,160); }
			if(f>=10 && f<20){ SetGraphicRect(304,100,352,160); }
			if(f>=20 && f<30){ SetGraphicRect(352,100,400,160);  }
			if(f>=30 && f<40){ SetGraphicRect(400,100,448,160);}
			f2 = 0;
		}
		if(GetSpeedX()>0){
			SetGraphicAngle(180,0,0);
			if(f2<7){ SetGraphicRect(256,160,304,224); }
			if(f2>=7 && f2<14){ SetGraphicRect(304,160,352,224); }
			if(f2>=14 && f2<21){ SetGraphicRect(352,160,400,224); }
			if(f2>=21){ SetGraphicRect(400,160,448,224); }
			f2++;
		}
		if(GetSpeedX()<0){
			if(f2<7){ SetGraphicRect(256,160,304,224); }
			if(f2>=7 && f2<14){ SetGraphicRect(304,160,352,224); }
			if(f2>=14 && f2<21){ SetGraphicRect(352,160,400,224); }
			if(f2>=21){ SetGraphicRect(400,160,448,224); }
			f2++;
		}
		DrawGraphic(GetX,GetY);
		f++;
		f2++;
		if(f==40){f=0;}
		DrawText("Youmu Konpaku",GetCenterX-123,GetCenterY-205,14,alph1);
	
}


	@BackGround{

		SetTexture(bg);

		SetRenderState(ALPHA);

		SetAlpha(255);
	
		SetGraphicRect(0,0,10000,10000);

		SetGraphicScale(1,1);

		SetGraphicAngle(0,0,0);

		DrawGraphic(GetCenterX-slide2,GetCenterY+slide);
	//slide+=2;	
	//slide2-=1; 
	}


	@Finalize{
		DeleteGraphic(bg);
		DeleteSE(s1);
		DeleteSE(s2);
		DeleteSE(d1);
		DeleteSE(d2);
		DeleteSE(t1);
		DeleteSE(t2);
	}



task maintask{
	move;
	wait(90);
	loop{
		wait(60);
		phase1;
		wait(90);
		move;
		wait(160);
		phase1b;
		wait(120);
		move;
		wait(120);
		phase3;
	loop(3){
		phase2;
		wait(90);
	}
		move;
	loop(4){
		phase2;
		wait(40);
	}
		wait(60);
		move;
	}
}
	task damage{
		loop{
		let bosslife = GetLife;
		wait(3);
			if(GetLife < 600 && GetLife > 300 && bosslife > GetLife){PlaySE(d1);}
			if(GetLife < 300 && GetLife > 0 && bosslife > GetLife){PlaySE(d2);}
		}
	}
	task timeout{
		loop{
	if(GetTimer == 10 || GetTimer == 9 || GetTimer == 8 || GetTimer == 7 || GetTimer == 6 || GetTimer == 5 || GetTimer == 4){PlaySE(t1);}
	if(GetTimer == 3 || GetTimer == 2 || GetTimer == 1){PlaySE(t2);}
		wait(60);}
	}
	task move{
		SetMovePosition03(GetCenterX-rand(-70,70),GetCenterY-rand(20,70),8,2); 
	}
task phase1{
	let dir =GetAngleToPlayer;
	let dir2 =GetAngleToPlayer;
	let dir3 = GetAngleToPlayer;
	let dir4 =GetAngleToPlayer;
	let woah = 1;
		loop(8){
			loop(woah){
				b(GetX+160*cos(dir),GetY+120*sin(dir),2.5,dir3,82,40);
				b(GetX+160*cos(dir),GetY+120*sin(dir),2.5,dir4,82,40);
				b(GetX+160*cos(dir2),GetY+120*sin(dir2),2.5,dir3,82,40);
				b(GetX+160*cos(dir2),GetY+120*sin(dir2),2.5,dir4,82,40);
			dir3+=25;
			dir4-=25;
			}
		dir3-=woah*25;
		dir4+=woah*25;
		PlaySE(s1);
		dir+=360/16;
		dir2-=360/16;
		if(woah < 14.4){woah+=1;}
		wait(7);
		}
	dir =GetAngleToPlayer;
	dir2 =GetAngleToPlayer;
	dir3 = GetAngleToPlayer;
	dir4 =GetAngleToPlayer;
		loop(8){
			loop(woah){
				b(GetX+160*cos(dir),GetY-240+120*sin(dir),2.5,dir3,82,40);
				b(GetX+160*cos(dir),GetY-240+120*sin(dir),2.5,dir4,82,40);
				b(GetX+160*cos(dir2),GetY-240+120*sin(dir2),2.5,dir3,82,40);
				b(GetX+160*cos(dir2),GetY-240+120*sin(dir2),2.5,dir4,82,40);
			dir3+=25;
			dir4-=25;
			}
		dir3-=woah*25;
		dir4+=woah*25;
		PlaySE(s1);
		dir+=360/16;
		dir2-=360/16;
		if(woah < 14.4){woah+=1;}
		wait(7);
		} 
	wait(120);
	dir = GetAngleToPlayer;
	dir2 = GetAngleToPlayer;
	dir3 = GetAngleToPlayer;
	dir4 =GetAngleToPlayer;
	woah = 0;
}

task phase1b{
	let dir =GetAngleToPlayer;
	let dir2 =GetAngleToPlayer;
	let dir3 = GetAngleToPlayer;
	let dir4 =GetAngleToPlayer;
	let woah = 1;
		loop(8){
			loop(woah){
				b(GetX+160*cos(dir),GetY+120*sin(dir),2.5,dir3,86,40);
				b(GetX+160*cos(dir),GetY+120*sin(dir),2.5,dir4,86,40);
				b(GetX+160*cos(dir2),GetY+120*sin(dir2),2.5,dir3,86,40);
				b(GetX+160*cos(dir2),GetY+120*sin(dir2),2.5,dir4,86,40);
			dir3+=25;
			dir4-=25;
			}
		dir3-=woah*25;
		dir4+=woah*25;
		PlaySE(s1);
		dir+=360/16;
		dir2-=360/16;
		if(woah < 14.4){woah+=1;}
		wait(7);
		}
	dir =GetAngleToPlayer;
	dir2 =GetAngleToPlayer;
	dir3 = GetAngleToPlayer;
	dir4 =GetAngleToPlayer;
		loop(8){
			loop(woah){
				b(GetX+160*cos(dir),GetY-240+120*sin(dir),2.5,dir3,86,40);
				b(GetX+160*cos(dir),GetY-240+120*sin(dir),2.5,dir4,86,40);
				b(GetX+160*cos(dir2),GetY-240+120*sin(dir2),2.5,dir3,86,40);
				b(GetX+160*cos(dir2),GetY-240+120*sin(dir2),2.5,dir4,86,40);
			dir3+=25;
			dir4-=25;
			}
		dir3-=woah*25;
		dir4+=woah*25;
		PlaySE(s1);
		dir+=360/16;
		dir2-=360/16;
		if(woah < 14.4){woah+=1;}
		wait(7);
		} 
	wait(120);
	dir = GetAngleToPlayer;
	dir2 = GetAngleToPlayer;
	dir3 = GetAngleToPlayer;
	dir4 =GetAngleToPlayer;
	woah = 0;
}

	task phase2{
	let angle =GetAngleToPlayer-40;
	let angle2 =GetAngleToPlayer+40;
loop(3){
	loop(5){
		CreateShot01(GetX, GetY, 3, angle, BLUE01, 0);
		CreateShot01(GetX, GetY, 3, angle+30, BLUE01, 0);
		CreateShot01(GetX, GetY, 3, angle-30, BLUE01, 0);
		CreateShot01(GetX, GetY, 3, angle+15, BLUE01, 0);
		CreateShot01(GetX, GetY, 3, angle-15,BLUE01, 0);
		CreateShot01(GetX, GetY, 3.5, angle+22.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 3.5, angle-22.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 3.5, angle+7.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 3.5, angle-7.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 4, angle-15, BLUE01, 0);
		CreateShot01(GetX, GetY, 4, angle+15, BLUE01, 0);
		CreateShot01(GetX, GetY, 4, angle, BLUE01, 0);
		CreateShot01(GetX, GetY, 4.5, angle+7.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 4.5, angle-7.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 5, angle, BLUE01, 0);

		CreateShot01(GetX, GetY, 3, angle2, BLUE01, 0);
		CreateShot01(GetX, GetY, 3, angle2+30, BLUE01, 0);
		CreateShot01(GetX, GetY, 3, angle2-30, BLUE01, 0);
		CreateShot01(GetX, GetY, 3, angle2+15, BLUE01, 0);
		CreateShot01(GetX, GetY, 3, angle2-15,BLUE01, 0);
		CreateShot01(GetX, GetY, 3.5, angle2+22.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 3.5, angle2-22.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 3.5, angle2+7.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 3.5, angle2-7.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 4, angle2-15, BLUE01, 0);
		CreateShot01(GetX, GetY, 4, angle2+15, BLUE01, 0);
		CreateShot01(GetX, GetY, 4, angle2, BLUE01, 0);
		CreateShot01(GetX, GetY, 4.5, angle2+7.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 4.5, angle2-7.5, BLUE01, 0);
		CreateShot01(GetX, GetY, 5, angle2, BLUE01, 0);
	angle+=360/5;}
		PlaySE(s1);
	wait(10);}
	let thing = 1;
	let dir = GetAngleToPlayer;
		loop(10){loop(6){CreateShot01(GetX, GetY, thing, dir, 140, 0); dir+=360/6;} thing+=0.3;}
		PlaySE(s1);
	}
task phase3{
	let dir = 60;
	let woah = 1.5;
	loop(2){
		loop(15){
			b2(GetX-dir,GetY,woah,GetAngleToPlayer,87,40);
			b2(GetX-dir,GetY,woah+1,GetAngleToPlayer,87,40);
			b2(GetX-dir,GetY,woah+2,GetAngleToPlayer,87,40);
		PlaySE(s1);
		dir+=8;
		woah+=0.1;
		wait(2);
		}
		woah = 1.5;
	woah = 1.5;
	dir = -60;
	wait(30);
		loop(15){
			b3(GetX-dir,GetY,woah,GetAngleToPlayer,83,40);
			b3(GetX-dir,GetY,woah+1,GetAngleToPlayer,83,40);
			b3(GetX-dir,GetY,woah+2,GetAngleToPlayer,83,40);
			b4(GetX-dir,GetY,woah,GetAngleToPlayer,83,40);
			b4(GetX-dir,GetY,woah+1,GetAngleToPlayer,83,40);
			b4(GetX-dir,GetY,woah+2,GetAngleToPlayer,83,40);
		PlaySE(s1);
		dir-=8;
		woah+=0.1;
		wait(2);
		} 
		woah = 1.5;
	wait(30);
	}
	woah = 1.5;
	loop(3){
	dir = 60;
		loop(15){
			b2(GetX-dir,GetY,woah,GetAngleToPlayer,87,40);
			b2(GetX-dir,GetY,woah+1,GetAngleToPlayer,87,40);
			b2(GetX-dir,GetY,woah+2,GetAngleToPlayer,87,40);
			b3(GetX-dir,GetY,woah,GetAngleToPlayer,87,40);
			b3(GetX-dir,GetY,woah+1,GetAngleToPlayer,87,40);
			b3(GetX-dir,GetY,woah+2,GetAngleToPlayer,87,40);
			b4(GetX-dir,GetY,woah,GetAngleToPlayer,87,40);
			b4(GetX-dir,GetY,woah+1,GetAngleToPlayer,87,40);
			b4(GetX-dir,GetY,woah+2,GetAngleToPlayer,87,40);
		PlaySE(s1);
		dir+=8;
		woah+=0.1;
		wait(2);
		}
		woah = 1.5;
	dir = -60;
	wait(4);
		loop(15){
			b5(GetX-dir,GetY,woah,GetAngleToPlayer,83,40);
			b5(GetX-dir,GetY,woah+1,GetAngleToPlayer,83,40);
			b5(GetX-dir,GetY,woah+2,GetAngleToPlayer,83,40);
			b5(GetX-dir,GetY,woah+3,GetAngleToPlayer,83,40);
			b6(GetX-dir,GetY,woah,GetAngleToPlayer,83,40);
			b6(GetX-dir,GetY,woah+1,GetAngleToPlayer,83,40);
			b6(GetX-dir,GetY,woah+2,GetAngleToPlayer,83,40);
			b6(GetX-dir,GetY,woah+3,GetAngleToPlayer,83,40);
			b7(GetX-dir,GetY,woah,GetAngleToPlayer,83,40);
			b7(GetX-dir,GetY,woah+1,GetAngleToPlayer,83,40);
			b7(GetX-dir,GetY,woah+2,GetAngleToPlayer,83,40);
			b7(GetX-dir,GetY,woah+3,GetAngleToPlayer,83,40);
			b8(GetX-dir,GetY,woah,GetAngleToPlayer,83,40);
			b8(GetX-dir,GetY,woah+1,GetAngleToPlayer,83,40);
			b8(GetX-dir,GetY,woah+2,GetAngleToPlayer,83,40);
			b8(GetX-dir,GetY,woah+3,GetAngleToPlayer,83,40);
		PlaySE(s1);
		dir-=8;
		woah+=0.1;
		wait(2);
	}
	}
}
	task b(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);

			while(!Obj_BeDeleted(obj)){
			wait(1000);
			yield;}
		}


	task b2(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);

			while(!Obj_BeDeleted(obj)){
    		Obj_SetAngle(obj,atan2(Obj_GetY(obj) - GetPlayerY, Obj_GetX(obj) - GetPlayerX)-180);
			wait(1000);
			yield;}
		}


	task b3(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);

			while(!Obj_BeDeleted(obj)){
    		Obj_SetAngle(obj,atan2(Obj_GetY(obj) - GetPlayerY, Obj_GetX(obj) - GetPlayerX)-180-40);
			wait(1000);
			yield;}
		}


	task b4(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);

			while(!Obj_BeDeleted(obj)){
    		Obj_SetAngle(obj,atan2(Obj_GetY(obj) - GetPlayerY, Obj_GetX(obj) - GetPlayerX)-180+40);
			wait(1000);
			yield;}
		}


	task b5(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);

			while(!Obj_BeDeleted(obj)){
    		Obj_SetAngle(obj,atan2(Obj_GetY(obj) - GetPlayerY, Obj_GetX(obj) - GetPlayerX)-180-15);
			wait(1000);
			yield;}
		}


	task b6(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);

			while(!Obj_BeDeleted(obj)){
    		Obj_SetAngle(obj,atan2(Obj_GetY(obj) - GetPlayerY, Obj_GetX(obj) - GetPlayerX)-180+15);
			wait(1000);
			yield;}
		}


	task b7(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);

			while(!Obj_BeDeleted(obj)){
    		Obj_SetAngle(obj,atan2(Obj_GetY(obj) - GetPlayerY, Obj_GetX(obj) - GetPlayerX)-180-35);
			wait(1000);
			yield;}
		}


	task b8(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);

			while(!Obj_BeDeleted(obj)){
    		Obj_SetAngle(obj,atan2(Obj_GetY(obj) - GetPlayerY, Obj_GetX(obj) - GetPlayerX)-180+35);
			wait(1000);
			yield;}
		}


	function wait(w){loop(w){yield;}
}

}
}