#TouhouDanmakufu
#Title[Reimu Spellcard 3]
#Text["Fantasy Explosion"
last spell, its very hard..]
#Player[FREE]
#ScriptVersion[2]


script_enemy_main
{
let CSD = GetCurrentScriptDirectory;
#include_function ".\newsfx.txt" // Non ZUN sfx
#include_function ".\function_cutin.txt"
#include_function ".\Obj_hpb.txt" // TLC Lifebar, no lags :)
#include_function ".\function_own.txt" // This script uses some Japanese functions
#include_function ".\function_value.txt"// Sadly they collide with some TheLastCorner Functions like the Cutin, so im using only function_cutin :(
let SpellBG1 = CSD~"system/1.png";
let SpellBG2 = CSD~"system/2.png";
let shot = GetCurrentScriptDirectory() ~ "kshotData.txt" ; // TLC shots
let frame = 0 ;
let angle     = 0;
    let angle2    = 0;
let angle3 = 0;
let cut = CSD ~ "system\Raymoo.png";
//let minx = GetClipMinX ;
//let maxx = GetClipMaxX ;
//let miny = GetClipMinY ;
//let maxy = GetClipMaxY ;
let bgalpha = 0;	//We create a new variable so that the background can fade in smoothly.
let bgangle = 0;	//Angle for the overlayed BG. 
let boss =  GetCurrentScriptDirectory ~ "system\raymoosprite.png" ;


@Initialize
{
LoadUserShotData( shot ) ;
cutin("NAZRIN", " "\""Fantasy Explosion"\" ,cut,0,0,552,620);
SetScore( 2500000 ) ;
LoadGraphic(SpellBG1);
LoadGraphic(SpellBG2);
LoadGraphic(cut);
SetX( GetCenterX ) ;
SetY( GetClipMinY + 130 ) ;
SetLife( 1200 ) ;
SetTimer( 70 ) ;
SetDamageRate( 16, 10 ) ;
SetInvincibility( 180 ) ;
let frame = 0 ;
hpb(1,0,0);
MainTask ;
}

@MainLoop
{
SetCollisionA( GetX, GetY, 24 ) ;
SetCollisionB( GetX, GetY, 24 ) ;
if ( frame % 360 == 0 )
  {
  moveToPlayer( rand( 30, 100 ), rand( -50, 50 ), 60, GetClipMinX + 32, GetClipMinY + 32, GetClipMaxX - 32, GetClipMinY + 160 ) ;
  }
yield ;
frame += 1 ;
}

@DrawLoop
{
DrawText("Reimu Hakurei", 40, 35, 12, 255);
LoadGraphic(boss) ;
SetTexture(boss) ;
SetGraphicRect( 0, 0, 63, 73 ) ;
DrawGraphic( GetX, GetY ) ;

}

@Finalize
{
DeleteGraphic(boss) ;

}

task MainTask
{
wait(60);
SetColor(255,0,0);
Concentration01(60);
SetColor(255,255,255);
PlaySE(charge);
wait(120);
primero;
wait(300);
segundo;
wait(300);
tercero;
}
task A {
		let ang=GetAngleToPlayer();
		let x=[GetX()-20,GetX()-20+(GetPlayerX()-(GetX()-20))/2,GetPlayerX()];
		let y=[GetY()-10,GetY()-10+(GetPlayerY()-(GetY()-10))/2,GetPlayerY()];
		ascent(cnt in 0..100) {
			ascent(cnt2 in -1..3) {
				let tm=x[1]+cos(ang+90)*(cnt2*90);
				let tm2=(x[0]+(tm-x[0])*cnt/100);
				let tm3=(tm+(x[2]-tm)*cnt/100);
				let xx=tm2+(tm3-tm2)*cnt/100;
				tm=y[1]+sin(ang+90)*(cnt2*90);
				tm2=(y[0]+(tm-y[0])*cnt/100);
				tm3=(tm+(y[2]-tm)*cnt/100);
				let yy=tm2+(tm3-tm2)*cnt/100;
				CreateShotA(0,xx,yy,20);
				SetShotDataA(0,0,0,0,0,0,0,1);
				SetShotKillTime(0,0);
				FireShot(0);
			}
			yield;
		}
		ang = rand(0,360);
		ascent(cnt in 0..56) {
			ang+=(360/56);
			let spd=0.02*(rand([0.75,1.75][cnt%2],[1.25,2.25][cnt%2]));
			CreateShotA(0,x[2],y[2],0);
			SetShotDataA(0,0,0,ang,0,spd,5,91);
			ascent(cnt2 in 0..30) {
				CreateShotA(1,rand(-5,5),rand(-5,5),rand_int(15,25));
				SetShotDataA(1,0,0,0,0,0,0,1);
				SetShotKillTime(1,0);
				AddShot(30+cnt2*5,0,1,0);
			}
			FireShot(0);
		}
	}
	
	task B {
		let tm=GetAngleToPlayer();
		ascent(cnt in 0..10) {
			CreateLaser01(GetX(),GetY(),4,cnt*36,250,10,66,30);
		}
	}
task primero{
      loop{
PlaySE(shot5);
A;
B;
wait(10);
PlaySE(lazor);
wait(90);
PlaySE(kira);
wait(80);
yield;
                }
}
task segundo{
loop(60){yield;}
		        loop(60) {
            loop(3) {
                angle2 = rand(0, 360);
                CreateShotA(0, GetX, GetY, 4);
                SetShotDataA(0, 0, 3, angle, 0, 0, 0, 92);
                FireShot(0);
                angle += 360 / 3;
            }
            angle += 7;
PlaySE(shot2);
			loop(3){yield;}
			yield;
		}
}
task tercero{
Concentration01(60);
PlaySE(charge);
loop(60){yield;}
		        loop {
            loop(3) {
                angle2 = rand(0, 360);
                CreateShotA(0, GetX, GetY, 4);
                SetShotDataA(0, 0, 2, angle, 0, 0, 0, 100);
                FireShot(0);
                CreateShotA(0, GetX, GetY, 4);
                SetShotDataA(0, 0, 2, angle3, 0, 0, 0, 100);
                FireShot(0);
                angle += 360 / 3;
angle3 -= 360 / 3;
            }
            angle += 7;
angle3 -= 7;
PlaySE(shot2);
			loop(3){yield;}
			yield;
		}
}
//function wait(t){
//loop(t){yield;}
//}
@BackGround{

		if (bgalpha < 255){bgalpha += 5;}


SetAlpha(bgalpha);
SetGraphicScale(1.2,1.2);	//The background is scaled up so it can fill the whole screen.
SetColor(255,255,255);
SetGraphicRect(0,0,512,512);

SetTexture(SpellBG1);
DrawGraphic(GetCenterX,GetCenterY);

SetTexture(SpellBG2);
SetGraphicAngle(0,0,bgangle);
DrawGraphic(GetCenterX,GetCenterY);
	}

}