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

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

let imgClownpiece = CSD~"./img/dot_Clownpiece.png";
let Cutin = GetCurrentScriptDirectory() ~ "./img/ClownpieceCutin.png";//Anyone

@Event{
    SetTimer(999);
    SetLife(900);
    SetScore(1000000);
}
 
@Initialize{
	SetAutoDeleteObject(true);
	Clownpiece = ObjEnemy_Create(OBJ_ENEMY_BOSS);	
    ObjEnemy_Regist(Clownpiece);	
	
	ObjMove_SetY(Clownpiece, GetCenterY-120);
	ObjMove_SetX(Clownpiece, GetCenterX);
	
	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);
	ConcentrationA3(Clownpiece,"STAR",60,7,150,[000,000,255]);
	ObjEnemyBossScene_SetSpellTimer(GetEnemyBossSceneObjectID,5940);
	wait(85);	
	SE_Play(explode,100);
	spellcall;
	SpellBG;
	wait(125);
	FireTask;	
}

task FireTask{
	wait(70);
	SE_Play(charge1,100);
	ConcentrationA3(Clownpiece,"STAR",60,7,150,[255,0,0]);
	wait(85);	
	SE_Play(explode,100);
	ObjEnemy_SetDamageRate(Clownpiece,14,0);
	Lazers;
	fire;
}



task Lazers{
loop{
SE_Play(lazer,70);	
SE_Play(explode,100);
CreateStraightLaserA1(GetCenterX-195,GetCenterY-150,0,1000,10,120,1003,10);
SpellBurstA1(GetCenterX-195,GetCenterY-150,"STAR",[255,0,0]);
wait(10);
SE_Play(explode,100);
CreateStraightLaserA1(GetCenterX-195,GetCenterY-50,0,1000,10,120,1003,10);
SpellBurstA1(GetCenterX-195,GetCenterY-50,"STAR",[255,0,0]);
wait(10);
SE_Play(explode,100);
CreateStraightLaserA1(GetCenterX-195,GetCenterY+50,0,1000,10,120,1003,10);
SpellBurstA1(GetCenterX-195,GetCenterY+50,"STAR",[255,0,0]);
wait(10);
SE_Play(explode,100);
CreateStraightLaserA1(GetCenterX-195,GetCenterY+150,0,1000,10,120,1003,10);
SpellBurstA1(GetCenterX-195,GetCenterY+150,"STAR",[255,0,0]);
wait(120);
//Second
SE_Play(lazer,70);	
SE_Play(explode,100);
CreateStraightLaserA1(GetCenterX+195,GetCenterY-150,180,1000,10,120,1003,10);
SpellBurstA1(GetCenterX+195,GetCenterY-150,"STAR",[255,0,0]);
wait(10);
SE_Play(explode,100);
CreateStraightLaserA1(GetCenterX+195,GetCenterY-50,180,1000,10,120,1003,10);
SpellBurstA1(GetCenterX+195,GetCenterY-50,"STAR",[255,0,0]);
wait(10);
SE_Play(explode,100);
CreateStraightLaserA1(GetCenterX+195,GetCenterY+50,180,1000,10,120,1003,10);
SpellBurstA1(GetCenterX+195,GetCenterY+50,"STAR",[255,0,0]);
wait(10);
SE_Play(explode,100);
CreateStraightLaserA1(GetCenterX+195,GetCenterY+150,180,1000,10,120,1003,10);
SpellBurstA1(GetCenterX+195,GetCenterY+150,"STAR",[255,0,0]);
wait(120);}
}

task fire{
	loop{
		SE_Play(shot,30);
		loop(3){CreateShotA1(ClownpieceX,ClownpieceY,3,rand(0,360),667,10);}
	wait(1);}
}

task spellcall{
	ObjEnemyBossScene_StartSpell(GetEnemyBossSceneObjectID);
	CutInS1(Clownpiece, "NAZRIN", "Under Star Antinomy", Cutin, 0, 0,444, 453);
}

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

task SpellBG{
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	
	ObjPrim_SetTexture(obj, CSD~"./img/BG/splbgC.png");
	ObjSprite2D_SetSourceRect(obj, 0, 0, 384, 448);
	Obj_SetRenderPriorityI(obj,25);
	ObjSprite2D_SetDestCenter(obj);
	ObjRender_SetPosition(obj,GetCenterX,GetCenterY,0);
}