script_enemy_main
{
    let count=0;//Az
    let MT=0;
    let mm=0;
    let life=0;
    let ten=0;
    let N15=0;
    let N17=0;
    let Level=0;

    @Initialize
{
    SetLife(5430);
    SetDamageRate(150,46);
    if (GetArgument<=5&&GetArgument!=4) {
        SetAngle(90);
    }
    if (GetArgument>=6) {
        SetLife(5415);
    }
    SetScore(15000);
    Level+=3;//Level+=GetPlayerLife();
}

function dead {
    SetDamageRate(0,0);

    if (N17==50) {
        if (GetArgument!=13) {
            PlaySE(GetCurrentScriptDirectory~"\se\baaaan.wav");
            SetCommonData("ii1",GetCommonDataDefault("ii1",0)+GetCommonDataDefault("ii2",0));
            SetCommonData("ii3",1);
        }
        CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,1);

        if (GetArgument==10||GetArgument==13) {
            ascent(let tt in 0..1) {
                SetShotDirectionType(PLAYER);
                CreateShot02(GetX(),GetY(),3.3,tt*120,0,0,72,2);
                CreateShot02(GetX(),GetY(),3.3,tt*120,0,0,72,5);
                CreateShot02(GetX(),GetY(),3.3,tt*120,0,0,72,8);
                SetShotDirectionType(ABSOLUTE);
            }
        }

        loop(3) {
            CreateItem(ITEM_SCORE,GetX()+rand(-18,18),GetY()+rand(38,64));
        }
        if (GetArgument==0) {
            loop(17) {
                CreateItem(ITEM_SCORE,GetX()+rand(-60,60),GetY()+rand(-28,74));
            }
        }
    }

    if (N17<100) {
        N17+=50;
    }
    if (N17>=100) {
        VanishEnemy;
    }
    if (count%3<=0) {
        Explosion01(GetX+rand(-10,10),GetY+rand(-10,10),24,0.1,20);
    }
}

task Shot13(let x, let y, let speed, let angle, let grf, let delay)
{
    let obj = Obj_Create(OBJ_SHOT);
    Obj_SetX(obj, x);
    Obj_SetY(obj, y);
    Obj_SetSpeed(obj, speed);
    Obj_SetAngle(obj, angle);
    ObjShot_SetGraphic(obj, grf);
    ObjShot_SetDelay(obj, delay);
    Obj_SetCollisionToPlayer(obj,false);

    while ( !Obj_BeDeleted(obj) )
    {
        yield;
    }
}


@MainLoop
{
    if (count%4==0) {
        life=GetLife();
    }if (ten==1&&count%4==1) {
        ten=0;
    }
    if (count%4==3&&GetLife()<life&&GetLife()>200) {
        ten=1;
    }

    if (GetArgument==0) {
        SetDamageRate(30,12);
        if (count<50) {
            SetSpeed(10-0.2*count);
        }
        if (count>50) {
            SetSpeed(0);
            SetDamageRate(150,12);
        }
        if (count>270) {
            SetSpeed((count-270)*0.1);
        }
        if (count>430) {
            VanishEnemy;
        }
        if (count==0) {
            SetAngle(90);
        }
        if (count==35||count==80||count==270) {
            SetAngle(GetAngleToPlayer());
        }
        if (count%8==0&&count>35&&count<145) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateShot01(GetX(),GetY(),6.2,GetAngle,RED04,12);
            CreateShot01(GetX(),GetY(),5.2,GetAngle,RED04,12);
        }
        if (GetLife<5400) {
            dead;
        }else {
            SetCollisionA(GetX(),GetY(),22);
            SetCollisionB(GetX(),GetY(),6);
        }
    }

    else if (GetArgument==1) {
        SetDamageRate(30,12);
        if (count<50) {
            SetSpeed(10-0.2*count);
        }
        if (count>50) {
            SetSpeed(0);
            SetDamageRate(150,12);
        }
        if (count>190) {
            SetSpeed((count-190)*0.1);
        }
        if (count>350) {
            VanishEnemy;
        }
        if (count==0) {
            SetAngle(90);
        }
        if (count==35||count==80||count==190) {
            SetAngle(GetAngleToPlayer());
        }
        if (count%8==0&&count>35&&count<145) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateShot01(GetX(),GetY(),6.2,GetAngle,RED04,12);
            CreateShot01(GetX(),GetY(),5.2,GetAngle,RED04,12);
            CreateShot01(GetX(),GetY(),5.2,GetAngle-120,RED04,12);
            CreateShot01(GetX(),GetY(),5.2,GetAngle+120,RED04,12);
            CreateShot01(GetX(),GetY(),6.2,GetAngle-120,RED04,12);
            CreateShot01(GetX(),GetY(),6.2,GetAngle+120,RED04,12);
        }
        if (GetLife<5400) {
            dead;
        }else {
            SetCollisionA(GetX(),GetY(),22);
            SetCollisionB(GetX(),GetY(),6);
        }
    }

    else if (GetArgument==0.5) {
        SetDamageRate(30,12);
        if (count<50) {
            SetSpeed(10-0.2*count);
        }
        if (count>50) {
            SetSpeed(0);
            SetDamageRate(150,12);
        }
        if (count>310) {
            SetSpeed((count-310)*0.1);
        }
        if (count>520) {
            VanishEnemy;
        }
        if (count==0) {
            SetAngle(90);
        }
        if (count==310) {
            SetAngle(GetAngleToPlayer());
        }
        if (GetLife<5400) {
            dead;
        }else {
            SetCollisionA(GetX(),GetY(),22);
            SetCollisionB(GetX(),GetY(),6);
        }
    }

    else if (GetArgument==4) {
        if (count==0) {
            SetLife(5422);
        }
        SetDamageRate(240,32);
        if (GetX>GetPlayerX+60||GetX<GetPlayerX-60) {
            SetDamageRate(120,11);
        }
        if (count>0) {
            SetSpeed(2.5);
        }if (count>300) {
            VanishEnemy;
        }
        if (count>=40&&count%16==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
            CreateShot02(GetX()-1,GetY(),4.4,90+10*rand_int(-2,2),0.1,2.5,249,0);
        }
        if (GetLife<5400) {
            dead;
        }
        else {
            if (count>=55) {
                SetCollisionA(GetX(),GetY()-5,25);
                SetCollisionB(GetX(),GetY(),13);
            }
        }
    }

    else if (GetArgument==5) {
        if (count>150) {
            VanishEnemy;
        }SetSpeed(6-count*0.1);
        if (count>70&&count<=100) {
            SetAngle(GetAngleToPlayer()-180);
        }
        if (count>70&&count<=100&&GetCommonDataDefault("Go",0)==0) {
            if (GetCenterX<GetX) {
                SetAngle(GetAngleToPlayer-180+18);
            }
            if (GetCenterX>GetX) {
                SetAngle(GetAngleToPlayer-180-18);
            }
        }
        if (GetLife<5400) {
            dead;
        }
        else {
            SetCollisionA(GetX(),GetY(),8);
            SetCollisionB(GetX(),GetY(),5);
            if (count>=80) {
                SetCollisionA(GetX(),GetY(),30);
            }
        }
        if (count==60&&GetCommonDataDefault("Go",0)>0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
            ascent(let tt in 0..6) {
                ascent(let t in 0..7-2*(GetCommonDataDefault("ii1",0)<500)) {
                    CreateShot02(GetX(),GetY()-8,0.3*t,GetAngleToPlayer()+tt*60,0.08,5-2*(GetCommonDataDefault("ii1",0)<500),169,24);
                }
            }
            if (GetCommonDataDefault("ii1",0)<500) {
                ascent(let t in 0..6) {
                    CreateShot02(GetX(),GetY()-8,0,GetAngleToPlayer()+30+t*60,0.2,3.4-2*(GetCommonDataDefault("ii1",0)<500),169,24);
                }
            }
        }
        if (count==90&&GetCommonDataDefault("Go",0)>0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
        }
    }

    else if (GetArgument==6) {
        if (count>320) {
            VanishEnemy;
        }
        if (count>110&&count<=135) {
            SetSpeed((count-70)*0.04+2*(GetCommonDataDefault("Go",0)>0));
            if (GetCommonDataDefault("Go",0)>0) {
                if (GetCenterX<GetX) {
                    SetAngle(GetAngleToPlayer+22);
                }
                if (GetCenterX>GetX) {
                    SetAngle(GetAngleToPlayer-22);
                }
            }
        }
        if (GetX-GetPlayerX>-33&&GetX-GetPlayerX<33) {
            SetDamageRate(200,46);
        }else {
            SetDamageRate(50,4);
        }
        if (GetLife<5400) {
            dead;
        }
        else {
            if (count>=112) {
                SetCollisionA(GetX(),GetY()-12,32);
                SetCollisionB(GetX(),GetY(),5);
            }
        }
        if (count>110&&count<=320&&count%4==0&&GetY<GetCenterY-55) {
            if (GetCommonDataDefault("Go",0)==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                CreateShot02(GetX(),GetY(),5.4+Level*0.5,GetAngleToPlayer()+15,-0.1,6.5,RED01,0);
                CreateShot02(GetX(),GetY(),5.4+Level*0.5,GetAngleToPlayer()-15,-0.1,6.5,RED01,0);
                CreateShot02(GetX(),GetY(),7.4+Level*0.5,GetAngleToPlayer()+15,-0.1,7.5,RED04,0);
                CreateShot02(GetX(),GetY(),7.4+Level*0.5,GetAngleToPlayer()-15,-0.1,7.5,RED04,0);
            }
            if (count==112) {
                N15=0;
                N15+=GetAngleToPlayer()
                 }
            if (count%8==0&&count<=162&&count>=112&&GetCommonDataDefault("Go",0)>0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
                ascent(let t in 0..2) {
                    CreateShot01(GetX(),GetY(),5,N15,72,6+t*3);
                }
            }
        }
        if (count>=112&&GetCommonDataDefault("Go",0)>0) {
            SetSpeed((count-110)*0.02);
        }
        if (GetCommonDataDefault("Mode",0)>=3) {
            if (count%17==0&&count<110) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                ascent(let t in 0..7) {
                    CreateShot01(GetX()+40*cos(GetAngleToPlayer()),GetY()+40*sin(GetAngleToPlayer()),2+count%40*t*0.01,GetAngleToPlayer()-count%140-t*8,196,10);
                }
            }
            if (count%8==0&&count>18&&count<96&&GetY+24<GetPlayerY) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateShot01(GetX()+8*cos(GetAngleToPlayer())+16*cos(GetAngleToPlayer()+90),GetY()+8*sin(GetAngleToPlayer())+16*sin(GetAngleToPlayer()+90),3.2,GetAngleToPlayer()+rand(-1,1),58,18);
                CreateShot01(GetX()+8*cos(GetAngleToPlayer())+16*cos(GetAngleToPlayer()-90),GetY()+8*sin(GetAngleToPlayer())+16*sin(GetAngleToPlayer()-90),3.2,GetAngleToPlayer()+rand(-1,1),58,18);
            }
        }
    }

    else if (GetArgument==7) {
        if (count>320) {
            VanishEnemy;
        }
        if (count>110&&count<=135) {
            SetSpeed((count-70)*0.04+0.6*(GetCommonDataDefault("Go",0)>0));
            if (count<=113&&GetCommonDataDefault("Go",0)>0) {
                if (GetCenterX<GetX) {
                    SetAngle(GetAngleToPlayer+22);
                }
                if (GetCenterX>GetX) {
                    SetAngle(GetAngleToPlayer-22);
                }
            }
        }
        if (count>110&&count<=135) {
            if (GetX-GetPlayerX>-33&&GetX-GetPlayerX<33) {
                SetDamageRate(200,46);
            }else {
                SetDamageRate(50,4);
                if (GetCommonDataDefault("Go",0)>0) {
                    SetDamageRate(70,14);
                }
            }
        }
        if (GetLife<5400) {
            dead;
        }
        else {
            if (count>=112) {
                SetCollisionA(GetX(),GetY()-12,20+12*(GetX-GetPlayerX<30));
                SetCollisionB(GetX(),GetY(),5);
            }
        }
        if (count>110&&count<=320&&count%4==0&&GetY<GetCenterY-55&&GetLife>5400) {
            if (GetCommonDataDefault("Go",0)==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                CreateShot02(GetX(),GetY(),7.4+Level*0.5,GetAngleToPlayer(),-0.1,6,RED01,0);
                CreateShot02(GetX(),GetY(),8.4+Level*0.5,GetAngleToPlayer(),-0.1,6.5,RED01,0);
                CreateShot02(GetX(),GetY(),9.4+Level*0.5,GetAngleToPlayer(),-0.1,7,RED04,0);
            }
            if (count==112) {
                N15=0;
                N15+=GetAngleToPlayer()
                 }
            if (count%8==0&&count<=162&&count>=112&&GetCommonDataDefault("Go",0)>0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
                ascent(let t in 0..2) {
                    CreateShot01(GetX(),GetY(),5,N15,72,6+t*3);
                }
            }
        }
        if (count>=112&&GetCommonDataDefault("Go",0)>0) {
            SetSpeed((count-110)*0.02);
        }
        if (GetCommonDataDefault("Mode",0)>=3) {
            if (count%17==0&&count<110) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                ascent(let t in 0..7) {
                    CreateShot01(GetX()+10*cos(GetAngleToPlayer()),GetY()+10*sin(GetAngleToPlayer()),2+count%40*t*0.01,GetAngleToPlayer()+count%140+t*8,196,10);
                }
            }
            if (count%8==0&&count>18&&count<96&&GetY+24<GetPlayerY) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateShot01(GetX()+8*cos(GetAngleToPlayer())+16*cos(GetAngleToPlayer()+90),GetY()+8*sin(GetAngleToPlayer())+16*sin(GetAngleToPlayer()+90),3.2,GetAngleToPlayer()+rand(-1,1),58,18);
                CreateShot01(GetX()+8*cos(GetAngleToPlayer())+16*cos(GetAngleToPlayer()-90),GetY()+8*sin(GetAngleToPlayer())+16*sin(GetAngleToPlayer()-90),3.2,GetAngleToPlayer()+rand(-1,1),58,18);
            }
        }
    }

    else if (GetArgument==8) {
        if (count>280) {
            VanishEnemy;
        }
        if (count>110&&count<=135) {
            SetSpeed((count-70)*0.04);
        }
        if (GetLife<5400) {
            dead;
        }
        else {
            if (count%12==0&&count<=182&&count>=112&&GetCommonDataDefault("Go",0)>0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot04.wav");
                ascent(let t in 0..2) {
                    CreateShot01(GetX(),GetY(),4,GetAngleToPlayer(),72,6+t*3);
                    CreateShot01(GetX(),GetY(),4,GetAngleToPlayer()+35,72,6+t*3);
                    CreateShot01(GetX(),GetY(),4,GetAngleToPlayer()-35,72,6+t*3);
                    CreateShot01(GetX(),GetY(),2.5,GetAngleToPlayer(),196,6+t*4);
                }
            }
            if (count>=112) {
                SetCollisionA(GetX(),GetY()-12,32);
                SetCollisionB(GetX(),GetY(),5);
            }
        }
        if (GetX-GetPlayerX>-32&&GetX-GetPlayerX<32) {
            SetDamageRate(120,46);
        }else {
            SetDamageRate(60,46);
        }
        if (count>110&&count<=166&&count%4==0&&GetCommonDataDefault("Go",0)==0) {
            if (GetCommonDataDefault("Mode",0)==2) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                CreateShot01(GetX(),GetY(),6.2,GetAngleToPlayer(),RED04,0);
                CreateShot01(GetX(),GetY(),7.2,GetAngleToPlayer(),RED01,0);
                CreateShot01(GetX(),GetY(),5.2,GetAngleToPlayer(),RED01,0);
            }
            if (GetCommonDataDefault("Mode",0)<=1&&GetCommonDataDefault("Go",0)==0) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                CreateShot01(GetX(),GetY(),rand(2,5),GetAngleToPlayer()+rand(-120,120),72,0);
            }
        }
        if (count>120&&count<=176&&count%5==4&&GetCommonDataDefault("Mode",0)>=3) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            SetShotDirectionType(PLAYER);
            CreateShot02(GetX,GetY,9.6,0,0,3.8,33,4);
            CreateShot02(GetX,GetY,9.6,33,0,3.8,33,4);
            CreateShot02(GetX,GetY,9.6,-33,0,3.8,33,4);
            ascent(let t in 0..12) {
                CreateShot01(GetX,GetY,9.5+t*0.5,33+t*6,RED04,4);
                CreateShot01(GetX,GetY,9.5+t*0.5,-33-t*6,RED04,4);
            }
            SetShotDirectionType(ABSOLUTE);
        }
    }

    else if (GetArgument==9) {
        if (count<=10) {
            SetAngle(270);
            SetLife(5403);
        }
        if (count<=10&&GetX==GetCenterX) {
            SetAngle(270);
            SetLife(5403);
        }
        if (count>230) {
            VanishEnemy;
        }
        if (GetLife<5400) {
            dead;
        }
        else {
            if (count>80) {
                SetCollisionA(GetX(),GetY(),8);
            }
        }
        SetDamageRate(100,20);
        if (count<80) {
            SetSpeed(4);
        }
        if (count==85) {
            SetAngle(GetAngle+rand(-60,60));
        }
        if (count>=85&&count<100) {
            SetSpeed(4-(count-80)*0.2);
        }
        if (count>=100&&count<190) {
            SetSpeed(0.8);
        }
        if (count>=190) {
            SetSpeed(4);
        }
        if (count>210&&count<=236&&count%4==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
            CreateShot01(GetX(),GetY(),4.2,GetAngleToPlayer(),72,0);
        }
        if (count%4==rand_int(0,3)&&count<84) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
            Shot13(GetX()+rand(-10,10),GetY()+rand(-10,10),1023,90,1,16);
        }
    }

    else if (GetArgument==10) {
        SetDamageRate(140,20);
        if (count<=0) {
            SetAngle(90);
            SetLife(5408);
            SetSpeed(3.8);
        }
        if (GetX-GetPlayerX>-85&&GetX-GetPlayerX<85&&count>=117) {
            SetDamageRate(165,55);
        }else {
            SetDamageRate(60,46);
        }
        if (count>=50&&count<=85) {
            SetSpeed(4.2-0.1*(count-50));
        }
        if (count<=25) {
            SetDamageRate(0,0);
        }
        if (GetCenterX<GetX&&count>=90&&count<=100) {
            SetAngle(GetAngleToPlayer+22);
        }
        if (GetCenterX>GetX&&count>=90&&count<=100) {
            SetAngle(GetAngleToPlayer-22);
        }
        if (count>=90) {
            SetSpeed(0.2+0.1*(count-90));
        }
        if (count>240) {
            VanishEnemy;
        }
        if (GetLife<5400) {
            dead;
        }
        else {
            SetCollisionA(GetX(),GetY(),8);
        }
    }

    else if (GetArgument==13) {
        if (count==2) {
            AddLife(-300);
        }
        if (GetLife<5400) {
            dead;
        }
    }

    count++;

}

@Finalize
{
}

@DrawLoop
{

    if (GetArgument<=1||GetArgument==6||GetArgument==7||GetArgument==10&&GetCommonDataDefault("Mode",0)>=3) {
        SetTexture(GetCurrentScriptDirectory~"\img\familiar.png");
        if (count<=1) {
            SetColor(0,0,0);
        }
        if (count>=1&&count<21) {
            SetColor((count-1)*10,(count-1)*10,(count-1)*10);
        }
        if (count>=41) {
            SetColor(211,211,211);
        }
        if (count>=100) {
            SetColor(211-(count-100)*12,211-(count-100)*12,211-(count-100)*12);
            if (211-(count-100)*12<=0) {
                SetColor(0,0,0);
            }
        }
        SetGraphicAngle(0,0,0);
        SetGraphicScale(1,1);
        SetAlpha(255);
        SetRenderState(ADD);
        SetGraphicRect(144,48,192,96);
        if (GetArgument==10) {
            SetGraphicRect(48,48,96,96);
        }
        DrawGraphic(GetX(),GetY());
    }

    SetTexture(GetCurrentScriptDirectory~"\img\dot-kaze-ti.png");
    if (count<=50) {
        SetAlpha(0);
    }
    if (count>=50&&count<=112) {
        SetAlpha((count-50)*4);
    }
    if (count>=112||GetArgument<=1||GetArgument==5) {
        SetAlpha(255);
    }
    if (GetArgument==2&&count>=460) {
        SetAlpha(255-(count-460)*60);
    }
    if (GetArgument==10) {
        SetAlpha(255);
    }
    SetGraphicRect(64,0,128,64);
    if (GetArgument==2||GetArgument>=5&&GetArgument!=10) {
        SetGraphicRect(192,0,256,64);
    }
    SetRenderState(ALPHA);
    SetColor(225+count%4*30,225+count%4*30,225+count%4*30);
    SetGraphicScale(0.95,0.95);
    SetGraphicAngle(0,0,-count*5);
    if (ten==1) {
        SetColor(60,60,140);
    }
    if (count<110&&GetArgument>=6&&GetArgument<=8) {
        if (GetX()<GetCenterX()) {
            DrawGraphic(GetX()+(count-110)*cos(count*4),GetY()+(count-110)*sin(count*4));
        }else {
            DrawGraphic(GetX()-(count-110)*cos(-count*4),GetY()-(count-110)*sin(-count*4));
        }
    }else {
        DrawGraphic(GetX(),GetY());
    }

    SetTexture(GetCurrentScriptDirectory~"\img\dot-kaze-ti.png");
    SetGraphicRect(0,0,64,64);
    if (GetArgument==2||GetArgument>=5&&GetArgument!=10) {
        SetGraphicRect(128,0,192,64);
    }
    SetColor(255,255,255);
    SetGraphicScale(0.8,0.8);
    SetGraphicAngle(0,0,count*4);
    if (ten==1) {
        SetColor(60,60,140);
    }
    if (count<110&&GetArgument>=6&&GetArgument<=8) {
        if (GetX()<GetCenterX()) {
            DrawGraphic(GetX()+(count-110)*cos(count*4),GetY()+(count-110)*sin(count*4));
        }else {
            DrawGraphic(GetX()-(count-110)*cos(-count*4),GetY()-(count-110)*sin(-count*4));
        }
    }else {
        DrawGraphic(GetX(),GetY());
    }

}
}
