task PointExtend(){
let ExtendPoint = 250;
let ExtendCount = 0;
let Point = GetPoint;

loop{
Point = GetPoint;
SetNormPoint(ExtendPoint);
if(ExtendCount == 0){if(Point >= 250){
		ExtendPlayer(1);
		ExtendPoint = 500;
		ExtendCount = 1;}
	yield;
	}
else if(ExtendCount == 1){if(Point >= 500){
		ExtendPlayer(1);
		ExtendPoint = 750;
		ExtendCount = 2;}
	yield;
	}
else if(ExtendCount == 2){if(Point >= 750){
		ExtendPlayer(1);
		ExtendPoint = 1000;
		ExtendCount = 3;}
	yield;
	}
else if(ExtendCount == 3){if(Point >= 1000){
		ExtendPlayer(1);
		ExtendPoint = 1500;
		ExtendCount = 4;}
	yield;
	}
else if(ExtendCount == 4){if(Point >= 1500){
		ExtendPlayer(1);
		ExtendPoint = 2000;
		ExtendCount = 5;}
	yield;
	}
else if(ExtendCount == 5){if(Point >= 2000){
		ExtendPlayer(1);
		ExtendPoint = 2500;
		ExtendCount = 6;}
	yield;
	}
else if(ExtendCount == 6){if(Point >= 2500){
		ExtendPlayer(1);
		ExtendPoint = 3000;
		ExtendCount = 7;}
	yield;
	}
else if(ExtendCount == 7){if(Point >= 3000){
		ExtendPlayer(1);
		ExtendPoint = 3750;
		ExtendCount = 8;}
	yield;
	}
else if(ExtendCount == 8){if(Point >= 3750){
		ExtendPlayer(1);
		ExtendPoint = 4500;
		ExtendCount = 9;}
	yield;
	}
else if(ExtendCount == 9){if(Point >= 4500){
		ExtendPlayer(1);
		ExtendPoint = 5500;
		ExtendCount = 10;}
	yield;
	}
else if(ExtendCount == 10){if(Point >= 5500){
		ExtendPlayer(1);
		ExtendPoint = 6750;
		ExtendCount = 11;}
	yield;
	}
else if(ExtendCount == 11){if(Point >= 6750){
		ExtendPlayer(1);
		ExtendPoint = 8000;
		ExtendCount = 12;}
	yield;
	}
else if(ExtendCount == 12){if(Point >= 8000){
		ExtendPlayer(1);
		ExtendPoint = 9999;
		ExtendCount = 13;}
	yield;
	}
else if(ExtendCount == 13){if(Point >= 9999){
		ExtendPlayer(1);
		AddPoint(-9999);
		ExtendPoint = 2000;
		ExtendCount = 14;}
	yield;
	}
else if(ExtendCount == 14){if(Point >= 2000){
		ExtendPlayer(1);
		ExtendPoint = 4000;
		ExtendCount = 15;}
	yield;
	}
else if(ExtendCount == 15){if(Point >= 4000){
		ExtendPlayer(1);
		ExtendPoint = 6000;
		ExtendCount = 16;}
	yield;
	}
else if(ExtendCount == 16){if(Point >= 6000){
		ExtendPlayer(1);
		ExtendPoint = 8000;
		ExtendCount = 17;}
	yield;
	}
else if(ExtendCount == 17){if(Point >= 8000){
		ExtendPlayer(1);
		ExtendPoint = 9999;
		ExtendCount = 18;}
	yield;
	}
else if(ExtendCount == 18){if(Point >= 9999){
		ExtendPlayer(1);
		ExtendPoint = 9999;
		ExtendCount = 19;}
	yield;
	}
else if(ExtendCount == 19){yield;}
}
}

task ScoreExtend(){
let ExtendCount = 0;
let Score = GetScore;

loop{
if(ExtendCount == 0){if(Score >= 25000000){
		ExtendPlayer(1);
		ExtendCount = 1;}
	yield;
	}
else if(ExtendCount == 1){if(Score >= 50000000){
		ExtendPlayer(1);
		ExtendCount = 2;}
	yield;
	}
else if(ExtendCount == 2){if(Score >= 80000000){
		ExtendPlayer(1);
		ExtendCount = 3;}
	yield;
	}
else if(ExtendCount == 3){if(Score >= 120000000){
		ExtendPlayer(1);
		ExtendCount = 4;}
	yield;
	}
else if(ExtendCount == 4){if(Score >= 160000000){
		ExtendPlayer(1);
		ExtendCount = 5;}
	yield;
	}
else if(ExtendCount == 5){if(Score >= 200000000){
		ExtendPlayer(1);
		ExtendCount = 6;}
	yield;
	}
else if(ExtendCount == 6){yield;}
}
}

task MagicPointOnStage(){

#include_function ".\Config.txt"

SetCommonData("MAGICPOINT",0);
yield;
let E = GetCommonData("EASY_START");
let N = GetCommonData("NORMAL_START");
let H = GetCommonData("HARD_START");
let L = GetCommonData("LUNATIC_START");

let AddToEnemy;
let ReduceToLive;
let ReduceToBomb;
let ReduceToMissRate = [0,0.8,1.6,3.2,6.4,12.8,19.2,25];
let Level;

let FirstPlayer = ChoosePlayerLife() - 4;
let ReduceToFirstPlayer = [1.5,3,5,7,10];
let ReduceRateUp = 1;


if(E > 0){SetCommonData("MAGICPOINT",5);AddToEnemy = 0.5;ReduceToLive = 0.004167;ReduceToBomb = 0.8;Level = 5;}
if(N > 0){SetCommonData("MAGICPOINT",10);AddToEnemy = 1.5;ReduceToLive = 0.004763;ReduceToBomb = 1.2;Level = 6;}
if(H > 0){SetCommonData("MAGICPOINT",15);AddToEnemy = 2.5;ReduceToLive = 0.005557;ReduceToBomb = 1.6;Level = 8;}
if(L > 0){SetCommonData("MAGICPOINT",25);AddToEnemy = 3.5;ReduceToLive = 0.008333;ReduceToBomb = 2.2;Level = 10;}

SetCommonData("MAGICPOINT_ADD",AddToEnemy);
SetCommonData("MAGICPOINT_REDUCE",ReduceToLive);

if(FirstPlayer >= 0){ReduceRateUp = ReduceToFirstPlayer[FirstPlayer];}

loop{
	let a	= GetCommonData("MAGICPOINT");
	let zanki = GetPlayerLife;
	let ReduceToMiss;

	if(OnBomb == true){
	a -= ReduceToBomb * ReduceRateUp;
	if(0 >= a){a = 0;}
	SetCommonData("MAGICPOINT",a);
	while(OnBomb == true){yield;}
	}

	if(OnPlayerMissed == true){
	while(OnPlayerMissed == true){yield;}
	if(OnBomb == true){break;}
	ReduceToMiss = Level * ReduceToMissRate[zanki] * ReduceRateUp;
	a -= ReduceToMiss;
	if(0 >= a){a = 0;}
	SetCommonData("MAGICPOINT",a);
	}

	if(a >= 1000){
	a = 999;
	SetCommonData("MAGICPOINT",a);
	}
yield;
}
}

function MagicPointDrawText(){

let textA = "MagicPoint";
let textB = ToString(GetCommonData("MAGICPOINT"));

DrawText(textA,64,400,12,255);
DrawText(textB,64,412,12,255);
}

function MasicPointAddNormal(Rate){
let MagicPoint = GetCommonData("MAGICPOINT");
let AddPoint = GetCommonData("MAGICPOINT_ADD");

if(OnBomb == false){
MagicPoint += AddPoint * Rate;
SetCommonData("MAGICPOINT",MagicPoint);
}
}

function MasicPointAddSpellCard{
let MagicPoint = GetCommonData("MAGICPOINT");
let AddPoint = GetCommonData("MAGICPOINT_ADD");

if(GetBombCountInThisSpell == 0&&GetMissCountInThisSpell == 0){
MagicPoint += AddPoint * 15;
SetCommonData("MAGICPOINT",MagicPoint);
}
}

function MasicPointReduce{
let MagicPoint = GetCommonData("MAGICPOINT");
let ReducePoint = GetCommonData("MAGICPOINT_REDUCE");

MagicPoint -= ReducePoint;
if(0 >= MagicPoint){MagicPoint = 0;}
SetCommonData("MAGICPOINT",MagicPoint);
}

task MusicControl{
let stage;
let Music1 = GetCurrentScriptDirectory~"\Bgm\ametowa.mp3";
let Music2 = GetCurrentScriptDirectory~"\Bgm\fukaki.mp3";
let Music3 = GetCurrentScriptDirectory~"\Bgm\toki.mid";

LoadMusic(Music1);
stage = GetCommonData("STAGE");
if(stage == 1){PlayMusic(Music1);}
while(stage == 1){stage = GetCommonData("STAGE");yield;}
DeleteMusic(Music1);
LoadMusic(Music2);
if(stage == 2){PlayMusic(Music2);}
while(stage == 2){stage = GetCommonData("STAGE");yield;}
DeleteMusic(Music2);
LoadMusic(Music3);
if(stage == 3){PlayMusic(Music3);}
while(stage == 3){stage = GetCommonData("STAGE");yield;}
DeleteMusic(Music3);
loop{yield;}
}

task BGControl{
SetCommonData("ON_SPELL",0);
let stage;
let spell;
let BG1 = GetCurrentScriptDirectory~"\BG\yun_3780.jpg";
let BG2 = GetCurrentScriptDirectory~"\BG\eyes0048.jpg";
let BG3 = GetCurrentScriptDirectory~"\BG\seiryu808.jpg";

stage = GetCommonData("STAGE");

if(stage == 1){LoadGraphic(BG1);
SetTexture(BG1);SetGraphicRect(0,0,384,448);SetAlpha(150);yield;}
while(stage == 1){stage = GetCommonData("STAGE");yield;}
DeleteGraphic(BG1);

if(stage == 2){LoadGraphic(BG2);SetGraphicScale(2,2);
SetTexture(BG2);SetGraphicRect(0,0,384,448);SetAlpha(255);yield;}
while(stage == 2){stage = GetCommonData("STAGE");
spell = GetCommonData("ON_SPELL");SetAlpha(255);
while(spell == 1){SetAlpha(120);yield;}
yield;}
DeleteGraphic(BG2);

if(stage == 3){LoadGraphic(BG3);
SetTexture(BG3);SetGraphicRect(0,0,384,448);SetAlpha(200);yield;}
while(stage == 3){stage = GetCommonData("STAGE");
spell = GetCommonData("ON_SPELL");SetAlpha(200);
while(spell == 1){SetAlpha(120);yield;}
yield;}
DeleteGraphic(BG3);

loop{yield;}
}
