#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Spell8"]
#Text["Woop"]


let objBoss;

let BossX;
let BossY;


#include "./Functions/Index.txt"
#include "./Functions/Dialogue.txt"


@Initialize {
	objBoss = ObjEnemy_Create(OBJ_ENEMY_BOSS);
	ObjEnemy_Regist(objBoss);
	renderkanako(objBoss);
	BossShotSound(objBoss, 100, 600);
	KanakoAura(objBoss, false);
	Sticks(objBoss, false);
	BottomEnemyMarker(objBoss, objBoss);
	DrawName("Kanako Yasaka", [20, 20, 200], 11);
	ObjMove_SetDestAtWeight(objBoss, GetStgFrameWidth/2, GetStgFrameHeight/3, 10, 5);
	Maintask;
	end;
} 

@Event { 
	alternative(GetEventType())
	case(EV_REQUEST_LIFE){
		SetScriptResult(5000);
     	}
	case(EV_REQUEST_TIMER){
		SetScriptResult(50);
	}
	case(EV_REQUEST_SPELL_SCORE){
		SetScriptResult(1000000);
	}
} 

@MainLoop {
	BossX = ObjMove_GetX(objBoss);
	BossY = ObjMove_GetY(objBoss);
	
	if(invisible==false){
	ObjEnemy_SetIntersectionCircleToShot(objBoss,BossX,BossY,21);
	ObjEnemy_SetIntersectionCircleToPlayer(objBoss,BossX,BossY,16);
	}
	
	if(GetPlayerInvincibilityFrame<=0){invisible=false;}
	else{invisible=true;}
	
	yield;
} 

@Finalize {

} 

let glAng = 90;

task Maintask{
wait(60);
SpellCard("Stick Sign &quot;fally sticks of doom&quot;");
Pattern;
}

task Pattern{

loop{
	ascent(i in 0..5){
	let obj = KillyStick(30+(i*80), -20, 90);
	Move(obj);
	Shoot(obj, ARROWHEAD_GREEN);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(10);
	}
	
	wait(90);
	
	descent(i in 0..5){
	let obj = KillyStick(30+(i*80), -20, 90);
	Move(obj);
	Shoot(obj, ARROWHEAD_MAGENTA);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(10);
	}
	
	ascent(i in 0..6){
	let obj = KillyStick(30+(i*80), -20, 90-11);
	Move(obj);
	Shoot(obj, ARROWHEAD_YELLOW);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(10);
	}
	
	descent(i in 0..6){
	let obj = KillyStick(30+(i*80), -20, 90+11);
	Move(obj);
	Shoot(obj, ARROWHEAD_ORANGE);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(10);
	}
	
	ascent(i in 0..6){
	let obj = KillyStick(30+(i*80), -20, 90-11);
	Move(obj);
	Shoot(obj, ARROWHEAD_RED);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(10);
	}
	
	descent(i in 0..6){
	let obj = KillyStick(30+(i*80), -20, 90+11);
	Move(obj);
	Shoot(obj, ARROWHEAD_PURPLE);
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/barrage2.wav", 60);
	wait(10);
	}
	wait(240);
}
	
	task Shoot(obj, graph){
	wait(70+rand(0,10));
	let count = 0;
		while(ObjMove_GetY(obj)<456){
			ascent(i in 0..6){
			let obj2 = CreateShotA1(ObjMove_GetX(obj), ObjMove_GetY(obj)-60, 0.2, 1*360/12+(i*360/6), graph, 5);
			ObjMove_AddPatternA2(obj2, 70, NO_CHANGE, NO_CHANGE, 0.005, 0, 5); 
			SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/smbullet.wav", 60);
			}
		wait(24);
		}
	}
	
	task Move(obj){
	wait(30);
	ObjMove_SetAcceleration(obj, 0.05);
	ObjMove_SetMaxSpeed(obj, 5);
	wait(130);
	ObjMove_SetAcceleration(obj, 0);
	ObjMove_SetSpeed(obj, 0);
	ScreenShake(0.5,5);
	while(ObjMove_GetY(obj)>=GetStgFrameHeight){yield;}
	SE_Play(GetCurrentScriptDirectory ~ "Functions/sfx/chargedown.wav", 120);
	ObjMove_SetAcceleration(obj, 0.1);
	ObjMove_SetMaxSpeed(obj, 5);
	wait(120);
	Obj_Delete(obj);
	}
}

function SpellCard(name){
	let Cutin = GetCurrentScriptDirectory ~ "Functions/img/Emotions/Kan1.png";
	ObjCutin_SetSpellcardS3(name, 25, 25, 255);
	ObjCutin_LaunchS3("KANAKO", Cutin, "Normal");
	TCallBg;
	bspell = true;
	let objScene = GetEnemyBossSceneObjectID();
	ObjEnemyBossScene_StartSpell(objScene);
	wait(210);
}


task end{
    while(ObjEnemy_GetInfo(objBoss, INFO_LIFE) > 0){yield;}
    Obj_Delete(objBoss);
	wait(1);
	SetCommonData("deathsound",1);
    DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    SetAutoDeleteObject(true);
    CloseScript(GetOwnScriptID());
} 
