#TouhouDanmakufu
#Title[Shinki's 2nd Spell -Lunatic-]
#Text[Devil's Recitation!]
#Player[FREE]
#BGM[.\infinity.mp3]
#ScriptVersion[2]
#BackGround[User(.\stgbg.png, 0, 0)]


script_enemy_main {
	let y = 0;
	let one = 1;
	let num = 12;
	let frame = 0;
	let shinkicut = GetCurrentScriptDirectory~"shinkicut.png";
	let frame2 = 0;
	let frame3 = 0;
	let background = GetCurrentScriptDirectory~"spellbg.png";
	let angle = 0;
	let angle2 = 0;
	let cardcall = GetCurrentScriptDirectory~"cardcall.wav";
	let shot = GetCurrentScriptDirectory~"shot.wav";
	let shot2 = GetCurrentScriptDirectory~"shot2.wav";
	let shot3 = GetCurrentScriptDirectory~"shot3.wav";
	let bounce = GetCurrentScriptDirectory~"bounce.wav";
	let explode = GetCurrentScriptDirectory~"explode.wav";
	let familiarspawn = GetCurrentScriptDirectory~"familiarspawn.wav";
	let time1 = GetCurrentScriptDirectory~"time1.wav";
	let time2 = GetCurrentScriptDirectory~"time2.wav";
	let frame = -120;
	let timer = GetTimer;
#include_function ".\lib\SHOT_REPLACE\shot_replace.dnh"
#include_function ".\shinkianimationyay.txt"
    @Initialize {
	LoadGraphic(shinkicut);
	LoadSE(cardcall);
	PlaySE(cardcall);
	CutIn(YOUMU, "God Art "\""Divine Thread of Life"\", shinkicut, 0, 0, 180, 256);
	DeleteSE("se\seEnemyExplode01.wav");
	DeleteSE("se\seUseSpellCard.wav");
        SetLife(1000);
	SetScore(200000);
        SetTimer(77);
        LoadSE(shot);
	LoadSE(bounce);
	LoadSE(time1);
	LoadSE(time2);
	LoadSE(shot2);
	LoadGraphic(background);
	LoadSE(shot3);
	LoadSE(familiarspawn);
	SetShotAutoDeleteClip(30, 70, 30, 30);
	shotinit;
	SetEnemyMarker(true);
	SetInvincibility(240);
	SetDamageRate(25, 20);
        SetMovePosition02(GetCenterX, GetClipMinY + 120, 120);
        
       
    }

task GenericSpell{
	angle=rand(0, 360);
	one = one*-1;
	loop(num){
		CreateShotA(1, GetX, GetY, 0);
		SetShotDataA(1, 0, 1, 90+angle, 0, -0.01, 0, BLUE03);
		SetShotDataA(1, 60, 0, 90+angle, 0.2*one, 0.02, 2, BLUE03);
		SetShotDataA(1, 240, NULL, NULL, 0, 0.02, 3, BLUE03);
	ascent(i in 0..40){
		CreateShotA(2, 0, 0, 30);
		SetShotDataA(2, 0, 0, 180+angle+(i*3), 0, 0.02, 0, RED01);
		SetShotDataA(2, 60, 0, 180+angle+(i*10), 0, 0.02, 2.5-(i/40), RED01);
		AddShot(60+(i*6), 1, 2, 0);
		CreateShotA(3, 0, 0, 30);
		SetShotDataA(3, 0, 0, angle-(i*3), 0, 0.02, 0, BLUE01);
		SetShotDataA(3, 60, 0, angle-(i*10), 0, 0.02, 2.5-(i/40), BLUE01);
		AddShot(60+(i*6), 1, 3, 0);
		}
	PlaySE(shot2);
	FireShot(1);
	angle+=360/num;
		} 
wait(60);
ExMove;
wait(60);
loop(8){
PlaySE(shot3);
loop(2){
CreateShot01(GetX, GetY, 2, angle+angle2, GREEN03, 0);
CreateShot01(GetX, GetY, 1.5, angle+angle2+10, GREEN03, 0);
angle+=180;
}
ExMove;
wait(10);
angle2+=20;
}
}


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

sub ExMove { ExMove_(GetCenterY-100, 10, rand(30, 60)); }
function ExMove_(height, ud, length) {
	
	if(GetPlayerX < GetX) {
		if(GetX - length <= GetClipMinX) {
			SetMovePosition03(GetX + length, rand(height+20 - ud, height + ud), 5, 1);
		} else {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 5, 1);
		}
	} else {
		if(GetX + length >= GetClipMaxX) {
			SetMovePosition03(GetX - length, rand(height - ud, height + ud), 5, 1);
		} else {
			SetMovePosition03(GetX + length, rand(height - ud, height + ud), 5, 1);
		}
	}
}
    @MainLoop {

SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 16);


if(frame==60){
GenericSpell;
frame=-350;
}

if(OnPlayerMissed){
frame=-60;
}

if(OnBomb){
frame=-180;
}

frame++;
yield;
}    



    @DrawLoop {
		animm;
    }

@BackGround{
   SetTexture(background);
   SetGraphicRect(0, 0 - y, 256, 256 - y);
   SetGraphicScale(2, 2);
   DrawGraphic(GetCenterX, GetCenterY);
   y+=1;
}


    @Finalize {
	

    }
}
