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

script_enemy_main {

let frame1 = 0;
let frame2 = -200;
let frame3 = 0;
let frame4 = 0;
let frame5 = 0;
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 = 0;
let acc12 = 0;
let random1 = 0;
let random2 = 0;
let random3 = 0;
let random4 = 0;

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\Eff1.wav";
let sh3 = GetCurrentScriptDirectory~"se\BulletWave.wav";
let Cut = GetCurrentScriptDirectory~"ef\cut.png";
	#include_function ".\function_cutin.txt";
	#include_function ".\maple.txt";

    @Initialize {

SetMovePosition03(GetCenterX, GetCenterY - 150, 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);

SetLife(900);
SetDamageRate(20, 0);
SetTimer(55);
SetInvincibility(120);
SetEnemyMarker(true);
SetShotAutoDeleteClip(128,128,128,20);

cutin("NAZRIN", "Spirit Illusion - Impossible Events", 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){
SetDamageRate(20, 0);
}

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(Obj_GetY(obj) >= GetCenterY) {
		loop(1){
BulletC(Obj_GetX(obj), Obj_GetY(obj), 1, angle, graphic + 1, 0);
}
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 == 10)
        { 
loop(3){
CreateShot02(Obj_GetX(obj), Obj_GetY(obj), 0, Obj_GetAngle(obj) + a2, 0.01, 1.5, 211, 10);
a2 += 360/3;
}
	PlaySE(sh1);
}


             yield;
      }
}
        if (frame1 == 60)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
        }
        if (frame1 == 120)
        { 
        loop(1)
        {
            
            BulletC(GetClipMinX - 30,GetClipMinY + 20,3,a1,199,0);
            a1 += 360/1;
        }
	frame1 = 110;
	a1 += 13;
	PlaySE(sh3);
        }
        if (frame4 == 180)
        { 
	frame1 = 130;
        }
        if (frame4 == 300)
        { 
        loop(1)
        {
            
            BulletC(GetClipMaxX + 30,GetClipMinY + 20,3,180+a3,200,0);
            a3 += 360/1;
        }
	frame4 = 290;
	a3 -= 13;
	PlaySE(sh3);
        }
        if (frame5 == 360)
        { 
	frame4 = 310;
        }
        if (frame5 == 480)
        { 
        loop(6)
        {
            
            BulletC(GetX,GetY,3,a4+GetAngleToPlayer,195,0);
            a4 += 360/6;
        }
	frame5 = 440;
	PlaySE(sh3);
        }
        if (frame6 == 540)
        { 
	frame5 = 500;
        }
        if (frame6 == 600)
        { 
	frame1 = 61;
	frame4 = 61;
	frame5 = 61;
	frame6 = 61;
	a1 = 0;
	a3 = 0;
	a4 = 0;
        }
        if (frame2 == 201)
        { 
SetMovePosition03(GetCenterX + rand(-100,100), GetCenterY - 100 + rand(-50,50), 10, 3); 
frame2 = 100;      
}
        if (frame3 == 30)
        { 
frame3 = 0;     
}
        frame1++;
        frame2++;
        frame3++;
        frame4++;
        frame5++;
        frame6++;
    }

    @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 {
    }
}
