task LymiaInit(shotdelay){
    LymiaSwitch;
    LoadGraphic(img_lymia);
    LoadGraphic(imgLBG1);
    LoadGraphic(imgLBG2);
    LSE("shine");
    LSE("ting1");
    LSE("lightning");
    LSE("charge");
    SetPlayerLifeImage(img_lymia, 100,160, 144, 202);
    SetSpeed(5.5, 3);
    XOffset=[0,-2,2];
    YOffset=[0,0,0];
    Left=[0,48,48];
    Right=[48,88,88];
    Flip=[1,-1,1];
    loop(shotdelay){yield;}
    if(!ExPlayer){
	LoadPlayerShotData(GetCurrentScriptDirectory~"LymiaShotData.txt");
    }else{
	LoadPlayerShotData(GetCurrentScriptDirectory~"LymiaShotData2.txt");
    }
    playershot=0;
}
sub LymiaMainLoop{
    hitboxcolor=4;
    if(count<-1){
	count++;
    }
    if((GetKeyState(VK_SHOT)==KEY_PUSH || GetKeyState(VK_SHOT)==KEY_HOLD)){
	if(count==-1&&!IsForbidShot){count = 0;}
    }
    if(GetKeyState(VK_SLOWMOVE)!=KEY_PUSH && GetKeyState(VK_SLOWMOVE)!=KEY_HOLD&&playershot==0){
        if(count == 0&&!IsForbidShot){
		laser(GetPlayerX,GetPlayerY,8.8,-90-angle1[angleshot%6], 2.5, 5,120,color%3,20);
		laser(GetPlayerX,GetPlayerY,6.5,-90-angle2[angleshot%6], 2.0, 5,100,color%3,20);
		laser(GetPlayerX,GetPlayerY,12,-90-25                  , 2.5, 5,150,color%3,20);
		laser(GetPlayerX,GetPlayerY,8.8,-90+angle1[angleshot%6], 2.5, 5,120,color%3,20);
		laser(GetPlayerX,GetPlayerY,6.5,-90+angle2[angleshot%6], 2.0, 5,100,color%3,20);
		laser(GetPlayerX,GetPlayerY,12,-90+25                  , 2.5, 5,150,color%3,20);

		loop(3){
			HomingBall(GetPlayerX,GetPlayerY,rand(1,5),rand(0,360), 10, 120,color%3);
		}

		angleshot++;
		color++;
		if(color>=3){color=0;}
        }
        if(count >= 20){
		count=-1;
        }
    }else if(!IsForbidShot&&playershot==0){
        if(count==0){
		HomingBall(GetPlayerX,GetPlayerY,rand(3,5),-90+20, 12, 120,color%3);
		HomingBall(GetPlayerX,GetPlayerY,rand(3,5),-90-20, 12, 120,color%3);

		if(shottype==0){
			laser(GetPlayerX,GetPlayerY,12,-90, 2, 5,200,color%3,0);

			color++;

			laser(GetPlayerX,GetPlayerY,8.8,-85, 2, 5,120,color%3,0);
			laser(GetPlayerX,GetPlayerY,8.8,-95, 2, 5,120,color%3,0);
			shottype=1;
		}else{
			laser(GetPlayerX,GetPlayerY,12,-87, 2, 5,140,color%3,0);
			laser(GetPlayerX,GetPlayerY,12,-93, 2, 5,140,color%3,0);

			color++;

			laser(GetPlayerX,GetPlayerY,8.8,-82, 2, 5,100,color%3,0);
			laser(GetPlayerX,GetPlayerY,8.8,-98, 2, 5,100,color%3,0);
			shottype=0;
		}
		if(color==3){color=0;}
        }
        if(count >= 20){
          count=-1;
        }
    }
    if(count >= 0){
      count++;
    }
    LymiaDrawLogic;
}

  function LymiaDrawLogic{
	Frame++;
	if(Frame==6){
		Frame=0;
		Pose++;
		if(Pose==4){
			Pose=0;
		}
	}
	if(GetKeyState(VK_RIGHT)==KEY_HOLD||GetKeyState(VK_RIGHT)==KEY_PUSH){
		Dir=2;
	}else if(GetKeyState(VK_LEFT)==KEY_HOLD||GetKeyState(VK_LEFT)==KEY_PUSH){
		Dir=1;
	}else{Dir=0;}
	if(OnEdgeOfScreen){Dir=0;}

	Rot+=12-Focus*10;
	if(GetKeyState(VK_SLOWMOVE)==KEY_HOLD&&Focus<1){Focus+=0.08;}
	if(GetKeyState(VK_SLOWMOVE)==KEY_FREE&&Focus>0){Focus-=0.08;}
	EffectsLogic;
	SparkleLogic;
  }

sub LymiaDrawLoop{
	SetColor(255,255,255);
	SetTexture(img_lymia);

	DrawSparkles;

	SetGraphicRect(90,10,154,54);
	SetGraphicScale(2.2-Focus,2.2-Focus);
	SetGraphicAngle(0,0,Rot);
	SetAlpha(Focus*(InvincibilityAlpha*0.8));
	DrawGraphic(GetPlayerX+ScreenShakeX,GetPlayerY+ScreenShakeY);

	SetGraphicScale(Flip[Dir],1);
	SetGraphicAngle(0,0,0);
	SetAlpha(InvincibilityAlpha);
	SetGraphicRect(Left[Dir],0+55*Pose,Right[Dir],53+55*Pose);

	SetColor(255,255,255);
	DrawGraphic(round(GetPlayerX+XOffset[Dir]+ScreenShakeX), round(GetPlayerY+YOffset[Dir]+ScreenShakeY));
}
sub LymiaFinalize{
    DeleteGraphic(img_lymia);
    DeleteGraphic(imgLBG1);
    DeleteGraphic(imgLBG2);
    DSE("shine");
    DSE("ting1");
    DSE("lightning");
    DSE("charge");
}

sub LymiaSpell{
    if(GetKeyState(VK_SLOWMOVE)==KEY_PUSH || GetKeyState(VK_SLOWMOVE)==KEY_HOLD){
      SetSpeed(0, 0);
      UseSpellCard("LymiaF", 0);
      
    }else{
      SetSpeed(3, 2);
      UseSpellCard("LymiaU", 0);
    }
}
