#TouhouDanmakufu
#Title[Advent of Akyu]
#Text[This is the worst.]
#Player[FREE]
#BackGround[User(.\stuff\black.jpg, 2, 1)]
#ScriptVersion[2]

script_enemy_main
{
	let akyu = GetCurrentScriptDirectory ~ "stuff\akyu.png";
	let man = GetCurrentScriptDirectory ~ "stuff\man.png";
	let tokiko = GetCurrentScriptDirectory ~ "stuff\tokiko.png";
	let white = GetCurrentScriptDirectory ~ "stuff\white.png";
	let a = GetCurrentScriptDirectory ~ "stuff\b.jpg";
	
	let teatime = false;
	let s = 0;
	let mantime = false;
	let oops = false;
	let flash = false;
	
	let made = false;
	let obj;
	let speed = 0;
	let alpha = 255;
	let frame = 0;
	let fade = false;
	let go = false;
	let dead = false;
	
	@Initialize
	{
		SetLife(9001);
		SetDurableSpellCard;
		MagicCircle(false);

		LoadGraphic(akyu);
		LoadGraphic(man);
		LoadGraphic(tokiko);
		LoadGraphic(white);
		LoadGraphic(a);

		SetMovePosition02(GetCenterX, GetCenterY - 120, 60);
		PlayMusic(GetCurrentScriptDirectory ~ "stuff\theme.mp3");

	}
	@MainLoop
	{
		SetCollisionA(GetX, GetY, 32);
		SetCollisionB(GetX, GetY, 16);
		SetEnemyMarker(true);
		if(made){make;}
		talk;
		if(s==3 && !OnEvent){
			s=4;
			abc;
		}
		Expert;
		if(GetPlayerLife==1){
			s=5;
			dead = true;
		}
		if(flash && speed<=500){
			speed+=10;
			fadetimer;
		}
		if(fade && alpha > 0){
			alpha -=0.3;
			mantime = false;
			oops = false;
		}
		if(alpha<1 && alpha > 0){
		go = true;
		}
		if(go)
		{
			go = false;
			alpha = 0;
			start;
		}
		frame++;
		yield;
	}
	@DrawLoop
	{
		if(teatime)
		{
		SetTexture(a);
		SetGraphicRect(0, 0, 800, 800);
		DrawGraphic(GetCenterX, GetCenterY);
		SetGraphicAngle(0, 0, frame);
		}
		if(!dead){
		SetTexture(akyu);
		SetGraphicRect(0, 0, 33, 58);
		DrawGraphic(GetX, GetY);
		}
		if(mantime){
		SetTexture(man);
		SetGraphicRect(0, 0, 31, 63);
		DrawGraphic(GetX-100, GetY);
		}
		if(oops){
		SetTexture(tokiko);
		SetGraphicRect(0, 0, 37, 37);
		DrawGraphic(GetX+100, GetY);
		}
	}
	@Finalize
	{
	}

	function Wait(n){loop(n){yield;}}

	task make
	{
			Obj_SetX(obj, GetX);
			Obj_SetY(obj, GetY);
			ObjEffect_SetVertexXY(obj, 0, -2*speed, -2*speed);
			ObjEffect_SetVertexXY(obj, 1, 2*speed, -2*speed);
			ObjEffect_SetVertexXY(obj, 2, 2*speed, 2*speed);
			ObjEffect_SetVertexXY(obj, 3, -2*speed, 2*speed);
			ObjEffect_SetVertexColor(obj, 0, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 1, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 2, alpha, 255, 255, 255);
			ObjEffect_SetVertexColor(obj, 3, alpha, 255, 255, 255);
	}
	
	task fadetimer
	{
		Wait(60);
		fade = true;
	}
	
	task talk{
		if(s==0){
			CreateEventFromScript("1");
			s=1;
			obj = Obj_Create(OBJ_EFFECT);
			ObjEffect_SetLayer(obj, 5);
			ObjEffect_SetTexture(obj, white);
			ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLEFAN);
			ObjEffect_CreateVertex(obj, 4);
			ObjEffect_SetVertexUV(obj, 0, 0, 0);
			ObjEffect_SetVertexUV(obj, 1, 3, 0);
			ObjEffect_SetVertexUV(obj, 2, 3, 3);
			ObjEffect_SetVertexUV(obj, 3, 0, 3);
			made = true;
		}
		if(s==1 && !OnEvent){
			mantime = true;
			CreateEventFromScript("2");
			s=2;
		}
		if(s==2 && !OnEvent){
			CreateEventFromScript("3");
			oops = true;
			s=3;
		}
		if(s==5 && !OnEvent){
			s=6;
			CreateEventFromScript("ALWAYS");
		}
		if(s==6 && !OnEvent){
			SetLife(0);
		}
	}
	
	task abc
	{
		DeleteMusic(GetCurrentScriptDirectory ~ "stuff\theme.mp3");
		PlayMusic(GetCurrentScriptDirectory ~ "stuff\hrng.mp3");
		flash = true;
		Wait(30);
		teatime = true;
	}
	
	task start
	{
		Wait(230);
		RUA;
	}
	
	task RUA
	{
		SetMovePosition02(GetPlayerX, GetPlayerY, 20);
		PlaySE(GetCurrentScriptDirectory ~ "stuff\dash.wav");
		ascent(i in 0..10)
		{
			CreateShot01(GetX, GetY, rand(0.2,6), GetAngleToPlayer-180+rand(-30,30), RED31, 10);
			CreateShot01(GetX, GetY, rand(0.2,6), GetAngleToPlayer-180+rand(-30,30), YELLOW31, 10);
			CreateShot01(GetX, GetY, rand(0.2,6), GetAngleToPlayer-180+rand(-30,30), ORANGE31, 10);
			CreateShot01(GetX, GetY, rand(0.2,6), GetAngleToPlayer-180+rand(-30,30), GREEN31, 10);
			CreateShot01(GetX, GetY, rand(0.2,6), GetAngleToPlayer-180+rand(-30,30), AQUA31, 10);
			CreateShot01(GetX, GetY, rand(0.2,6), GetAngleToPlayer-180+rand(-30,30), BLUE31, 10);
			CreateShot01(GetX, GetY, rand(0.2,6), GetAngleToPlayer-180+rand(-30,30), PURPLE31, 10);
			Wait(2);
		}
		CreateShot01(GetX, GetY, 0.5, GetAngleToPlayer, RED22, 10);
		CreateShot01(GetX, GetY, 0.5, GetAngleToPlayer+51, YELLOW22, 10);
		CreateShot01(GetX, GetY, 0.5, GetAngleToPlayer+102, ORANGE22, 10);
		CreateShot01(GetX, GetY, 0.5, GetAngleToPlayer+153, GREEN22, 10);
		CreateShot01(GetX, GetY, 0.5, GetAngleToPlayer+204, AQUA22, 10);
		CreateShot01(GetX, GetY, 0.5, GetAngleToPlayer+255, BLUE22, 10);
		CreateShot01(GetX, GetY, 0.5, GetAngleToPlayer+306, PURPLE22, 10);
		Wait(30);
		if(!dead){RUA;}
	}
}

script_event 1{

@Initialize{}

@MainLoop{
	TextOutA("\c[RED]Oh hello there.");
	TextOutA("\c[RED]You're here for a spellcard battle aren't you.");
	TextOutA("\c[RED]Hehe, it's written all over your face.");
	TextOutA("\c[RED]Well I'm not too experienced with this kind of thing...");
	TextOutA("\c[RED]But I do have a few spellcards saved up for such an occasion.");
	TextOutA("\c[RED]Hold on just a moment.");
	End;
 }

@Finalize{}
}

script_event 2{

@Initialize{}

@MainLoop{
	TextOutA("\c[BLUE]Hello there Akyu.");
	TextOutA("\c[BLUE]And you too, (insert player name here).");
	TextOutA("\c[RED]Oh why hello Rinnosuke, I didn't see you come in.");
	TextOutA("\c[BLUE]I brought that strange potion you requested.");
	TextOutA("\c[RED]Ah thank you very much. Please place it on my desk over there.");
	TextOutA("\c[BLUE]Alrig");
	End;
 }

@Finalize{}
}

script_event 3{

@Initialize{}

@MainLoop{
	TextOutA("\c[PURPLE]RAWR! I AM HERE AND YOUR ASS IS MINE!");
	TextOutA("\c[BLUE]GWAHH!");
	TextOutA("\c[WHITE]The potion flew out of Rinnosuke's hands and smashed all over Akyu's face.");
	TextOutA("\c[WHITE]*Insert crashing sound here*");
	TextOutA("\c[PURPLE]WHAT WAS THAT? I HEARD A CRASHING SOUND!");
	TextOutA("\c[BLUE]...");
	TextOutA("\c[BLUE]Just run.");
	TextOutA("\c[PURPLE]WHAT?");
	TextOutA("\c[BLUE]I SAID RUN GODDAMMI");
	End;
 }

@Finalize{}
}

script_event ALWAYS{

@Initialize{}

@MainLoop{
	TextOutA("ALWAYS");
	TextOutA("I WANNA BE WITH YOU");
	TextOutA("AND MAKE BELIEVE WITH YOU");
	TextOutA("AND LIVE IN HARMONY HARMONY");
	TextOutA("OH LOVE!!!");
	End;
 }

@Finalize{}
}