/***************************************************************************************

						メインファイル

****************************************************************************************/

#include "global.h"

int	Init( void );

int global_counter;	/*ゲームのモード*/
int	key;			/*キーの情報を格納*/
int	i,j;
int stage_count;
int time_count;

/*メイン関数*/
void main(void)
{
	if(Init())	return;

	sound_play(10);

	while(key != KEY_START)
	{
		key=key_hit_check();

		switch(global_counter)
		{

			case	0:
				title_draw();
				if(key==KEY_A)	
				{
					sound_stop();
					sound_play(10);
					text_screen_init();
					global_counter++;
				}
				break;

			case	1:
				stage_draw();
				if(key==KEY_A)	
				{
					sound_stop();
					text_screen_init();
					global_counter++;
				}
				break;

			case	2:
				main_draw();
				if(key == KEY_B){
					if(stage_count==1) sound_playx(9);
					else if(stage_count==2) sound_playx(20);
					else if(stage_count==3) sound_playx(30);
					else if(stage_count==4) sound_playx(0);					
				}

				if(key==KEY_A)	
				{
					text_screen_init();
					sound_stop();
					global_counter++;
				}
				break;
		
			case	3:
								draw();

				game();
				/*time_count--;*/
				if(key == KEY_Y1){
					text_screen_init();
					cursor_display(0);
					global_counter=0;
					sound_play(10);
				}
				if(key == KEY_Y3){ 
					if(stage_count==1) sound_playx(9);
					else if(stage_count==2) sound_playx(20);
					else if(stage_count==3) sound_playx(30);
					else if(stage_count==4) sound_playx(0);
				}
				if((x0==17&&y0==12)&&(x1==5&&y1==4)&&(x2==11&&y2==4)&&(x3==17&&y3==4)
						&&(x4==5&&y4==8)&&(x5==11&&y5==8)&&(x6==17&&y6==8)&&(x7==5&&y7==12)&&(x8==11&&y8==12)){
							draw();
							cursor_display(0);
							sys_wait(50);
							if(stage_count==1) sound_playx(9);
							else if(stage_count==2) sound_playx(20);
							else if(stage_count==3) sound_playx(30);
							else if(stage_count==4) sound_playx(0);					
							text_screen_init();
							global_counter++;
				}
				break;

			case	4:
				sprite_draw1();
				if((key == KEY_A) || (bgm_check()==0)){
					global_counter++;
					sound_play(10);
				}
				break;

			case	5:
					text_screen_init();
					if(stage_count<=3){
						text_put_string(8,9,"おめでとうー！");
						text_put_string(5,11,"TRY TO NEXT STAGE！");
					}
					else if(stage_count==4){
						sound_stop();
						text_screen_init();
						global_counter=6;
						break;
					}
					sys_wait(150);
					stage_count++;
					x0=17,y0=12;
					x1=11, y1=8;
					x2=17,y2=4;
					x3=5,y3=12;
					x4=5, y4=4;
					x5=5,y5=8;
					x6=11,y6=12;
					x7=17,y7=8;
					x8=11,y8=4;
					xx=5,yy=4;
					global_counter=1;
				break;

			case	6:
				ending_draw();
				text_screen_init();
				x0=17,y0=12;
				x1=11, y1=8;
				x2=17,y2=4;
				x3=5,y3=12;
				x4=5, y4=4;
				x5=5,y5=8;
				x6=11,y6=12;
				x7=17,y7=8;
				x8=11,y8=4;
				xx=5,yy=4;
				stage_count=1;
				global_counter=0;
				sound_play(10);

				break;

		
		}	

		sys_wait(5);	

	}

	sound_function_end();
	wwc_set_color_mode(COLOR_MODE_GRAYSCALE);
}


int	Init(void)
{
	if(sound_function())	return	1;

	draw_setup();
	global_counter=0;
	stage_count=1;
	time_count=999;

	x0=17,y0=12;
	x1=11, y1=8;
	x2=17,y2=4;
	x3=5,y3=12;
	x4=5, y4=4;
	x5=5,y5=8;
	x6=11,y6=12;
	x7=17,y7=8;
	x8=11,y8=4;
	xx=5,yy=4;

	return 0;

}

