#e
#Title[^uꂽԁvij]
#Text[]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User()]
script_enemy_main
{
    let count=0;
    let count2=0;
    let count3=0;
    let move=0;
    let get;
    let try;

    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;
    let ang2=0;

    let step=0;
    let x0=0;
    let x1=0;
    let y0=0;
    let y1=0;
    let idou=0;
    let bem=0;
    let N15=0;
    let i=0;
    let laser=0;
    let laserSE=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;
    }

    @Initialize()
    {
        SetCommonData("ii1",2500);
        MagicCircle(false);
        SetEnemyMarker(true);
        if (IsCommonDataAreaExists("Spell")==false) {
            CreateCommonDataArea("Spell");
        }
        load();
        SetLife(600);
        SetDamageRate(0,512);
        SetTimer(30);
        SetInvincibility(9999);
        SetNormPoint(-1);
        LoadGraphic(img);
        SetShotAutoDeleteClip(32,32,32,32);
        SetMovePositionRandom01(0,200,3,GetX,GetY-33,GetX,GetY-33);
        move=60;
        LoadGraphic(bg);
        LoadGraphic(bg2);
        LoadGraphic(bg3);
        SetDurableSpellCard();
        LoadGraphic(GetCurrentScriptDirectory~"\img\dot-kaze-ti.png");
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadUserShotData(GetCurrentScriptDirectory~".\shot_All.txt");

        if(GetCommonDataDefault("ii1",0)<2000) {
        get=GetCommonDataDefaultEx("Spell","2no4get",0);
        try=GetCommonDataDefaultEx("Spell","2no4try",0);}
        else {
        get=GetCommonDataDefaultEx("Spell","2no4get2",0);
        try=GetCommonDataDefaultEx("Spell","2no4try2",0);}
        try++;
        if(GetCommonDataDefault("ii1",0)<2000) {
            SetCommonDataEx("Spell","2no4try",try);
	}
        else {
            SetCommonDataEx("Spell","2no4try2",try);
	}
        save();

    }

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

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

    @MainLoop()
    {
        if (count2<=88) {
            SetCollisionA(GetX(),GetY(),18);
            SetCollisionB(GetX(),GetY(),5);
        }
        if (count2==50) {
            SetColor(255,0,0);
            Concentration01(2);
        }
        if (count2>88&&count2<=138) {
            SetCollisionA(GetX(),GetY(),14+(count2-88)*1.7);
            SetCollisionB(GetX(),GetY(),5+(count2-88)*2);
        }
        if (count2>=138) {
            SetCollisionA(GetX(),GetY(),109);
            SetCollisionB(GetX(),GetY(),105);
        }
        if (count2==80) {
            SetMovePositionRandom01(0,200,6,cx,178,cx,178);move=50;
        }

        if (count%3==0) {
            x0=GetPlayerX();
            y0=GetPlayerY();
        }
        if (count%3==1) {
            x1=GetPlayerX();
            y1=GetPlayerY();
        }
        if (count%3==2) {
            if (x0==x1&&y0==y1) {
                idou=0;
            }else {
                idou=1;
            }
        }

        if (count2<=60) {
            SetTimer(31);
        }

        if (count>40&&count%3==0)
        {
            AddLife(-1);
        }

        if (count2<=80&&OnBomb) {
            mm=1;
        }
        if (count2>80&&!OnBomb) {
            mm=0;
        }

        if (mm==0&&OnBomb)
        {
            PlaySE(GetCurrentScriptDirectory~"\se\bom13.wav");
            SetCommonData("flash2",145);
            SetTimer(0);
        }

        if (count>50&&bem==0)
        {
            if (count%6==0&&idou==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Laser.wav");
                ang+=2;
                SetCollisionB(GetX(),GetY(),52);
                CreateLaserB(N15,600,7,254,5);
                SetLaserDataB(N15,0,0,80,-3,ang+180,0,ang+181,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,600,7,254,5);
                SetLaserDataB(N15,0,0,80,-3,ang+300,0,ang+300,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,600,7,254,5);
                SetLaserDataB(N15,0,0,80,-3,ang+60,0,ang+62,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,7,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+120,0,ang+120,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,7,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+240,0,ang+240,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,7,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+360,0,ang+360,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
            }
            if (count%6==0&&idou==1) {
                PlaySE(GetCurrentScriptDirectory~"\se\Laser.wav");
                ang+=2;
                SetCollisionB(GetX(),GetY(),52);
                CreateLaserB(N15,600,7,253,5);
                SetLaserDataB(N15,0,0,80,-3,ang+120,0,ang+121,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,600,7,253,5);
                SetLaserDataB(N15,0,0,80,-3,ang+240,0,ang+240,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,600,7,253,5);
                SetLaserDataB(N15,0,0,80,-3,ang+360,0,ang+362,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,7,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+180,0,ang+180,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,7,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+300,0,ang+300,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,7,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+60,0,ang+60,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
            }
        }

        if (count>50&&bem==1)
        {
            if (count%3==0&&idou==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Laser.wav");
                ang+=2;
                SetCollisionB(GetX(),GetY(),52);
                CreateLaserB(N15,600,12,254,5);
                SetLaserDataB(N15,0,0,80,-3,ang+180,0,ang+181,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,600,12,254,5);
                SetLaserDataB(N15,0,0,80,-3,ang+300,0,ang+300,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,600,12,254,5);
                SetLaserDataB(N15,0,0,80,-3,ang+60,0,ang+62,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,8,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+120,0,ang+120,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,8,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+240,0,ang+240,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,8,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+360,0,ang+360,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
            }
            if (count%3==0&&idou==1) {
                PlaySE(GetCurrentScriptDirectory~"\se\Laser.wav");
                ang+=2;
                SetCollisionB(GetX(),GetY(),52);
                CreateLaserB(N15,600,12,253,5);
                SetLaserDataB(N15,0,0,80,-3,ang+120,0,ang+121,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,600,12,253,5);
                SetLaserDataB(N15,0,0,80,-3,ang+240,0,ang+240,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,600,12,253,5);
                SetLaserDataB(N15,0,0,80,-3,ang+360,0,ang+362,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,8,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+180,0,ang+180,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,8,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+300,0,ang+300,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
                CreateLaserB(N15,400,8,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+60,0,ang+60,0);
                SetShotKillTime(N15,44);
                FireShot(N15);
            }
            if (count2<60*18&&count%8==0&&GetCommonDataDefault("ii1",0)<2000) {
                ascent( let t in 0..5 ) {
                    CreateShot01(GetX()+110*cos(count*1.05+72*t),GetY()+110*sin(count*1.05+72*t),1.6,count*1.05+72*t+rand(-1,1),169,20)
                }
            }
            if (count2<60*18&&count%6==0&&GetCommonDataDefault("ii1",0)>=2000) {
                ascent( let t in 0..6 ) {
                    CreateShot01(GetX()+110*cos(count*1.05+60*t),GetY()+110*sin(count*1.05+60*t),1.6,count*1.05+60*t+rand(-1,1),169,20)
                }
            }
        }

        if (count>50&&bem==2)
        {
            if (idou==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Laser.wav");
                ang+=1.05+ang2;
                ang2+=0.0033;
                SetCollisionB(GetX(),GetY(),52);
                CreateLaserB(N15,600,20,254,2);
                SetLaserDataB(N15,0,0,80,-3,ang+180,0,ang+181,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,600,20,254,2);
                SetLaserDataB(N15,0,0,80,-3,ang+300,0,ang+300,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,600,20,254,2);
                SetLaserDataB(N15,0,0,80,-3,ang+60,0,ang+62,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,400,14,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+120,0,ang+120,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,400,14,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+240,0,ang+240,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,400,14,253,45);
                SetLaserDataB(N15,0,0,80,-3,ang+360,0,ang+360,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
            }
            if (idou==1) {
                PlaySE(GetCurrentScriptDirectory~"\se\Laser.wav");
                ang+=1.05+ang2;
                ang2+=0.0033;
                SetCollisionB(GetX(),GetY(),52);
                CreateLaserB(N15,600,20,253,2);
                SetLaserDataB(N15,0,0,80,-3,ang+120,0,ang+121,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,600,20,253,2);
                SetLaserDataB(N15,0,0,80,-3,ang+240,0,ang+240,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,600,20,253,2);
                SetLaserDataB(N15,0,0,80,-3,ang+360,0,ang+362,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,400,14,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+180,0,ang+180,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,400,14,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+300,0,ang+300,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
                CreateLaserB(N15,400,14,254,45);
                SetLaserDataB(N15,0,0,80,-3,ang+60,0,ang+60,0);
                SetShotKillTime(N15,20);
                FireShot(N15);
            }
            if (count2>60*29&&count2%22==0&&GetCommonDataDefault("ii1",0)>=2000) {
                PlaySE(GetCurrentScriptDirectory~"\se\Beam.wav");
                ascent( let t in 0..45 ) {
                    CreateShot01(GetX()+110*cos(6*t),GetY()+110*sin(6*t),2.6,135+6*t+rand(-1,1),100,20)
                }
            }
        }

        if (count2>=160) {
            count++;
        }count2++;
        if (count2>=130) {
            count3++;
            tame++;
        }
        if (count==10) {
            PlaySE(GetCurrentScriptDirectory~"\se\warp02.wav");
            SetScore(7500000);
            CutIn(YOUMU,"^uꂽԁv",0,0,0,0,0);
        }

        if (GetEnemyLife()<=500) {
            if (laserSE<=0) {
                SetColor(155,0,255);
                Concentration01(195);
                PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
                laserSE=1;
                laser=180;
            }
        }
        if (GetEnemyLife()<=268) {
            if (laserSE<=2) {
                SetColor(155,0,255);
                Concentration01(195);
                PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
                laserSE=3;
                laser=180;
            }
        }

        if (laser==1) {
            PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
            bem++;
        }
        if (laser>0) {
            laser--;
        }
        if (GetEnemyLife()==210) {
            PlaySE(GetCurrentScriptDirectory~"\se\Baaaaaaaan.wav");
        }


        if(count2==80){PlaySE(GetCurrentScriptDirectory~"\se\puu811.wav");}
        if (count2>185&&bombalpha>0) {
            bombalpha-=5;
        }

        c+=5;
        move--;

    }

    @Finalize()
    {
        if (GotSpellCardBonus()==true) {
            get++;
            if(GetCommonDataDefault("ii1",0)<2000) {
            SetCommonDataEx("Spell","2no4get",get);
            }
            else {
            SetCommonDataEx("Spell","2no4get2",get);
            }
        }
        save();

        SetShotAutoDeleteClip(32,32,32,32);
        loop(80) {
            CreateItem(ITEM_SCORE,GetX()+rand(-150,150),GetY()+rand(-90,135));
        }

    }

    @DrawLoop()
    {
        if (GetEnemyLife>0) {
            SetTexture(GetCurrentScriptDirectory~"\img\circle_l.png");
            SetGraphicAngle(0,0,-c);
            SetAlpha(255);
            SetRenderState(ADD);
            SetColor(150+100*sin(c/2+30),150+100*sin(c/2+180),150+100*sin(c/2+240));
            if (count2<=88) {
                SetGraphicScale(0,0);
            }
            if (count2>88) {
                SetGraphicScale(0.02*(count2-88)+0.05*sin(count2),0.02*(count2-88)+0.05*sin(count2));
            }
            if (count2>=138) {
                SetGraphicScale(1.0+0.05*sin(count2),1.0+0.05*sin(count2));
            }
            SetGraphicRect(256,256,512,512);
            //DrawGraphic(GetX(),GetY());
            //SetGraphicRect(0,0,256,256);
            //DrawGraphic(GetX(),GetY());
            //SetGraphicRect(0,256,256,512);
            DrawGraphic(GetX(),GetY());
        }

        SetTexture(img);
        SetAlpha(255);
        SetGraphicAngle(0,0,0);
        SetColor(bombalpha,bombalpha,bombalpha);
        SetRenderState(ALPHA);
        SetGraphicScale(1,1);
        SetGraphicRect(0,0,128,128);
        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 (int(GetSpeedX())==0&&count2/12%4>=0&&move<=0) {
            SetGraphicRect(0,0,128,128);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=1&&move<=0) {
            SetGraphicRect(0,128,128,256);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=2&&move<=0) {
            SetGraphicRect(0,256,128,384);
        }
        if (int(GetSpeedX())==0&&count2/12%4>=3&&move<=0) {
            SetGraphicRect(0,384,128,512);
        }
        if (tame>0) {
            SetGraphicRect(128*3,0,128*4,128);
        }
        if (tame>32) {
            SetGraphicRect(128*3,128,128*4,256);
        }
        if (tame>42) {
            SetGraphicRect(128*3,256,128*4,384);
        }
        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);
        }
        DrawGraphic(GetX(),GetY());

        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);
    }

}

