ハートに16連射。(8)


タイニーシュウォッチです。思いつきで書き殴ってみました。
1本ソースはわざとで、敢えて初心者入門本でありがちなサンプルソースっぽく仕立ててます。
流石に状態遷移無しでは作れませんが。酷い有様になるのが見えてるし。
C言語知ってるけどゲームは作ったことない人向けな簡単なゲームのソースといったところです。
多少なりとも遊べて、且つ単純な作りのゲームって、実は選抜に困ったり。


息抜きし過ぎっすね。>俺
ジャンケンゲームのリソース作りに苦戦してまして。<言い訳


tiny shooting watch


main.c

/*---------------------------------------------------------------------------------
	
	tiny shooting watch
	
	version 0.01
	Jan 26, 2010
	
	By. REGEKATSU
	
---------------------------------------------------------------------------------*/

#include <nds.h>
#include <stdio.h>
#include <string.h>


typedef enum{
	MAIN_INIT, 
	MAIN_READY, 
	MAIN_START, 
	MAIN_STOP
}MAIN_ACT;

typedef struct{
	
	u16 act;
	
	int score;
	int high_score;
	int time;
	int frame;
	
}MainStatus;

static MainStatus st_main;


//---------------------------------------------------------------------------------
int main(void) {
//---------------------------------------------------------------------------------
	
	memset(&st_main, 0, sizeof(st_main));
	consoleDemoInit();
	iprintf("tiny shooting watch\n\nversion 0.01\nJan 26, 2010\n\nBy. REGEKATSU\n\n");
	
	while(1) {
		
		swiWaitForVBlank();
		scanKeys();
		
		switch(st_main.act){
			
		case MAIN_INIT:
			
			st_main.time = 10;
			st_main.frame = st_main.time * 60;
			
			iprintf("\x01b[8;0Htime      :%3d", st_main.time);
			iprintf("\x01b[9;0Hscore     :%3d", st_main.score);
			iprintf("\x01b[10;0Hhigh score:%3d", st_main.high_score);
			iprintf("\x01b[12;0Hshooting ready?");
			
			st_main.score = 0;
			st_main.act = MAIN_READY;
			break;
			
		case MAIN_READY:
			
			if( ( (keysDown() & KEY_A) && !(keysCurrent() & KEY_B) ) ||
			( (keysDown() & KEY_B) && !(keysCurrent() & KEY_A) ) ){
				st_main.score++;
				st_main.frame--;
				iprintf("\x01b[9;0Hscore     :%3d", st_main.score);
				iprintf("\x01b[12;0Hshooting start!");
				st_main.act = MAIN_START;
			}
			break;
			
		case MAIN_START:
			
			if( ( (keysDown() & KEY_A) && !(keysCurrent() & KEY_B) ) ||
			( (keysDown() & KEY_B) && !(keysCurrent() & KEY_A) ) ){
				st_main.score++;
				iprintf("\x01b[9;0Hscore     :%3d", st_main.score);
			}
			
			if(st_main.frame % 60 == 0){
				st_main.time--;
				iprintf("\x01b[8;0Htime      :%3d", st_main.time);
			}
			
			if(st_main.frame != 0){
				st_main.frame--;
				
			}else{
				iprintf("\x01b[12;0Hshooting stop! ");
				
				if(st_main.score > st_main.high_score){
					st_main.high_score = st_main.score;
				}
				st_main.act = MAIN_STOP;
			}
			
			break;
			
		case MAIN_STOP:
			
			if(keysDown() & (KEY_A | KEY_B)){
				st_main.act = MAIN_INIT;
			}
			break;
			
		}
		
	}
	
}

//---------------------------------------------------------------------------------