#include	"global.h"

void	game(void);

int	x0,y0,x1,y1,x2,y2,x3,y3,x4,y4,x5,y5,x6,y6,x7,y7,x8,y8;
int xx,yy;

/*メイン処理*/
void	game( void )
{
	draw();

	/* カーソル表示 */
	cursor_display(1);
	cursor_set_type( 3, 30 );
	if(xx>=5 && xx<18 && yy>=4 && yy<13){
		cursor_set_location( xx, yy, 6, 4 );
	}

	/* アイコン移動 */
	if(key == KEY_X2){
		if(xx<16){
			xx+=6;
		}
		else{
			xx=17;
		}
	}	
	if(key == KEY_X1){
		if(yy>4){
			yy-=4;
		}
		else{
			yy=4;
		}
	}
	if(key == KEY_X3){
		if(yy<12){
			yy+=4;
		}
		else{
			yy=12;
		}
	}
	if(key == KEY_X4){
		if(xx>5){
			xx-=6;
		}
		else{
			xx=5;
		}
	}
	/* パネル移動 */
	if(xx==x1 && yy==y1){
		if(key == KEY_B){
			/*sound_playx((stage_count-1)*10+1);*/
			if(stage_count==1)sound_playx(19);
			else if(stage_count>=2) sound_playx((stage_count-1)*10+1);			
		}
		else if(key == KEY_A){
			if((x1-6)==x0 && y1 ==y0) x1-=6,x0+=6;
			else if((x1+6)==x0 && y1==y0) x1+=6,x0-=6;
			else if((y1-4)==y0 && x1==x0) y1-=4,y0+=4;
			else if((y1+4)==y0 && x1==x0) y1+=4,y0-=4;
		}
	}
	else if(xx==x2 && yy==y2){
		if(key == KEY_B){
			if(stage_count==1)sound_playx(29);
			else if(stage_count>=2) sound_playx((stage_count-1)*10+2);			
		}
		else if(key == KEY_A){
			if((x2-6)==x0 && y2 ==y0) x2-=6,x0+=6;
			else if((x2+6)==x0 && y2==y0) x2+=6,x0-=6;
			else if((y2-4)==y0 && x2==x0) y2-=4,y0+=4;
			else if((y2+4)==y0 && x2==x0) y2+=4,y0-=4;
		}
	}
	else if(xx==x3 && yy==y3){
		if(key == KEY_B){
			sound_playx((stage_count-1)*10+3);
		}
		else if(key == KEY_A){
			if((x3-6)==x0 && y3 ==y0) x3-=6,x0+=6;
			else if((x3+6)==x0 && y3==y0) x3+=6,x0-=6;
			else if((y3-4)==y0 && x3==x0) y3-=4,y0+=4;
			else if((y3+4)==y0 && x3==x0) y3+=4,y0-=4;
		}
	}
	else if(xx==x4 && yy==y4){
		if(key == KEY_B){
			sound_playx((stage_count-1)*10+4);
		}
		else if(key == KEY_A){
			if((x4-6)==x0 && y4 ==y0) x4-=6,x0+=6;
			else if((x4+6)==x0 && y4==y0) x4+=6,x0-=6;
			else if((y4-4)==y0 && x4==x0) y4-=4,y0+=4;
			else if((y4+4)==y0 && x4==x0) y4+=4,y0-=4;
		}
	}
	 if(xx==x5 && yy==y5){
		if(key == KEY_B){
			sound_playx((stage_count-1)*10+5);
		}
		else if(key == KEY_A){
			if((x5-6)==x0 && y5 ==y0) x5-=6,x0+=6;
			else if((x5+6)==x0 && y5==y0) x5+=6,x0-=6;
			else if((y5-4)==y0 && x5==x0) y5-=4,y0+=4;
			else if((y5+4)==y0 && x5==x0) y5+=4,y0-=4;
		}
	}
	else if(xx==x6 && yy==y6){
		if(key == KEY_B){
			sound_playx((stage_count-1)*10+6);
		}
		else if(key == KEY_A){
			if((x6-6)==x0 && y6 ==y0) x6-=6,x0+=6;
			else if((x6+6)==x0 && y6==y0) x6+=6,x0-=6;
			else if((y6-4)==y0 && x6==x0) y6-=4,y0+=4;
			else if((y6+4)==y0 && x6==x0) y6+=4,y0-=4;
		}
	}
	else if(xx==x7 && yy==y7){
		if(key == KEY_B){
			sound_playx((stage_count-1)*10+7);
		}
		else if(key == KEY_A){
			if((x7-6)==x0 && y7 ==y0) x7-=6,x0+=6;
			else if((x7+6)==x0 && y7==y0) x7+=6,x0-=6;
			else if((y7-4)==y0 && x7==x0) y7-=4,y0+=4;
			else if((y7+4)==y0 && x7==x0) y7+=4,y0-=4;
		}
	}
	else if(xx==x8 && yy==y8){
		if(key == KEY_B){
			sound_playx((stage_count-1)*10+8);
		}
		else if(key == KEY_A){
			if((x8-6)==x0 && y8 ==y0) x8-=6,x0+=6;
			else if((x8+6)==x0 && y8==y0) x8+=6,x0-=6;
			else if((y8-4)==y0 && x8==x0) y8-=4,y0+=4;
			else if((y8+4)==y0 && x8==x0) y8+=4,y0-=4;
		}
	}
	

	

}

