//use chain as state machines to slice a single task to many frames void DrawStart(void){//draw start screen if(d==0){//reset menu SelSong=0; SelLevel=0; if (clean==1){cleanscreen();} //clean screen else d++; } else if(d==1){//print title1 video_puts(50,16,parapara); d++; } else if(d==2){//init menu video_puts(15,51,SetSong); video_puts(15,61,song0); d++; } else if(d==3){ video_puts(15,71,song1); video_puts(15,81,song2); d++; } else if(d==4){ video_puts(70,51,level); video_puts(70,61,practice); d++; } else if(d==5){ video_puts(70,71,basic); video_puts(70,81,hard); d++; } else if(d==6){ video_putchar(5, 61, 40); video_putchar(60, 61, 40); d++; } else if(d==7){//init highlight effects video_highlight(14,61+10*SelSong,46,67+10*SelSong); d++; } else if(d==8){ video_highlight(69,61+10*SelLevel,106,67+10*SelLevel); d++; } else if(d==9){//draw logo video_putarrow(10,16,10); video_putarrow(17,16,11); video_putarrow(24,16,12); video_putarrow(31,16,13); d++; } else if(d==10){//draw logo video_putarrow(10,23,14); video_putarrow(17,23,15); video_putarrow(24,23,16); video_putarrow(31,23,17); d++; } else if(d==11){//print title2 video_puts(58,30,revolution); d++; } else if(d==12){//draw screen finished d=0; draw=0; } } void DrawPlaying(void){//draw playing mode screen if (d==0){ if (clean==1){cleanscreen();} //clean screen first else d++; } else if (d==1){//init animation edges video_line(43,1,43,98,1); video_line(85,1,85,98,1); video_line(64,1,64,98,1); video_line(43,10,85,10,1); video_line(43,20,85,20,1); d++; } else if (d==2){//statistic information video_putsmalls(4,60,perfect1); video_putsmalls(88,60,perfect1); video_putsmalls(4,76,good1); video_putsmalls(88,76,good1); video_putsmalls(4,84,miss1); video_putsmalls(88,84,miss1); d++; } else if (d==3){//the pattern of detecting hands waving video_putarrow(30,8,1); video_putarrow(20,16,3); video_putarrow(30,24,7); d++; } else if (d==4){ video_putarrow(90,8,1); video_putarrow(100,16,5); video_putarrow(90,24,7); d++; } else if (d==5){//init animation arrows lpat[0]=pattern[SelSong][0][0]; rpat[0]=pattern[SelSong][1][0]; lpat[1]=pattern[SelSong][0][1]; rpat[1]=pattern[SelSong][1][1]; lpat[2]=pattern[SelSong][0][2]; rpat[2]=pattern[SelSong][1][2]; lpat[3]=pattern[SelSong][0][3]; rpat[3]=pattern[SelSong][1][3]; lpat[4]=pattern[SelSong][0][4]; rpat[4]=pattern[SelSong][1][4]; ypos[0]=15; ypos[1]=33; ypos[2]=51; ypos[3]=69; ypos[4]=87; patflag=0; patnum=4; d++; } else if (d==6){//draw arrows video_putarrow(xl,ypos[0],lpat[0]); video_putarrow(xr,ypos[0],rpat[0]); video_putarrow(xl,ypos[1],lpat[1]); video_putarrow(xr,ypos[1],rpat[1]); video_putarrow(xl,ypos[2],lpat[2]); video_putarrow(xr,ypos[2],rpat[2]); video_putarrow(xl,ypos[3],lpat[3]); video_putarrow(xr,ypos[3],rpat[3]); video_putarrow(xl,ypos[4],lpat[4]); video_putarrow(xr,ypos[4],rpat[4]); d++; } else if (d==7){//reset time, statistics data, animation variables, sensors signals minute=time_minute; sec=time_second; compare_pat=0; L_done=0; R_done=0; L_good=0; R_good=0; L_perfect=0; R_perfect=0; L_miss=0; R_miss=0; time=0; patflag=0; compare_pat=patflag+1; patnum=0; state_y_R=no_state_y_R; state_z_R=no_state_z_R; state_y_L=no_state_y_L; state_z_L=no_state_z_L; axis_flag=0; LHU=0; LHR=0; LHD=0; LHL=0; RHU=0; RHR=0; RHD=0; RHL=0; d=0; draw=0; } } void DrawResult(void){//draw statistic screen and calculate result if(d==0){ if (clean==1) cleanscreen();//clean screen first else d++; } else if(d==1){//init screen video_puts(30,11,statistics); video_puts(30,81,score); d++; } else if(d==2){ video_puts(5,41,hitrate); video_puts(5,51,good1); d++; } else if(d==3){ video_puts(64,31,left); video_puts(92,31,right); d++; } else if(d==4){ video_puts(5,71,miss1); video_puts(5,61,perfect1); d++; } else if(d==5){//calculate hit rates for both hands L_hitrate=100*(L_good+L_perfect)/(L_good+L_perfect+L_miss); d++; } else if(d==6){ R_hitrate=100*(R_good+R_perfect)/(R_good+R_perfect+R_miss); d++; } else if(d==7){//calculate scores final_score=(L_perfect+R_perfect)*4+(L_good+R_good)*3+(R_hitrate+L_hitrate); d++; } else if(d==8){ final_score=final_score*(4+(int)SelLevel); d++; } else if(d==9){ sprintf(ts,"%d",final_score ); video_puts(70,81,ts); d++; } else if(d==10){//print result sprintf(ts,"%d",R_perfect ); video_puts(96,61,ts); sprintf(ts,"%d",R_miss ); video_puts(96,71,ts); sprintf(ts,"%d",L_perfect ); video_puts(72,61,ts); sprintf(ts,"%d",L_miss ); video_puts(72,71,ts); d++; } else if(d==11){ sprintf(ts,"%d\%",R_hitrate ); video_puts(96,41,ts); sprintf(ts,"%d",R_good ); video_puts(96,51,ts); sprintf(ts,"%d\%",L_hitrate ); video_puts(72,41,ts); sprintf(ts,"%d",L_good ); video_puts(72,51,ts); d++; } else if(d==12){ d=0; draw=0; } }