#TouhouDanmakufu[Single]
#ScriptVersion[3]
#ID["K-01-04"]
#Title["Fire Sign \"Gift of Prometheus\""]
#Text[""]

#include "script/default_system/Default_ShotConst.txt"
#include"script/default_system/Default_Effect.txt"
#include "./funclib.txt"
#include "./cutin.txt"

let objEnemy;
let objPlayer;
let backSpell;
let backOverlay;

let dead = false;

let boom = gcsd~"sfx/se_enep00.wav";
let tan2 = gcsd~"sfx/se_tan02.wav";

@Event
{
	SetLife(320);
	SetTimer(60);
	SetScore(16000);
	LoadSound(boom);LoadSound(tan2);
}

@Initialize
{
	let img = gcsd ~ "kazu.png";
	let ct = gcsd~ "ct.png";

	objPlayer = GetPlayer;
	objEnemy = StartBoss;
	CutIn(objEnemy, 0, "Fire Sign \"Gift of Prometheus\"", "RED", ct, 0, 0, 240, 384);

	SetTexture(objEnemy, img);
	ObjRender_SetScaleXYZ(objEnemy, 0.3, 0.3, 0.3);
	DrawSprite2D(objEnemy, 0, 0, 160, 256);

	SetDamageRate(objEnemy, 10, 0);
	MoveFrame(objEnemy, GetCenterX, 160, 60);

	MainTask;
	Background;
}

@MainLoop
{
	SetCollisionShot(objEnemy, GetX(objEnemy), GetY(objEnemy), 32);
	SetCollisionPlayer(objEnemy, GetX(objEnemy), GetY(objEnemy), 24);

	if(GetLife(objEnemy) <= 0 && dead == false)
	{
		Death;
		dead = true;
	}

	yield;
}

task MainTask
{
	loop(120){yield;}
	attack;
}

task attack
{
	let dist = 0;

	loop
	{
		loop(3)
		{
			if(!dead){PlaySE(tan2);}
			ascent(v in 1..4)
			{
				ascent(a in 0..45)
				{
					let shotFire = CreateShotA1(GetX(objEnemy), GetY(objEnemy), (1+0.2*-cos(a*64))*(0.5*v), a*8+GetAngleToPlayer2(objEnemy), DS_FIRE_RED, 10);
				}
			}
			loop(60){yield;}
		}
		loop(60){yield;}
		MoveSpeed(objEnemy, GetX(objPlayer), GetY(objPlayer), 3);
		while(ObjMove_GetSpeed(objEnemy)>0)
		{
			if(!dead){PlaySE(tan2);}
			let shotFire = CreateShotA1(GetX(objEnemy), GetY(objEnemy), rand(1, 3), ObjMove_GetAngle(objEnemy)+rand(150, 210), DS_FIRE_RED, 10);
			yield;
		}
		loop(30){yield;}
	}
}

task Death
{
	PlaySE(boom);
	TExplosionA(GetX(objEnemy), GetY(objEnemy), 10, 1);
	Obj_Delete(objEnemy);Obj_Delete(backSpell);Obj_Delete(backOverlay);
	loop(30){yield;DeleteShotAll(TYPE_ALL, TYPE_ITEM);}
	CloseScript(GetOwnScriptID());
}

task Background
{
	let a = 0;

	backSpell = ObjPrim_Create(OBJ_SPRITE_2D);
	SetTexture(backSpell, gcsd~"back.png");
	ObjSprite2D_SetSourceRect(backSpell, 0, 0, 512, 512);
	ObjSprite2D_SetDestRect(backSpell, 0, 0, 512, 512);
	ObjRender_SetAlpha(backSpell, 0);
	Obj_SetRenderPriorityI(backSpell, 20);

	backOverlay = ObjPrim_Create(OBJ_SPRITE_2D);
	SetTexture(backOverlay, gcsd~"backover.png");
	ObjSprite2D_SetSourceRect(backOverlay, 0, 0, 200, 200);
	ObjSprite2D_SetDestRect(backOverlay, -320, -320, 320, 320);
	Obj_SetRenderPriorityI(backOverlay, 20);
	ObjRender_SetAlpha(backOverlay, 0);
	ObjRender_SetPosition(backOverlay, GetCenterX, GetCenterY, 0);

	let r = 0;

	loop
	{
		if(a<255){a+=2.5;}
		else{a=255;}
		ObjRender_SetAlpha(backSpell, a);
		ObjRender_SetAlpha(backOverlay, (a/255*100));
		r+=0.2;
		ObjRender_SetAngleZ(backOverlay, r+20*sin(5*r));
		yield;
	}
}