script_enemy_main {
    let CSD = GetCurrentScriptDirectory;
    let f = 0;
    let f2 = 0;
    let framer = 1;

    let cutinFamImg = GetArgument;

    let textdata = CSD ~ "spellcardanm.png";

    @Initialize {
        LoadGraphic(cutinFamImg);
        LoadGraphic(textdata);

        SetLife(9999);

	movement;
      	summontext;
	summonhexagon;
    }

    @MainLoop {
        yield;
    }

    @DrawLoop {
	if(GetCommonData("cutinType")==1 && f<254 && framer==1){
		f+=255;
		if(f>254){framer=0;}
	}	
	if(GetCommonData("cutinType")==1 && framer==0){
		if(f2>60){
			f-=2;
			if(f<5){framer=2;}
		}
	}
	if(GetCommonData("cutinType")>1){f=255;}
	SetTexture(cutinFamImg);
	SetAlpha(f);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(1,1);
	SetRenderState(ALPHA);
	SetAlpha(200);
	SetGraphicRect(GetCommonData("boundL"),GetCommonData("boundT"),GetCommonData("boundR"),GetCommonData("boundB"));
                DrawGraphic(GetX, GetY);

	f2++;
    }

    @Finalize {
	DeleteGraphic(cutinFamImg);
    }

    task summonhexagon {
	let x = 0;
	let yyPos = 0;
	let xxPos = 0;
	loop{
		while(x<1){
			hexagontext(GetCenterX+50,GetCenterY+150,0,0,1.4,1.4);
			hexagontext(GetCenterX+50,GetCenterY+150,0,45,1.4,1.4);
			hexagontext(GetCenterX+50,GetCenterY+150,0,90,1.4,1.4);
			hexagontext(GetCenterX+50,GetCenterY+150,0,135,1.4,1.4);
			hexagontext(GetCenterX+50,GetCenterY+150,0,180,1.4,1.4);
			hexagontext(GetCenterX+50,GetCenterY+150,0,225,1.4,1.4);
			hexagontext(GetCenterX+50,GetCenterY+150,0,270,1.4,1.4);
			hexagontext(GetCenterX+50,GetCenterY+150,0,315,1.4,1.4);

			hexagontext(GetCenterX+50,GetCenterY+150,0,0,1.2,1.2);
			hexagontext(GetCenterX+50,GetCenterY+150,0,45,1.2,1.2);
			hexagontext(GetCenterX+50,GetCenterY+150,0,90,1.2,1.2);
			hexagontext(GetCenterX+50,GetCenterY+150,0,135,1.2,1.2);
			hexagontext(GetCenterX+50,GetCenterY+150,0,180,1.2,1.2);
			hexagontext(GetCenterX+50,GetCenterY+150,0,225,1.2,1.2);
			hexagontext(GetCenterX+50,GetCenterY+150,0,270,1.2,1.2);
			hexagontext(GetCenterX+50,GetCenterY+150,0,315,1.2,1.2);

			hexagontext2(GetCenterX+50,GetCenterY+150,0,0,1.0,1.0);
			hexagontext2(GetCenterX+50,GetCenterY+150,0,45,1.0,1.0);
			hexagontext2(GetCenterX+50,GetCenterY+150,0,90,1.0,1.0);
			hexagontext2(GetCenterX+50,GetCenterY+150,0,135,1.0,1.0);
			hexagontext2(GetCenterX+50,GetCenterY+150,0,180,1.0,1.0);
			hexagontext2(GetCenterX+50,GetCenterY+150,0,225,1.0,1.0);
			hexagontext2(GetCenterX+50,GetCenterY+150,0,270,1.0,1.0);
			hexagontext2(GetCenterX+50,GetCenterY+150,0,315,1.0,1.0);

			hexagontext(0,80,0,0,0.9,0.9);
			hexagontext(0,80,0,45,0.9,0.9);
			hexagontext(0,80,0,90,0.9,0.9);
			hexagontext(0,80,0,135,0.9,0.9);
			hexagontext(0,80,0,180,0.9,0.9);
			hexagontext(0,80,0,225,0.9,0.9);
			hexagontext(0,80,0,270,0.9,0.9);
			hexagontext(0,80,0,315,0.9,0.9);

			x++;
		}
		yield;
	}
    } 

    task summontext {
	let x = 0;
	let yyPos = 0;
	let xxPos = 0;
	loop{
		while(x<5){
			spellcardtext(GetClipMinX,GetClipMaxY-22-yyPos,1);
			spellcardtext(GetClipMaxX,GetClipMinY+20+yyPos,-1);

			//spellcardtext(GetClipMinX+xxPos,GetClipMaxY,1);
			//spellcardtext(GetClipMaxX-xxPos+22,GetClipMinY,-1);
			x++;

			yyPos+=54;
			xxPos+=54;
		}
		yield;
	}
    } 

    // text animation for spellcard spawn ( HEXAGON STYLE )
    task hexagontext2(x,y,v,draai,sx,sy) {
	let obj = Obj_Create(OBJ_EFFECT);
	let alphret = 0;
	let as = 0;
	let angle = draai;
        let c = 0;
	ObjEffect_SetTexture(obj,textdata);
	
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetSpeed(obj,v);
	Obj_SetAngle(obj,0);
	ObjEffect_SetAngle(obj,0,0,angle);
	ObjEffect_SetRenderState(obj,ADD);
	Obj_SetAlpha(obj,100);
        ObjEffect_SetScale(obj, sx, sy);

	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj, 4);

          // Second vertex (number 0)
          ObjEffect_SetVertexXY(obj, 0, -48, -128);
          ObjEffect_SetVertexUV(obj, 0, 0, 0);

          // Second vertex (number 1)
          ObjEffect_SetVertexXY(obj, 1, 48, -128);
          ObjEffect_SetVertexUV(obj, 1, 128, 0);
 
          // Third vertex (number 2)
          ObjEffect_SetVertexXY(obj, 2, -48, -104);
          ObjEffect_SetVertexUV(obj, 2, 0, 32);

          // Fourth vertex (number 3)
          ObjEffect_SetVertexXY(obj, 3, 48, -104);
          ObjEffect_SetVertexUV(obj, 3, 128, 32);

	  while(! Obj_BeDeleted(obj)){
		ObjEffect_SetAngle(obj,0,0,angle);	

	  	ObjEffect_SetVertexColor(obj,0,alphret,255,255,255);
	 	ObjEffect_SetVertexColor(obj,1,alphret,255,255,255);
	  	ObjEffect_SetVertexColor(obj,2,alphret,255,255,255);
	  	ObjEffect_SetVertexColor(obj,3,alphret,255,255,255);
		if(as==0){alphret+=10; angle--; if(alphret>250){as=1;} }
		if(as==1){angle--; c++; if(c==60){as=2;} }		
		if(as==2){alphret-=2; angle--; if(alphret<5){as=0;} }

		
		yield;
	  }
 
    }

    // text animation for spellcard spawn ( HEXAGON STYLE )
    task hexagontext(x,y,v,draai,sx,sy) {
	let obj = Obj_Create(OBJ_EFFECT);
	let alphret = 0;
	let as = 0;
	let angle = draai;
        let c = 0;
	ObjEffect_SetTexture(obj,textdata);
	
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetSpeed(obj,v);
	Obj_SetAngle(obj,0);
	ObjEffect_SetAngle(obj,0,0,angle);
	ObjEffect_SetRenderState(obj,ADD);
	Obj_SetAlpha(obj,255);
        ObjEffect_SetScale(obj, sx, sy);

	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj, 4);

          // Second vertex (number 0)
          ObjEffect_SetVertexXY(obj, 0, -48, -128);
          ObjEffect_SetVertexUV(obj, 0, 0, 0);

          // Second vertex (number 1)
          ObjEffect_SetVertexXY(obj, 1, 48, -128);
          ObjEffect_SetVertexUV(obj, 1, 128, 0);
 
          // Third vertex (number 2)
          ObjEffect_SetVertexXY(obj, 2, -48, -104);
          ObjEffect_SetVertexUV(obj, 2, 0, 32);

          // Fourth vertex (number 3)
          ObjEffect_SetVertexXY(obj, 3, 48, -104);
          ObjEffect_SetVertexUV(obj, 3, 128, 32);

	  while(! Obj_BeDeleted(obj)){
		ObjEffect_SetAngle(obj,0,0,angle);	

	  	ObjEffect_SetVertexColor(obj,0,alphret,255,255,255);
	 	ObjEffect_SetVertexColor(obj,1,alphret,255,255,255);
	  	ObjEffect_SetVertexColor(obj,2,alphret,255,255,255);
	  	ObjEffect_SetVertexColor(obj,3,alphret,255,255,255);
		if(as==0){alphret+=20; angle++; if(alphret>250){as=1;} }
		if(as==1){angle++; c++; if(c==60){as=2;} }		
		if(as==2){alphret-=2; angle++; if(alphret<5){as=0;} }

		
		yield;
	  }
 
    }

    // text animation for spellcard spawn
    task spellcardtext(x,y,v) {
	let obj = Obj_Create(OBJ_EFFECT);
	let alphret = 0;
	let as = 0;
	ObjEffect_SetTexture(obj,textdata);
	
	Obj_SetX(obj,x);
	Obj_SetY(obj,y);
	Obj_SetSpeed(obj,v);
	Obj_SetAngle(obj,-30);
	ObjEffect_SetAngle(obj,0,0,-30);
	ObjEffect_SetRenderState(obj,ADD);
	Obj_SetAlpha(obj,100);
	
	ObjEffect_SetPrimitiveType(obj, PRIMITIVE_TRIANGLESTRIP);
	ObjEffect_CreateVertex(obj, 4);

          // Second vertex (number 0)
          ObjEffect_SetVertexXY(obj, 0, -1024, -16);
          ObjEffect_SetVertexUV(obj, 0, 0, 0);

          // Second vertex (number 1)
          ObjEffect_SetVertexXY(obj, 1, 1024, -16);
          ObjEffect_SetVertexUV(obj, 1, 2048, 0);
 
          // Third vertex (number 2)
          ObjEffect_SetVertexXY(obj, 2, -1024, 16);
          ObjEffect_SetVertexUV(obj, 2, 0, 32);

          // Fourth vertex (number 3)
          ObjEffect_SetVertexXY(obj, 3, 1024, 16);
          ObjEffect_SetVertexUV(obj, 3, 2048, 32);

	loop{
	  	ObjEffect_SetVertexColor(obj,0,alphret,255,255,255);
	 	ObjEffect_SetVertexColor(obj,1,alphret,255,255,255);
	  	ObjEffect_SetVertexColor(obj,2,alphret,255,255,255);
	  	ObjEffect_SetVertexColor(obj,3,alphret,255,255,255);
		if(as==0){alphret+=20; if(alphret>250){as=1;} }
		if(as==1){wacht(60); as=2; }
		if(as==2){alphret-=2; if(alphret<5){as=0;} }	
		yield;
	}
 
    }


    // movement path task to imitate the cutin animation.
    task movement{
	if(GetCommonData("cutinType")==1){
		SetMovePosition03(GetCenterX,GetCenterY+100,15,10);
		wacht(60);
		SetMovePosition01(GetCenterX,GetClipMinY-256,3);
		wacht(120);
		VanishEnemy;
	}
	if(GetCommonData("cutinType")==3){
		SetMovePosition01(GetCenterX,GetCenterY,15);
		wacht(30);
		SetMovePosition01(GetCenterX-16,GetCenterY+16,0.5);
		wacht(80);
		SetMovePosition01(GetClipMinX-256,GetCenterY+100,15);
		wacht(60);
		VanishEnemy;
	}
	if(GetCommonData("cutinType")==4){
		SetMovePosition01(GetCenterX,GetCenterY,15);
		wacht(30);
		SetMovePosition01(GetCenterX+50,GetCenterY,0.5);
		wacht(90);
		SetMovePosition01(GetClipMaxX+256,GetCenterY,15);
		wacht(60);
		VanishEnemy;
	}
    }

    // wait function
    function wacht(w){
	loop(w){
		yield; 
    	}
    }
    #include_function ".\cutin.txt"
}