#include "enemy.h"
#include "sequencer.h"
#include "stage.h"

#define SEQ_END -1
#define SEQ_PAUSE 100
#define SEQ_GOTO 101

int eventDelay;

Event sequence[]=
{
	{0,type,64,Y,mX,mY},
	{0,type,256,Y,mX,mY},
	{0,type,512,Y,mX,mY},
	{0,type,704,Y,mX,mY},
	{0,type,832,Y,mX,mY},
	{0,type,960,Y,mX,mY},
	{0,type,1088,Y,mX,mY},
	{0,type,1152,Y,mX,mY},
	{0,type,1216,Y,mX,mY},
	{0,type,1344,Y,mX,mY},
	{0,type,1472,Y,mX,mY},
	{0,type,1536,Y,mX,mY},


	/*{10,0,0,0,-5,0},
	{10,1,0,1600,0,-5},
	{10,2,600,0,5,0},
	{10,3,600,1600,-5,-5},
	{10,4,219,900,5,-5},
	{10,5,263,1005,0,5},
	{10,6,0,0,-5,0},
	{30,SEQ_PAUSE,0,0,0,0},
	{30,SEQ_GOTO,0,0,0,0},
	{10,SEQ_END,0,0,0,0}*/
};

int currentEvent;

void InitSequencer ()
{
	eventDelay = sequence[0].delay;
	currentEvent = 0;
}

void UpdateSequencer ()
{
	if(currentStage==0)
	{
		if ( eventDelay > 0)
		{
			eventDelay -= 1;
			return;
		}

	}
	if (sequence[currentEvent].type >= 0 && sequence[currentEvent].type <= 7)
	{
		for (int a = 0; a < NUM_ENEMIES; a++)
		{
			if(enemies[a].active == false)
			{
				enemies[a].active = true;
				enemies[a].type = sequence[currentEvent].type;
				enemies[a].xDirection = sequence[currentEvent].xDirection;
				enemies[a].yDirection = sequence[currentEvent].yDirection;
				enemies[a].kill = 0;
				enemies[a].respawntime = 0;
				enemies[a].X  = sequence[currentEvent].X;
				enemies[a].Y  = sequence[currentEvent].Y;
				break;
			}
		}
		currentEvent += 1;
		eventDelay = sequence[currentEvent].delay;
	}
	else if ( sequence[currentEvent].type == SEQ_PAUSE)
	{
		currentEvent += 1;
		eventDelay = sequence[currentEvent].delay;

	}
	else if ( sequence[currentEvent].type == SEQ_GOTO)
	{
		currentEvent = sequence[currentEvent].X;
		eventDelay = sequence[currentEvent].delay;
	}
}
