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

    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 mm=0;
    let shot=0;
    let tame=0;
    let tame2=0;
    let d=70;
    let ang=0;

    task Shot12(let x, let y, let speed, let angle, let grf, let delay)
    {
        //弾タスク初期化
        let obj = Obj_Create(OBJ_SHOT);//弾オブジェクトを作成
        let count8 = 0;
        let N16 = 0;
        Obj_SetX(obj, x);//x座標設定
        Obj_SetY(obj, y);//y座標設定;
        Obj_SetSpeed(obj, speed);//速度設定
        Obj_SetAngle(obj, angle);//移動角度設定
        ObjShot_SetGraphic(obj, grf);//画像設定
        ObjShot_SetDelay(obj, delay);//遅延時間設定
        ObjShot_SetBombResist(obj,true);

        while ( !Obj_BeDeleted(obj) )
        {//削除されるまでループを実行
            if (absolute(GetPlayerY-Obj_GetY(obj))<124&&absolute(GetPlayerX-Obj_GetX(obj))<86)
            {
                Obj_SetSpeed(obj,3);
            }else {
                Obj_SetSpeed(obj, speed);
            }
            if (absolute(GetPlayerY-Obj_GetY(obj))>64&&absolute(GetPlayerX-Obj_GetX(obj))>8&&count8%15==0&&count8>3&&count8<90)
            {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                CreateShotA(N16,Obj_GetX(obj),Obj_GetY(obj),2);
                SetShotDataA(N16,0,0,0,count8*8,0,0,RED04);
                SetShotDataA(N16,100-count8,NULL,angle,0,0.02,2,170);
                FireShot(N16);
                if (GetPlayerY-Obj_GetY(obj)>64) {
                    CreateShotA(N16,Obj_GetX(obj),Obj_GetY(obj),2);
                    SetShotDataA(N16,0,0,0,count8*8,0,0,RED04);
                    SetShotDataA(N16,100-count8,NULL,angle+180,0,0.02,2,170);
                    FireShot(N16)
                }
            }
            count8++;
            yield;
        }
    }

    task Shot13(let x, let y, let speed, let angle, let grf, let delay)
    {
        //弾タスク初期化
        let obj = Obj_Create(OBJ_SHOT);//弾オブジェクトを作成
        let count8 = 0;
        let N16 = 0;
        Obj_SetX(obj, x);//x座標設定
        Obj_SetY(obj, y);//y座標設定;
        Obj_SetSpeed(obj, speed);//速度設定
        Obj_SetAngle(obj, angle+rand(-11,11));//移動角度設定
        ObjShot_SetGraphic(obj, grf);//画像設定
        ObjShot_SetDelay(obj, delay);//遅延時間設定
        ObjShot_SetBombResist(obj,true);

        while ( !Obj_BeDeleted(obj) )
        {//削除されるまでループを実行
            if (count8%6==0&&count8>3&&count8<90)
            {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
                SetShotDirectionType(PLAYER);
                CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1.5,180+rand(-65,65),196,0);
                CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2.5+(GetCommonDataDefault("miss",0)==2),180+rand(-35,35),169,0);
                CreateShot01(Obj_GetX(obj),Obj_GetY(obj),1.5,rand(-65,65),196,0);
                CreateShot01(Obj_GetX(obj),Obj_GetY(obj),2.5+(GetCommonDataDefault("miss",0)==2),rand(-35,35),169,0);
                CreateShot01(Obj_GetX(obj),Obj_GetY(obj),3,180+rand(-35,35),169,0);
                SetShotDirectionType(ABSOLUTE);
            }
            count8++;
            yield;
        }
    }

    @Initialize()
    {
        SetLife(2560);
        MagicCircle(false);
        SetEnemyMarker(true);
        SetDamageRate(62,30);
        SetTimer(36);
        LoadGraphic(img);
        SetShotAutoDeleteClip(32,32,32,32);
        SetMovePositionRandom01(0,200,3,cx,118+15*(GetCommonDataDefault("miss",0)==2),cx,118+15*(GetCommonDataDefault("miss",0)==2));
        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;
        }
        SetCollisionA(GetX(),GetY()-16,38);
        SetCollisionB(GetX(),GetY(),14);

        SetCommonData("Black",222);

        if (count4<15&&count%440==9) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
            ascent(let t in 0..20+10*(GetCommonDataDefault("ii1",0)>=2000)) {
                CreateShot01(GetX(),GetY()+2,5.2,GetAngleToPlayer()+t*(18-6*(GetCommonDataDefault("ii1",0)>=2000)),33,15);
            }
            ascent(let tt in 0..3) {
                ascent(let t in 0..20+10*(GetCommonDataDefault("ii1",0)>=2000)) {
                    CreateShot01(GetX(),GetY()+2,4.2-tt,GetAngleToPlayer()+t*(18-6*(GetCommonDataDefault("ii1",0)>=2000)),49,15);
                }
            }
        }

        if (count4<15&&count>=15&&count%9==0&&count%880>=29&&count%880<=180) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
            ascent(let t in 0..6) {
                Shot12(GetX(),GetY(), 3, -count/1.6+t*45, 169, 20)
            }
        }

        if (count4<15&&count>=15&&count%9==0&&count%880>=469&&count%880<=620) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
            ascent(let t in 0..6) {
                Shot12(GetX(),GetY(), 3, count/1.6+t*45, 169, 20)
            }
        }

        if (count4<15&&count>=15&&count%5==0&&count%880>=29&&count%880<=180) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            ascent(let t in 0..8) {
                CreateShot01(GetX()+count%440,GetY()+count%440/8,2+t%2*1.2+1*(GetCommonDataDefault("ii1",0)>=2000),count*1.2+t*45,72,20);
            }
            ascent(let t in 0..8) {
                CreateShot01(GetX()+count%440,GetY()+count%440/8,3+t%2*1.0,count*0.2+t*45,169,20);
            }
        }

        if (count4<15&&count>=15&&count%5==0&&count%880>=469&&count%880<=620) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            ascent(let t in 0..8) {
                CreateShot01(GetX()-count%440,GetY()+count%440/8,2+t%2*1.2+1*(GetCommonDataDefault("ii1",0)>=2000),-count*1.2+t*45,72,20);
            }
            ascent(let t in 0..8) {
                CreateShot01(GetX()-count%440,GetY()+count%440/8,3+t%2*1.0,-count*0.2+t*45,169,20);
            }
        }

        if (count4<15&&count>=15&&count%15==0&&count%440>=230&&count%440<=330) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            if (count%30<=14) {
                Shot13(GetX(),GetY(), 8, GetAngleToPlayer+90, 55, 10);
                CreateShot01(GetX(),GetY()+2,5,GetAngleToPlayer()+33,169,10);
                CreateShot01(GetX(),GetY()+2,5,GetAngleToPlayer()-33,169,10);
                CreateShot01(GetX(),GetY()+2,6,GetAngleToPlayer()+44,169,10);
                CreateShot01(GetX(),GetY()+2,6,GetAngleToPlayer()-44,169,10);
            }
            else {
                Shot13(GetX(),GetY(), 8, GetAngleToPlayer-90, 55, 10);
                CreateShot01(GetX(),GetY()+2,5,GetAngleToPlayer()+33,169,10);
                CreateShot01(GetX(),GetY()+2,5,GetAngleToPlayer()-33,169,10);
                CreateShot01(GetX(),GetY()+2,6,GetAngleToPlayer()+44,169,10);
                CreateShot01(GetX(),GetY()+2,6,GetAngleToPlayer()-44,169,10);
            }
        }

        if (count%440==420) {
            count+=2
               }

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

        if (GetLife<15) {
            SetDamageRate(0,0);
            count4++;
        }

        if (count4<15&&GetLife<5) {
            AddLife(6);
        }

        if (count4>0) {
            DeleteEnemyShotInCircle(ALL,GetX,GetY,(count4)*4.2);
        }

        if (count4==1) {
            PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
        }

        if (count4>160) {
            AddLife(-400);
        }

        if (count4<15&&count2==66) {
            SetColor(255,0,0);
            Concentration01(145);
            PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
        }

        if (count4<15&&count%440==285) {
            SetColor(255,0,0);
            Concentration01(175);
            PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
        }

        if (count4<15&&count>244&&count%220==157) {
            SetMovePositionRandom01(12,rand(1,5),6,GetCenterX()-99,90+30*(GetCommonDataDefault("ii1",0)>=2000),GetCenterX()+99,160+30*(GetCommonDataDefault("ii1",0)>=2000));
            move=130;
        }

        yield;
    }

    @Finalize()
    {
        SetShotAutoDeleteClip(32,32,32,32);
    }

    @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());

    }


}

