#東方弾幕風
#Title[「劇団運命座」]
#Text[]
#Player[FREE]
#ScriptVersion[2]
#BackGround[User()]
script_enemy_main
{
    let count=0;
    let count2=0;
    let count3=0;
    let ten=0;
    let life=0;
    let R=0;
    let R2=0;
    let R3=0;
    let N15=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 step=0;
    let mm=0;
    let xip=0;
    let R=50;
    let bombex=0;
    let bombdamage=0;

    function IntToString(num) {
        let retStr = "";//戻り値
        let numStr = ToString(num);

        let i = 0;
        while (i < length(numStr)) {
            let tmp = numStr[i];
            if (tmp == '.') {	//小数点で終了
                break;
            }
            retStr = retStr ~ [tmp];
            i++;
        }
        return retStr;
    }

    task ShotObject(let x, let y, let speed, let angle, let grf, let delay)
    {
        //弾タスク初期化
        let obj = Obj_Create(OBJ_SHOT);//弾オブジェクトを作成
        let count8 = 0;
        let N15 = 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);//遅延時間設定

        while ( !Obj_BeDeleted(obj) )
        {//削除されるまでループを実行
            if (count8%7==0&&count8>20&&count8<80)
            {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                ascent(let t in 0..6) {
                    CreateShotA(N15,x,y,0);
                    SetShotDataA(N15,0,4,90+t*60,0,-0.3,1.5,55);
                    SetShotDataA(N15,10,NULL,NULL,0,0,0,55);
                    SetShotDataA(N15,60,NULL,NULL,0,0.01,1.8,55);
                    FireShot(N15);
                }
                ascent(let t in 0..6) {
                    CreateShotA(N15,x,y,0);
                    SetShotDataA(N15,0,4,90+t*60,0,-0.3,1.5,143);
                    SetShotDataA(N15,10,NULL,NULL,0,0,0,174);
                    SetShotDataA(N15,60,NULL,NULL,0,0.01,1.8,174);
                    FireShot(N15);
                }
            }
            if (count8==10)
            {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot02.wav");
                ascent(let tt in 0..8) {
                    ascent(let t in 0..18) {
                        CreateShotA(N15,x+50*cos(t*20),y+50*sin(t*20),20);
                        SetShotDataA(N15,0,0,t*20,0,0,0,RED01);
                        SetShotDataA(N15,220,1.1+0.15*tt,NULL,0,0,9,RED01);
                        FireShot(N15);
                    }
                }
            }
            if (count8==220) {
                PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
            }
            if (count8>=220) {
                speed+=0.01;
                Obj_SetSpeed(obj, speed);
            }
            count8++;
            yield;
        }
    }

    task Shotdd(xx)
    {
        let dd = 0;
        while ( dd<320 )
        {

            //if(dd%320==18)
            //{xip=0;xip+=GetPlayerX();if(dd<=320){xip=cx;}}

            if (dd%320>=20&&dd%320<=240)
            {
                let y=20*sin(xx*78)+(dd%320)*2.5-70;
                if (dd%9==0)
                {
                    CreateShotA(N15,xx+R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,RED01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,195);
                    SetShotDataA(N15,140-(dd%320)/2,0,-dd+90,0,-0.1,0,195);
                    SetShotDataA(N15,210-(dd%320)/2,0,110,rand(-0.01,0.01),0.001,0.4,63);
                    SetShotDataA(N15,210,NULL,NULL,0,0.015,1.7+rand(-0.1,0.1),63);
                    FireShot(N15);
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                }
                if (dd%9==3)
                {
                    CreateShotA(N15,xx+R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,RED01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,195);
                    SetShotDataA(N15,140-(dd%320)/2,0,-dd+270,0,-0.1,0,195);
                    SetShotDataA(N15,210-(dd%320)/2,0,110,rand(-0.01,0.01),0.001,0.4,63);
                    SetShotDataA(N15,210,NULL,NULL,0,0.015,1.7+rand(-0.1,0.1),63);
                    FireShot(N15);
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                }
                if (dd%9==0)
                {
                    CreateShotA(N15,xx-R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,BLUE01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,196);
                    SetShotDataA(N15,140-(dd%320)/2,0,dd+90,0,-0.1,0,196);
                    SetShotDataA(N15,210-(dd%320)/2,0,125,rand(-0.01,0.01),0.001,0.4,71);
                    SetShotDataA(N15,210,NULL,NULL,0,0.007,1.6+rand(-0.1,0.1),71);
                    FireShot(N15);
                }
                if (dd%9==3)
                {
                    CreateShotA(N15,xx-R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,BLUE01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,196);
                    SetShotDataA(N15,140-(dd%320)/2,0,dd+270,0,-0.1,0,196);
                    SetShotDataA(N15,210-(dd%320)/2,0,125,rand(-0.01,0.01),0.001,0.4,71);
                    SetShotDataA(N15,210,NULL,NULL,0,0.007,1.6+rand(-0.1,0.1),71);
                    FireShot(N15);
                }

                if (dd%24==3)
                {
                    ascent( let t in 0..10 ) {
                        CreateShotA(N15,xx-(R*sin(dd*3)/5)*5+(R*sin(dd*3)/5)*t,y,15);
                        SetShotDataA(N15,0,0,0,0,0,0,255);
                        SetShotDataA(N15,24,0,rand(-1,1),0,-0.02,-1.5,170);
                        FireShot(N15);
                    }PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
                }
                if (dd%24==15)
                {
                    ascent( let t in 0..10 ) {
                        CreateShotA(N15,xx-(R*sin(dd*3)/5)*5+(R*sin(dd*3)/5)*t,y,15);
                        SetShotDataA(N15,0,0,0,0,0,0,255);
                        SetShotDataA(N15,24,0,180+rand(-1,1),0,-0.02,-1.5,170);
                        FireShot(N15);
                    }PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
                }
            }

            dd++;
            yield;
        }
    }

    task Shotdd2(xx)
    {
        let dd = 0;
        while ( dd<320 )
        {

            //if(dd%320==18)
            //{xip=0;xip+=GetPlayerX();if(dd<=320){xip=cx;}}

            if (dd%320>=20&&dd%320<=240)
            {
                let y=20*sin(xx*78)+(dd%320)*2.5-70;
                if (dd%9==0)
                {
                    CreateShotA(N15,xx+R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,RED01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,195);
                    SetShotDataA(N15,140-(dd%320)/2,0,-dd+90,0,-0.1,0,195);
                    SetShotDataA(N15,210-(dd%320)/2,0,90,rand(-0.04,0.04),-0.001,-0.4,65);
                    SetShotDataA(N15,210,NULL,NULL,0,-0.01,-1.7+rand(-0.1,0.2),65);
                    FireShot(N15);
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                }
                if (dd%9==3)
                {
                    CreateShotA(N15,xx+R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,RED01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,195);
                    SetShotDataA(N15,140-(dd%320)/2,0,-dd+270,0,-0.1,0,195);
                    SetShotDataA(N15,210-(dd%320)/2,0,90,rand(-0.04,0.04),-0.001,-0.4,65);
                    SetShotDataA(N15,210,NULL,NULL,0,-0.01,-1.7+rand(-0.1,0.2),65);
                    FireShot(N15);
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                }
                if (dd%9==0)
                {
                    CreateShotA(N15,xx-R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,BLUE01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,196);
                    SetShotDataA(N15,140-(dd%320)/2,0,dd+90,0,-0.1,0,196);
                    SetShotDataA(N15,210-(dd%320)/2,0,90,rand(-0.04,0.04),-0.001,-0.4,65);
                    SetShotDataA(N15,210,NULL,NULL,0,-0.01,-1.7+rand(-0.1,0.2),65);
                    FireShot(N15);
                }
                if (dd%9==3)
                {
                    CreateShotA(N15,xx-R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,BLUE01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,196);
                    SetShotDataA(N15,140-(dd%320)/2,0,dd+270,0,-0.1,0,196);
                    SetShotDataA(N15,210-(dd%320)/2,0,90,rand(-0.04,0.04),-0.001,-0.4,65);
                    SetShotDataA(N15,210,NULL,NULL,0,-0.01,-1.7+rand(-0.1,0.2),65);
                    FireShot(N15);
                }

                if (dd%24==3)
                {
                    ascent( let t in 0..10 ) {
                        CreateShotA(N15,xx-(R*sin(dd*3)/5)*5+(R*sin(dd*3)/5)*t,y,15);
                        SetShotDataA(N15,0,0,0,0,0,0,255);
                        SetShotDataA(N15,24,0,rand(-1,1),0,-0.02,-1.5,170);
                        FireShot(N15);
                    }PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
                }
                if (dd%24==15)
                {
                    ascent( let t in 0..10 ) {
                        CreateShotA(N15,xx-(R*sin(dd*3)/5)*5+(R*sin(dd*3)/5)*t,y,15);
                        SetShotDataA(N15,0,0,0,0,0,0,255);
                        SetShotDataA(N15,24,0,180+rand(-1,1),0,-0.02,-1.5,170);
                        FireShot(N15);
                    }PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
                }
            }

            dd++;
            yield;
        }
    }

    task Shotdd3(xx)
    {
        let dd = 0;
        while ( dd<320 )
        {

            //if(dd%320==18)
            //{xip=0;xip+=GetPlayerX();if(dd<=320){xip=cx;}}

            if (dd%320>=20&&dd%320<=240)
            {
                let y=20*sin(xx*78)+(dd%320)*2.5-70;
                if (dd%9==0)
                {
                    CreateShotA(N15,xx+R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,RED01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,195);
                    SetShotDataA(N15,140-(dd%320)/2,0,-dd+90,0,-0.1,0,195);
                    SetShotDataA(N15,210-(dd%320)/2,0,190,0,-0.001,-0.4,83);
                    SetShotDataA(N15,250-(dd%320)/3,NULL,NULL,0,-0.01,-1.5,83);
                    FireShot(N15);
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                }
                if (dd%9==3)
                {
                    CreateShotA(N15,xx+R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,RED01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,195);
                    SetShotDataA(N15,140-(dd%320)/2,0,-dd+270,0,-0.1,0,195);
                    SetShotDataA(N15,210-(dd%320)/2,0,10,0,-0.001,-0.4,83);
                    SetShotDataA(N15,250-(dd%320)/3,NULL,NULL,0,-0.01,-1.5,83);
                    FireShot(N15);
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                }
                if (dd%9==0)
                {
                    CreateShotA(N15,xx-R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,BLUE01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,196);
                    SetShotDataA(N15,140-(dd%320)/2,0,dd+90,0,-0.1,0,196);
                    SetShotDataA(N15,210-(dd%320)/2,0,10,0,-0.001,-0.4,83);
                    SetShotDataA(N15,250-(dd%320)/3,NULL,NULL,0,-0.01,-1.6,83);
                    FireShot(N15);
                }
                if (dd%9==3)
                {
                    CreateShotA(N15,xx-R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,BLUE01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,196);
                    SetShotDataA(N15,140-(dd%320)/2,0,dd+270,0,-0.1,0,196);
                    SetShotDataA(N15,210-(dd%320)/2,0,190,0,-0.001,-0.4,83);
                    SetShotDataA(N15,250-(dd%320)/3,NULL,NULL,0,-0.01,-1.6,83);
                    FireShot(N15);
                }

                if (dd%24==3)
                {
                    ascent( let t in 0..10 ) {
                        CreateShotA(N15,xx-(R*sin(dd*3)/5)*5+(R*sin(dd*3)/5)*t,y,15);
                        SetShotDataA(N15,0,0,0,0,0,0,255);
                        SetShotDataA(N15,24,0,rand(-1,1),0,-0.02,-1.5,170);
                        FireShot(N15);
                    }PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
                }
                if (dd%24==15)
                {
                    ascent( let t in 0..10 ) {
                        CreateShotA(N15,xx-(R*sin(dd*3)/5)*5+(R*sin(dd*3)/5)*t,y,15);
                        SetShotDataA(N15,0,0,0,0,0,0,255);
                        SetShotDataA(N15,24,0,180+rand(-1,1),0,-0.02,-1.5,170);
                        FireShot(N15);
                    }PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
                }
            }

            dd++;
            yield;
        }
    }

    task Shotdd4(xx)
    {
        let dd = 0;
        while ( dd<320 )
        {

            //if(dd%320==18)
            //{xip=0;xip+=GetPlayerX();if(dd<=320){xip=cx;}}

            if (dd%320>=20&&dd%320<=240)
            {
                let y=20*sin(xx*78)+(dd%320)*2.5-70;
                if (dd%9==0)
                {
                    CreateShotA(N15,xx+R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,RED01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,195);
                    SetShotDataA(N15,140-(dd%320)/2,0,-dd+90,0,-0.1,0,195);
                    SetShotDataA(N15,210-(dd%320)/2,0,140,rand(-0.04,0.04),-0.001,-0.4,68);
                    SetShotDataA(N15,210,NULL,NULL,0,-0.01,-2.2+rand(-0.1,0.2),68);
                    FireShot(N15);
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                }
                if (dd%9==3)
                {
                    CreateShotA(N15,xx+R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,RED01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,195);
                    SetShotDataA(N15,140-(dd%320)/2,0,-dd+270,0,-0.1,0,195);
                    SetShotDataA(N15,210-(dd%320)/2,0,220,rand(-0.04,0.04),-0.001,-0.4,68);
                    SetShotDataA(N15,210,NULL,NULL,0,-0.01,-2.2+rand(-0.1,0.2),68);
                    FireShot(N15);
                    PlaySE(GetCurrentScriptDirectory~"\se\Shot00.wav");
                }
                if (dd%9==0)
                {
                    CreateShotA(N15,xx-R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,BLUE01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,196);
                    SetShotDataA(N15,140-(dd%320)/2,0,dd+90,0,-0.1,0,196);
                    SetShotDataA(N15,210-(dd%320)/2,0,220,rand(-0.04,0.04),-0.001,-0.4,68);
                    SetShotDataA(N15,210,NULL,NULL,0,-0.01,-2.2+rand(-0.1,0.2),68);
                    FireShot(N15);
                }
                if (dd%9==3)
                {
                    CreateShotA(N15,xx-R*sin(dd*3),y,15);
                    SetShotDataA(N15,0,0,0,0,0,0,BLUE01);
                    SetShotDataA(N15,60-(dd%320)/3,0,0,0,0,0,196);
                    SetShotDataA(N15,140-(dd%320)/2,0,dd+270,0,-0.1,0,196);
                    SetShotDataA(N15,210-(dd%320)/2,0,140,rand(-0.04,0.04),-0.001,-0.4,68);
                    SetShotDataA(N15,210,NULL,NULL,0,-0.01,-2.2+rand(-0.1,0.2),68);
                    FireShot(N15);
                }

                if (dd%24==3)
                {
                    ascent( let t in 0..10 ) {
                        CreateShotA(N15,xx-(R*sin(dd*3)/5)*5+(R*sin(dd*3)/5)*t,y,15);
                        SetShotDataA(N15,0,0,0,0,0,0,255);
                        SetShotDataA(N15,24,0,rand(-1,1),0,-0.02,-1.5,170);
                        FireShot(N15);
                    }PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
                }
                if (dd%24==15)
                {
                    ascent( let t in 0..10 ) {
                        CreateShotA(N15,xx-(R*sin(dd*3)/5)*5+(R*sin(dd*3)/5)*t,y,15);
                        SetShotDataA(N15,0,0,0,0,0,0,255);
                        SetShotDataA(N15,24,0,180+rand(-1,1),0,-0.02,-1.5,170);
                        FireShot(N15);
                    }PlaySE(GetCurrentScriptDirectory~"\se\Shot01.wav");
                }
            }

            dd++;
            yield;
        }
    }

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

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

    @Initialize()
    {
        MagicCircle(false);
        SetEnemyMarker(true);
        if (IsCommonDataAreaExists("Spell")==false) {
            CreateCommonDataArea("Spell");
        }
        load();
        SetLife(1680);
        SetDamageRate(28+bombdamage,0);
        SetTimer(101);
        SetInvincibility(150);
        SetNormPoint(-1);
        LoadGraphic(img);
        SetShotAutoDeleteClip(16,16,16,16);
        SetMovePositionRandom01(0,200,3,cx,138,cx,138);
        move=59;
        LoadGraphic(bg);
        LoadGraphic(bg2);
        LoadGraphic(GetCurrentScriptDirectory~"\img\remiria.png");
        LoadGraphic(GetCurrentScriptDirectory~"\img\circle_l.png");
        LoadUserShotData(GetCurrentScriptDirectory~".\shot_All.txt");

        get=GetCommonDataDefaultEx("Spell","3no5get",0);
        try=GetCommonDataDefaultEx("Spell","3no5try",0);
        try++;
        SetCommonDataEx("Spell","3no5try",try);
        save();

    }

    @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;
        }
        if (OnBomb==true) {
            bombex=1;
        }
        if (bombex==1&&OnBomb==false) {
            bombex=0;
            bombdamage+=6;
        }

        SetDamageRate(28+bombdamage,0);

        if (OnBomb==true&&GetLife<100) {
            SetDamageRate(0,0);
        }

        SetCollisionA(GetX(),GetY()-16,32);
        SetCollisionB(GetX(),GetY(),8);

        if (count%430==190)
        {
            d=20*sin(GetX*26);
        }

        if (count%31==2&&count%1720<=185)
        {
            Shotdd(d+count%430*3);
        }

        if (count%31==2&&count%1720<=185+430&&count%1720>=430)
        {
            Shotdd3(500-d-count%430*3);
        }

        if (count%31==2&&count%1720<=185+860&&count%1720>=860)
        {
            Shotdd2(d+count%430*3);
        }

        if (count%31==2&&count%1720<=185+860+430&&count%1720>=860+430)
        {
            Shotdd4(500-d-count%430*3);
        }

        if (count>=115&&count%42==40&&rand(0,100)<=40) {
            SetMovePositionRandom01(50,rand(10,40),7,cx-50,90,cx+50,150);
            move=53;
        }


        if (count2>=80) {
            count++;
        }count2++;
        if (count2>=59&&count2<=120) {
            tame++;
        }if (count2==10) {
            PlaySE(GetCurrentScriptDirectory~"\se\puu81.wav");
            SetColor(255,0,0);
            Concentration01(200);
        }
        if (count==10) {
            PlaySE(GetCurrentScriptDirectory~"\se\warp02.wav");
            SetScore(12000000);
            CutIn(YOUMU,"「劇団運命座」",0,0,0,0,0);
        }

        c+=4;
        move--;

        yield;
    }

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

        SetShotAutoDeleteClip(32,32,32,32);
        loop(120) {
            CreateItem(ITEM_SCORE,GetX()+rand(-170,170),GetY()+rand(-95,138));
        }CreateItem(ITEM_BOMB,GetX(),GetY()+21);

    }

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

        if (OnEnemySpell==true&&OnBomb==true&&bombalpha>0) {
            bombalpha-=5;
        }
        if (OnEnemySpell==true&&OnBomb==false&&bombalpha<255) {
            bombalpha+=5;
        }

        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 (count2/12%4>=0&&move<=0) {
            SetGraphicRect(0,0,128,128);
        }
        if (count2/12%4>=1&&move<=0) {
            SetGraphicRect(0,128,128,256);
        }
        if (count2/12%4>=2&&move<=0) {
            SetGraphicRect(0,256,128,384);
        }
        if (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);
            tame=0;
        }
        if (GetSpeedX()<0&&move>8) {
            SetGraphicRect(256,128,384,256);
            tame=0;
        }
        if (GetSpeedX()>=0&&move>0) {
            SetGraphicRect(256,256,384,384);
            tame=0;
        }
        if (GetSpeedX()>=0&&move>8) {
            SetGraphicRect(256,384,384,512);
            tame=0;
        }
        if (ten==1&&OnBomb==false&&GetLife>20) {
            SetColor(160,160,180);
        }
        DrawGraphic(GetX(),GetY());

        if (bombalpha<255) {
            SetTexture(img);
            SetAlpha(255-bombalpha);
            SetGraphicRect(128*6,0,128*7,128);
            SetColor(255,200,200);
            SetGraphicScale(1.1,1.1);
            SetRenderState(ALPHA);
            if (count2/4%4>=0) {
                SetGraphicRect(128*6,0,128*7,128);
            }
            if (count2/4%4>=1) {
                SetGraphicRect(128*6,128,128*7,256);
            }
            if (count2/4%4>=2) {
                SetGraphicRect(128*6,256,128*7,384);
            }
            if (count2/4%4>=3) {
                SetGraphicRect(128*6,384,128*7,512);
            }
            DrawGraphic(GetX()+15*cos(count2*28),GetY()+30*cos(count2*18));
            if (count2/4%4>=1) {
                SetGraphicRect(128*6,0,128*7,128);
            }
            if (count2/4%4>=2) {
                SetGraphicRect(128*6,128,128*7,256);
            }
            if (count2/4%4>=3) {
                SetGraphicRect(128*6,256,128*7,384);
            }
            if (count2/4%4>=0) {
                SetGraphicRect(128*6,384,128*7,512);
            }
            DrawGraphic(GetX()-30*cos(count2*18),GetY()-15*cos(count2*28));
            if (count2/4%4>=2) {
                SetGraphicRect(128*6,0,128*7,128);
            }
            if (count2/4%4>=3) {
                SetGraphicRect(128*6,128,128*7,256);
            }
            if (count2/4%4>=0) {
                SetGraphicRect(128*6,256,128*7,384);
            }
            if (count2/4%4>=1) {
                SetGraphicRect(128*6,384,128*7,512);
            }
            DrawGraphic(GetX()+24*cos(count2*46),GetY()-40*cos(count2*58));
            if (count2/4%4>=3) {
                SetGraphicRect(128*6,0,128*7,128);
            }
            if (count2/4%4>=0) {
                SetGraphicRect(128*6,128,128*7,256);
            }
            if (count2/4%4>=1) {
                SetGraphicRect(128*6,256,128*7,384);
            }
            if (count2/4%4>=2) {
                SetGraphicRect(128*6,384,128*7,512);
            }
            DrawGraphic(GetX()-44*cos(count2*46),GetY()+20*cos(count2*58));
        }

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

    @BackGround()
    {
        SetTexture(bg);
        SetGraphicRect(0,0,384,448);
        SetRenderState(ALPHA);
        SetGraphicScale(1,1);
        SetGraphicAngle(0,0,0);
        SetColor(255,255,255);
        if (count2<=1) {
            SetAlpha(0);
        }
        if (count2>1) {
            SetAlpha(count3*10);
        }
        if (count2>=26) {
            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);
    }

}

