//wood

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Gems.png");

let SEshots5=("script\SoundEffects\shots5.wav");
let SElaserm2=("script\SoundEffects\laserm2.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");

let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=rand_int(0,40); let time=0; let animation=0;
let ani=4;
let shots=0;

let scale=1;
let anispeed=4;
let animation=0;
let gemangle=0;
let EFgem=0;
let gem1=[];
let enemycolor=5;
enemycolor=(enemycolor-1)*40;

let shotcolor=0; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

if(GetArgument==1){ SetAngle(270+rand(-5,5)); }
if(GetArgument==2){ SetAngle(90+rand(-5,5)); }
SetSpeed(2);

@Initialize{
	LoadGraphic("\script\Images\Enemies\Gems.png");

	LoadSE("script\SoundEffects\shots5.wav");
	LoadSE("script\SoundEffects\laserm2.wav");

	SetInvincibility(20);
	if(GetArgument==1){ SetLife(6); }
	if(GetArgument==2){ SetLife(20); }
	SetDamageRate(10,2); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

let weaken=1;
	if(GetCommonData("PlayerType")==1){ weaken=1.5; } //Fire>Wood
	if(GetCommonData("PlayerType")==5){ weaken=0.5; } //Water<Wood
SetDamageRate(10*weaken,2.5*weaken);

if(GetX<=minx-32 || GetX>=maxx+32 || GetY<=miny-32 || GetY>=maxy+32 && frame>=60){ VanishEnemy; }

if((GetX>minx && GetX<maxx) && (GetY>miny && GetY<maxy)){
SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);

if(time%6==0){
let shotx=0;
	CreateShotA(shotx,GetX,GetY,15);
	SetShotDataA(shotx,0,1,GetAngle-90,0,-0.08,0,31);
	SetShotDataA(shotx,60,0,NULL,0,0.1,2,31);
	FireShot(shotx);
	CreateShotA(shotx,GetX,GetY,15);
	SetShotDataA(shotx,0,1,GetAngle+90,0,-0.08,0,31);
	SetShotDataA(shotx,60,0,NULL,0,0.1,2,31);
	FireShot(shotx);
PlaySE(SEshots5);
}

if(frame%24==0){
let shotx=0;
	CreateLaserA(shotx,GetX,GetY,600,10,139,45);
	SetLaserDataA(shotx,0,GetAngle+90,0,0,0,0);
	SetShotKillTime(shotx,90);
	FireShot(shotx);
PlaySE(SElaserm2);
}
if((frame+12)%24==0){
let shotx=0;
	CreateLaserA(shotx,GetX,GetY,600,10,139,45);
	SetLaserDataA(shotx,0,GetAngle-90,0,0,0,0);
	SetShotKillTime(shotx,90);
	FireShot(shotx);
PlaySE(SElaserm2);
}

} //Onscreen

SetAngle(GetAngle+2*cos(time*5));


if(time==0){
let gemcolor=120;
	loop(6){
	EFgem=(Obj_Create(OBJ_EFFECT));
	Obj_SetPosition(EFgem,GetX,GetY);
	ObjEffect_SetLayer(EFgem,3); ObjEffect_SetTexture(EFgem,GRenemy); ObjEffect_SetRenderState(EFgem,ALPHA);
	ObjEffect_SetPrimitiveType(EFgem,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(EFgem,4);
	ObjEffect_SetVertexXY(EFgem,0,-6,-10); ObjEffect_SetVertexUV(EFgem,0,0,40);
	ObjEffect_SetVertexXY(EFgem,1,6,-10); ObjEffect_SetVertexUV(EFgem,1,12,40);
	ObjEffect_SetVertexXY(EFgem,2,-6,10); ObjEffect_SetVertexUV(EFgem,2,0,60);
	ObjEffect_SetVertexXY(EFgem,3,6,10); ObjEffect_SetVertexUV(EFgem,3,12,60);
	ObjEffect_SetVertexColor(EFgem,0,255,127+128*cos(gemcolor),127+128*cos(gemcolor-120),127+128*cos(gemcolor-240));
	ObjEffect_SetVertexColor(EFgem,1,255,127+128*cos(gemcolor),127+128*cos(gemcolor-120),127+128*cos(gemcolor-240));
	ObjEffect_SetVertexColor(EFgem,2,255,127+128*cos(gemcolor),127+128*cos(gemcolor-120),127+128*cos(gemcolor-240));
	ObjEffect_SetVertexColor(EFgem,3,255,127+128*cos(gemcolor),127+128*cos(gemcolor-120),127+128*cos(gemcolor-240));
	gem1=gem1~[EFgem];
	}
}

if(time>=0){
let i=0;
	while(i<length(gem1)){
	Obj_SetPosition(gem1[i],GetX+30*cos(gemangle),GetY+10*sin(gemangle));
	if(Obj_GetY(gem1[i])<GetY){ ObjEffect_SetLayer(gem1[i],1); }
	if(Obj_GetY(gem1[i])>=GetY){ ObjEffect_SetLayer(gem1[i],2); }

	ObjEffect_SetVertexUV(gem1[i],0,0+animation,40);
	ObjEffect_SetVertexUV(gem1[i],1,12+animation,40);
	ObjEffect_SetVertexUV(gem1[i],2,0+animation,60);
	ObjEffect_SetVertexUV(gem1[i],3,12+animation,60);

	gemangle+=360/length(gem1);
	i++;
	}
gemangle+=5;
if(time%anispeed==0){
	animation+=12;
	if(animation>=72){ animation=0; }
	}
}


oldX=GetX;
oldY=GetY;
frame++;
time++;

if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
	SetTexture(GRenemy);
	SetGraphicRect(0+enemycolor,0,40+enemycolor,40);
	SetGraphicAngle(0,0,0);
	SetGraphicScale(1,1);
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
PlaySE(SEdeath);
	loop(5){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
	loop(3){ CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}
}

}