let cdr = GetCurrentScriptDirectory();

function TCreateBoss
{
	return (ObjEnemy_Create(OBJ_ENEMY_BOSS))
}

task TRenderBoss(ObjBoss){
	let BossImg = cdr ~ "img/boss_reisen.png";
	ObjPrim_SetTexture(ObjBoss, BossImg);
	ObjSprite2D_SetSourceRect(ObjBoss, 2, 2, 128, 128);
	ObjSprite2D_SetDestCenter(ObjBoss);
	ObjRender_SetScaleXYZ(ObjBoss, 1.25, 1.25, 0);
	Obj_SetRenderPriority(ObjBoss,0.3);
}


task SetBossImg(Boss, id){
	/*
		id number key:
	
		1-3 = standing animation sprites. animation should be 1->4->1 and repeat
		
		4-5 = blinking standing animation sprites.
		
		6-9 = moving animations
		
		10-12 = spell casting
		
		13-15 = attack 1
		
		16-20 = attack 2
	*/
	
	alternative(id)
	case(1){
		ObjSprite2D_SetSourceRect(Boss, 2, 2, 128, 128);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(2){
		ObjSprite2D_SetSourceRect(Boss, 2, 130, 128, 128*2);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(3){
		ObjSprite2D_SetSourceRect(Boss, 2, 258, 128, 128*3);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(4){
		ObjSprite2D_SetSourceRect(Boss, 130, 2, 128*2, 128);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(5){
		ObjSprite2D_SetSourceRect(Boss, 130, 130, 128*2, 128*2);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(6){
		ObjSprite2D_SetSourceRect(Boss, 258, 2, 128*3, 128);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(7){
		ObjSprite2D_SetSourceRect(Boss, 258, 130, 128*3, 128*2);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(8){
		ObjSprite2D_SetSourceRect(Boss, 258, 258, 128*3, 128*3);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(9){
		ObjSprite2D_SetSourceRect(Boss, 258, 386, 128*3, 128*4);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(10){
		ObjSprite2D_SetSourceRect(Boss, 128*3 + 2, 2, 128*4, 128);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(11){
		ObjSprite2D_SetSourceRect(Boss, 128*3 + 2, 128*1 + 2, 128*4, 128*2);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	case(12){
		ObjSprite2D_SetSourceRect(Boss, 128*3 + 2, 128*2, 128*4, 128*3);
		ObjSprite2D_SetDestCenter(Boss);
		ObjRender_SetScaleXYZ(Boss, 1.25, 1.25, 0);
		ObjRender_SetX(Boss, ObjMove_GetX(Boss));
		ObjRender_SetY(Boss, ObjMove_GetY(Boss));
		Obj_SetRenderPriority(Boss,0.3);
	}
	others{
		
	}
}

let EAngle = 90;
let attack = 0;

task TAttack(num){
	attack = num;
}

task TAnimate{
	let dir = 0;
	let speed = 0;
	let f = 0;
	let f2 = 0;
	let f3 = 0;
	let hover = 0;
	let hovertrue = false;
	
	
	let count = 0;
	let faintscale = 2;
	let color = [255,0,255];
	
	while(!Obj_IsDeleted(objEnemy)){
		
		TRenderBoss(objEnemy);
						
		dir = ObjMove_GetAngle(objEnemy);
		speed = ObjMove_GetSpeed(objEnemy);
		
		if(attack==0){
		
		if(speed==0){
			
			if(f<6){SetBossImg(objEnemy, 1);
				}
			if(f>=6 && f<12){SetBossImg(objEnemy, 2);
				}
			if(f>=12 && f<18){SetBossImg(objEnemy, 3);
				}
			if(f>=18 && f<24){SetBossImg(objEnemy, 2);
				}
			if(f>=24 && f<30){SetBossImg(objEnemy, 1);
				}
			if(f>=30 && f<36){SetBossImg(objEnemy, 4);
				}
			if(f>=36 && f<42){SetBossImg(objEnemy, 5);
				}
			if(f>=42 && f<48){SetBossImg(objEnemy, 2);
				}
				
			f2=0;
			f3=0;
			hovertrue=true;
		}
		else if(cos(dir)<0){
			f2++;
			ObjRender_SetAngleXYZ(objEnemy,0,180,0);
			if(f2<4){SetBossImg(objEnemy, 6);
				}
			if(f2>=4 && f2< 8){SetBossImg(objEnemy, 7);
				}
			if(f2>=8 && f2< 12){SetBossImg(objEnemy, 8);
				}
			if(f2>=12){SetBossImg(objEnemy, 9);
				}
			hovertrue=false;
		}
		else if(cos(dir)>0){
			f2++;
			ObjRender_SetAngleXYZ(objEnemy,0,0,0);
			if(f2<4){SetBossImg(objEnemy, 6);
				}
			if(f2>=4 && f2< 8){SetBossImg(objEnemy, 7);
				}
			if(f2>=8 && f2< 12){SetBossImg(objEnemy, 8);
				}
			if(f2>=12){SetBossImg(objEnemy, 9);
				}
			hovertrue=false;
		} 		
		
		}		
		
		if (attack==1){
			f3++;
			if(f3<4){SetBossImg(objEnemy, 9);
			}
			if(f3>=4 && f3<8){SetBossImg(objEnemy, 10);
			}
			if(f3>=8 && f3<12){SetBossImg(objEnemy, 11);
			}
			if(f3>=12 && f3<60*2){SetBossImg(objEnemy, 12);
			}
			if(f3>=60*2){attack = 0;
			}
			hovertrue=false;
		}
		
		if (attack==2){
			f3++;
			if(f3<20){SetBossImg(objEnemy, 9);
			}
			if(f3>=20 && f3<24){SetBossImg(objEnemy, 10);
			}
			if(f3>=24 && f3<32){SetBossImg(objEnemy, 11);
			}
			if(f3>=32 && f3<38){SetBossImg(objEnemy, 12);
			}
			if(f3>=38){attack = 0;
			}
			hovertrue=false;
		}
		if (attack==3){
			f3++;
			if(f3<20){SetBossImg(objEnemy, 9);
			}
			if(f3>=20 && f3<24){SetBossImg(objEnemy, 10);
			}
			if(f3>=24 && f3<32){SetBossImg(objEnemy, 11);
			}
			if(f3>=32 && f3<38){SetBossImg(objEnemy, 12);
			}
			if(f3>=38){attack = 0;
			}
			hovertrue=false;
		}
		
		
		f++;
		if(f==48){f=0;}
		
		count++;
		if(count==5){count=0;}
		
		hover++;
		
		ObjRender_SetPosition(objEnemy,ObjMove_GetX(objEnemy),ObjMove_GetY(objEnemy)+0.3*sin(hover*3),0);
	
		yield;
	}	
}

