script_enemy_main
{
    let count=0;//地獄陰陽球
    let MT=0;
    let mm=0;
    let N15=0;
    let N16=0;
    let N17=0;
    let N18=0;
    let Level=0;
    let life=0;
    let ten=0;

function dead {
    SetDamageRate(0,0);

    if (N17==50) {
        if (BeVanished==false) {
            PlaySE(GetCurrentScriptDirectory~"\se\Baaaan2.wav");
            CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX,GetY,0,0,2);
            PlaySE(GetCurrentScriptDirectory~"\se\Baaaan.wav");
            SetCommonData("ii1",GetCommonDataDefault("ii1",0)+GetCommonDataDefault("ii2",0));
            SetCommonData("ii3",1);
            if (GetArgument==0) {
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy01.txt",GetX(),GetY(),0,0,6);
            }
            if (GetArgument==1) {
                CreateEnemyFromFile(GetCurrentScriptDirectory~"Enemy01.txt",GetX(),GetY(),0,0,6.5);
            }
            if (GetArgument==5) {
                SetCommonData("Go",GetCommonDataDefault("Go",0)+1);
                if (N15>12) {
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX+95,GetY,0,0,2);
                    CreateEnemyFromFile(GetCurrentScriptDirectory~"Servant10.txt",GetX-95,GetY,0,0,2);
                }
                loop(20) {
                    CreateItem(ITEM_SCORE,GetX()+rand(-66,66),GetY()+rand(-25,65));
                }
            }
        }
        if (GetArgument==4&&BeVanished==false) {
            CreateItem(ITEM_BOMB,GetX(),GetY()+16);
            loop(30) {
                CreateItem(ITEM_SCORE,GetX()+rand(-126,126),GetY()+rand(-65,95));
            }
        }
    }

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

@Initialize
{
    SetLife(5464);
    SetDamageRate(190,12);
    SetScore(50000);
    Level+=3;//Level+=GetPlayerLife();
}


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

    if (GetArgument<5) {
        SetSpeed(1);
        SetAngle(90);
        if (GetY()>=512) {
            VanishEnemy;
        }
        if (GetArgument==1) {
            SetSpeed(0.5);
        }
        if (count>=0&&count<=20) {
            SetLife(500);
        }

        let toAngle=atan2(GetPlayerY()-GetY(), GetPlayerX()-GetX());
        if (toAngle>=360) {
            toAngle-=360;
        }
        if (toAngle<0) {
            toAngle+=360;
        }
        let ret=toAngle-mm;
        if ((ret>0&&ret<=180)||(ret<=0&&ret<=-180)) {
            mm+=0.1;
        }
        if ((ret>0&&ret>180)||(ret<=0&&ret>-180)) {
            mm-=0.1;
        }
        if (mm>=360) {
            mm-=360;    //360°以上なら0〜360内に補正
        }
        if (mm<0) {
            mm+=360;    //0°未満なら0〜360内に補正
        }
        if (GetLife<5400) {
            dead;
        }
        if (count<1) {
            mm=toAngle;
        }

        if (count>40&&count%4==0) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot06.wav");
            CreateShot01(GetX+41*cos(mm),GetY+41*sin(mm),2.8,mm,72,1);
            ascent(let t in 1..6) {
                CreateShot01(GetX+33*cos(mm+t*60),GetY+33*sin(mm+t*60),2.8,mm+t*60,196,1);
            }
        }

        if (GetLife<5400) {
            dead;
        }
        else {
            if (count>5) {
                SetCollisionA(GetX(),GetY(),24);
                SetCollisionB(GetX(),GetY(),7);
            }
        }
    }

    else if (GetArgument>=6) {

        SetSpeed(1);
        SetAngle(90);
        if (GetArgument==6.5) {
            SetSpeed(0.5);
        }
        if (GetY()>=512) {
            VanishEnemy;
        }
        if (count>=0&&count<=60) {
            SetLife(5520);
        }
        if (count>=40&&count%2<=0) {
            CreateItem(ITEM_SCORE,GetX()+rand(-18,18),GetY()+rand(-18,18));
        }
    }

    if (GetArgument==5) {
        SetSpeed(3.5-0.02*count);
        SetAngle(90);
        if (count>420) {
            VanishEnemy;
        }
        if (count==100) {
            PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
            ascent(let t in 1..5) {
                ascent(let mm in 1..9) {
                    CreateShot02(GetX()+28*t,GetY(),0,90,0.05,0.1+mm*0.5,169,25);
                }
            }
            ascent(let t in 1..5) {
                ascent(let mm in 1..9) {
                    CreateShot02(GetX()-28*t,GetY(),0,90,0.05,0.1+mm*0.5,169,25);
                }
            }
        }
        if (GetCommonDataDefault("miss",0)!=0&&GetPlayerLife<=3) {
            if (count%10==2&&count>=200&&count<=360) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateShot01(GetX(),GetY(),2.5,GetAngleToPlayer(),72,25);
            }
        }
        if (GetCommonDataDefault("miss",0)!=0&&GetPlayerLife>3) {
            if (count>=170&&count<=360) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                CreateShot01(GetX()+rand(-32,32),GetY()+rand(-25,25),0.8+(count-170)*0.025,GetAngleToPlayer(),196,25);
            }
        }
        if (GetCommonDataDefault("miss",0)==0) {
            if (count%20==9&&count>=170&&count<=300) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                mm+=13;
                ascent(let t in 0..60) {
                    CreateShot02(GetX(),GetY(),1.7,GetAngleToPlayer()+t*6+rand(-1,1),0,1.7,196,2);
                }
            }
        }
        if (count>=0&&count<=60) {
            SetAngle(90);
            SetLife(5520);
        }
        if (count>=30&&count<=86) {
            N15+=0.5;
        }
        if (count>=130&&count<=186) {
            N15-=0.5;
        }
        if (GetLife<5400) {
            dead;
        }
        else {
            SetCollisionA(GetX(),GetY(),15);
            SetCollisionB(GetX(),GetY(),8);
        }
    }

    count++;

}

@Finalize
{
}

@DrawLoop
{

    if (GetArgument==5) {
        SetTexture(GetCurrentScriptDirectory~"\img\familiar.png");
        SetColor(211,0,0);
        if (count<=20) {
            SetColor((count)*10,0,0);
        }
        SetGraphicAngle(0,0,0);
        SetGraphicScale(0.4,0.4);
        SetAlpha(255);
        SetRenderState(ADD);
        SetGraphicRect(48,48,96,96);
        ascent(let t in 1..5) {
            DrawGraphic(GetX()-N15*t,GetY());
            DrawGraphic(GetX()+N15*t,GetY());
        }
    }

    if (GetArgument<3) {
        SetTexture(GetCurrentScriptDirectory~"\img\familiar.png");
        SetColor(211,211,211);
        if (count<=20) {
            SetColor((count)*10,0,0);
        }
        SetGraphicScale(1.2+0.2*sin(count*3),1.2+0.2*sin(count*3));
        SetAlpha(255);
        SetRenderState(ADD);
        SetGraphicRect(144,48,192,96);
        SetGraphicScale(0.3,1.2);
        ascent(let t in 0..6) {
            SetGraphicAngle(0,0,mm+90+t*60);
            DrawGraphic(GetX+15*cos(mm+t*60),GetY+15*sin(mm+t*60));
        }
        SetGraphicAngle(0,0,mm+90);
        DrawGraphic(GetX+25*cos(mm),GetY+25*sin(mm));
    }

    if (GetArgument>=6) {
        SetTexture(GetCurrentScriptDirectory~"\img\familiar.png");
        SetColor(211,0,0);
        if (count<=20) {
            SetColor((count)*10,0,0);
        }
        SetGraphicAngle(0,0,0);
        SetGraphicScale(1.4,1.4);
        if (count<=20) {
            SetGraphicScale((count)*0.07,(count)*0.07);
        }
        SetAlpha(255);
        SetRenderState(ADD);
        SetGraphicRect(48,48,96,96);
        DrawGraphic(GetX(),GetY());
    }

    else {
        SetTexture(GetCurrentScriptDirectory~"\img\dot-kaze-ti.png");
        if (count<=50) {
            SetAlpha(0);
        }
        if (count>=50&&count<=112) {
            SetAlpha((count-50)*4);
        }
        if (count>=112) {
            SetAlpha(255);
        }if (GetArgument<=5) {
            SetAlpha(255);
        }
        SetGraphicRect(64,0,128,64);
        if (GetArgument<5) {
            SetGraphicRect(64,64,128,128);
        }
        SetRenderState(ALPHA);
        SetColor(225+count%4*30,225+count%4*30,225+count%4*30);
        SetGraphicScale(1.12,1.12);
        SetGraphicAngle(0,0,-count*5);
        if (ten==1) {
            SetColor(60,60,120);
        }
        DrawGraphic(GetX(),GetY());

        if (count<=50) {
            SetAlpha(0);
        }
        if (count>=50&&count<=112) {
            SetAlpha((count-50)*4);
        }
        if (count>=112) {
            SetAlpha(255);
        }if (GetArgument<=5) {
            SetAlpha(255);
        }
        SetGraphicRect(64,0,128,64);
        if (GetArgument<5) {
            SetGraphicRect(64,64,128,128);
        }
        SetRenderState(ALPHA);
        SetColor(225+count%4*30,225+count%4*30,225+count%4*30);
        SetGraphicScale(0.8,0.8);
        SetGraphicAngle(0,0,count*5);
        if (ten==1) {
            SetColor(60,60,120);
        }
        DrawGraphic(GetX(),GetY());

        SetGraphicRect(0,0,64,64);
        if (GetArgument<5) {
            SetGraphicRect(0,64,64,128);
        }
        SetColor(255,255,255);
        SetGraphicScale(0.65,0.65);
        SetGraphicAngle(0,0,90);
        if (ten==1) {
            SetColor(60,60,120);
        }
        DrawGraphic(GetX(),GetY());
    }






}
}
