#include".\shot\AllStarShot_Const.txt"
#include".\Resources.txt"
#include".\selibrary.txt"
#include".\lib\AnimLib.h"
#include".\lib\DialogueLibrary.h"
#include".\OzzieEffects.txt"

let Clownpiece = ID_INVALID;
let ClownpieceX = 0;
let ClownpieceY = 0;

let imgClownpiece = CSD~"./img/dot_Clownpiece.png";

@Event{
    SetTimer(999);
    SetLife(1200);
    SetScore(1000000);
}
 
@Initialize{
	SetAutoDeleteObject(true);	
	Clownpiece = ObjEnemy_Create(OBJ_ENEMY_BOSS);	
    ObjEnemy_Regist(Clownpiece);		
	
	ObjMove_SetX(Clownpiece, GetCenterX);
	ObjMove_SetY(Clownpiece, GetCenterY-120);
	
	RenderClownpiece;
	BossManage;
	MainTask;     
}

task RenderClownpiece{
	ObjPrim_SetTexture(Clownpiece,imgClownpiece);
	ObjSprite2D_SetDestCenter(Clownpiece);	
	ObjRender_SetScaleXYZ(Clownpiece,1,1,0);
	
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 32, 32, 96, 96);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 32, 160, 96, 224);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 32, 288, 96, 352);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 160, 32, 224, 96);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_IDLE, 160, 160, 224, 224);
	
	ObjAnim_AddFrameA1(Clownpiece, ANIM_MOVE, 288, 288, 352, 352);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_MOVE, 288, 416, 352, 480);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_MOVEEND, 288, 288, 352, 352);
		
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 544, 32, 608, 96);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 544, 160, 608, 224);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 544, 288, 608, 352);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 672, 32, 736, 96);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 672, 160, 736, 224);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACK, 672, 288, 736, 352);
	ObjAnim_AddFrameA1(Clownpiece, ANIM_ATTACKEND, 544, 160, 608, 224);
	
	ObjAnim_SetLoopPointA1(Clownpiece, ANIM_MOVE, 1);
	ObjAnim_SetLoopPointA1(Clownpiece, ANIM_ATTACK, 5);
	ObjAnim_SetSpeedA1(Clownpiece, ANIM_IDLE, 7);
	ObjAnim_SetSpeedA1(Clownpiece, ANIM_MOVE, 4);
	ObjAnim_SetSpeedA1(Clownpiece, ANIM_ATTACK, 3);
	ObjAnim_SetSpeedA1(Clownpiece, ANIM_ATTACKEND, 3);
	ObjAnim_StartAnimationA1(Clownpiece, 10, 3);
}


@MainLoop{
	yield;
}

task MainTask{
	ObjEnemy_SetDamageRate(Clownpiece,0,0);
	wait(60);
	SE_Play(charge1,100);
	ConcentrationA2(Clownpiece,"STAR",60,7,150,[0,0,255]);
	ObjEnemyBossScene_SetSpellTimer(GetEnemyBossSceneObjectID,5940);
	FireTask;	
}

task FireTask{
	wait(130);
	ClownBullet(GetCenterX-rand(-160,+160),GetCenterY-230,50,90,778,1007,[0,0,255]);//Blue Type
	wait(240);
	SE_Play(charge1,100);
	ConcentrationA3(Clownpiece,"STAR",60,7,150,[0,0,255]);
	wait(85);	
	SE_Play(explode,100);
	ObjEnemy_SetDamageRate(Clownpiece,26,2);
	ClownBullet(GetCenterX-170,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX-120,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX-70,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX-20,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX+20,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX+70,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX+120,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX+160,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(360);
	ClownBullet(GetCenterX-rand(-160,+160),GetCenterY+230,50,270,776,1003,[255,0,0]);
	wait(240);
	SE_Play(charge1,100);
	ConcentrationA3(Clownpiece,"STAR",60,7,150,[255,0,0]);//Red Type
	wait(85);	
	SE_Play(explode,100);
	ClownBullet(GetCenterX+150,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX+100,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX+50,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX+0,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX-50,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX-100,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX-150,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	wait(360);
	SE_Play(charge1,100);
	ConcentrationA3(Clownpiece,"STAR",60,7,150,[200,200,200]);
	wait(85);	
	SE_Play(explode,100);
	LastBombs;
}

task LastBombs{
	loop{
	ClownBullet(GetCenterX-170,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX-120,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX-70,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX-20,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX+20,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX+70,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX+120,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(2);
	ClownBullet(GetCenterX+160,GetCenterY-230,10,90,778,1007,[0,0,255]);
	wait(240);
	ClownBullet(GetCenterX+150,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX+100,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX+50,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX+0,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX-50,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX-100,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(2);
	ClownBullet(GetCenterX-150,GetCenterY+230,20,270,776,1003,[255,0,0]);
	wait(240);}
}

task ClownBullet(posX,posY,Mspeed,Langle,graphic1,graphic2,color){
	SE_Play(shot,30);
	let Bullet = CreateShotA1(ClownpieceX,ClownpieceY,0,0,graphic1,10);
	ObjMove_SetDestAtFrame(Bullet,posX,posY,Mspeed);
	Obj_GetValue(Bullet, "Fireball");
	wait(60);
	CreateStraightLaserA1(ObjMove_GetX(Bullet),ObjMove_GetY(Bullet),Langle,2000,20,120,graphic2,60);
	wait(60);
	SE_Play(lazer,70);	
	SE_Play(explode,100);
	SpellBurstA1(ObjMove_GetX(Bullet),ObjMove_GetY(Bullet),"STAR",color);
	wait(1);
	Obj_Delete(Bullet);
}


task BossManage{

	while(ObjEnemy_GetInfo(Clownpiece,INFO_LIFE)>0){
		
		ClownpieceX = ObjMove_GetX(Clownpiece);
        ClownpieceY = ObjMove_GetY(Clownpiece);

		ObjEnemy_SetIntersectionCircleToShot(Clownpiece, ClownpieceX, ClownpieceY, 20);
		yield;
	}
	
	Obj_Delete(Clownpiece);
	
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
    CloseScript(GetOwnScriptID()); 
}