#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["Non card #2"]
#Text["non with diddy"]

let bossObj;
let BG;
let bossX = 0;
let bossY = 0;
let imgBoss = GetCurrentScriptDirectory ~ "BarrelBlast.png";
let bg = GetCurrentScriptDirectory ~ "bramble.png";
let familiar = GetCurrentScriptDirectory ~ "BarrelEnemy.txt";

//
#include "script/DonkeyKong/Donkey_ShotConst.txt"

@Initialize {

	bossObj = ObjEnemy_Create(OBJ_ENEMY_BOSS);//define boss and register it
	//BG = ObjPrim_Create(OBJ_SPRITE_2D);//not really a boss
	ObjEnemy_Regist(bossObj);
	//ObjMove_SetPosition(bossObj,192,-100);//warp boss to location


	ObjMove_SetDestAtFrame(bossObj,192,120,30);// move boss to desired x y location at desired speed
	
	mainTask; //run main task
}

@Event {
	alternative(GetEventType())//set boss timer and life
	case(EV_REQUEST_LIFE) {
		SetScriptResult(2000);
	}
	case(EV_REQUEST_TIMER) {
		SetScriptResult(60);
	}
}

@MainLoop {
	bossX = ObjMove_GetX(bossObj);
	bossY = ObjMove_GetY(bossObj);
	
	ObjEnemy_SetIntersectionCircleToShot(bossObj,bossX,bossY,24);//collision for shots and player
	ObjEnemy_SetIntersectionCircleToPlayer(bossObj,bossX,bossY,21);
	
	yield;
}

task renderBG {
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,21); 
	ObjPrim_SetTexture(obj,bg); 
	ObjSprite2D_SetSourceRect(obj,0,0,256,256);
	ObjSprite2D_SetDestRect(obj,0,0,GetStgFrameWidth,GetStgFrameHeight);
} 

@Finalize {

}

function wait(w) {
	loop(w){yield;}
}

task mainTask {
	renderBoss;
	renderBG;
	TFinalize;
	wait(60);
	movement;
}

task renderBoss {
	let x =0;
	ObjPrim_SetTexture(bossObj,imgBoss);
	ObjSprite2D_SetSourceRect(bossObj,x,65,x+63,129);
	ObjSprite2D_SetDestCenter(bossObj);
	//ObjRender_SetScaleXYZ(bossObj,2,2,0);
	let temp = 0;
	
	while(!Obj_IsDeleted(bossObj)) {
		temp++;
		if(temp==2){
		x = modc(x+65,1040);
		ObjSprite2D_SetSourceRect(bossObj,x,65,x+63,129);
		temp=0;
		}
		yield;
	}

	

}


task movement {
	//wait(120);
	ringBanana;
	
}

function ringBanana{
	let angle1 = 0;
	let angle2 = 0;
	let angle3 = 0;
	let temp=0;
	loop{
		CreateShotA1(bossX,bossY,2,angle1,Banana,0);
		CreateShotA1(bossX,bossY,3,angle2,Banana,0);
		CreateShotA1(bossX,bossY,4,angle3,Banana,0);
		CreateShotA1(bossX,bossY,4,angle3+180,Banana,0);
		if(temp%30==0){
			loop(17){
				CreateShotA1(bossX,bossY,3.4,rand(0,360),Banana,0);
			}
			
		}
		temp++;
		angle1+=7;
		angle2-= 15;
		angle3+= 25;
		wait(2);
	}
	//CreateShotA1(BossX,BossY,3,Angle,banana,0)
	
}

task TFinalize{
        while(ObjEnemy_GetInfo(bossObj, INFO_LIFE) > 0){yield;}
        Obj_Delete(bossObj);
        DeleteShotAll(TYPE_ALL, TYPE_IMMEDIATE);
        SetAutoDeleteObject(true);
        CloseScript(GetOwnScriptID());
    }
