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

script_enemy_main {

let frame1 = -30;
let frame2 = 0;
let frame3 = 0;
let frame4 = 0;
let w = 1;
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 lifeamt = 0;
let lifetot = 0;
let a1 = 0;
let a2 = 0;
let a3 = 0;
let a4 = 2;
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\Sprite.png";
let Custom = GetCurrentScriptDirectory~"sup\supershot3.txt";
let MC = GetCurrentScriptDirectory~"ef\MC.png";
let CBG1 = GetCurrentScriptDirectory~"ef\CBG1.png";
let CBG2 = GetCurrentScriptDirectory~"ef\CBG2.png";
let CBG3 = GetCurrentScriptDirectory~"ef\CBG3.png";
let NBG1 = GetCurrentScriptDirectory~"ef\nbg1.png";
let life = GetCurrentScriptDirectory~"ef\lifebar.png";
let charge = GetCurrentScriptDirectory~"se\Charge2.wav";
let sh1 = GetCurrentScriptDirectory~"se\Shot1.wav";
let sh2 = GetCurrentScriptDirectory~"se\fam.wav";
let sh3 = GetCurrentScriptDirectory~"se\Laser4.wav";
let timer = GetTimer;
let time1 = GetCurrentScriptDirectory~"se\time1.wav";
let time2 = GetCurrentScriptDirectory~"se\time2.wav";
let Cut = GetCurrentScriptDirectory~"ef\Cut.png";
	#include_function ".\cutin.txt";
	#include_function ".\blossom.txt";

    @Initialize {
	LoadSE(time1);
LoadSE(time2);

SetMovePosition02(GetCenterX, GetCenterY - 150, 0);
PlaySE(GetCurrentScriptDirectory~"cardcall.wav");
LoadUserShotData(Custom);
LoadGraphic(SP);
LoadGraphic(MC);
LoadGraphic(Cut);
LoadGraphic(CBG1);
LoadGraphic(CBG2);
LoadGraphic(CBG3);
LoadGraphic(NBG1);
LoadGraphic(life);
LoadSE(charge);
LoadSE(sh1);
LoadSE(sh2);
LoadSE(sh3);

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

cutin("NAZRIN", "Evil Sign 'Wheel of Fate'", Cut, 0, 0, 300, 450);
SetScore(50000);
LastSpell;
SetDurableSpellCard;
    }

    @MainLoop {
if(GetTimer!=timer && (GetTimer < 10 && GetTimer>3)){
	PlaySE(time1);
	}

	if(GetTimer!=timer && GetTimer < 4){
	PlaySE(time2);
	

	
}

timer = GetTimer;

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, false);

     while(Obj_BeDeleted(obj)==false) {

             if(Obj_GetX(obj)<GetClipMinX){
		loop(1){
CreateShot01(Obj_GetX(obj)+0.1, Obj_GetY(obj), v, 180 - Obj_GetAngle(obj), graphic + 1, 0);
}
Obj_Delete(obj);
             }
             if(Obj_GetX(obj)>GetClipMaxX){
		loop(1){
CreateShot01(Obj_GetX(obj)-0.1, Obj_GetY(obj), v, 180 - Obj_GetAngle(obj), graphic + 1, 0);
}
Obj_Delete(obj);
             }
             if(Obj_GetY(obj)<GetClipMinY){
		loop(1){
CreateShot01(Obj_GetX(obj), Obj_GetY(obj)+0.1, v, 0 - Obj_GetAngle(obj), graphic + 1, 0);
}
Obj_Delete(obj);
             }

             yield;
      }
}

        if (frame1 == 190)
        { 

        loop(18)
        {
            CreateShot01(GetX+10*cos(a2), GetY+10*sin(a2),3,a2,98,10);
            CreateShot01(GetX+10*cos(a2), GetY+10*sin(a2),3,a2+2,98,10);
            CreateShot01(GetX+10*cos(a2), GetY+10*sin(a2),3,a2-2,98,10);
	a2 += 360/18;
        }
	a2 += 27;
	PlaySE(sh1);
	frame1 = 160;
        }

        if (frame6 >= 1 && frame6 <= 4)
        { 
	Explosion01(GetX,GetY,10,0.2,50);
	}

        if (frame2 == 80)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
	}

        if (frame2 == 190)
        { 
	SetMovePosition03(GetCenterX, GetCenterY - 150, 10, 5);
        CreateEnemyFromFile(GetCurrentScriptDirectory~"last\lastfam.txt", GetX, GetY, 0, 0, 0); 
	PlaySE(sh2);
        }
        if (frame2 == 880)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
	}
        if (frame2 == 990)
        { 
	SetMovePosition03(GetCenterX, GetCenterY - 150, 10, 5);
        CreateEnemyFromFile(GetCurrentScriptDirectory~"last\lastfamright.txt", GetX, GetY, 0, 0, 0); 
        CreateEnemyFromFile(GetCurrentScriptDirectory~"last\lastfamleft.txt", GetX, GetY, 0, 0, 0); 
	PlaySE(sh2);
        }
        if (frame2 == 1580)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
	}
        if (frame2 == 1690)
        { 
	SetMovePosition03(GetCenterX, GetCenterY - 150, 10, 5);
        CreateEnemyFromFile(GetCurrentScriptDirectory~"last\lastfamrightcorner.txt", GetX, GetY, 0, 0, 0); 
        CreateEnemyFromFile(GetCurrentScriptDirectory~"last\lastfamleftcorner.txt", GetX, GetY, 0, 0, 0); 
        CreateEnemyFromFile(GetCurrentScriptDirectory~"last\lastfamrightcorner2.txt", GetX, GetY, 0, 0, 0); 
        CreateEnemyFromFile(GetCurrentScriptDirectory~"last\lastfamleftcorner2.txt", GetX, GetY, 0, 0, 0); 
	PlaySE(sh2);
        }
        if (frame2 == 2380)
        { 
	StartMapleConcentrate;
	PlaySE(charge);
	}
        if (frame2 == 2390)
        { 
	SetMovePosition03(GetCenterX, GetCenterY - 150, 10, 5);
        CreateEnemyFromFile(GetCurrentScriptDirectory~"last\lastfammid.txt", GetX, GetY, 0, 0, 0); 
	PlaySE(sh2);
        }


        frame1++;
        frame2++;
        frame3++;
        frame4++;
        frame6++;
        frame7++;
    }

    @DrawLoop {

let SP = GetCurrentScriptDirectory~"sp\Sprite.png";
let MC = GetCurrentScriptDirectory~"ef\MC.png";
let CBG1 = GetCurrentScriptDirectory~"ef\CBG1.png";
let CBG2 = GetCurrentScriptDirectory~"ef\CBG2.png";

SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(0, anim2, 416, 1024+anim2);
SetAlpha(255);
SetColor(150+acc7,230,120+acc4);
DrawGraphic(GetCenterX, GetCenterY);

SetTexture(CBG1);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(0, -anim2, 416, 1024-anim2);
SetAlpha(100);
SetColor(150+acc7,230,120+acc4);
DrawGraphic(GetCenterX, GetCenterY+10);

SetTexture(CBG2);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(0.5+acc8,0.5+acc8);
SetGraphicRect(0, 0, 480, 480);
SetAlpha(100);
SetColor(200+acc4,0,0);
DrawGraphic(GetCenterX, GetCenterY);

SetTexture(CBG3);
SetRenderState(ADD);
SetGraphicAngle(0,0,45);
SetGraphicScale(0.8*cos(acc9),0.8*sin(acc9));
SetGraphicRect(0, 0, 480, 480);
SetAlpha(255);
SetColor(255,255,255);
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG3);
SetRenderState(ADD);
SetGraphicAngle(0,0,45);
SetGraphicScale(0.8*cos(acc9-5),0.8*sin(acc9-5));
SetGraphicRect(0, 0, 480, 480);
SetAlpha(255);
SetColor(255,0,0);
DrawGraphic(GetCenterX, GetCenterY);
SetTexture(CBG3);
SetRenderState(ADD);
SetGraphicAngle(0,0,45);
SetGraphicScale(0.8*cos(acc9-10),0.8*sin(acc9-10));
SetGraphicRect(0, 0, 480, 480);
SetAlpha(255);
SetColor(255,0,0);
DrawGraphic(GetCenterX, GetCenterY);

loop(GetLife){
SetTexture(life);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,atan2(GetY-GetY-50*sin(lifeamt+90),GetX-GetX-50*cos(lifeamt-90)));
SetGraphicScale(1.2,1.2);
SetGraphicRect(0, 0, 5, 2);
SetAlpha(140);
SetColor(255,255,255);
DrawGraphic(GetX-50*cos(lifeamt-90), GetY-50*sin(lifeamt+90));
lifeamt += 360/360;
}
loop(72){
SetTexture(life);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,atan2(GetY-GetY-50*sin(lifetot+90),GetX-GetX-50*cos(lifetot-90)));
SetGraphicScale(1.2,1.2);
SetGraphicRect(5, 0, 9, 4);
SetAlpha(255);
SetColor(255,255,255);
DrawGraphic(GetX-50*cos(lifetot-90), GetY-50*sin(lifetot+90));
lifetot += 360/72;
}
lifeamt = 0;
lifetot = 0;

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

if (GetSpeedX == 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(0, 0, 125, 125);
SetAlpha(155);
DrawGraphic(GetX+5, GetY+3*sin(anim1));
}
if (GetSpeedX > 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(-1,1);
SetGraphicRect(256, 0, 381, 125);
SetAlpha(155);
DrawGraphic(GetX, GetY+3*sin(anim1));
}
if (GetSpeedX < 0){
SetTexture(SP);
SetRenderState(ALPHA);
SetGraphicAngle(0,0,0);
SetGraphicScale(1,1);
SetGraphicRect(256, 0, 381, 125);
SetAlpha(155);
DrawGraphic(GetX - 10, GetY+3*sin(anim1));
}
acc1 += 5;
acc2 += 2;
anim1 += 7;
anim2 += 0.6;
anim3++;
acc5 += 2;
acc6 += 0.5;
acc3 = 0.2*cos(acc2);
acc4 = 55*cos(acc6);
acc7 = 0.5*cos(acc2);
acc8 = 0.06*cos(acc2);
acc9 += 0.7;
}
    @Finalize {
SetMovePosition03(GetClipMinX-300, GetCenterY - 100, 10, 4);
	if(GotSpellCardBonus==true){ PlaySE(GetCurrentScriptDirectory~".\se\capture.wav"); }
	if(GotSpellCardBonus==false){ PlaySE(GetCurrentScriptDirectory~".\se\fail.wav"); }
	PlaySE(GetCurrentScriptDirectory~".\se\enemoff.wav");
    }
}
