
script_enemy_main
{
    let count=0;
    let count2=0;
    let count3=0;
    let R=0;
    let R2=0;
    let R3=0;
    let ac=0;
    let N15=0;
    let step=0;
    let MT=0;
    let cx=GetCenterX();
    let cy=GetCenterY();
    let get;
    let try;

    let pass=GetCurrentScriptDirectory~"Spell.dat";

    let bombalpha=255;

    let cx=GetCenterX();
    let mm=0;
    let shot=0;
    let tame=0;
    let tame2=0;
    let c=0;
    let d=60;
    let ang=0;
    let angW=0;
    let MT=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 load() {
        LoadCommonDataEx("Spell",pass);
    }

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

    @Initialize()
    {
        MagicCircle(false);
        SetEnemyMarker(true);
        if (IsCommonDataAreaExists("Spell")==false) {
            CreateCommonDataArea("Spell");
        }
        load();
        SetLife(1000);
        SetDamageRate(12,0);
        SetTimer(120);
        SetInvincibility(200);
        SetNormPoint(-1);
        SetShotAutoDeleteClip(32,64,32,32);//SetEffectForZeroLife(115,160,1);
        SetMovePositionRandom01(0,200,3,cx,128,cx,128);
        LoadGraphic(GetCurrentScriptDirectory~"\img\dot_flandre.png");
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadUserShotData(GetCurrentScriptDirectory~".\shot_All.txt");

        get=GetCommonDataDefaultEx("Spell","4no4get",0);
        try=GetCommonDataDefaultEx("Spell","4no4try",0);
        try++;
        SetCommonDataEx("Spell","4no4try",try);
        save();

    }

    @MainLoop() {

        SetCommonData("Black2",238);

        if (count==1) {
            PlaySE(GetCurrentScriptDirectory~"\se\puu811.wav");
            SetColor(255,255,128);
            Concentration01(113);
        }
        if (count>=117&&count%2==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
        }
        if (count>=220&&count%8==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
        }
        if (step==0&&GetEnemyLife()>440&&GetEnemyLife()<=785) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            step++;
        }
        if (step==1&&GetEnemyLife()<=440) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            step++;
        }
        if (count>=82&&count%2==0&&GetEnemyLife()>785) {
            ang+=3;
            ascent( let t in 0..6 ) {
                CreateShot02(224,124,5.5,ang+count*3+t*60,-0.1,-3.4,19,35);
            }
        }
        if (count%2==0&&GetEnemyLife()>440&&GetEnemyLife()<=785) {
            ang+=angW;
            ascent( let t in 0..6 ) {
                CreateShot02(224,124,5.5,rand(0,3)+ang+count*3+t*60,-0.1,-3.4,23,35);
            }
        }
        if (count%2==0&&GetEnemyLife()<=440) {
            ang+=angW;
            ascent( let t in 0..6 ) {
                CreateShot02(224,124,5.5,rand(0,1)+ang+count*3+t*60,-0.1,-3.4,22,35);
            }
        }
        if (count>=150&&count%6==0&&GetEnemyLife()>785) {
            CreateShot02(224,124,4.5,ang+rand(-4,4)+count*4,-0.1,-1.6,17,0);
            CreateShot02(224,124,4.5,ang+count*4+120,-0.1,-1.6,17,0);
        }
        if (count%6==0&&GetEnemyLife()>480&&GetEnemyLife()<=785) {
            angW=2;
            CreateShot02(224,124,4.5,ang*2+rand(-12,12)+count*12,-0.1,-1.6,41,0);
            CreateShot02(224,124,4.2,rand(-124,124)+ang+count*2,-0.1,-2.2,17,0);
        }
        if (count%7==0&&GetEnemyLife()>440&&GetEnemyLife()<=480) {
            CreateShot01(224,124,1.6,rand(-55,55)+count*11,49,0);
            CreateShot02(224,134,3.2,count*5+rand(-124,124),-0.1,-2.8,41,0);
        }
        if (count%8==0&&GetEnemyLife()<=440) {
            angW=1;
            CreateShot01(224,124,2,rand(-124,124)+count*6,49,0);
            CreateShot01(224,124,2,rand(-124,124)+180+count*6,49,0);
            CreateShot02(224,124,4.5,rand(-124,124)+-ang-count*4,-0.1,-1.6,41,0);
            CreateShot02(224,124,4.2,rand(-124,124)+ang+count*2,-0.1,-2.2,17,0);
        }
        if (count%8==4&&GetTimer<=30) {
            angW=1;
            CreateShot01(224,124,2,rand(-124,124)+count*6,49,0);
            CreateShot01(224,124,2,rand(-124,124)+180+count*6,49,0);
            CreateShot02(224,124,4.5,rand(-124,124)+-ang-count*4,-0.1,-1.6,41,0);
            CreateShot02(224,124,4.2,rand(-124,124)+ang+count*2,-0.1,-2.2,17,0);
        }
        if (count>=180&&count%16==0) {
            let tLaser=0;
            CreateLaserB(tLaser,512,8,41,0);
            SetLaserDataB(tLaser,0,0,25,0,270,1,270,1);
            SetLaserDataB(tLaser,25,0,25,0,NULL,2.4,NULL,2.8);
            SetShotKillTime(tLaser,82);
            FireShot(tLaser);
            CreateLaserB(tLaser,512,8,41,0);
            SetLaserDataB(tLaser,0,0,25,0,270,-1,270,-1);
            SetLaserDataB(tLaser,25,0,25,0,NULL,-2.4,NULL,-2.8);
            SetShotKillTime(tLaser,82);
            FireShot(tLaser);
        }
        if (count>=244&&count%24==0) {
            let tLaser=0;
            CreateLaserB(tLaser,512,8,41,0);
            SetLaserDataB(tLaser,0,0,6,0,90-20,-0.5,90-20,-0.5);
            SetLaserDataB(tLaser,35,0,25,0,NULL,-1,NULL,-1);
            SetShotKillTime(tLaser,45);
            FireShot(tLaser);
            CreateLaserB(tLaser,512,8,41,0);
            SetLaserDataB(tLaser,0,0,6,0,90+20,0.5,90+20,0.5);
            SetLaserDataB(tLaser,35,0,25,0,NULL,1,NULL,1);
            SetShotKillTime(tLaser,45);
            FireShot(tLaser);
        }SetCollisionA(GetX(),GetY()-18,48);
        SetCollisionB(GetX(),GetY(),22);
        if (GetEnemyLife<=0&&MT==0) {
            SetPlayerInvincibility(140);
            MT++;
            SetCommonData("last",true);
            return;
        }

        if (count2>=70) {
            count++
        }count2++;
        if (count2>=40) {
            tame++;
        }if (count>=10) {
            count3++;
        }
        if (count==10) {
            PlaySE(GetCurrentScriptDirectory~"\se\warp02.wav");
            SetScore(8000000);
            CutIn(YOUMU,"???????????????",0,0,0,0,0);
        }

        c+=7;
        yield;
    }

    @Finalize()
    {
        if (GotSpellCardBonus()==true) {
            get++;
            SetCommonDataEx("Spell","4no4get",get);
        }
        save();

        SetShotAutoDeleteClip(32,32,32,32);
        loop(150) {
            CreateItem(ITEM_SCORE,GetX()+rand(-190,190),GetY()+rand(-100,130));
        }
        CreateItem(ITEM_1UP,GetX(),GetY()+20);
        SetCommonData("last",false);

    }

    @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 (count<=1) {
                SetGraphicScale(0,0);
            }
            if (count>1) {
                SetGraphicScale(0.02*count,0.02*count);
            }
            if (count>=50) {
                SetGraphicScale(1.0+0.1*sin((count-50)*3),1.0+0.1*sin((count-50)*3));
            }
            DrawGraphic(GetX(),GetY());
        }

        SetTexture(GetCurrentScriptDirectory~"\img\dot_flandre.png");
        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 (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);
        }
        DrawGraphic(GetX(),GetY());

        if (count>=10) {
            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);
        }
    }


}

