let BossPhase = 1; //Differentiates between normal poses and attack poses

task AnimateBossA1_ZUN(ID, Path){ // Animates bosses with ZUN-styled sprites

	ObjPrim_SetTexture(ID, Path); 
	
	let IdleNumber = 4;	//How many sprites there are in the idle pose/first row.
	let MoveNumber = 4;	//How many sprites there are in the moving poses/second and third row.
	
	let AnimationIdleInterval = 8;	//How slow the idle pose moves in frames
	let AnimationMoveInterval = 2;	//How fast the moving poses move in frames 
	let AnimationStopInterval = 2;	//How fast the slowing poses (moving back to idle) move in frames
	
	let AnimationTimer = 0;
	let AnimationIsMove = "IDLE";
	
	let YOffset = 0;
	let XWidth = 64;
	let YLength = 64;
	
	Animate;
	
	task Animate{
		let type = "RIGHT";
		
		loop{
			
			if(ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) >= 0.3 || ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) <= -0.3){
				if(AnimationIsMove == "IDLE"){
					AnimationIsMove = "MOVE";
					AnimationTimer = 0;
					
					if(ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) >= 0.1) { type = "RIGHT"; }
					if(ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) <= -0.1){ type = "LEFT" }
				}
			}
			else if(AnimationIsMove == "MOVE"){
				AnimationIsMove = "STOP";
				AnimationTimer = 0;
			}
			
		alternative(AnimationIsMove)
			case("IDLE"){
					let i = truncate(AnimationTimer/AnimationIdleInterval); // Truncate removes decimals. I goes up like 0/8, 1/8, 2/8 etc, which is 0. 
																			// i+=1 every 8 frames.
						ObjSprite2D_SetSourceRect(ID, XWidth*(i-1), YOffset, XWidth*i, YOffset+YLength);
						WriteLog(i);
				if(AnimationTimer > AnimationIdleInterval*IdleNumber){AnimationTimer = 0;}
			}
			
			case("MOVE"){
				let j = truncate(AnimationTimer/AnimationMoveInterval)+1;
				
				if(j<=MoveNumber){
					alternative(type)
					case("RIGHT"){
						ObjSprite2D_SetSourceRect(ID, XWidth*(j-1), YOffset+YLength, XWidth*j, YOffset+YLength*2);
					}
					
					case("LEFT"){
						ObjSprite2D_SetSourceRect(ID, XWidth*(j-1), YOffset+YLength, XWidth*j, YOffset+YLength*2);
					}
				}
			}
			
			case("STOP"){
					let k = MoveNumber-truncate(AnimationTimer/AnimationMoveInterval);
					
						if(k>0){
							alternative(type)
							case("RIGHT"){
								ObjSprite2D_SetSourceRect(ID, XWidth*(k-1), YOffset+YLength, XWidth*k, YOffset+YLength*2);
							}	
							case("LEFT"){
								ObjSprite2D_SetSourceRect(ID, XWidth*(k-1), YOffset+YLength*2, XWidth*k, YOffset+YLength*3);
							}	
						}						
						
				if(AnimationTimer > AnimationStopInterval*MoveNumber){AnimationTimer = 0; AnimationIsMove = "IDLE"; ObjRender_SetScaleX(ID, 1);}
			}
			
			ObjSprite2D_SetDestCenter(ID);
			AnimationTimer++;
			yield;
		}
	}
}

task AnimateBossA2_ZUN(ID, Path, Width, Height){ // Animates bosses with ZUN-styled sprites and only one moving pose/row

	ObjPrim_SetTexture(ID, Path); 
	
	let IdleNumber = 4;	//How many sprites there are in the idle pose/first row.
	let MoveNumber = 4;	//How many sprites there are in the moving poses/second and third row.
	
	let AnimationIdleInterval = 6;	//How slow the idle pose moves in frames
	let AnimationMoveInterval = 2;	//How fast the moving poses move in frames 
	let AnimationStopInterval = 1;	//How fast the slowing poses (moving back to idle) move in frames
	let AnimationActionInterval = 3;	//How fast the action poses move in frames
	
	let AnimationTimer = 0;
	let AnimationIsMove = "IDLE";
	
	let YOffset = 0;
	let XWidth = Width;
	let YLength = Height;
	
	let AttackAnim = 0;
	
	Animate;
	
	task Animate{
		
		loop{
			if( AnimationIsMove == "IDLE" &&  (| ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) |) >= 0.3 && BossPhase == 1){
					AnimationIsMove = "MOVE";
					AnimationTimer = 0;
					
					if(ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) >= 0.1) { ObjRender_SetScaleX(ID, 1);}
					if(ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) <= -0.1){ ObjRender_SetScaleX(ID, -1);}
			}
			else if( AnimationIsMove == "MOVE" && (| ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) |) < 0.3 && BossPhase == 1){
				AnimationIsMove = "STOP";
				AnimationTimer = 0;
			}
			
		alternative(AnimationIsMove)
			case("IDLE"){
				if(BossPhase == 1){
					let i = truncate(AnimationTimer/AnimationIdleInterval);
						ObjSprite2D_SetSourceRect(ID, XWidth*(i-1), YOffset, XWidth*i, YOffset+YLength);
				if(AnimationTimer > AnimationIdleInterval*IdleNumber){AnimationTimer = 0;}
				}
			}
			
			case("MOVE"){
				if(BossPhase == 1){
					let j = truncate(AnimationTimer/AnimationMoveInterval)+1;
					if(j<=MoveNumber)
					{
						ObjSprite2D_SetSourceRect(ID, XWidth*(j-1), YOffset+YLength, XWidth*j, YOffset+YLength*2);
					}
				}
			}
			
			case("STOP"){
				if(BossPhase == 1){
					let k = MoveNumber-truncate(AnimationTimer/AnimationMoveInterval);
					if(k>0)
					{
						ObjSprite2D_SetSourceRect(ID, XWidth*(k-1), YOffset+YLength, XWidth*k, YOffset+YLength*2);
					}
					if(AnimationTimer > AnimationStopInterval*MoveNumber){AnimationTimer = 0; AnimationIsMove = "IDLE"; ObjRender_SetScaleX(ID, 1);}
				}
			}
			
			if(BossPhase == 2){ //Kogasa Swipe Left
				ObjRender_SetAngleY(bossObj,180);
				if(AttackAnim<AnimationActionInterval){ObjSprite2D_SetSourceRect(bossObj,0,96*2,96,96*3);}
				if(AttackAnim>=AnimationActionInterval && AttackAnim<AnimationActionInterval*2){ObjSprite2D_SetSourceRect(bossObj,96,96*2,192,96*3);}
				if(AttackAnim>=AnimationActionInterval*2 && AttackAnim<AnimationActionInterval*3){ObjSprite2D_SetSourceRect(bossObj,0,96*3,96,96*4);}
				if(AttackAnim>=AnimationActionInterval*3 && AttackAnim<AnimationActionInterval*4){ObjSprite2D_SetSourceRect(bossObj,96,96*3,192,96*4);}
				if(AttackAnim>=AnimationActionInterval*4 && AttackAnim<AnimationActionInterval*5){ObjSprite2D_SetSourceRect(bossObj,0,96*4,96,96*5);}
				if(AttackAnim>=AnimationActionInterval*5 && AttackAnim<AnimationActionInterval*6){ObjSprite2D_SetSourceRect(bossObj,96,96*4,192,96*5);}
				
				AttackAnim++;
				if(AttackAnim>=AnimationActionInterval*6){AttackAnim = 0; ObjRender_SetAngleY(bossObj,0);}
			}
			
			if(BossPhase == 3){ //Kogasa Swipe Right
				if(AttackAnim<AnimationActionInterval){ObjSprite2D_SetSourceRect(bossObj,0,96*2,96,96*3);}
				if(AttackAnim>=AnimationActionInterval && AttackAnim<AnimationActionInterval*2){ObjSprite2D_SetSourceRect(bossObj,96,96*2,192,96*3);}
				if(AttackAnim>=AnimationActionInterval*2 && AttackAnim<AnimationActionInterval*3){ObjSprite2D_SetSourceRect(bossObj,0,96*3,96,96*4);}
				if(AttackAnim>=AnimationActionInterval*3 && AttackAnim<AnimationActionInterval*4){ObjSprite2D_SetSourceRect(bossObj,96,96*3,192,96*4);}
				if(AttackAnim>=AnimationActionInterval*4 && AttackAnim<AnimationActionInterval*5){ObjSprite2D_SetSourceRect(bossObj,0,96*4,96,96*5);}
				if(AttackAnim>=AnimationActionInterval*5 && AttackAnim<AnimationActionInterval*6){ObjSprite2D_SetSourceRect(bossObj,96,96*4,192,96*5);}
				
				AttackAnim++;
				if(AttackAnim>=AnimationActionInterval*6){AttackAnim = 0;}
			}
			
			if(BossPhase == 4){ //Letty Action
				 
			}
			
			ObjSprite2D_SetDestCenter(ID);
			AnimationTimer++;
			yield;
		}
	}
}

task AnimateBossA1_CtC(ID, Path){ // Animates bosses with CtC-styled sprites

	ObjPrim_SetTexture(ID, Path); 
	
	let AnimationIdleInterval = 6;	//How slow the idle pose moves in frames
	let AnimationMoveInterval = 5;	//How fast the moving poses move in frames 
	let AnimationStopInterval = 16;	//How fast the slowing poses (moving back to idle) move in frames
	let AnimationActionInterval = 6;	//How fast the slowing poses (moving back to idle) move in frames
	
	let AnimationIsMove = "IDLE";
	
	let AttackAnim = 0;
	let AttackAnim2 = 0;
	
	Animate;
	
	task Animate{
		let type = "RIGHT";
		
		loop{
			
			if(ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) >= 0.3 || ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) <= -0.3 && BossPhase == 1){
				if(AnimationIsMove == "IDLE"){
					AnimationIsMove = "MOVE";
					
					if(ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) >= 0.1) { type = "RIGHT"; }
					if(ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) <= -0.1){ type = "LEFT" }
				}
			}
			else if( AnimationIsMove == "MOVE" && (| ObjMove_GetSpeed(ID)*cos(ObjMove_GetAngle(ID)) |) < 0.3 && BossPhase == 1){
				AnimationIsMove = "STOP";
			}
			
		alternative(AnimationIsMove)
			case("IDLE"){
				if(BossPhase == 1){
				
					if(AttackAnim<AnimationIdleInterval*-1){ObjSprite2D_SetSourceRect(bossObj,512,128,512+128,128*2);}
					if(AttackAnim>=AnimationIdleInterval*-1 && AttackAnim<0){ObjSprite2D_SetSourceRect(bossObj,512,0,512+128,128);}
					
					if(AttackAnim>=0 && AttackAnim<AnimationIdleInterval){ObjSprite2D_SetSourceRect(bossObj,0,0,128,128);}
					if(AttackAnim>=AnimationIdleInterval && AttackAnim<AnimationIdleInterval*2){ObjSprite2D_SetSourceRect(bossObj,0,128,128,128*2);}
					if(AttackAnim>=AnimationIdleInterval*2 && AttackAnim<AnimationIdleInterval*3){ObjSprite2D_SetSourceRect(bossObj,0,128*2,128,128*3);}
					if(AttackAnim>=AnimationIdleInterval*3 && AttackAnim<AnimationIdleInterval*4){ObjSprite2D_SetSourceRect(bossObj,128,0,128*2,128);}
					if(AttackAnim>=AnimationIdleInterval*4 && AttackAnim<AnimationIdleInterval*5){ObjSprite2D_SetSourceRect(bossObj,128,128,128*2,128*2);}
					
					AttackAnim++;
					AttackAnim2 = 0;
					if(AttackAnim>=AnimationIdleInterval*5){AttackAnim = 0;}
				}
			}
			
			case("MOVE"){
				alternative(type)
				case("RIGHT"){
					if(BossPhase == 1){
						if(AttackAnim<AnimationMoveInterval){ObjSprite2D_SetSourceRect(bossObj,128*2,128*2,128*3,128*3);}
						if(AttackAnim>=AnimationMoveInterval){ObjSprite2D_SetSourceRect(bossObj,128*2,128*3,128*3,128*4);}
						
						AttackAnim++;
					}
				}
				case("LEFT"){
					if(BossPhase == 1){
						if(AttackAnim<AnimationMoveInterval){ObjSprite2D_SetSourceRect(bossObj,128*2,0,128*3,128);}
						if(AttackAnim>=AnimationMoveInterval){ObjSprite2D_SetSourceRect(bossObj,128*2,128,128*3,128*2);}
						
						AttackAnim++;
					}
				}
			}
			
			case("STOP"){
				alternative(type)
				case("RIGHT"){
					if(BossPhase == 1){
						if(AttackAnim<AnimationStopInterval){ObjSprite2D_SetSourceRect(bossObj,128*2,128*3,128*3,128*4);}
						if(AttackAnim>=AnimationStopInterval && AttackAnim<AnimationStopInterval*2){ObjSprite2D_SetSourceRect(bossObj,128*2,128*2,128*3,128*3);}
						
						if(AttackAnim >= AnimationStopInterval*2){AttackAnim = 0; AnimationIsMove = "IDLE";}
						AttackAnim++;
					}
				}
				
				case("LEFT"){
					if(BossPhase == 1){
						if(AttackAnim<AnimationStopInterval){ObjSprite2D_SetSourceRect(bossObj,128*2,128,128*3,128*2);}
						if(AttackAnim>=AnimationStopInterval && AttackAnim<AnimationStopInterval*2){ObjSprite2D_SetSourceRect(bossObj,128*2,0,128*3,128);}
						
						if(AttackAnim >= AnimationStopInterval*2){AttackAnim = 0; AnimationIsMove = "IDLE";}
						AttackAnim++;
					}
				}
				
			}
			
			if(BossPhase == 2){ //Letty Action
				if(AttackAnim2<AnimationActionInterval){ObjSprite2D_SetSourceRect(bossObj,512,0,512+128,128);}
				if(AttackAnim2>=AnimationActionInterval && AttackAnim<AnimationActionInterval*2){ObjSprite2D_SetSourceRect(bossObj,512,128,512+128,128*2);}
				if(AttackAnim2>=AnimationActionInterval*2){ObjSprite2D_SetSourceRect(bossObj,512,128*2,512+128,128*3);}
				
				AttackAnim2++;
				AttackAnim = AnimationIdleInterval*-2;
			}
			
			ObjSprite2D_SetDestCenter(ID);
			yield;
		}
	}
}

