#TouhouDanmakufu
#Title[TEN_DESIRES_EX_BOSS_SP_10]
#Text[By Shockman2.]
#Player[FREE]
#BGM[.\mu\bgm.mp3]
#ScriptVersion[2]

script_enemy_main {

let frame1 = 0;
let frame2 = 10000;
let frame3 = 10000;
let frame4 = 0;
let frame5 = 10000;
let frame6 = 0;
let frame7 = 0;
let frame8 = 0;
let frame9 = 0;
let frame10 = 0;
let frame11 = 0;
let anim1 = 0;
let anim2 = 0;
let anim3 = 0;
let anim4 = 0;
let anim5 = 0;
let anim6 = 0;
let a1 = 0;
let a2 = 0;
let a3 = 0;
let a4 = 0;
let a5 = 0;
let a6 = 0;
let a7 = 0;
let a8 = 0;
let acc1 = 0;
let acc2 = 0;
let acc3 = 0;
let acc4 = 0;
let acc5 = 0;
let acc6 = 0;
let acc7 = 0;
let acc8 = 0;
let acc9 = 0;
let acc10 = 0;
let acc11 = 1;
let acc12 = 0;
let random1 = 0;
let random2 = 0;
let random3 = 0;
let random4 = 0;
let incr = 2;

let SP = GetCurrentScriptDirectory~"sp\sp.png";
let Custom = GetCurrentScriptDirectory~"sup\supershot.txt";
let MC = GetCurrentScriptDirectory~"ef\MC.png";
let CBG1 = GetCurrentScriptDirectory~"ef\cbg1.png";
let CBG2 = GetCurrentScriptDirectory~"ef\cbg2.png";
let NBG1 = GetCurrentScriptDirectory~"ef\nbg1.png";
let BAR = GetCurrentScriptDirectory~"ef\barrier.png";
let BAR2 = GetCurrentScriptDirectory~"ef\barrier2.png";
let charge = GetCurrentScriptDirectory~"se\Charge2.wav";
let sh1 = GetCurrentScriptDirectory~"se\Shot1.wav";
let sh2 = GetCurrentScriptDirectory~"se\BulletWave.wav";
let sh3 = GetCurrentScriptDirectory~"se\stars.wav";
let Cut = GetCurrentScriptDirectory~"ef\cut.png";
	#include_function ".\function_cutin.txt";
	#include_function ".\maple.txt";

    @Initialize {

SetMovePosition03(GetCenterX, GetCenterY - 100, 10, 10);

LoadUserShotData(Custom);
LoadGraphic(SP);
LoadGraphic(MC);
LoadGraphic(Cut);
LoadGraphic(CBG1);
LoadGraphic(CBG2);
LoadGraphic(NBG1);
LoadGraphic(BAR);
LoadGraphic(BAR2);
LoadSE(charge);
LoadSE(sh1);
LoadSE(sh2);
LoadSE(sh3);
if (GetPlayerType == REIMU_A){
SetLife(1000);
}
if (GetPlayerType == REIMU_B){
SetLife(500);
}
if (GetPlayerType == MARISA_A){
SetLife(450);
}
if (GetPlayerType == MARISA_B){
SetLife(450);
}
if (GetPlayerType == USER_PLAYER){
SetLife(1000);
}
SetDamageRate(0, 0);
SetTimer(99);
SetInvincibility(120);
SetEnemyMarker(true);
SetShotAutoDeleteClip(128,128,128,128);

cutin("NAZRIN", "Soul - Circle of Spirit", Cut, 0, 0, 283, 478);
SetScore(50000);
    }

    @MainLoop {
SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 24);
yield;

if (OnBomb == true){
SetDamageRate(0, 0);
}
if (OnBomb == false && frame4 >= 3000){
SetDamageRate(20, 0);
}

task BulletA(x,y,v,angle,graphic,delay) {
     let obj=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj, x, y);
     Obj_SetAngle(obj, angle);
     Obj_SetSpeed(obj, v);
     ObjShot_SetGraphic(obj, graphic);
     ObjShot_SetDelay  (obj, delay);
     ObjShot_SetBombResist (obj, true);

     while(Obj_BeDeleted(obj)==false) {

if (frame1 == 200 || frame1 == 370){
        loop(100)
        {
            CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),0);
	    SetShotDataA(1,0,5,a2,0,-0.1,1,242);
	    SetShotDataA(1,80,NULL,90,0,0.03,10,242);
	    FireShot(1);
            a2 += 360/100;
        }
	PlaySE(sh3);
Obj_Delete(obj);
      }
             yield;
}
}

task BulletB(x,y,v,angle,graphic,delay) {
     let obj=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj, x, y);
     Obj_SetAngle(obj, angle);
     Obj_SetSpeed(obj, v);
     ObjShot_SetGraphic(obj, graphic);
     ObjShot_SetDelay  (obj, delay);
     ObjShot_SetBombResist (obj, true);

     while(Obj_BeDeleted(obj)==false) {

if (frame2 == 200 || frame2 == 300){
        loop(100)
        {
            CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),0);
	    SetShotDataA(1,0,5,a2,0,-0.1,1,242);
	    SetShotDataA(1,80,NULL,90,0,0.03,10,242);
	    FireShot(1);
            a2 += 360/100;
        }
	PlaySE(sh3);
Obj_Delete(obj);
      }
             yield;
}
}
task BulletC(x,y,v,angle,graphic,delay) {
     let obj=Obj_Create(OBJ_SHOT);

     Obj_SetPosition(obj, x, y);
     Obj_SetAngle(obj, angle);
     Obj_SetSpeed(obj, v);
     ObjShot_SetGraphic(obj, graphic);
     ObjShot_SetDelay  (obj, delay);
     ObjShot_SetBombResist (obj, true);

     while(Obj_BeDeleted(obj)==false) {

if (frame3 == 350){
        loop(100)
        {
            CreateShotA(1,Obj_GetX(obj),Obj_GetY(obj),0);
	    SetShotDataA(1,0,5,a2,0,-0.07,0.003,242);
	    FireShot(1);
            a2 += 360/100;
        }
	PlaySE(sh3);
Obj_Delete(obj);
      }
             yield;
}
}
        if (frame1 == 60)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
        }
        if (frame1 == 170)
        {  
        BulletA(GetX,GetY,3,0,234,0);
	PlaySE(sh2);
        }
        if (frame1 >= 260 && frame1 <= 340)
        { 
        loop(2)
        {
            
            CreateShot01(GetX+rand(-50,50),GetY+rand(-50,50),rand(1,3),a1+rand(-20,20),158,5);
            a1 += 360/1;
        }
	a1 += 5;
	PlaySE(sh2);
        }
        if (frame1 == 340)
        {  
        BulletA(GetX,GetY,3,180,234,0);
	PlaySE(sh2);
        }
        if (frame1 >= 430 && frame1 <= 510)
        { 
        loop(2)
        {
            
            CreateShot01(GetX+rand(-50,50),GetY+rand(-50,50),rand(1,3),-a1+rand(-20,20),158,5);
            a1 += 360/1;
        }
	a1 += 5;
	PlaySE(sh2);
        }
        if (frame1 == 510)
        {  
        frame1 = 169;
        }
        if (frame4 == 1500)
        {  
	DeleteEnemyShot(ALL);
	PlaySE(sh1);
        frame1 = 5000;
        frame2 = 0;
        }
        if (frame4 == 3000)
        {  
	DeleteEnemyShot(ALL);
	PlaySE(sh1);
        frame1 = 50000;
        frame2 = 50000;
        frame3 = 0;
        frame5 = 0;
        }
        if (frame2 == 170)
        {  
        BulletB(GetX,GetY,3,0,234,0);
	PlaySE(sh2);
        }
        if (frame2 == 250)
        {  
        BulletB(GetX,GetY,3,180,234,0);
	PlaySE(sh2);
        }
        if (frame2 == 301)
        {  
        frame2 = 100;
        }
        if (frame2 >= 110 && frame2 <= 9999)
        { 
        loop(1)
        {
            
            CreateShot01(GetX+rand(-50,50),GetY+rand(-50,50),rand(2.7,3),-a1+rand(-20,20),158,5);
            a1 += 360/1;
        }
	a1 += 45;
	PlaySE(sh2);
        }
        if (frame3 == 170)
        {  
        BulletC(GetClipMinX-40,GetClipMinY-40,0.8,45,234,0);
        BulletC(GetClipMaxX+40,GetClipMinY-40,0.8,135,234,0);
        BulletC(GetClipMinX-40,GetClipMaxY+40,0.8,-45,234,0);
        BulletC(GetClipMaxX+40,GetClipMaxY+40,0.8,-135,234,0);
	PlaySE(sh2);
        }
        if (frame5 == 350)
	{
        loop(20)
        {
            
            CreateShot01(GetX,GetY,1.5,a3+GetAngleToPlayer,158,5);
            CreateShot01(GetX,GetY,1.6,a3+GetAngleToPlayer,158,5);
            CreateShot01(GetX,GetY,1.7,a3+GetAngleToPlayer ,158,5);
            a3 += 360/20;
        }
	PlaySE(sh2);
	frame5 = 277+acc11;
	acc11++;
        }
        if (frame4 >= 3350)
	{
SetMovePosition01(GetCenterX + 600*cos(a4), GetCenterY + 600*sin(a4), 5);
	a4 += 2;
        }
if (frame4 >= 3000 && OnBomb == true){
frame3 = 160;
DeleteEnemyShot(ALL);
}
if (frame4 >= 3000 && OnPlayerMissed == true){
frame3 = 160;
DeleteEnemyShot(ALL);
}
if (frame4 >= 3000){
SetDamageRate(20, 0);
}
        frame1++;
        frame2++;
        frame3++;
        frame4++;
        frame5++;
    }

    @DrawLoop {
SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,acc7);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 800, 800);
SetAlpha(255);
DrawGraphic(GetCenterX, GetCenterY);

SetTexture(CBG2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,-45);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 256000, 256000);
SetAlpha(80);
DrawGraphic(GetCenterX - acc5, GetCenterY - acc5);

SetTexture(CBG2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,-45);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 256000, 256000);
SetAlpha(80);
DrawGraphic(GetCenterX - acc8, GetCenterY - acc6);

SetTexture(MC);
SetRenderState(ADD);
SetGraphicAngle(0,0,acc1);
SetGraphicScale(1+acc3,1+acc3);
SetGraphicRect(0, 0, 128, 128);
SetAlpha(255);
DrawGraphic(GetX, GetY);

if (GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1+acc10);
SetGraphicRect(0, 0, 52, 86);
SetAlpha(255);
DrawGraphic(GetX + 2, GetY);
}
if (GetSpeedX > 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1+acc10);
SetGraphicRect(52, 0, 103, 86);
SetAlpha(255);
DrawGraphic(GetX + 10, GetY);
}
if (GetSpeedX < 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(-1,1+acc10);
SetGraphicRect(52, 0, 103, 86);
SetAlpha(255);
DrawGraphic(GetX - 10, GetY);
}

if (OnBomb == true){
SetTexture(BAR);
SetRenderState(ADD);
SetGraphicAngle(0,0,acc1);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 256, 256);
SetAlpha(100);
DrawGraphic(GetX, GetY);
SetTexture(BAR2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,acc1);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 256, 256);
SetAlpha(100);
DrawGraphic(GetX, GetY);
}

acc1 += 8;
acc2++;
anim1++;
anim2++;
anim3++;
if (acc2 <= 40){acc3 += 0.01;}
if (acc2 >= 40){acc3 -= 0.01;}
if (acc2 == 80){acc2 = 0;}

if (acc9 <= 20){acc10 += 0.002;}
if (acc9 >= 20){acc10 -= 0.002;}
if (acc9 == 40){acc9 = 0;}
acc5 += 0.5;
acc6++;
acc7 += 0.2;
acc8 += 1.2;
acc9++;
}
    @Finalize {
    }
}
