デモプレイを実装。
タイトル画面で一定時間なにもしないでいるとデモプレイに遷移する。
CPU 操作で行われるような一般的なデモプレイではなくタイムアタックのようなモード。
45秒間のデモ動作中に何連射できるか測定が可能。
但しスコアは保持されない。おまけプログラムとも言う。
デモ動作時間を経過するか、スタートボタンを押すことでタイトル画面へ戻る。
…そろそろちゃんとしたスプライトとバックグラウンドを取り込もうかと思う。
Demo.h
/*--------------------------------------------------------------------------------- shtwatch demo module header version 0.01 Feb 13, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #ifndef _DEMO_H_ #define _DEMO_H_ #ifdef __cplusplus extern "C" { #endif void Demo_Clear(void); void Demo_Update(void); #ifdef __cplusplus } #endif #endif //_DEMO_H_
Demo.c
/*--------------------------------------------------------------------------------- shtwatch demo module routine version 0.01 Feb 13, 2010 By. REGEKATSU ---------------------------------------------------------------------------------*/ #include <stdio.h>//debug print #include <string.h> #include <nds/ndstypes.h> #include <nds/arm9/input.h> #include "Demo.h" #include "Exec.h" #include "Spr.h" #define END_TIME 45 #define SET_TIME(x) ((x)*60) typedef enum{ DEMO_INIT, DEMO_EXEC, DEMO_EXIT }DEMO_ACT; typedef struct{ u16 act; u32 frame; int time; int score; }DemoStatus; static DemoStatus st_demo; void demo_Init(void); void demo_Exec(void); void demo_Exit(void); void demo_ExecTime(void); void demo_DrawTime(int time); void demo_ExecScore(void); void demo_DrawScore(int score); //--------------------------------------------------------------------------------- void Demo_Clear(void){ //--------------------------------------------------------------------------------- demo_Exit(); } //--------------------------------------------------------------------------------- void Demo_Update(void){ //--------------------------------------------------------------------------------- switch(st_demo.act){ case DEMO_INIT: demo_Init(); break; case DEMO_EXEC: demo_Exec(); break; case DEMO_EXIT: demo_Exit(); break; } } //--------------------------------------------------------------------------------- void demo_Init(void){ //--------------------------------------------------------------------------------- memset(&st_demo, 0, sizeof(st_demo)); st_demo.frame = SET_TIME(END_TIME); Spr_SetColon(0); Spr_SetCursor(0); demo_DrawTime(st_demo.time); demo_DrawScore(st_demo.score); st_demo.frame--; st_demo.act = DEMO_EXEC; } //--------------------------------------------------------------------------------- void demo_Exec(void){ //--------------------------------------------------------------------------------- if( ( ( (keysDown() & KEY_A) && !(keysCurrent() & KEY_B) ) || ( (keysDown() & KEY_B) && !(keysCurrent() & KEY_A) ) ) && ( (keysCurrent() & ~(KEY_A | KEY_B)) == 0) ) { demo_ExecScore(); } if(st_demo.frame % SET_TIME(1) == 0){ demo_ExecTime(); } //一定時間が経過、またはスタートボタンが押されたらタイトルへ遷移する。 if(st_demo.frame != 0){ st_demo.frame--; }else{ st_demo.act = DEMO_EXIT; } if( (keysDown() & KEY_START) && ( (keysCurrent() & ~KEY_START) == 0) ){ st_demo.act = DEMO_EXIT; } } //--------------------------------------------------------------------------------- void demo_Exit(void){ //--------------------------------------------------------------------------------- printf("\x01b[2J");//debug print Spr_Clear(); Exec_SetAction(EXEC_TITLE); st_demo.act = DEMO_INIT; } //--------------------------------------------------------------------------------- void demo_ExecTime(void){ //--------------------------------------------------------------------------------- st_demo.time++; demo_DrawTime(st_demo.time); } //--------------------------------------------------------------------------------- void demo_DrawTime(int time){ //--------------------------------------------------------------------------------- printf("\x01b[9;5H%2d", time);//debug print Spr_SetNumber(SEG_SECOND, time, false); } //--------------------------------------------------------------------------------- void demo_ExecScore(void){ //--------------------------------------------------------------------------------- if(st_demo.score < 9999){ st_demo.score++; } demo_DrawScore(st_demo.score); } //--------------------------------------------------------------------------------- void demo_DrawScore(int score){ //--------------------------------------------------------------------------------- printf("\x01b[9;0H%4d", score);//debug print if(score == 0){ Spr_SetNumber(SEG_MINUTE, score, false); Spr_SetSegment(0, 0, SEG_HOUR); }else if(score < 100){ Spr_SetNumber(SEG_MINUTE, score, false); Spr_SetSegment(0, 0, SEG_HOUR); }else if(score <= 9999){ Spr_SetNumber(SEG_MINUTE, score % 100, true); Spr_SetNumber(SEG_HOUR, score / 100, false); } } //---------------------------------------------------------------------------------