#TouhouDanmakufu[Single]
#ScriptVersion[3]
#Title["CasperSlide"]
#Text["Dance"]
//#BGM["script/Casper/ChaChaSlide.mp3"]

let bossObj;
let cirno;
let Charlie;

let BG;
let bossX = 0;
let bossY = 0;
let imgBoss = GetCurrentScriptDirectory ~ "SuwakoMaster.png";
let imgOther = GetCurrentScriptDirectory ~ "OtherMaster.png";

let bossHomeX = GetCenterX;
let bossHomeY = 140;
let yAngle = 0;
//let act = "";
let residualBullets = [];
//let lagMemory=0;
let bgm;// = GetCurrentScriptDirectory ~ "ChaChaSlide.mp3";
	let drawRectLeft = 0;
	let drawRectTop = 0;
	let rectSize = 128;
	let dir = 1;
	let CharlieDir = 1;
	
	let hopHeight = 130;
	let slideHeight = 260;
	let stompHeight = 390;
	let clapHeight = 520;
	let funkyHeight = 650;
	let lowHeight = 780;
	let toTheHeight = 910;
	let turnHeight = 1040;
	let backHeight = 1170;
	let chaChaHeight = 1300;
	let hatHeight = 1430;
	
	let cirIdleHeight =0;
	let cirFreezeHeight = 130;
	let cirSpinHeight = 260;
	let cirRectLeft = 0;
	let cirRectTop = 130;
	
	let CharlieHeight1 = 390;
	let CharlieHeight2 = 650;
	let charlieRectTop = 390;
	let charlieRectLeft = 0;
	let charlieRectSize = 256;
	
	 let objScene = GetEnemyBossSceneObjectID();

#include "script/Casper/Casper_ShotConst.txt"
#include ".\usefulFunctions.txt"

@Initialize {
	ObjEnemyBossScene_StartSpell(objScene);

	//LoadSound(bgm);
	//StartSlow(TARGET_ALL, 60);
	//bgm = Sound("script/Casper/ChaChaSlide.wav");
		//bgm = PlaySyncBGM("script/Casper/ChaChaSlide.wav",0,230,20);
	
	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,bossHomeX,-100);//warp boss to location


	//ObjMove_SetDestAtSpeed(bossObj,bossHomeX,bossHomeY,5);// move boss to desired x y location at desired speed
	
	cirno = ObjEnemy_Create(OBJ_ENEMY);//define boss and register it
		ObjEnemy_Regist(cirno);
	bgm = PlaySyncBGM("script/Casper/ChaChaSlide.mp3",0,230,20);//was moved from line 52 re sync
	mainTask; //run main task
	
}

@Event {
	alternative(GetEventType())//set boss timer and life
	case(EV_REQUEST_LIFE) {
		SetScriptResult(5000);
	}
	case(EV_REQUEST_TIMER) {
		SetScriptResult(237);//230 not enough
	}
	case(EV_PAUSE_ENTER){ObjSound_Stop(bgm);}
   case(EV_PAUSE_LEAVE){ObjSound_Play(bgm);}
   case(EV_REQUEST_IS_DURABLE_SPELL){SetScriptResult(true);}
   case(EV_TIMEOUT){CloseScript(GetOwnScriptID);
   //FinalizeStageScene();
   return;}
}

@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 sunspikeBG {
	let bg = GetCurrentScriptDirectory ~ "SunspikeBG.png";
	let rainbow = GetCurrentScriptDirectory ~ "Rainbow.png";
	let obj = ObjPrim_Create(OBJ_SPRITE_2D);
	Obj_SetRenderPriorityI(obj,21); 
	ObjPrim_SetTexture(obj,bg); 
	ObjSprite2D_SetSourceRect(obj,0,0,384,448);
	ObjSprite2D_SetDestRect(obj,0,0,GetStgFrameWidth,GetStgFrameHeight);
	let timer =0;
	let num = floor(rand(25,40));
	while(!Obj_IsDeleted(bossObj)){
		if(timer == num){
			box;
			num = floor(rand(22,35));
			timer =0;
		}
		timer++;
		yield;
	}
	yield;
	
	task box{//task works
		let coinflip = rand(0,288+256);
		let color = rand(0,260);
		let counter =0;
		if(coinflip<288){//vertical scrolling
			let position = rand(-16,GetStgFrameWidth+16);
			let dir = 1;
			let speed = rand(3,5);
			if(rand(-1,1)>0){
				dir=-1;
			}
			
			let rect1 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriorityI(rect1,22); 
			ObjPrim_SetTexture(rect1,rainbow); 
			ObjSprite2D_SetSourceRect(rect1,0,color,2,color+2);
			ObjSprite2D_SetDestRect(rect1,position,-64+288+dir*288,position+1,0+224+dir*224);
		
			let rect2 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriorityI(rect2,22); 
			ObjPrim_SetTexture(rect2,rainbow); 
			ObjSprite2D_SetSourceRect(rect2,0,color,2,color+2);
			ObjSprite2D_SetDestRect(rect2,position+31,-64+288+dir*288,position+32,0+224+dir*224);
		
			let rect3 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriorityI(rect3,22); 
			ObjPrim_SetTexture(rect3,rainbow); 
			ObjSprite2D_SetSourceRect(rect3,0,color,2,color+2);
			ObjSprite2D_SetDestRect(rect3,position,-64+288+dir*288,position+32,-64-dir+288+dir*288);
			
			let rect4 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriorityI(rect4,22); 
			ObjPrim_SetTexture(rect4,rainbow); 
			ObjSprite2D_SetSourceRect(rect4,0,color,2,color+2);
			ObjSprite2D_SetDestRect(rect4,position,-dir+224+dir*224,position+32,0+224+dir*224);
			
			while(counter<515){
				ObjSprite2D_SetDestRect(rect1,position,-64+288+dir*288-dir*counter,position+1,0+224+dir*224-dir*counter);
				//ObjSprite2D_SetDestRect(rect1,position,-64+counter,position+1,0+counter);
				ObjSprite2D_SetDestRect(rect2,position+31,-64+288+dir*288-dir*counter,position+32,0+224+dir*224-dir*counter);
				//ObjSprite2D_SetDestRect(rect2,position+31,-64+counter,position+32,0+counter);
				ObjSprite2D_SetDestRect(rect3,position,-64+288+dir*288-dir*counter,position+32,-64-dir+288+dir*288-dir*counter);
				//ObjSprite2D_SetDestRect(rect3,position,-64+counter,position+32,-63+counter);
				ObjSprite2D_SetDestRect(rect4,position,-dir+224+dir*224-dir*counter,position+32,0+224+dir*224-dir*counter);
				//ObjSprite2D_SetDestRect(rect4,position,-1+counter,position+32,0+counter);
				counter+=speed;
				color= (color+1)%256;
				ObjSprite2D_SetSourceRect(rect1,0,color,2,color+2);
				ObjSprite2D_SetSourceRect(rect2,0,color,2,color+2);
				ObjSprite2D_SetSourceRect(rect3,0,color,2,color+2);
				ObjSprite2D_SetSourceRect(rect4,0,color,2,color+2);
				if(counter>=515){
					Obj_Delete(rect1);
					Obj_Delete(rect2);
					Obj_Delete(rect3);
					Obj_Delete(rect4);
				}
				yield;
			}
		}else{//horizontal scrolling
			let position = rand(-16,GetStgFrameHeight+16);
			let dir = 1;
			let speed = rand(3,5);
			if(rand(-1,1)>0){
				dir=-1;
			}
			
			let rect1 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriorityI(rect1,22); 
			ObjPrim_SetTexture(rect1,rainbow); 
			ObjSprite2D_SetSourceRect(rect1,0,color,2,color+2);
			ObjSprite2D_SetDestRect(rect1,-64+256+dir*256,position,0+192+dir*192,position+1);
		
			let rect2 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriorityI(rect2,22); 
			ObjPrim_SetTexture(rect2,rainbow); 
			ObjSprite2D_SetSourceRect(rect2,0,color,2,color+2);
			ObjSprite2D_SetDestRect(rect2,-64+256+dir*256,position+31,0+192+dir*192,position+32);
		
			let rect3 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriorityI(rect3,22); 
			ObjPrim_SetTexture(rect3,rainbow); 
			ObjSprite2D_SetSourceRect(rect3,0,color,2,color+2);
			ObjSprite2D_SetDestRect(rect3,-64+256+dir*256,position,-64-dir+256+dir*256,position+32);
			
			let rect4 = ObjPrim_Create(OBJ_SPRITE_2D);
			Obj_SetRenderPriorityI(rect4,22); 
			ObjPrim_SetTexture(rect4,rainbow); 
			ObjSprite2D_SetSourceRect(rect4,0,color,2,color+2);
			ObjSprite2D_SetDestRect(rect4,-dir+192+dir*192,position,0+192+dir*192,position+32);
			
			while(counter<515){
				ObjSprite2D_SetDestRect(rect1,-64+256+dir*256-dir*counter,position,0+192+dir*192-dir*counter,position+1);
				//ObjSprite2D_SetDestRect(rect1,position,-64+288+dir*288-dir*counter,position+1,0+224+dir*224-dir*counter);
				//ObjSprite2D_SetDestRect(rect1,position,-64+counter,position+1,0+counter);
				ObjSprite2D_SetDestRect(rect2,-64+256+dir*256-dir*counter,position+31,0+192+dir*192-dir*counter,position+32);
				//ObjSprite2D_SetDestRect(rect2,position+31,-64+288+dir*288-dir*counter,position+32,0+224+dir*224-dir*counter);
				//ObjSprite2D_SetDestRect(rect2,position+31,-64+counter,position+32,0+counter);
				ObjSprite2D_SetDestRect(rect3,-64+256+dir*256-dir*counter,position,-64-dir+256+dir*256-dir*counter,position+32);
				//ObjSprite2D_SetDestRect(rect3,position,-64+288+dir*288-dir*counter,position+32,-64-dir+288+dir*288-dir*counter);
				//ObjSprite2D_SetDestRect(rect3,position,-64+counter,position+32,-63+counter);
				ObjSprite2D_SetDestRect(rect4,-dir+192+dir*192-dir*counter,position,0+192+dir*192-dir*counter,position+32);
				//ObjSprite2D_SetDestRect(rect4,position,-dir+224+dir*224-dir*counter,position+32,0+224+dir*224-dir*counter);
				//ObjSprite2D_SetDestRect(rect4,position,-1+counter,position+32,0+counter);
				counter+=speed;
				color= (color+1)%256;
				ObjSprite2D_SetSourceRect(rect1,0,color,2,color+2);
				ObjSprite2D_SetSourceRect(rect2,0,color,2,color+2);
				ObjSprite2D_SetSourceRect(rect3,0,color,2,color+2);
				ObjSprite2D_SetSourceRect(rect4,0,color,2,color+2);
				if(counter>=515){
					Obj_Delete(rect1);
					Obj_Delete(rect2);
					Obj_Delete(rect3);
					Obj_Delete(rect4);
				}
		
				yield;
			}
			
		}
		yield;
		
		
		
	}
} 

@Finalize {
	if(ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SHOOTDOWN_COUNT)
        +ObjEnemyBossScene_GetInfo(objScene, INFO_PLAYER_SPELL_COUNT) == 0){
    AddScore(ObjEnemyBossScene_GetInfo(objScene, INFO_SPELL_SCORE));
	}
	CloseScript(GetOwnScriptID);
}

task mainTask {
	
	sunspikeBG;
	movement;
	renderBoss;
	renderCir;
	//clapShot1;
	
}

task renderBoss {
	
	ObjPrim_SetTexture(bossObj,imgBoss);
	ObjSprite2D_SetSourceRect(bossObj,0,0,128,128);
	ObjSprite2D_SetDestCenter(bossObj);
	ObjRender_SetScaleXYZ(bossObj,1,1,0);
	//ObjMove_SetAngle(bossObj,270);
	while(!Obj_IsDeleted(bossObj)){
		ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		//ObjSprite2D_SetDestCenter(bossObj);
		ObjRender_SetScaleXYZ(bossObj,rectSize/128,rectSize/128,0);
		ObjRender_SetAngleXYZ(bossObj,0,90-(dir*90)+yAngle,0);
	/*
	if(cos(dir) < 0) { ObjRender_SetAngleXYZ(bossObj,0,0,0);}
	else if(cos(dir) > 0) { ObjRender_SetAngleXYZ(bossObj,0,180,0);}
	*/
	
		yield;
	}			
	
	
}

task TEnd
{
	while(ObjEnemyBossScene_GetInfo(bossObj, INFO_TIMER) > 0)
	{
		yield;
	}
	DeleteShotAll(TYPE_ALL, TYPE_ITEM);
	Obj_Delete(bossObj);

	loop(10){yield;}

	CloseScript(GetOwnScriptID());
}
task movement {
		
		ceilingDrop("center");
		idle(80);
		idle(30);//since moving playsyncbgm
		//
		//peace;
		//
		funky(400);//480
		clapShot1;//784
		idle(5);//789
		toThe("left");
		idle(10);
		back(bossX,bossY,bossHomeX);
		idle(130);
		hop(3,40);
		idle(25);
		idle(17);
		stomp("right","center");
		idle(17);
		stomp("left","center");
		idle(30);
		chaCha(205);
		idle(45);
		turnOut;
		idle(10);
		toThe("left");
		back(bossX,bossY,bossHomeX);
		idle(135);
		hop(3,40);
		idle(25);
		idle(17);//all idle(17); are temporary to compensate for the change in the stomp timing
		stomp("right","center");
		idle(5);
		idle(17);
		stomp("left","center");
		idle(25);
		chaCha(185);
		idle(10);
		funky(110);
		toThe("right");
		toThe("left");
		idle(10);
		back(bossX,bossY,bossHomeX);/////////////////////////////////////////////////////////////////
		idle(50);//20+30
		hop(3,40);
		idle(65);
		hop(3,40);
		idle(45);//60-15
		idle(17);
		stomp("right","right");
		//stomp("right");
		idle(2);//17-15
		stomp("left","left");
		//stomp("left");
		slideToThe("left");////this is synced always maintain frame count prior to this point
		idle(30);
		slideToThe("right");
		idle(30);
		crissCross;
		chaCha(190);
		idle(30);
		goToWork;//starts a little early, but needs time for bullets to be relevant and  
		toThe("left");
		idle(10);
		back(bossX,bossY,bossHomeX);
		idle(65);
		hop(3,40);
		hop(4,30);
		idle(5);
		hop(3,40);
		hop(4,30);
		idle(20);
		idle(17);
		stomp("right","right");
		//stomp("right");
		idle(12);
		stomp("left","left");
		//stomp("left");
		handsOnKnees;
		chaCha(215);
		turnOut;
		toThe("left");
		back(bossX,bossY,bossHomeX);
		idle(140);
		hop(3,25);
		hop(4,25);
		hop(5,25);
		hop(6,25);
		hop(7,25);
		idle(40);
		stomp("right","center");
		idle(35);
		stomp("left","center");
		idle(45);
		stomp("right","center");
		idle(35);
		stomp("left","center");
		idle(35);
		stomp("right","center");
		idle(30);
		stomp("left","center");
		idle(1);
		freeze;
		residualBullets = low;
		hop(3,40);
		let bulletTemp = 0;
		loop(length(residualBullets)){//550
			ObjShot_SetDeleteFrame(residualBullets[bulletTemp],90);
			ObjMove_SetSpeed(residualBullets[bulletTemp],5);
			ObjMove_SetAngle(residualBullets[bulletTemp],atan2(ObjMove_GetY(residualBullets[bulletTemp])-bossY,ObjMove_GetX(residualBullets[bulletTemp])-bossX));
			bulletTemp++;
		}
		idle(20);
		stomp("right","center");
		idle(25);
		stomp("left","center");
		
		idle(30);
		chaCha(205);
		idle(45);
		turnOut;
		toThe("left");
		idle(30);
		back(bossX,bossY,bossHomeX);
		idle(105);
		hop(3,40);
		idle(60);
		hop(3,40);//in sync
		idle(30);
		reverse(1);
		idle(20);
		reverse(1);
		idle(25);
		slideToThe("left");
		idle(35);
		slideToThe("right");
		idle(35);
		reverse(2);
		idle(10);
		reverse(2);
		idle(10);
		chaCha(110);//shrink theses chachas were all 205
		idle(10);
		chaCha(130);// 2nd and 4th bigger
		idle(5);
		chaCha(110);
		idle(10);
		chaCha(130);
		idle(5);
		turnOut;
		idle(15);
		toThe("left");
		idle(10);
		back(bossX,bossY,bossHomeX);
		idle(95);
		hop(3,40);
		hop(4,40);
		idle(5);
		hop(3,40);
		hop(4,40);
		idle(40);
		stomp("right","center");
		idle(20);
		stomp("left","center");
		charlieBrown;
		slideToThe("right");
		idle(30);
		slideToThe("left");
		idle(25);
		back(bossX,bossY,bossHomeX);
		idle(55);
		chaCha(205);
		idle(30);
		peace;
		TEnd;
		//CloseScript(GetOwnScriptID);
		//return;		
		yield;
	}

	function ceilingDrop(position) {//35frames
		
		drawRectLeft = 910;
		drawRectTop = stompHeight;
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		if(position == "center"){
			ObjMove_SetPosition(bossObj,bossHomeX,bossHomeY-200);
			ObjMove_SetDestAtFrame(bossObj,bossHomeX,bossHomeY,25);
			wait(20);
		
			drawRectLeft = 1040;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft = 1170;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft = 1300;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
		}else if(position == "right"){
			ObjMove_SetPosition(bossObj,bossX,bossHomeY-200);
			ObjMove_SetDestAtFrame(bossObj,bossX,GetStgFrameHeight+20,30);
			wait(30);
			ceilingDrop("center");
		}else{
			ObjMove_SetPosition(bossObj,bossX,bossHomeY-200);
			ObjMove_SetDestAtFrame(bossObj,bossX,GetStgFrameHeight+20,30);
			wait(30);
			ceilingDrop("center");
		}
	}
	
	function idle(duration) {
		
		let time = 0;
		if(drawRectTop!=0){
			drawRectLeft =0;
		}
		drawRectTop = 0;
		
		let temp = 0;
		while(time<duration) {
			//if(drawRectTop ==0 ){clapShot1;}
			if(temp==4){
				drawRectLeft = modc(drawRectLeft+130,8*130);
				//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
				temp=0;
				
			}
			temp++;
			time++;
			yield;
		}
	}
	
	function funky(duration) {

		drawRectTop = funkyHeight;
		drawRectLeft =0;
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		wait(6);
		let funkyTime = 6;
		let funkyTemp = 0;
		while(funkyTime<duration) {
			//if(drawRectTop ==0 ){clapShot1;}
			if(funkyTemp==5){
				drawRectLeft += 130;
				if(drawRectLeft == 910){
					drawRectLeft = 130;
				}
			CreateShotA1(rand(0,GetStgFrameWidth),0,rand(2,5),rand(38,142),rand(121,136),0);
				// = drawTemp + 130;
				//ObjSprite2D_SetSourceRect(bossObj,130+drawRectLeft,drawRectTop,130+drawRectLeft+rectSize,drawRectTop+rectSize);
				funkyTemp=0;
				
			}
			funkyTemp++;
			funkyTime++;
			yield;
		}
		
	}
	
	
	
	function toThe(direction) {//110
		dir = 1;
		if (direction == "left"){
			dir = -1;
		}
		//ObjMove_SetAngle(bossObj,180*dir);
		ObjRender_SetAngleXYZ(bossObj,0,90-(dir*90),0);
		let temp = 0;
		let draw = 0;
		
		drawRectTop = toTheHeight;
		let yStart = ObjMove_GetY(bossObj);
		
			drawRectLeft = 0;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			let shotY =0;
			loop(GetStgFrameHeight/10){//bulletloop
				
				//let shotTemp = 0;
				
					let shot = CreateShotA1(GetCenterX-(dir*GetCenterX),10+10*shotY,7,90-(dir*90),12,0);
					ObjMove_SetDestAtFrame(shot,bossHomeX+dir*150,ObjMove_GetY(shot),70);
					shotY++;
					ObjShot_SetDeleteFrame(shot,70);
				
				
				
			}
			drawRectLeft += 130;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft += 130;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			
			ObjMove_SetDestAtFrame(bossObj,bossHomeX+dir*150,bossHomeY,60);
			
		loop(60) {
			if(temp<5){
				drawRectLeft = 520;
			}else if(temp<10){
				drawRectLeft = 650;
			}else if(temp<15){
				drawRectLeft = 780;
			}else{
				drawRectLeft = 910;
			}
			
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			//ObjMove_SetDestAtFrame(bossObj,ObjMove_GetX(bossObj)+ 2*dir,bossHomeY,1);
			temp++;
			yield;
		}
		idle(35);
			
	} 
	
	function back(currentX,currentY,destX) {
		drawRectTop = backHeight;
		drawRectLeft = 0;
		let temp = 0;
		let a = 0.25;
		let b = -10;
		let xMovement = absolute(destX-currentX);
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		wait(5);
		drawRectLeft = 130;
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		wait(5);
		
		let shotY =0;
			loop(GetStgFrameHeight/10){//bulletloop
				
				//let shotTemp = 0;
				
					let shot = CreateShotA1(round((ObjMove_GetX(bossObj))/GetStgFrameWidth)*GetStgFrameWidth,10+10*shotY,0,90-(dir*90),12,0);
					ObjMove_SetDestAtFrame(shot,GetCenterX,ObjMove_GetY(shot),40);
					shotY++;
					ObjShot_SetDeleteFrame(shot,60);
				
				
				
			}
			
		let backTemp = 0;
		loop((-4*b)/(4*a)) {
		
			//if(drawRectTop ==0 ){clapShot1;}
			if(backTemp==5){
				drawRectLeft += 130;
				if(drawRectLeft == 650){
					drawRectLeft = 260;
				}
				// = drawTemp + 130;
				//ObjSprite2D_SetSourceRect(bossObj,130+drawRectLeft,drawRectTop,130+drawRectLeft+rectSize,drawRectTop+rectSize);
				backTemp=0;
				
			}
			backTemp++;
			
		
	
			
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			ObjMove_SetDestAtFrame(bossObj,currentX+temp*(-dir*xMovement)/((-4*b)/(4*a)),currentY+b*temp+(a*temp*temp),1);
			temp++;
			yield;
		}
			
			drawRectLeft = 650;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft = 780;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
	}
	
	function hop(number,length) {//at^2+bt+yStart=0 
		let temp = 0;
		let draw = 0;
		let b = -400/length;//always jumps 100 pixels
		let a = -b/length;//lands after length frames
		drawRectTop = hopHeight;
		let yStart = ObjMove_GetY(bossObj);
		
			drawRectLeft = 0;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft = 130;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
		loop((-4*b)/(4*a)) {
			if(temp<4){
			drawRectLeft = 260;
			}else if(temp<8){
			drawRectLeft = 390;
			}else if (temp<12){
			drawRectLeft = 520;
			}else if(temp<((-2*b)/(4*a))){
			drawRectLeft = 650;
			}else if(temp<((-4*b)/(4*a))-12){
			drawRectLeft = 780;
			}else if(temp<((-4*b)/(4*a))-8){
			drawRectLeft = 910;
			}else if(temp<((-4*b)/(4*a))-4){
			drawRectLeft = 1040;
			}else{
			drawRectLeft = 1430;
			}
			
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			ObjMove_SetDestAtFrame(bossObj,ObjMove_GetX(bossObj),bossHomeY+b*temp+(a*temp*temp),1);
			temp++;
			draw++;
			yield;
		}
			geometry(bossX,bossY,5,number,5,6,rand(0,90),147,0);
			drawRectLeft = 1170;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft = 1300;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
	}
	
	function stomp(direction,fall) {
		let dir = 1;
		if (direction == "left"){
			dir = -1;
		}
		//ObjMove_SetAngle(bossObj,180*dir);
		//ObjRender_SetAngleXYZ(bossObj,0,90-(dir*90),0);
		let temp = 0;
		let draw = 0;
		let a = -0.45;//-0.25;
		let b = 12;//10;
		let c = GetStgFrameHeight-bossHomeY;
		drawRectTop = stompHeight;
		let yStart = ObjMove_GetY(bossObj);
		
			drawRectLeft = 0;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft += 130;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			
			
		loop(ceil((-b-((b*b)-4*a*c)^0.5)/(2*a))) {
			if(temp<4){
			drawRectLeft = 260;
			}else if(temp<8){
			drawRectLeft = 390;
			}else if (temp<12){
			drawRectLeft = 520;
			}else if(temp<((-2*b)/(4*a))){
			drawRectLeft = 650;
			}else if(temp<((-4*b)/(4*a))-12){
			drawRectLeft = 780;
			
			}else{
			drawRectLeft = 910;
			if(modc(temp,4)==0){geometry(bossX,bossY,10,8,1,3,rand(0,90),rand(13,14.9),0);}
			}
			
			ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			ObjMove_SetDestAtFrame(bossObj,ObjMove_GetX(bossObj)+ 3*dir,bossHomeY-b*temp-(a*temp*temp),1);
			temp++;
			draw++;
			yield;
		}
		ceilingDrop(fall);
			
	}
	
	function chaCha(time) {
		drawRectTop = chaChaHeight;
		drawRectLeft = 0;
		wait(5);
		drawRectLeft = 130;
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		wait(5);

		let chaChaTemp = 0;
		loop(time-25) {
		
			if(chaChaTemp==6){//was 5
				drawRectLeft += 130;
				if(drawRectLeft == 780){
					drawRectLeft = 260;
				}
				// = drawTemp + 130;
				//ObjSprite2D_SetSourceRect(bossObj,130+drawRectLeft,drawRectTop,130+drawRectLeft+rectSize,drawRectTop+rectSize);
				chaChaTemp=0;
				let shot = CreateShotA1(1,1,3,rand(1,89),22,0);
				bound(shot);
				residualBullets = residualBullets ~ [shot];
				let shot2 = CreateShotA1(GetStgFrameWidth-1,1,3,rand(91,179),22,0);
				bound(shot2);
				residualBullets = residualBullets ~ [shot2];
			}
			chaChaTemp++;
			yield;
		}
			
			drawRectLeft = 780;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft = 130;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft=0;
			wait(5);
	}
	
	function turnOut {
		drawRectLeft = 0;
		drawRectTop = turnHeight;
		let turnTemp=-5;
		let temp=0;
		loop(length(residualBullets)){
			ObjMove_SetAngularVelocity(residualBullets[temp],ObjMove_GetSpeed(residualBullets[temp]));
			temp++;
		}
		wait(5);
		loop(50){
			if(modc(turnTemp,5) == 0){
				drawRectLeft+=130;
			}
			turnTemp++;
			wait(1);
		}
		wait(10);
		idle(20);
		temp=0;
		loop(length(residualBullets)){
			ObjMove_SetAngularVelocity(residualBullets[temp],0);
			temp++;
		}
	}
	
	function low {
		drawRectLeft =0;
		drawRectTop = lowHeight;
		let lowDir =1;
		let lowArray = [];
		let lowArray2 = [];
		wait(6);
		drawRectLeft+=130;
		wait(6);
		drawRectLeft+=130;
		wait(6);
		drawRectLeft+=130;
		let lowTemp = 0;
		dir = 1;
		loop(415){
			
			if(modc(lowTemp,6)==0){//renderloop
				drawRectLeft+=130;
				if(drawRectLeft==1040){
					drawRectLeft= 520;
				}
				
			}
			if(modc(lowTemp,30)==0){//bulletloop
				let shotX =0;
				//let shotTemp = 0;
				loop(22){
					let shot = CreateShotA1(10+17*shotX+rand(-5,5),0,0,90,29,0);
					shotX++;
					ObjShot_SetDeleteFrame(shot,1500);
					lowArray = lowArray ~ [shot];
				}
				let arrayPointer = 0;
				loop(floor(lowTemp/30)){
					loop(22){
						ObjMove_SetDestAtFrame(lowArray[arrayPointer],ObjMove_GetX(lowArray[arrayPointer])+lowDir*rand(3,5),ObjMove_GetY(lowArray[arrayPointer])+rand(28,30),12);
						arrayPointer++;
					}
					lowDir = -lowDir;
				}
				geometry(rand(0,GetStgFrameWidth),GetStgFrameHeight,0,8,1,3,rand(0,45),2,0);
			}
			
			ObjMove_SetDestAtSpeed(bossObj,bossX+dir*32,bossY+5,3);
			if(bossX>GetStgFrameWidth-30){dir=-1;}
			if(bossX<30){dir=1;}
			lowTemp++;
			wait(1);
		}
		//to the top
		drawRectTop = chaChaHeight;
		drawRectLeft = 0;
		wait(5);
		drawRectLeft = 130;
		wait(5);
		lowTemp=0;
		loop(415){
			if(modc(lowTemp,5)==0){//renderloop
				drawRectLeft += 130;
				if(drawRectLeft == 780){
					drawRectLeft = 260;
				}
			}
			if(modc(lowTemp,30)==0){//bulletloop move old bullets
				let shotX =0;
				//let shotTemp = 0;
				let arrayPointer = 0;
				loop(ceil(415/30)){
					loop(22){
						ObjMove_SetDestAtFrame(lowArray[arrayPointer],ObjMove_GetX(lowArray[arrayPointer])+lowDir*rand(3,5),ObjMove_GetY(lowArray[arrayPointer])-rand(28,30),12);
						arrayPointer++;
					}
					lowDir = -lowDir;
				}
				geometry(rand(0,GetStgFrameWidth),0,0,8,1,3,rand(0,45),2,0);
			}
			if((lowTemp>60)&&(modc(lowTemp,30)==0)){//bulletloop create bullets at bottom
				let shotX =0;
				//let shotTemp = 0;
				loop(22){
					let shot2 = CreateShotA1(10+17*shotX+rand(-5,5),GetStgFrameHeight,0,270,29,0);
					shotX++;
					lowArray2 = lowArray2 ~ [shot2];
				}
				let arrayPointer2 = 0;
				loop(floor((lowTemp-60)/30)){
					loop(22){
						ObjMove_SetDestAtFrame(lowArray2[arrayPointer2],ObjMove_GetX(lowArray2[arrayPointer2])+lowDir*rand(3,5),ObjMove_GetY(lowArray2[arrayPointer2])-rand(28,30),12);
						arrayPointer2++;
					}
					lowDir = -lowDir;
				}
				ObjMove_SetDestAtSpeed(bossObj,bossX,bossY-20,3);
			}
			
			lowTemp++;
			yield;
		}
		let sumArray = lowArray ~ lowArray2;
		return sumArray;
	}
	
	function slideToThe(direction) {
		let dir = 1;
		if (direction == "left"){
			dir = -1;
		}
		//ObjMove_SetAngle(bossObj,180*dir);
		//ObjRender_SetAngleXYZ(bossObj,0,90-(dir*90),0);
		let temp = 0;
		let draw = 0;
		
		drawRectTop = slideHeight;
		let yStart = ObjMove_GetY(bossObj);
		
			drawRectLeft = 0;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft += 130;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			drawRectLeft += 130;
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(5);
			
			ObjMove_SetDestAtFrame(bossObj,bossHomeX+dir*150,bossHomeY,60);
			
		loop(60) {
			if(temp<3){
			drawRectLeft = 260;
			}else if(temp<6){
			drawRectLeft = 390;
			}else if (temp<9){
			drawRectLeft = 520;
			}else if(temp<12){
			drawRectLeft = 650;
			}else if(temp<15){
			drawRectLeft = 780;
			}else if(temp<18){
			drawRectLeft = 910;
			}else if(temp<21){
				drawRectLeft = 1040;
			}else if(temp<60-12){
				if(modc(temp,8)<4){
				drawRectLeft = 1170;
				}else{drawRectLeft = 1300;
				}
			}else if(temp<60-9){
				drawRectLeft = 1430;
			}else if(temp<60-6){
				drawRectLeft = 1560;
			}else if(temp<60-3){
				drawRectLeft = 1690;
			}
			CreateShotA1(GetCenterX-dir*150+dir*5*temp,bossY+48,7,90,81,0);
			CreateShotA1(GetCenterX-dir*150+dir*5*temp,bossY+16,7,270,81,0);
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			//ObjMove_SetDestAtFrame(bossObj,ObjMove_GetX(bossObj)+ 2*dir,bossHomeY,1);
			temp++;
			yield;
		}
		drawRectLeft += 130;
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		wait(5);
			
	}

	function clapShot1 {//304
	
	drawRectTop = clapHeight;
	drawRectLeft = 0;
	
	let lHand1 = ObjShot_Create(OBJ_SHOT);
	ObjMove_SetPosition(lHand1,40,GetStgFrameHeight+60);
	ObjMove_SetAngle(lHand1,270);
	ObjMove_SetSpeed(lHand1,0);
	ObjShot_SetGraphic(lHand1,hand2);
	ObjRender_SetScaleXYZ(lHand1,0.70,0.70,0);
	ObjShot_SetSpellResist(lHand1, true);
	ObjShot_Regist(lHand1);
	
	let rHand1 = ObjShot_Create(OBJ_SHOT);
	ObjMove_SetPosition(rHand1,50,GetStgFrameHeight+60);
	ObjMove_SetAngle(rHand1,270);
	ObjMove_SetSpeed(rHand1,0);
	ObjShot_SetGraphic(rHand1,hand2);
	ObjRender_SetScaleXYZ(rHand1,0.70,0.70,0);
	ObjShot_SetSpellResist(rHand1, true);
	ObjShot_Regist(rHand1);
	
	let rHand2 = ObjShot_Create(OBJ_SHOT);
	ObjMove_SetPosition(rHand2,GetStgFrameWidth-40,GetStgFrameHeight+60);
	ObjMove_SetAngle(rHand2,270);
	ObjMove_SetSpeed(rHand2,0);
	ObjShot_SetGraphic(rHand2,hand2);
	ObjRender_SetScaleXYZ(rHand2,0.70,0.70,0);
	ObjRender_SetAngleXYZ(rHand2,0,180,0);
	ObjShot_SetSpellResist(rHand2, true);
	ObjShot_Regist(rHand2);
	
	let lHand2 = ObjShot_Create(OBJ_SHOT);
	ObjMove_SetPosition(lHand2,GetStgFrameWidth-60,GetStgFrameHeight+60);
	ObjMove_SetAngle(lHand2,0);
	ObjMove_SetSpeed(lHand2,0);
	ObjShot_SetGraphic(lHand2,hand2);
	ObjRender_SetScaleXYZ(lHand2,0.70,0.70,0);
	ObjRender_SetAngleXYZ(lHand2,0,180,0);
	ObjShot_SetSpellResist(lHand2, true);
	ObjShot_Regist(lHand2);
	
	ObjMove_SetDestAtSpeed(lHand1,40,GetStgFrameHeight-40,2);
	ObjMove_SetDestAtSpeed(rHand1,60,GetStgFrameHeight-40,2);
	ObjMove_SetDestAtSpeed(lHand2,GetStgFrameWidth-60,GetStgFrameHeight-40,2);
	ObjMove_SetDestAtSpeed(rHand2,GetStgFrameWidth-40,GetStgFrameHeight-40,2);
	wait(5);
	

	
	
	//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
	wait(5);
	drawRectLeft += 130;
	//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
	wait(5);
	drawRectLeft += 130;
	//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
	wait(5);
	drawRectLeft += 130;
	//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
	wait(15);
	clap;
	wait(43);
	loop(2){
		clap;
		wait(13);
		clap;
		clap;
		wait(27);
		clap;
		wait(23);
		clap;
		wait(3);
	}
	wait(1);
	
	wait(60);
	ObjMove_SetDestAtSpeed(lHand1,40,GetStgFrameHeight+60,2);
	ObjMove_SetDestAtSpeed(rHand1,60,GetStgFrameHeight+60,2);
	ObjMove_SetDestAtSpeed(rHand2,GetStgFrameWidth-40,GetStgFrameHeight+60,2);
	ObjMove_SetDestAtSpeed(lHand2,GetStgFrameWidth-60,GetStgFrameHeight+60,2);
	
		function clap{
		drawRectLeft =390;
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		ObjMove_SetDestAtSpeed(lHand1,47,GetStgFrameHeight-40,2.25);
		ObjMove_SetDestAtSpeed(rHand1,53,GetStgFrameHeight-40,2.25);
		ObjMove_SetDestAtSpeed(rHand2,GetStgFrameWidth-47,GetStgFrameHeight-40,2.25);
		ObjMove_SetDestAtSpeed(lHand2,GetStgFrameWidth-53,GetStgFrameHeight-40,2.25);
		
		wait(3);
		drawRectLeft += 130;
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		wait(3);
		drawRectLeft += 130;
		//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
		wait(3);
		geometry(50,GetStgFrameHeight-40,10,10,1,3,rand(0,90),12,0);//set render priority to between the hands?
		geometry(GetStgFrameWidth-50,GetStgFrameHeight-40,10,10,1,3,rand(0,90),12,0);
		
		ObjMove_SetDestAtSpeed(lHand1,40,GetStgFrameHeight-40,1);
		ObjMove_SetDestAtSpeed(rHand1,60,GetStgFrameHeight-40,1);
		ObjMove_SetDestAtSpeed(rHand2,GetStgFrameWidth-40,GetStgFrameHeight-40,1);
		ObjMove_SetDestAtSpeed(lHand2,GetStgFrameWidth-60,GetStgFrameHeight-40,1);
		
		
		let temp = 0;
		loop(8){
			temp+=1;
			drawRectLeft = 650 + 130*modc(temp,3);
			//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
			wait(3);
		}
		drawRectLeft = 520;
		yield;
		}
	}
	
	function crissCross {
		function ringShot {
			let speedAdjust = 0;
			let angAdjust;
			loop(3){
				angAdjust = -25;
				loop(3){
					CreateShotA1(bossX,bossY,3+(speedAdjust%4.5),angleToPlayer+angAdjust,ring,0);
					angAdjust+=25;
				}
				speedAdjust+=1.5;
			}
		}
		drawRectLeft = 1430;
		drawRectTop = 390;
		rectSize = 256;
		
		
		wait(5);
		drawRectTop += 260;
		dir =-1;
		ObjMove_SetDestAtFrame(bossObj,40,bossHomeY,30);
		wait(5);
		drawRectTop += 260;
		ringShot;
		wait(5);
		drawRectTop += 260;
		wait(25);
		
		drawRectTop = 390;
		wait(5);
		drawRectTop += 260;
		dir = 1;
		ObjMove_SetDestAtFrame(bossObj,GetStgFrameWidth-40,bossHomeY,30);
		wait(5);
		drawRectTop += 260;
		ringShot;
		wait(5);
		drawRectTop += 260;
		wait(70);
		
		drawRectTop = 390;
		wait(5);
		drawRectTop += 260;
		dir = -1;
		ObjMove_SetDestAtFrame(bossObj,40,bossHomeY,30);
		wait(5);
		drawRectTop += 260;
		ringShot;
		wait(5);
		drawRectTop += 260;
		wait(25);
		
		drawRectTop = 390;
		wait(5);
		drawRectTop += 260;
		dir = 1;
		ObjMove_SetDestAtFrame(bossObj,GetStgFrameWidth-40,bossHomeY,30);
		wait(5);
		drawRectTop += 260;
		ringShot;
		wait(5);
		drawRectTop += 260;
		wait(35);
		
		ObjMove_SetDestAtFrame(bossObj,bossHomeX,bossHomeY,30);
		rectSize = 128;
	}
	
	function goToWork {//240frames
		drawRectLeft = 0;
		drawRectTop = 0;
		wait(5);
		rectSize = 256;
		drawRectTop = hatHeight;
		loop(5){
			wait(5);
			drawRectLeft+=260;
		}
		let hatTemp =1;
		loop(170){
			if(hatTemp%5 == 0){
				drawRectLeft += 260;
				if(drawRectLeft >= 1820){
					drawRectLeft = 1300;
				}// 2 tentacles
				CreateShotB2(bossX+66,bossY,5*cos(4.5*hatTemp),-10,0,0.5,10,10,13,0);
				CreateShotB2(bossX+66,bossY,5*cos(4.5*hatTemp+180),-10,0,0.5,10,10,13,0);
				CreateShotB2(bossX+66,bossY,5,-10,0,0.5,10,10,13,0);
				CreateShotB2(bossX+66,bossY,-5,-10,0,0.5,10,10,13,0);
				CreateShotB2(bossX+66,bossY,rand(-5,5),-10,0,0.5,10,10,44,0);
				}
			
			
			hatTemp++;
			yield;
		}
		
		
		
		drawRectLeft = 1820;
		wait(5);
		drawRectLeft = 2080;
		wait(5);
		rectSize =128;
		drawRectLeft = 0;
		drawRectTop=0;
		//idle(200);
		
		
	}
	
	function handsOnKnees {
		let temp = 0;
		let lHand = ObjShot_Create(OBJ_SHOT);
		ObjMove_SetPosition(lHand,40,-60);
		//ObjMove_SetAngle(lHand,135);
		ObjRender_SetAngleXYZ(lHand,0,0,135);
		ObjMove_SetSpeed(lHand,0);
		ObjShot_SetGraphic(lHand,hand2);
		ObjRender_SetScaleXYZ(lHand,0.70,0.70,0);
		Obj_SetRenderPriorityI(lHand, 80);
		ObjShot_SetSpellResist(lHand, true);
		ObjShot_Regist(lHand);
	
		let rHand = ObjShot_Create(OBJ_SHOT);
		ObjMove_SetPosition(rHand,GetStgFrameWidth-40,-60);
		ObjMove_SetAngle(rHand,135);
		ObjRender_SetAngleXYZ(rHand,0,180,135);
		ObjMove_SetSpeed(rHand,0);
		ObjShot_SetGraphic(rHand,hand2);
		ObjRender_SetScaleXYZ(rHand,0.70,0.70,0);
		Obj_SetRenderPriorityI(rHand, 80);
		ObjShot_SetSpellResist(rHand, true);
		ObjShot_Regist(rHand);
		//idle(20);
		
		ObjMove_SetDestAtFrame(lHand,40,GetStgFrameHeight-70,25);
		ObjMove_SetDestAtFrame(rHand,GetStgFrameWidth-40,GetStgFrameHeight-70,25);
		idle(25);
		
		//ObjMove_SetDestAtSpeed(lHand,GetStgFrameWidth-40,GetStgFrameHeight-70,5);
		//ObjMove_SetAcceleration(lHand,-0.25);
		//ObjMove_SetDestAtSpeed(rHand,40,GetStgFrameHeight-70,5);
		//angle(lHand2,135);
		while(!Obj_IsDeleted(lHand)){
			if(temp%(12)==0){
				CreateShotA1(ObjMove_GetX(lHand)+6,ObjMove_GetY(lHand)-30,5,270,82,0);
				CreateShotA1(ObjMove_GetX(lHand)-33,ObjMove_GetY(lHand)-30,5,270,82,0);
				CreateShotA1(ObjMove_GetX(rHand)+33,ObjMove_GetY(rHand)-30,5,270,82,0);
				CreateShotA1(ObjMove_GetX(rHand)-6,ObjMove_GetY(rHand)-30,5,270,82,0);
				//temp = 0;
			}
			
			if(temp<165){
				if(drawRectTop!=0){
					drawRectLeft =0;
				}
				drawRectTop = 0;
				if(temp%8==0){
					drawRectLeft = modc(drawRectLeft+130,8*130);
				}
				ObjMove_SetDestAtFrame(lHand,GetCenterX*(1-cos(2*temp)),GetStgFrameHeight-70,1);
				ObjMove_SetDestAtFrame(rHand,GetCenterX*(1+cos(2*temp)),GetStgFrameHeight-70,1);
			}else if(temp>=165 && temp<= 500){
				drawRectTop = funkyHeight;
				if(temp%5==0){
					
					drawRectLeft += 130;
					if(drawRectLeft == 910){
						drawRectLeft = 130;
					}
					CreateShotA1(rand(0,GetStgFrameWidth),0,rand(2,5),rand(38,142),rand(121,136),0);
				}
				ObjMove_SetDestAtFrame(lHand,GetCenterX*(1-cos(2*temp)),GetStgFrameHeight-70,1);
				ObjMove_SetDestAtFrame(rHand,GetCenterX*(1+cos(2*temp)),GetStgFrameHeight-70,1);
			}else if(temp==501){
				
				ObjMove_SetDestAtSpeed(lHand,ObjMove_GetX(lHand),-70,5);
				ObjMove_SetDestAtSpeed(rHand,ObjMove_GetX(rHand),-70,5);
				ObjShot_SetDeleteFrame(lHand,75);
				ObjShot_SetDeleteFrame(rHand,75);
			}else{
				if(temp%5==0){
					drawRectTop =0;
					drawRectLeft += 130;
					if(drawRectLeft == 1040){
						drawRectLeft = 0;
					}
				}
			} 
			temp++;
			yield;
		}
		
	}
	
	function freeze {
		dir = -1;
		ObjMove_SetDestAtSpeed(cirno,bossX-50,bossY,5);
		wait(6);
		loop(4){
			wait(7);
			cirRectLeft+=130;
		}
		idle(21);
		//let cirTime = 0;
		cirRectTop = 0;
		cirRectLeft =0;
		drawRectTop = funkyHeight;
		drawRectLeft =0;
		/*loop(4){
			wait(6);
			cirRectLeft+=130;
		}*/
		let Ice = CreateShotA1(bossX+10,bossY-5,0,270,ice,0);
		cirIdle(130);		
		let left = CreateShotA1(-20,bossY,5,0,hand1,0);
		ObjMove_SetDestAtFrame(left,GetCenterX-90,bossY,30);
		let right = CreateShotA1(GetStgFrameWidth+20,bossY,5,180,hand1,0);
		ObjRender_SetAngleXYZ(right,0,180,0);
		ObjMove_SetDestAtFrame(right,GetCenterX+90,bossY,30);
		ObjShot_SetDeleteFrame(left,35);
		ObjShot_SetDeleteFrame(right,35);
		dir = 1;
		drawRectTop= clapHeight;
		drawRectLeft =390;
		cirIdle(5);
		drawRectLeft += 130;
		cirIdle(5);
		drawRectLeft += 130;
		cirIdle(20);
		ObjMove_SetDestAtSpeed(cirno,-bossX,-bossY,6);//animate cirno as well
		//let bulletGraphic = 260;
		Obj_Delete(Ice);
			
			loop(4){
				//CreateShotA1(bossX+rand(-20,20),bossY+rand(-20,20),rand(3,5),rand(235,315),smallIce1,0);
				let big = CreateShotB2(bossX+rand(-20,20), bossY+rand(-20,20), rand(-3,3), rand(-3,-5), 0, 0.25, 3, 5, smallIce1, 5);
				let small = CreateShotB2(bossX+rand(-20,20), bossY+rand(-20,20), rand(-3,3), rand(-3,-5), 0, 0.25, 3, 5, smallIce2, 5);
				let rand1 = rand(0.4,0.8);
				let rand2 = rand(0.4,0.8);
				ObjRender_SetScaleXYZ(big,rand1,rand1,0);
				ObjRender_SetScaleXYZ(big,rand2,rand2,0);
				ObjShot_SetDeleteFrame(big,35);
				ObjShot_SetDeleteFrame(small,35);
			
			}
			
			
			loop(7){//30 claps total
				let tempY = GetPlayerY;
				loop(4){
					let left = CreateShotA1(-20,tempY,5,0,hand1,0);
					ObjMove_SetDestAtFrame(left,GetCenterX-45,tempY,30);
					ObjShot_SetSpellResist(left, true);
					let right = CreateShotA1(GetStgFrameWidth+20,tempY,5,180,hand1,0);
					ObjRender_SetAngleXYZ(right,0,180,0);
					ObjRender_SetScaleXYZ(left,0.5,0.5,0);
					ObjRender_SetScaleXYZ(right,0.5,0.5,0);
					ObjMove_SetDestAtFrame(right,GetCenterX+45,tempY,30);
					ObjShot_SetSpellResist(right, true);
					ObjShot_SetDeleteFrame(left,35);
					ObjShot_SetDeleteFrame(right,35);
					wait(5);
				
				
				cirRectTop = cirSpinHeight;
				cirRectLeft = 640;
				drawRectLeft+=130;
				cirRectLeft+=130;
				
				if(drawRectLeft==1040){drawRectLeft=650;}
				wait(5);
				drawRectLeft+=130;
				cirRectLeft+=130;
				if(drawRectLeft==1040){drawRectLeft=650;}
				wait(5);
				drawRectLeft+=130;
				cirRectLeft+=130;
				if(drawRectLeft==1040){drawRectLeft=650;}
				}
			}
			
		drawRectLeft = 520;
		idle(30);
		//Obj_Delete(cirno);
		
	}
	
	function cirIdle(duration) {
		
		let temp = 0;
		let time =0;
		
			//if(drawRectTop ==0 ){clapShot1;}
			while(time<duration){
			
				if(temp==6){
					cirRectLeft += 130; 
					if(cirRectLeft==6*130){
						cirRectLeft=0;
					}
				//ObjSprite2D_SetSourceRect(bossObj,drawRectLeft,drawRectTop,drawRectLeft+rectSize,drawRectTop+rectSize);
				temp=0;
				
			}
			temp++;
			time++;
			//cirTime++;
			yield;
			}
	}
	
	task renderCir {
		ObjPrim_SetTexture(cirno,imgOther);
		ObjSprite2D_SetSourceRect(cirno,0,130,128,258);
		ObjSprite2D_SetDestCenter(cirno);
		ObjRender_SetScaleXYZ(cirno,1,1,0);
		ObjMove_SetPosition(cirno,-73,bossHomeY);
		while(!Obj_IsDeleted(cirno)){
			ObjSprite2D_SetSourceRect(cirno,cirRectLeft,cirRectTop,cirRectLeft+128,cirRectTop+128);
			yield;
		}
		
	}
	
	function reverse(amount) {
		residualBullets = [];
		ObjMove_SetDestAtFrame(bossObj,bossHomeX,bossHomeY,10);
		let reverseTemp =0;
		let bulletDir = [];
		loop(57+(15*amount)){
			yAngle+=5;
			residualBullets = residualBullets ~ [CreateShotA1(bossX,bossY,rand(1.75,2.75),rand(0,360),33,0)];
			//residualBullets = residualBullets ~ [CreateShotA1(bossX,bossY,rand(2,3),rand(0,360),3,0)];
			residualBullets = residualBullets ~ [CreateShotA1(bossX,bossY,rand(1.75,2.75),rand(0,360),81,0)];
			yield;
		}
		wait(10);
		loop(length(residualBullets)){//for each bullet
			ObjMove_SetSpeed(residualBullets[reverseTemp],0);
			bulletDir = bulletDir ~[(-1)^(floor(rand(0,2)))];
			reverseTemp++;
		}
		loop(20){
			reverseTemp=0;
			loop(length(residualBullets)){//for each bullet
				//ObjMove_SetDestAtSpeed(residualBullets[reverseTemp],bossX,bossY,rand(2.75,3.5));
				ObjMove_SetAngle(residualBullets[reverseTemp],ObjMove_GetAngle(residualBullets[reverseTemp])+9*bulletDir[reverseTemp]);
				reverseTemp++;
			}
			yield;
		}
		reverseTemp=0;
		loop(length(residualBullets)){//for each bullet
			ObjMove_SetSpeed(residualBullets[reverseTemp],rand(3.25,4));
			reverseTemp++;
		}
		yAngle =0;
	}
	
	task renderCharlie {
		ObjPrim_SetTexture(Charlie,imgOther);
		ObjSprite2D_SetSourceRect(Charlie,0,0,256,256);
		ObjSprite2D_SetDestCenter(Charlie);
		ObjRender_SetScaleXYZ(Charlie,1,1,0);
		ObjMove_SetPosition(Charlie,GetCenterX,GetStgFrameHeight+130);
		while(!Obj_IsDeleted(cirno)){
			ObjSprite2D_SetSourceRect(Charlie,charlieRectLeft,charlieRectTop,charlieRectLeft+256,charlieRectTop+256);
			yield;
		}
		
	}
	
	function charlieBrown {
		drawRectLeft =0;
		drawRectTop=0;
		Charlie = ObjEnemy_Create(OBJ_ENEMY);
		ObjEnemy_Regist(Charlie);
		renderCharlie;
		let CharlieTemp = 0;
		let temp = 0;
		
		let length = 240;
		let b = -400/length;//always jumps 100 pixels
		let a = -b/length;//lands after length frames
		let yStart = GetStgFrameHeight+30;
		
		
		loop((-4*b)/(4*a)){
			if(CharlieTemp == 0 || CharlieTemp == 12 || CharlieTemp == 102){
				CharlieDir = 1;
				charlieRectLeft = 0;
				charlieRectTop =CharlieHeight1;
				if(CharlieTemp ==102){
					CharlieTemp = 0;
				}
				
			}else if(CharlieTemp == 6 || CharlieTemp == 96){
				if(CharlieTemp == 96){
					CharlieDir = -1;
				}
				charlieRectLeft = 260;
				charlieRectTop =CharlieHeight1;
			}else if(CharlieTemp == 18 || CharlieTemp == 72){
				if(CharlieTemp == 72){
					CharlieDir = -1;
				}
				charlieRectLeft = 520;
				charlieRectTop =CharlieHeight1;
				
			}else if(CharlieTemp == 24 || CharlieTemp == 48){
				charlieRectLeft = 780;
				charlieRectTop =CharlieHeight1;
			}else if(CharlieTemp == 30){
				charlieRectLeft = 1040;
				charlieRectTop =CharlieHeight1;
			}else if(CharlieTemp == 36){
				charlieRectLeft = 0;
				charlieRectTop =CharlieHeight2;
			}else if(CharlieTemp == 42){
				charlieRectLeft = 260;
				charlieRectTop =CharlieHeight2;
			}else if(CharlieTemp == 54){
				charlieRectLeft = 540;
				charlieRectTop =CharlieHeight2;
			}else if(CharlieTemp == 66){
				charlieRectLeft = 780;
				charlieRectTop =CharlieHeight2;
			}else if(CharlieTemp == 78){
				CharlieDir = 1;
				charlieRectLeft = 1040;
				charlieRectTop =CharlieHeight2;
				
			}
			if(temp>120 &&temp%30==0){
					geometry(bossX,bossY,5,floor(rand(3,7)),5,6,rand(0,90),147,0);
			}
			ObjMove_SetDestAtFrame(Charlie,ObjMove_GetX(Charlie),yStart+b*temp+(a*temp*temp),1);
			temp++;
			CharlieTemp++;
			
			yield;
		}
		Obj_Delete(Charlie);
	}
	
	function peace {//~15seconds
		dir = 1;
		residualBullets = [];
		loop(40){
			CreateShotA1(rand(0,GetStgFrameWidth),0,rand(2,5),rand(38,142),rand(121,136),0);
			idle(6);
		}
		let shotY =0;
			loop(GetStgFrameHeight/10){//bulletloop
				
				//let shotTemp = 0;
				
					let rightShot = CreateShotA1(GetStgFrameWidth,10+10*shotY,0,90-(dir*90),12,0);
					ObjMove_SetDestAtFrame(rightShot,GetCenterX+40,ObjMove_GetY(rightShot),40);
					residualBullets = residualBullets ~ [rightShot];
					let leftShot = CreateShotA1(0,10+10*shotY,0,90-(dir*90),81,0);
					ObjMove_SetDestAtFrame(leftShot,GetCenterX-40,ObjMove_GetY(leftShot),40);
					residualBullets = residualBullets ~ [leftShot];
					shotY++;
					ObjShot_SetDeleteFrame(leftShot,80);
					ObjShot_SetDeleteFrame(rightShot,80);
				
				
				
			}
		loop(7){
			CreateShotA1(rand(0,GetStgFrameWidth),0,rand(2,5),rand(38,142),rand(121,136),0);
			idle(6);
		}
		let temp =0;
		loop(length(residualBullets)){
			ObjMove_SetDestAtFrame(residualBullets[temp],GetCenterX+((-1)^(temp))*GetCenterX,ObjMove_GetY(residualBullets[temp]),40);
			temp++;
		}
		loop(7){
			CreateShotA1(rand(0,GetStgFrameWidth),0,rand(2,5),rand(38,142),rand(121,136),0);
			idle(6);
		}
		//cirno = ObjEnemy_Create(OBJ_ENEMY);
		cirRectTop = cirFreezeHeight;
		cirRectLeft=520;
		ObjMove_SetPosition(cirno,-70,GetPlayerY);
		let ice2 =CreateShotA1(-10,GetPlayerY,6,0,ice,0);
		ObjMove_SetDestAtSpeed(cirno,GetStgFrameWidth+40,GetPlayerY,6);
		loop(10){
			CreateShotA1(rand(0,GetStgFrameWidth),0,rand(2,5),rand(38,142),rand(121,136),0);
			idle(6);
			cirRectLeft+=130;
			if(cirRectLeft>650){cirRectLeft = 520;}
		}
		let chaIceY = ObjMove_GetY(ice2);
		Obj_Delete(ice2);
		
		loop(4){
				//CreateShotA1(bossX+rand(-20,20),bossY+rand(-20,20),rand(3,5),rand(235,315),smallIce1,0);
				let big = CreateShotB2(GetStgFrameWidth,chaIceY, rand(-3,3), rand(-3,-5), 0, 0.25, 3, 5, smallIce1, 5);
				let small = CreateShotB2(GetStgFrameWidth,chaIceY, rand(-3,3), rand(-3,-5), 0, 0.25, 3, 5, smallIce2, 5);
				let rand1 = rand(0.4,0.8);
				let rand2 = rand(0.4,0.8);
				ObjRender_SetScaleXYZ(big,rand1,rand1,0);
				ObjRender_SetScaleXYZ(big,rand2,rand2,0);
				ObjShot_SetDeleteFrame(big,35);
				ObjShot_SetDeleteFrame(small,35);
			
			}
		loop(16){
			CreateShotA1(rand(0,GetStgFrameWidth),0,rand(2,5),rand(38,142),rand(121,136),0);
			let shot = CreateShotA1(GetStgFrameWidth,chaIceY,3,rand(91,269),22,0);
			idle(6);
		}
		loop(40){
			let shot = CreateShotA1(GetStgFrameWidth,chaIceY,3,rand(91,269),22,0);
			idle(6);
		}
		drawRectLeft = 0;
		drawRectTop = 0;
		wait(5);
		rectSize = 256;
		drawRectTop = hatHeight;
		loop(5){
			wait(5);
			drawRectLeft+=260;
		}
		let hatTemp =1;
		loop(60){
			
			if(hatTemp%5 == 0){
				drawRectLeft += 260;
				if(drawRectLeft >= 1820){
					drawRectLeft = 1300;
				}// 2 tentacles
				CreateShotB2(bossX+66,bossY,5*cos(4.5*hatTemp),-10,0,0.5,10,10,13,0);
				CreateShotB2(bossX+66,bossY,5*cos(4.5*hatTemp+180),-10,0,0.5,10,10,13,0);
				CreateShotB2(bossX+66,bossY,5,-10,0,0.5,10,10,13,0);
				CreateShotB2(bossX+66,bossY,-5,-10,0,0.5,10,10,13,0);
				CreateShotB2(bossX+66,bossY,rand(-5,5),-10,0,0.5,10,10,44,0);
				}
			
			
			hatTemp++;
			yield;
		}
		
		
		
		drawRectLeft = 1820;
		wait(5);
		drawRectLeft = 2080;
		wait(5);
		rectSize =128;
		let ringShot = CreateShotA1(bossX,bossY,7.5,angleToPlayer,ring,0);
		bound(ringShot);
		drawRectLeft = 0;
		drawRectTop=0;
		idle(20);
		drawRectTop = backHeight;
		drawRectLeft = 0;
		dir = -dir;
		temp = 0;
		let a = 0.25;
		let b = -10;
		let currentX = bossX;
let currentY = bossY;
		let xMovement = GetStgFrameWidth+GetCenterX-currentX;
		wait(5);
		drawRectLeft = 130;
		wait(5);
			
		let backTemp = 0;
		loop((-4*b)/(4*a)) {
		

			if(backTemp==5){
				drawRectLeft += 130;
				if(drawRectLeft == 650){
					drawRectLeft = 260;
				}
				backTemp=0;
				
			}
			backTemp++;
			
			ObjMove_SetDestAtFrame(bossObj,currentX+temp*(-dir*xMovement)/((-4*b)/(4*a)),currentY+b*temp+(a*temp*temp),1);
			temp++;
			yield;
		}
	}
	/*
	function bounceGeometry(x,y,radius,sides,density,speed,angle,graphic,delay) {//if density==1 is a circle with sides bullets
	 let theta = angle;
	 let lastAngle = 90-(360/(sides*2));
	 let geometryBulletArray = [];
	 loop(sides){
		 let x1 = x+radius*cos(theta);
		 let y1 = y+radius*sin(theta);
		 let x2 = x+radius*cos(theta+(360/sides));
		 let y2 = y+radius*sin(theta+(360/sides));
		 let dist = GetDistance(x1,y1,x2,y2)/density;
		let theta2 = GetPointAngle(x2,y2,x1,y1);
		let i = 1;
		let angle2 = theta;
		loop(density){
			let pi = (180-(360/sides))/2;
			let gamma = (i*360)/(density*sides);
			let delta = 180-(pi+gamma);
			let shot = bounceShot(x1+dist*i*cos(theta2),y1+dist*i*sin(theta2),(speed*sin(pi))/(sin(delta)),angle2,graphic);
			//geometryBullets(x,y,x1,y1,shot,radius,speed,sides,density,dist,i,theta,theta2,angle2,graphic,delay);
			let dist2 = GetDistance(x,y,ObjMove_GetX(shot),ObjMove_GetY(shot));
			//ObjMove_SetSpeed(shot,speed*dist2^2/radius^2);
			//ObjMove_SetDestAtFrame(shot,x1+(i*dist*GetStgFrameHeight/radius)*cos(angle2),y1+(i*dist*GetStgFrameHeight/radius)*sin(angle2),100);
			
			angle2 += 360/(density*sides);
			geometryBulletArray = geometryBulletArray ~ [shot];
			i++;
		}
		 theta += (360/sides);
	 }
	
	 return geometryBulletArray;
	 
 }
*/

 



