#TouhouDanmakufu
#Title["SUPER HARMONY FISTS OF LOVE"]
#Text[]
#Image[]
#BackGround[Default]
#Player[FREE]
#ScriptVersion[2]

script_enemy_main
{
	let frame=0;
    let BossCutIn=GetCurrentScriptDirectory~"FIST.png";
	#include_function ".\spellcard.txt";
	#include_function ".\fist_replace.txt";
    let alpha=255;
task attack{
    PlaySE(GetCurrentScriptDirectory~"sound\Charge.wav");
    Concentration01(60);
    loop(60){yield;}
    descent(i in 0..18){alpha=i*15; yield;}
    SetMovePosition02(GetCenterX, GetClipMinY-200, 1);
    yield;
    wave1;
}
task wave1{
    exshots;
    PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
    loop(4){
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        ascent(i in -3..4){
            shots(GetClipMinX+i*30*cos(atan2(GetClipMaxY-GetClipMinY, GetClipMaxX-GetClipMinX)-90),
            GetClipMinY+i*30*sin(atan2(GetClipMaxY-GetClipMinY, GetClipMaxX-GetClipMinX)-90),
            atan2(GetClipMaxY-GetClipMinY, GetClipMaxX-GetClipMinX), 6+i);
        }
        loop(200){yield;}
        PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
        ascent(i in -3..4){
            shots(GetClipMaxX+i*30*cos(atan2(GetClipMaxY-GetClipMinY, GetClipMinX-GetClipMaxX)-90),
            GetClipMinY+i*30*sin(atan2(GetClipMaxY-GetClipMinY, GetClipMinX-GetClipMaxX)-90),
            atan2(GetClipMaxY-GetClipMinY, GetClipMinX-GetClipMaxX), 6+i);
        }
        loop(200){yield;}
    }
    loop(200){yield;}
    PlaySE(GetCurrentScriptDirectory~"sound\Shot2.wav");
    wave2;
}
task exshots{
    loop(16){
        ascent(i in 0..10){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            ascent(j in 0..6){
                CreateShot01(GetCenterX, GetClipMinY, 3, i*9+j*60, CIRNO01, 10);
                CreateShot01(GetCenterX, GetClipMinY, 3, i*9+j*60+30, WHITE01, 10);
            }
            loop(10){yield;}
        }
    }
}
task wave2{
    exshots2;
    PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
    loop(2){
        loop(200){yield;}
        ascent(i in -3..4){
            shotsb(GetClipMinX+i*50*cos(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMinX)-90),
            GetClipMinY+i*50*sin(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMinX)-90),
            atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMinX)-60, 6+i);
        }
        loop(200){yield;}
        ascent(i in -3..4){
            shotsb(GetClipMinX+i*50*cos(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMinX)-90),
            GetClipMinY+i*50*sin(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMinX)-90),
            atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMinX)+60, 6+i);
        }
        loop(200){yield;}
        ascent(i in -3..4){
            shotsb(GetClipMaxX+i*50*cos(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMaxX)-90),
            GetClipMinY+i*50*sin(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMaxX)-90),
            atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMaxX)-60, 6+i);
        }
        loop(200){yield;}
        ascent(i in -3..4){
            shotsb(GetClipMaxX+i*50*cos(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMaxX)-90),
            GetClipMinY+i*50*sin(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMaxX)-90),
            atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetClipMaxX)+60, 6+i);
        }
    }
    loop(200){yield;}
    PlaySE(GetCurrentScriptDirectory~"sound\Shot2.wav");
    wave3;
}
task wave3{
    exshots;
    PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
    loop(4){
        loop(200){yield;}
        ascent(i in -3..4){
            shots(GetCenterX+i*50*cos(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetCenterX)-90),
            GetClipMinY+i*50*sin(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetCenterX)-90),
            atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetCenterX)-60, 6+i);
        }
        loop(200){yield;}
        ascent(i in -3..4){
            shots(GetCenterX+i*50*cos(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetCenterX)-90),
            GetClipMinY+i*50*sin(atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetCenterX)-90),
            atan2(GetPlayerY-GetClipMinY, GetPlayerX-GetCenterX)+60, 6+i);
        }
    }
}
task exshots2{
    loop(16){
        ascent(i in 0..10){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            ascent(j in 0..3){
                CreateShot01(GetClipMinX, GetClipMinY, 3, i*9+j*120, CIRNO01, 10);
                CreateShot01(GetClipMinX, GetClipMinY, 3, i*9+j*120+60, WHITE01, 10);
                CreateShot01(GetClipMaxX, GetClipMinY, 3, 180-i*9+j*120, CIRNO01, 10);
                CreateShot01(GetClipMaxX, GetClipMinY, 3, 180-i*9+j*120+60, WHITE01, 10);
            }
            loop(10){yield;}
        }
    }
}
task shots(x, y, angle, type){
    let counter=type*7;
    let obj=Obj_Create(OBJ_SHOT);
    Obj_SetPosition(obj, x, y);
    Obj_SetSpeed(obj, 3);
    Obj_SetAngle(obj, angle);
    ObjShot_SetGraphic(obj, type);
    ObjShot_SetBombResist(obj, true);
    while(Obj_BeDeleted(obj)==false){
        counter++;
        if(counter%49==0){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 3, Obj_GetAngle(obj)+90, 40+type, 10);
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 3, Obj_GetAngle(obj)-90, 40+type, 10);
        }
        yield;
    }
}
task shotsb(x, y, angle, type){
    let counter=type*8;
    let obj=Obj_Create(OBJ_SHOT);
    Obj_SetPosition(obj, x, y);
    Obj_SetSpeed(obj, 3);
    Obj_SetAngle(obj, angle);
    ObjShot_SetGraphic(obj, type);
    ObjShot_SetBombResist(obj, true);
    while(Obj_BeDeleted(obj)==false){
        counter++;
        if(counter%56==0){
            PlaySE(GetCurrentScriptDirectory~"sound\Shot1.wav");
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 3, Obj_GetAngle(obj)+90, 40+type, 10);
            CreateShot01(Obj_GetX(obj), Obj_GetY(obj), 3, Obj_GetAngle(obj)-90, 40+type, 10);
        }
        yield;
    }
}
task bossgraphic{
    yield;
    let obj=Obj_Create(OBJ_EFFECT);
    Obj_SetPosition(obj, GetX, GetY);
    ObjEffect_SetTexture(obj, BossCutIn);
    ObjEffect_SetLayer(obj, 4);
    ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
    ObjEffect_CreateVertex(obj, 4);
    ObjEffect_SetVertexUV(obj, 0, 0, 0);
    ObjEffect_SetVertexUV(obj, 1, 256, 0);
    ObjEffect_SetVertexUV(obj, 2, 0, 416);
    ObjEffect_SetVertexUV(obj, 3, 256, 416);
    ObjEffect_SetVertexXY(obj, 0, -128, -208);
    ObjEffect_SetVertexXY(obj, 1, 128, -208);
    ObjEffect_SetVertexXY(obj, 2, -128, 208);
    ObjEffect_SetVertexXY(obj, 3, 128, 208);
    while(Obj_BeDeleted(obj)==false){
        Obj_SetPosition(obj, GetX, GetY-121);
        ObjEffect_SetAngle(obj, 0, 0, 180);
        ascent(i in 0..4){ObjEffect_SetVertexColor(obj, i, alpha, 255, 255, 255);}
        if(alpha==0){Obj_Delete(obj);}
        yield;
    }
}
	@Initialize
	{
		SetInvincibility(200);
		SetLife(500);
		LoadGraphic(BossCutIn);
		SetMovePosition02(GetCenterX,120,20);
		CutIn(YOUMU, "''SUPER HARMONY FISTS OF LOVE''",BossCutIn,0,0,256,416);
		spellbonus(10000000);
		timer;
		SetCommonData("timercount", 5400);
        bossgraphic;
        survival=1;
        SetCommonData("ONSPELL", "TRUE");
        if(GetCommonDataDefault("NOMISSCOUNT", -1)==-1){
            initmeh;
        }
	}
	
	@MainLoop
	{
        SetShotAutoDeleteClip(300, 300, 300, 300);
        SetDamageRate(0, 0);
		frame++;
		yield;
        if(frame==90){attack;}
}
	
	@Finalize
	{
        SetShotAutoDeleteClip(32, 32, 32, 32);
		AddScore(spellbonustotal);
		if(spellbonustotal>0)
		{
		PlaySE(GetCurrentScriptDirectory~"sound\se_cardget.wav");
		loop(50)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}else{
		loop(15)
		{
			CreateItem(ITEM_SCORE,GetX+rand(-100,100),GetY+rand(20,100));
		}
		}
		 
        if(GetMissCountInThisSpell==0){
            SetCommonData("NOMISSCOUNT", GetCommonData("NOMISSCOUNT")+1);
        }
	}
	
	@DrawLoop
	{
	}
}