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

script_enemy_main {

let frame1 = 0;
let frame2 = 0;
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 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 kospin = 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 charge = GetCurrentScriptDirectory~"se\Charge2.wav";
let sh1 = GetCurrentScriptDirectory~"se\Eff1.wav";
let sh2 = GetCurrentScriptDirectory~"se\Shot1.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);
LoadSE(charge);
LoadSE(sh1);
LoadSE(sh2);

SetLife(1000);
SetDamageRate(20, 20);
SetTimer(60);
SetInvincibility(120);
SetEnemyMarker(true);
SetShotAutoDeleteClip(128,128,128,128);

cutin("NAZRIN", "Death Sign - Doors into the Spirit World", Cut, 0, 0, 238, 480);
SetScore(50000);
    }

    @MainLoop {
SetCollisionA(GetX, GetY, 32);
SetCollisionB(GetX, GetY, 24);
yield;
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) {

            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 4, Obj_GetAngle(obj) - 180 + rand(-2,2), 73, 5);
            a1 += 360/6;

             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 (frame1 == 149)
{
             BulletC(Obj_GetX(obj), Obj_GetY(obj), rand(1,2), 270 + rand(-30,30), 80, 10);
 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 (Obj_GetAngle(obj) >= 110 && Obj_GetAngle(obj) <= 270){
             Obj_SetAngle(obj,Obj_GetAngle(obj) - 2);
}
if (Obj_GetAngle(obj) <= 420 && Obj_GetAngle(obj) > 270){
             Obj_SetAngle(obj,Obj_GetAngle(obj) + 2);
}
Obj_SetSpeed(obj, Obj_GetSpeed(obj) + 0.01);

             yield;
      }
}
        if (frame1 == 60)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
        }
        if (frame1 == 165)
        { 
	frame1 = 135;
        }
        if (frame1 >= 150 && frame1 <= 165)
        { 
        
        loop(7)
        {
            CreateShotA(1,GetX,GetY,0);
	    SetShotDataA(1,0,4,a2,0,-0.05,0,67);
	    SetShotDataA(1,100,0,a2-90,0,0.04,10,65);
	    FireShot(1);
            CreateShotA(1,GetX,GetY,0);
	    SetShotDataA(1,0,4,-a2,0,-0.05,0,67);
	    SetShotDataA(1,100,0,-a2+90,0,0.04,10,65);
	    FireShot(1);
            a2 += 360/7;
        }
	a2 += 1;
	PlaySE(sh2);
        }
        frame1++;
        frame2++;
        frame3++;
        frame4++;
    }

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

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

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

if (anim1 < 10 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 50, 81);
SetAlpha(255);
DrawGraphic(GetX + 2, GetY);
}
if (anim1 >= 10 && anim1 < 20 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 50, 81);
SetAlpha(255);
DrawGraphic(GetX + 3, GetY);
}
if (anim1 >= 20 && anim1 < 30 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(50, 0, 100, 81);
SetAlpha(255);
DrawGraphic(GetX + 4, GetY);
}
if (anim1 >= 30 && anim1 < 40 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(100, 0, 150, 81);
SetAlpha(255);
DrawGraphic(GetX + 5, GetY);
}
if (anim1 >= 40 && anim1 < 50 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(150, 0, 200, 81);
SetAlpha(255);
DrawGraphic(GetX + 6, GetY);
}
if (anim1 >= 50 && anim1 <= 60 && GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(200, 0, 250, 81);
SetAlpha(255);
DrawGraphic(GetX + 7, GetY);
}
if (anim1 == 60){
anim1 = 0;
}
if (GetSpeedX > 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(200, 81, 250, 160);
SetAlpha(255);
DrawGraphic(GetX + 10, GetY);
}
if (GetSpeedX < 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(-1,1);
SetGraphicRect(200, 81, 250, 160);
SetAlpha(255);
DrawGraphic(GetX - 10, GetY);
}
acc1 += 8;
acc2++;
anim1++;
anim2++;
anim3++;
if (acc2 <= 40){acc3 += 0.01;}
if (acc2 >= 40){acc3 -= 0.01;}
if (acc2 == 80){acc2 = 0;}
acc5++;
}
    @Finalize {
loop(30){
CreateItem(ITEM_SCORE,GetX + rand(10,60)*cos(rand(0,360)),GetY + rand(10,60)*sin(rand(0,360)));
}
StartMapleExplode;
CreateItem(ITEM_1UP,GetX,GetY);
    }
}
