

script_enemy_main
{
    let count=0;
    let count2=0;
    let count3=0;
    let ten=0;
    let life=0;
    let get;
    let try;

    let move=0;

    let pass=GetCurrentScriptDirectory~"Spell.dat";

    let cx=GetCenterX();
    let img=GetCurrentScriptDirectory~"img\dot_remilia.png";
    let bg=GetCurrentScriptDirectory~"img\st00.png";
    let bg2=GetCurrentScriptDirectory~"img\moon3-1.png";
    let bg3=GetCurrentScriptDirectory~"img\cloud.png";

    let WALL_TOP = 8;
    let WALL_LEFT = 4;
    let WALL_RIGHT = 2;
    let WALL_BOTTOM = 1;
    let sh00=GetCurrentScriptDirectory~"\se\Shot00.wav";
    let Beem=GetCurrentScriptDirectory~"\se\Shot01.wav";

    let mm=0;
    let shot=0;
    let tame=0;
    let tame2=0;
    let d=70;
    let c=0;
    let ang=0;
    let ang2=0;

    task Laser(x,y,s,a,l,w,g,d,rm)
    {
        let obj = Obj_Create(OBJ_LASER);
        let c = 0;
        Obj_SetX(obj,x);
        Obj_SetY(obj,y);
        Obj_SetAngle(obj,a);
        ObjShot_SetGraphic(obj,g);
        ObjShot_SetDelay(obj,d);
        ObjLaser_SetLength(obj,l);
        ObjLaser_SetWidth(obj,w);
        ObjShot_SetBombResist(obj,true);
        ObjShot_ToItem(obj,false);
        ObjLaser_SetSource(obj,false);

        while (c<rm)
        {
            ObjLaser_SetLength(obj,l);
            l+=s;
            c++;
            if (d>=c) {
                ObjLaser_SetWidth(obj,20);
            }else {
                ObjLaser_SetWidth(obj,w);
            }
            if (c>=d+20) {
                Obj_SetCollisionToPlayer(obj,false);
            }
            if (c>=rm-20) {
                w=w/1.2;
                ObjLaser_SetWidth(obj,w);
            }
            if (c>=rm) {
                Obj_Delete(obj);
            }
            yield;
        }

    }

#include_function ".\BGfx.txt"

    @Initialize()
    {
        MagicCircle(false);
        SetEnemyMarker(true);
        SetLife(4600);
        SetDamageRate(135,44);
        SetTimer(39);
        SetNormPoint(-1);
        LoadGraphic(img);
        SetShotAutoDeleteClip(32,32,32,32);
        SetMovePositionRandom01(0,200,5,cx,105,cx,105);
        LoadGraphic(bg);
        LoadGraphic(bg2);
        LoadGraphic(bg3);
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadUserShotData(GetCurrentScriptDirectory~".\shot_All.txt");

    }

    @MainLoop()
    {
        if (count2%4==0) {
            life=GetLife();
        }if (ten==1&&count2%4==1) {
            ten=0;
        }
        if (count2%4==3&&GetLife()<life&&GetLife()>0) {
            ten=1;
        }
        SetCommonData("Black",240);

        ang=GetAngleToPlayer();

        if (count>60&&count<100&&count%4==0&&c<=2)
        {
            let i=0;
            //CreateLaser01(GetX(),GetY(),6,ang+45,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang-45,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang+135,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang-135,168,5,241,25);

            while (i<360)
            {
                CreateShot02(GetX()+20*cos(i-count),GetY()+20*sin(i-count),2,i-count,0.1,3.6,169,20);
                i+=30;
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            }
        }
        if (count>110&&count<150&&count%4==0&&c<=2)
        {
            let i=0;
            //CreateLaser01(GetX(),GetY(),6,ang+45,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang-45,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang+135,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang-135,168,5,241,25);

            while (i<360)
            {
                CreateShot02(GetX()+20*cos(15+i+count),GetY()+20*sin(15+i+count),2,15+i+count,0.1,3.6,169,20);
                i+=30;
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            }
        }

        if (count>50&&count<150&&count%12==0&&c<=2&&GetCommonDataDefault("ii1",0)>=2000)
        {
            let i=0;
            //CreateLaser01(GetX(),GetY(),6,ang+45,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang-45,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang+135,168,5,241,25);
            //CreateLaser01(GetX(),GetY(),6,ang-135,168,5,241,25);

            while (i<360)
            {
                CreateShot02(GetX()+20*cos(i-count),GetY()+20*sin(i-count),2,i-count*3,0.1,2.2-(GetCommonDataDefault("ii1",0)<2000),RED02*(GetCommonDataDefault("ii1",0)>=2000)+46*(GetCommonDataDefault("ii1",0)<2000),20);
                i+=30;
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            }
        }

        if (count>70&&count<240&&count%4==0&&c==3)
        {
            CreateShot02(GetX(),GetY(),10,ang+10+36*((150-(count-70))/150),-0.2,7,196,0);
            CreateShot02(GetX(),GetY(),10,ang-10-36*((150-(count-70))/150),-0.2,7,196,0);
            CreateShot02(GetX(),GetY(),11,ang+12+36*((150-(count-70))/150),-0.2,7,196,0);
            CreateShot02(GetX(),GetY(),11,ang-12-36*((150-(count-70))/150),-0.2,7,196,0);
            CreateShot02(GetX(),GetY(),10,ang+120+36*((150-(count-70))/150),-0.2,5,196,0);
            CreateShot02(GetX(),GetY(),10,ang-120-36*((150-(count-70))/150),-0.2,5,196,0);
            CreateShot02(GetX(),GetY(),11,ang+122+36*((150-(count-70))/150),-0.2,5,196,0);
            CreateShot02(GetX(),GetY(),11,ang-122-36*((150-(count-70))/150),-0.2,5,196,0);
            PlaySE(sh00);
        }

        if (count==140) {
            ang2=-140;
        }

        if (count<440&&count>170&&count%2==0) {
            ang2+=12.32;
        }

        if (count<442&&count>210&&count%2==0&&c==3)
        {

            CreateShot02(GetX()+30,GetY(),8,180+90+ang2,-0.2,5,RED32,10);
            CreateShot02(GetX()+30,GetY(),9,180+90+ang2,-0.2,5.3,RED32,10);
            CreateShot02(GetX()+30,GetY(),10,180+90+ang2,-0.2,5.6,RED32,10);
            CreateShot02(GetX()+30,GetY(),11,180+90+ang2,-0.2,6,RED32,10);
            CreateShot02(GetX()-30,GetY(),8,180+90-ang2,-0.2,5,RED32,10);
            CreateShot02(GetX()-30,GetY(),9,180+90-ang2,-0.2,5.3,RED32,10);
            CreateShot02(GetX()-30,GetY(),10,180+90-ang2,-0.2,5.6,RED32,10);
            CreateShot02(GetX()-30,GetY(),11,180+90-ang2,-0.2,6,RED32,10);
            CreateShot02(GetX()+30,GetY(),8,90+ang2,-0.2,5,RED32,10);
            CreateShot02(GetX()+30,GetY(),9,90+ang2,-0.2,5.3,RED32,10);
            CreateShot02(GetX()+30,GetY(),10,90+ang2,-0.2,5.6,RED32,10);
            CreateShot02(GetX()+30,GetY(),11,90+ang2,-0.2,6,RED32,10);
            CreateShot02(GetX()-30,GetY(),8,90-ang2,-0.2,5,RED32,10);
            CreateShot02(GetX()-30,GetY(),9,90-ang2,-0.2,5.3,RED32,10);
            CreateShot02(GetX()-30,GetY(),10,90-ang2,-0.2,5.6,RED32,10);
            CreateShot02(GetX()-30,GetY(),11,90-ang2,-0.2,6,RED32,10);
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
        }

        if (count==62&&c==4)
        {
            ascent(let t in 0..72) {
                Laser(GetX(),GetY(),9,t*5,12,11,41,86,134);
            }
        }

        if (count<180&&count>80&&count%18==0&&c==4)
        {
            ascent(let t in 0..36) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                CreateShot01(GetX(),GetY(),6,t*10,33,30);
                CreateShot01(GetX(),GetY(),7,5+t*10,33,30);
                CreateShot01(GetX(),GetY(),8,t*10,33,30);
            }
        }

        if (count==150&&c<=3)
        {//ランダムに移動場所を決める
            SetMovePositionRandom01(rand(50,80),80,5,GetClipMinX()+100,100,GetClipMaxX()-100,100);
            move=70;
        }

        if (count==160&&c<=2) {
            count=60;
            c++;
        }if (count==290&&c==3) {
            count=60;
            c=4;
        }if (count==260&&c==4) {
            count=60;
            c=0;
        }
        SetCollisionA(GetX(),GetY(),32);
        SetCollisionB(GetX(),GetY(),14);

        if (count2==40) {
            SetColor(255,0,0);
            Concentration01(165);
            PlaySE(GetCurrentScriptDirectory~"\se\puu811.wav");
        }

        if (count==140&&c==3) {
            SetColor(255,0,0);
            Concentration01(225);
            PlaySE(GetCurrentScriptDirectory~"\se\puu811.wav");
        }

        if (count2>=90) {
            count++;
        }count2++;
        if (count>=10) {
            count3++;
        }move--;


        yield;
    }

    @Finalize()
    {}

    @DrawLoop()
    {
        SetTexture(img);
        SetAlpha(255);
        SetGraphicAngle(0,0,0);
        SetColor(255,255,255);
        SetRenderState(ALPHA);
        SetGraphicScale(1,1);
        SetGraphicRect(0,0,128,128);
        if (int(GetSpeedX())==0&&count2/12%4>=0) {
            SetGraphicRect(0,0,128,128);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=1) {
            SetGraphicRect(0,128,128,256);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=2) {
            SetGraphicRect(0,256,128,384);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=3) {
            SetGraphicRect(0,384,128,512);
        }
        if (GetSpeedX()<0&&count2<=d) {
            SetGraphicRect(256,0,384,128);
        }
        if (GetSpeedX()<0&&count2<=d-8) {
            SetGraphicRect(256,128,384,256);
        }
        if (GetSpeedX()>=0&&count2<=d) {
            SetGraphicRect(256,256,384,384);
        }
        if (GetSpeedX()>=0&&count2<=d-8) {
            SetGraphicRect(256,384,384,512);
        }
        if (GetSpeedX()<0&&move>0) {
            SetGraphicRect(256,0,384,128);
        }
        if (GetSpeedX()<0&&move>8) {
            SetGraphicRect(256,128,384,256);
        }
        if (GetSpeedX()>=0&&move>0) {
            SetGraphicRect(256,256,384,384);
        }
        if (GetSpeedX()>=0&&move>8) {
            SetGraphicRect(256,384,384,512);
        }
        if (int(GetSpeedX())==0&&tame>0) {
            SetGraphicRect(128*4,0,128*5,128);
        }
        if (int(GetSpeedX())==0&&tame>0&&tame2<12) {
            SetGraphicRect(128*4,128,128*5,256);
        }
        if (ten==1&&OnBomb==false) {
            SetColor(160,160,180);
        }
        DrawGraphic(GetX(),GetY());

    }


}

