#e
#Title[_puUUUvij]
#Text[]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User()]
script_enemy_main
{
    let count=0;
    let count2=0;
    let count3=0;
    let count4=0;
    let R=0;
    let R2=0;
    let R3=0;
    let R4=0;
    let o=0;
    let move=0;
    let get;
    let try;
    let tame=0;
    let tame2=0;
    let tame3=0;
    let tame4=0;
    let ten=0;
    let life=0;

    let pass=GetCurrentScriptDirectory~"Spell.dat";

    let bombalpha=255;

    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 sh00=GetCurrentScriptDirectory~"\se\Shot00.wav";
    let mm=0;
    let shot=0;
    let tame=0;
    let tame2=0;
    let c=0;
    let d=60;
    let ang=0;

    function IntToString(num) {
        let retStr = "";//߂l
        let numStr = ToString(num);

        let i = 0;
        while (i < length(numStr)) {
            let tmp = numStr[i];
            if (tmp == '.') {	//_ŏI
                break;
            }
            retStr = retStr ~ [tmp];
            i++;
        }
        return retStr;
    }

    function CreateWayShot02(Way,Gap,PosX,PosY,Dist,Speed,Angle,Accelerate,MaxSpeed,Graphic,Delay) {
        ascent(let i in 0..Way) {
            CreateShot02(PosX+Dist*cos(Angle+Gap*(i+0.5-(Way * 0.5))),PosY+Dist*sin(Angle+Gap*(i+0.5-(Way * 0.5))),Speed,Angle+Gap*(i+0.5-(Way*0.5)),Accelerate,MaxSpeed,Graphic,Delay);
        }
    }

    task Laser(x,y,s,a,l,w,g,d)
    {
        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);
        //Obj_SetSpeed(obj,s);// s ͐Lт鑬x
        ObjLaser_SetLength(obj,l);
        ObjLaser_SetWidth(obj,w);
        ObjShot_SetBombResist(obj,true);
        ObjShot_ToItem(obj,false);
        ObjLaser_SetSource(obj,false);
        PlaySE(GetCurrentScriptDirectory~"\se\Laser2.wav");

        while (c<200&&GetEnemyLife>0)
        {
            ObjLaser_SetLength(obj,l);
            l+=s;
            c++;
            if (d>=c) {
                ObjLaser_SetWidth(obj,20);
            }else {
                ObjLaser_SetWidth(obj,w);
            }
            if (a<272&&a>268) {
                Obj_SetAngle(obj,273);
            }
            if (c>=126) {
                Obj_SetCollisionToPlayer(obj,false);
            }
            if (c>=132) {
                w=w/1.2;
                ObjLaser_SetWidth(obj,w);
            }
            if (c==142) {
                Obj_Delete(obj);
            }
            if (GetEnemyLife<=0) {
                DeleteEnemyShotImmediatelyInCircle(ALL,GetX,GetY,2000);
            }
            yield;
        }

    }

    @Initialize()
    {
        SetCommonData("ii1",2500);
        MagicCircle(false);
        SetEnemyMarker(true);
        if (IsCommonDataAreaExists("Spell")==false) {
            CreateCommonDataArea("Spell");
        }
        load();
        SetLife(1000);
        SetDamageRate(30,0);
        SetTimer(66);
        SetX(cx);
        SetInvincibility(150);
        SetNormPoint(-1);
        LoadGraphic(img);
        SetShotAutoDeleteClip(128,128,128,128);
        SetMovePositionRandom01(0,200,9,cx,78,cx,78);
        move=90;
        LoadGraphic(bg);
        LoadGraphic(bg2);
        LoadGraphic(bg3);
        LoadGraphic(GetCurrentScriptDirectory~"\img\dot_flandre.png");
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadUserShotData(GetCurrentScriptDirectory~".\shot_All.txt");

        if(GetCommonDataDefault("ii1",0)<2000) {
        get=GetCommonDataDefaultEx("Spell","1no6get",0);
        try=GetCommonDataDefaultEx("Spell","1no6try",0);}
        else {
        get=GetCommonDataDefaultEx("Spell","1no6get2",0);
        try=GetCommonDataDefaultEx("Spell","1no6try2",0);}
        try++;
        if(GetCommonDataDefault("ii1",0)<2000) {
            SetCommonDataEx("Spell","1no6try",try);
	}
        else {
            SetCommonDataEx("Spell","1no6try2",try);
	}
        save();

    }

    function load() {
        LoadCommonDataEx("Spell",pass);
    }

    function save() {
        SaveCommonDataEx("Spell",pass);
    }

    @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;
        }
        if (count3>=260&&count3<=360&&count%6==5&&OnBomb==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(8,4,GetX,GetY,0,3.8,count*5,0,8,169,5);
            CreateWayShot02(8,4,GetX,GetY,0,2.8,count*9,0,8,169,5);
            CreateWayShot02(8,4,GetX,GetY,0,3.6,count*5,0,8,169,5);
            CreateWayShot02(8,4,GetX,GetY,0,2.6,count*9,0,8,169,5);
        }

        if (count3>=950&&count3<1150&&count%6==5&&OnBomb==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(10,2+(count-950)/13,GetX,GetY,0,8.5-(count-950)/12,125,0,8,169,5);
            CreateWayShot02(10,2+(count-950)/13,GetX,GetY,0,8.5-(count-950)/12,55,0,8,169,5);
            CreateWayShot02(10,2+(count-950)/13,GetX,GetY,0,8.35-(count-950)/12,125,0,8,196,5);
            CreateWayShot02(10,2+(count-950)/13,GetX,GetY,0,8.35-(count-950)/12,55,0,8,196,5);
        }

        if (count3<=1160&&count3>=1150&&count%4==2&&OnBomb==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(10,2+(count-950)/13,GetX,GetY,0,8.5-(count-950)/12,125,0,8,169,5);
            CreateWayShot02(10,2+(count-950)/13,GetX,GetY,0,8.5-(count-950)/12,55,0,8,169,5);
        }

        SetCollisionA(GetX(),GetY()-19,25+count4/1.7);
        SetCollisionB(GetX(),GetY(),12);

        if (count3<=260&&count3%62==0&&R4<=4)
        {
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant03.txt",cx-100+40*R4,-55,0,0,10+R4);
            R4++;
        }

        if (count3>260&&count3%62==0&&R4<=4)
        {
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant03.txt",cx-100+40*R4,-55,0,0,R4);
            R4++;
        }

        if (count3>=260&&count3%42==0&&R4<=4&&R<=1)
        {
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant03.txt",cx-100+40*R4,-55,0,0,R4);
            R4++;
        }

        if (count3>=260&&count3%42==0&&R4<=4&&R>1)
        {
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant03.txt",cx+100-40*R4,-55,0,0,R4);
            R4++;
        }

        if (count3>=260&&count3%42==0&&R4>4&&R<=2)
        {
            R4=0;
            R++;
        }

        if (count3>=460&&count3%42==21&&R3<=4&&R2<=0)
        {
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant03.txt",cx-100+40*R4,-55,0,0,5+R3);
            R3++;
        }

        if (count3>=460&&count3%42==21&&R3>4&&R2<=0)
        {
            R3=0;
            R2++;
        }

        if (count3>=380&&count3<=620&&count%8==5&&OnBomb==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            ascent( let t in 0..7 ) {
                CreateShot12(GetX+33,GetY,rand(-4,4.6),rand(4.0,4.0),0,-0.03,0,3.6,169,22);
            }
            ascent( let t in 0..7 ) {
                CreateShot12(GetX-33,GetY,rand(-4.6,4),rand(4.0,4.0),0,-0.03,0,3.6,169,22);
            }
        }

        if (count3>=680&&count3<750&&count%18==10&&OnBomb==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(8,12,GetX+30,GetY-40,0,3.1+(750-680)*0.010,GetAngleToPlayer-1,0,8,169,5);
            CreateWayShot02(8,12,GetX-30,GetY-40,0,3.1+(750-680)*0.010,GetAngleToPlayer+1,0,8,169,5);
            CreateWayShot02(8,12,GetX+30,GetY-40,0,3.0+(750-680)*0.010,GetAngleToPlayer-1,0,8,196,5);
            CreateWayShot02(8,12,GetX-30,GetY-40,0,3.0+(750-680)*0.010,GetAngleToPlayer+1,0,8,196,5);
        }

        if (count3>=750&&count3<=974&&count%18==10&&OnBomb==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateWayShot02(8,12,GetX+30,GetY-40,0,3.1+(count-680)*0.011,GetAngleToPlayer-1,0,8,169,5);
            CreateWayShot02(8,12,GetX-30,GetY-40,0,3.1+(count-680)*0.011,GetAngleToPlayer+1,0,8,169,5);
            CreateWayShot02(8,12,GetX+30,GetY-40,0,3.0+(count-680)*0.011,GetAngleToPlayer-1,0,8,196,5);
            CreateWayShot02(8,12,GetX-30,GetY-40,0,3.0+(count-680)*0.011,GetAngleToPlayer+1,0,8,196,5);
        }

        if (count>=115&&count%42==40&&rand(0,100)<=70&&tame3<=0) {
            SetMovePositionRandom01(85,rand(10,40),7,GetPlayerX()+rand(-60,60),50,GetPlayerX()+rand(-60,60),120);
            move=43;
            tame2++;
        }

        if (count2>=80) {
            count++;
        }count2++;
        if (count2>=60) {
            count3++;
            tame++;
        }
        if (count2==30) {
            SetColor(255,0,0);
            Concentration01(115);
            PlaySE(GetCurrentScriptDirectory~"\se\puu811.wav");
        }
        if (count2==81) {
            PlaySE(GetCurrentScriptDirectory~"\se\warp02.wav");
            SetScore(15000000);
            CutIn(YOUMU,"_puUUUv",GetCurrentScriptDirectory~"img\remiria2.png",0,0,512,512);
        }

        if (count3>=1060&&count3<1405)
        {
            tame3++;
        }

        if (count3==1000) {
            SetColor(255,0,0);
            Concentration01(185);
            PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
        }

        if (count3==1065) {
            SetMovePositionRandom01(85,rand(10,40),7,cx,80,cx,80);
            move=43;
            tame2++;
            count3+=100;
        }

        if (count3==1222) {
            Laser(cx,GetClipMinY,12,90,0,12,185,110);
        }

        if (count3>=1225&&count3<=1380&&count3%4==0) {
            Laser(cx+22+R,GetClipMinY,12,90,0,12,185,110);
            Laser(cx-22-R,GetClipMinY,12,90,0,12,185,110);
            R+=22;
        }

        if (count3==1235) {
            SetCommonData("Sign",1);
        }

        if (count3==1335) {
            SetCommonData("Sign",2);
        }

        if (count3<=1535&&GetLife<350) {
            SetDamageRate(1,0);
        }

        if (count3>=1545&&GetLife<350) {
            SetDamageRate(9,0);
        }

        if (count3>=1545&&OnBomb==true) {
            SetDamageRate(3,0);
        }

        if (count3>=1380&&count3<=1520) {
            DeleteEnemyShotInCircle(ALL,GetX,GetY,(count3-1380)*4);
        }

        //if(count3>=1520&&count3%180==0){tame4++;}

        if (count3==1500)
        {
            ascent( let t in 0..5 ) {
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant04.txt",cx,-65,0,0,t);
            }
        }

        SetCommonData("x",GetX);
        SetCommonData("y",GetY);

        if (count3>=1520) {
            SetX(GetX*((100-count4)/100)+(cx+65*cos(count/2+90))*((count4)/100));
            SetY(GetY*((100-count4)/100)+(122-25*cos(count+90))*((count4)/100));
        }

        if (count3>=1660&&count%840>=160&&count%840<=420&&count%12==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            CreateWayShot02(8,19,GetX+30,GetY-40,0,2.8,GetAngleToPlayer,0,8,RED02,25);
            CreateWayShot02(8,19,GetX-30,GetY-40,0,2.8,GetAngleToPlayer+180,0,8,RED02,25);
        }

        if (count3>=1660&&count%840>=580&&count%12==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            CreateWayShot02(8,19,GetX+30,GetY-40,0,2.8,GetAngleToPlayer+180,0,8,RED02,25);
            CreateWayShot02(8,19,GetX-30,GetY-40,0,2.8,GetAngleToPlayer,0,8,RED02,25);
        }

        if (count3>=1520&&count4<100) {
            count4+=0.25;
        }

        c+=5;
        move--;
        yield;

    }

    @Finalize()
    {
        DeleteEnemyShotImmediatelyInCircle(ALL,GetX,GetY,2000);

        if (GotSpellCardBonus()==true) {
            get++;
            if(GetCommonDataDefault("ii1",0)<2000) {
            SetCommonDataEx("Spell","1no6get",get);
            }
            else {
            SetCommonDataEx("Spell","1no6get2",get);
            }
        }
        save();

        SetShotAutoDeleteClip(32,32,32,32);
        ascent( let t in 0..50 ) {
            CreateItem(ITEM_SCORE,GetX()+150*cos(t*7.2),GetY()+20+150*sin(t*7.2));
        }
        ascent( let t in 0..50 ) {
            CreateItem(ITEM_SCORE,GetX()+100*cos(3.6+t*7.2),GetY()+20+100*sin(3.6+t*7.2));
        }
        if (GetCommonDataDefault("miss",0)!=2) {
            CreateItem(ITEM_1UP,GetX(),GetY()+20);
        }

    }

    @DrawLoop()
    {
        if (GetEnemyLife>0) {
            SetTexture(GetCurrentScriptDirectory~"\img\circle_l.png");
            SetGraphicAngle(0,0,-c);
            SetGraphicRect(0,0,256,256);
            SetAlpha(255);
            SetRenderState(ADD);
            SetColor(160+20*sin(c),160+20*sin(c),160+20*sin(c));
            if (count2<=58) {
                SetGraphicScale(0,0);
            }
            if (count2>58) {
                SetGraphicScale(0.02*(count2-58)+0.1*sin(count2*3),0.02*(count2-58)+0.1*sin(count2*3));
            }
            if (count2>=108) {
                SetGraphicScale(1.0+0.1*sin(count2*3),1.0+0.1*sin(count2*3));
            }
            DrawGraphic(GetX(),GetY());
        }

        if (OnEnemySpell==true&&OnBomb==true&&bombalpha>0) {
            bombalpha-=5;
        }
        if (OnEnemySpell==true&&OnBomb==false&&bombalpha<255) {
            bombalpha+=5;
        }

        SetTexture(img);
        SetAlpha(255);
        SetGraphicAngle(0,0,0);
        SetColor(bombalpha,bombalpha,bombalpha);
        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&&move>0) {
            SetGraphicRect(256,0,384,128);
        }
        if (GetSpeedX()<0&&move>9) {
            SetGraphicRect(256,128,384,256);
        }
        if (GetSpeedX()>=0&&move>0) {
            SetGraphicRect(256,256,384,384);
        }
        if (GetSpeedX()>=0&&move>9) {
            SetGraphicRect(256,384,384,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 (tame>0&&tame2<=0) {
            SetGraphicRect(128*3,0,128*4,128);
        }
        if (tame>32&&tame2<=0) {
            SetGraphicRect(128*3,128,128*4,256);
        }
        if (tame>42&&tame2<=0) {
            SetGraphicRect(128*3,256,128*4,384);
        }
        if (tame3>40&&tame4<=0) {
            SetGraphicRect(128*4,0,128*5,128);
        }
        if (tame3>56&&tame4<=0) {
            SetGraphicRect(128*4,128,128*5,256);
        }
        if (ten==1&&OnBomb==false) {
            SetColor(160,160,180);
        }
        DrawGraphic(GetX(),GetY());

        if (bombalpha<255) {
            SetTexture(img);
            SetAlpha(255-bombalpha);
            SetGraphicRect(128*6,0,128*7,128);
            SetColor(255,200,200);
            SetGraphicScale(1.1,1.1);
            SetRenderState(ALPHA);
            if (count2/4%4>=0) {
                SetGraphicRect(128*6,0,128*7,128);
            }
            if (count2/4%4>=1) {
                SetGraphicRect(128*6,128,128*7,256);
            }
            if (count2/4%4>=2) {
                SetGraphicRect(128*6,256,128*7,384);
            }
            if (count2/4%4>=3) {
                SetGraphicRect(128*6,384,128*7,512);
            }
            DrawGraphic(GetX()+15*cos(count2*28),GetY()+30*cos(count2*18));
            if (count2/4%4>=0) {
                SetGraphicRect(128*6,384,128*7,512);
            }
            if (count2/4%4>=1) {
                SetGraphicRect(128*6,0,128*7,128);
            }
            if (count2/4%4>=2) {
                SetGraphicRect(128*6,128,128*7,256);
            }
            if (count2/4%4>=3) {
                SetGraphicRect(128*6,256,128*7,384);
            }
            DrawGraphic(GetX()-30*cos(count2*18),GetY()-15*cos(count2*28));
            if (count2/4%4>=0) {
                SetGraphicRect(128*6,256,128*7,384);
            }
            if (count2/4%4>=1) {
                SetGraphicRect(128*6,384,128*7,512);
            }
            if (count2/4%4>=2) {
                SetGraphicRect(128*6,0,128*7,128);
            }
            if (count2/4%4>=3) {
                SetGraphicRect(128*6,128,128*7,256);
            }
            DrawGraphic(GetX()+24*cos(count2*46),GetY()-40*cos(count2*58));
            if (count2/4%4>=0) {
                SetGraphicRect(128*6,128,128*7,256);
            }
            if (count2/4%4>=1) {
                SetGraphicRect(128*6,256,128*7,384);
            }
            if (count2/4%4>=2) {
                SetGraphicRect(128*6,384,128*7,512);
            }
            if (count2/4%4>=3) {
                SetGraphicRect(128*6,0,128*7,128);
            }
            DrawGraphic(GetX()-44*cos(count2*46),GetY()+20*cos(count2*58));
        }

        if (count>=10) {
            if(GetCommonDataDefault("ii1",0)<2000) {
                SetFontColor(255,255,255,64,64,255);
            }
            else {
                SetFontColor(255,196,196,255,0,0);
            }
            let posX = 80;
            if (try>=1000) {
                posX+=21;
            }if (try>=100) {
                posX+=14;
            }else if (try>=10) {
                posX+=7;
            }
            if (get>=1000) {
                posX+=15;
            }if (get>=100) {
                posX+=10;
            }else if (get>=10) {
                posX+=5;
            }
            DrawText("Score "~IntToString(get)~" / "~IntToString(try)~"",GetClipMaxX()-posX,GetClipMinY()+44,10,196);
        }
    }

    @BackGround()
    {
        SetTexture(bg);
        SetGraphicRect(0,0,384,448);
        SetRenderState(ALPHA);
        SetGraphicScale(1,1);
        SetGraphicAngle(0,0,0);
        SetColor(255,255,255);
        if (count3<=1) {
            SetAlpha(0);
        }
        if (count3>1) {
            SetAlpha(count3*5);
        }
        if (count3>=51) {
            SetAlpha(255);
        }
        DrawGraphic(GetCenterX(),GetCenterY());

        SetTexture(bg2);
        SetRenderState(ADD);
        SetGraphicAngle(0,0,-count2);
        if (count2<=1) {
            SetColor(0,0,0);
        }
        if (count2>1) {
            SetColor(count2,count2,count2);
        }
        if (count2>=128) {
            SetColor(128,128,128);
        }
        DrawGraphic(GetCenterX(),GetCenterY()-30);
        SetGraphicScale(1.9,1.9);
        SetGraphicAngle(0,0,count2);
        DrawGraphic(GetCenterX(),GetCenterY()-30);

        SetTexture(bg3);
        SetGraphicAngle(0,0,0);
        SetGraphicRect(-count2,512,1028-count2,768);
        SetGraphicScale(1,1);
        SetAlpha(255);
        if (count2<=1) {
            SetColor(0,0,0);
        }
        if (count2>1) {
            SetColor(count2*2,count2*2,count2*2);
        }
        if (count2>=128) {
            SetColor(255,255,255);
        }
        SetRenderState(SUBTRACT);
        DrawGraphic(GetCenterX(),GetCenterY()+100);
        DrawGraphic(GetCenterX(),GetCenterY()+100);
    }

}

