ハートに16連射。(18)


サイコロゲームモード(シークレット 1)です。
サイコロを止めてく毎に残りのサイコロの回転速度が上昇してく以外は
スロットゲームと殆ど同じです。


ビルドには下記ソース以外に、
「ハートに16連射。(12)」に記した全てのモジュールが必要だったり…。


ハートに16連射。(12)
http://d.hatena.ne.jp/dumbo001/20100201/p1


diceMode module test


main.c

/*---------------------------------------------------------------------------------
	
	shtwatch
	diceMode module test
	
	version 0.01
	Feb 03, 2010
	
	By. REGEKATSU
	
---------------------------------------------------------------------------------*/

#include <string.h>
#include <nds/ndstypes.h>
#include <nds/interrupts.h>
#include <nds/system.h>
#include <nds/arm9/input.h>
#include "Bg.h"
#include "Spr.h"
#include "State.h"
#include "DiceMode.h"


typedef enum{
	MAIN_INIT, 
	MAIN_RESET, 
	MAIN_EXEC
}MAIN_ACT;

typedef struct{
	u16 act;
}MainStatus;

static MainStatus st_main;


void main_Init(void);
void main_Reset(void);
bool main_IsReset(void);


//---------------------------------------------------------------------------------
int main(void){
//---------------------------------------------------------------------------------
	
	lcdSwap();
	
	while(1) {
		swiWaitForVBlank();
		scanKeys();
		
		Spr_Update();
		
		if(main_IsReset()){
			st_main.act = MAIN_RESET;
		}
		
		switch(st_main.act){
			
		case MAIN_INIT:
			main_Init();
			st_main.act = MAIN_RESET;
			break;
			
		case MAIN_RESET:
			main_Reset();
			st_main.act = MAIN_EXEC;
			break;
			
		case MAIN_EXEC:
			DiceMode_Update();
			
			if(DiceMode_IsExit()){
				return 0;
			}
			break;
			
		}
		
	}
	
}

//---------------------------------------------------------------------------------
void main_Init(void){
//---------------------------------------------------------------------------------
	
	memset(&st_main, 0, sizeof(st_main));
	Bg_Init();
	Spr_Init();
	State_Init();
	
	State_SetDiceMode(true);
	
	Bg_DrawConsString(0, 0, "diceMode module test\n\nversion 0.01\nFeb 03, 2010\n\nBy. REGEKATSU\n\n\n");
	
}

//---------------------------------------------------------------------------------
void main_Reset(void){
//---------------------------------------------------------------------------------
	
	DiceMode_Clear();
	
}

//---------------------------------------------------------------------------------
bool main_IsReset(void){
//---------------------------------------------------------------------------------
	
	bool ans = false;
	
	u32 keys;
	
	if(keysDown() & (KEY_L | KEY_R | KEY_SELECT | KEY_START)){
		
		keys = keysDown() | keysHeld();
		keys = keys & (KEY_L | KEY_R | KEY_SELECT | KEY_START);
		
		if(keys == (KEY_L | KEY_R | KEY_SELECT | KEY_START)){
			ans = true;
		}
		
	}
	
	return ans;
	
}

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


diceMode.h

/*---------------------------------------------------------------------------------
	
	shtwatch
	diceMode module header
	
	version 0.01
	Feb 03, 2010
	
	By. REGEKATSU
	
---------------------------------------------------------------------------------*/

#ifndef _DICE_MODE_H_
#define _DICE_MODE_H_


#ifdef __cplusplus
extern "C" {
#endif


void DiceMode_Clear(void);
void DiceMode_Update(void);
bool DiceMode_IsExit(void);


#ifdef __cplusplus
}
#endif

#endif	//_DICE_MODE_H_


diceMode.c

/*---------------------------------------------------------------------------------
	
	shtwatch
	diceMode module routine
	
	version 0.01
	Feb 03, 2010
	
	By. REGEKATSU
	
---------------------------------------------------------------------------------*/

#include <stdio.h>//debug print
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <nds/ndstypes.h>
#include <nds/arm9/input.h>
#include "DiceMode.h"
#include "Spr.h"
#include "State.h"


#define DICE_MAX 3
#define SET_WAIT(x) (2-(x))


typedef enum{
	DICE_MODE_INIT, 
	DICE_MODE_READY, 
	DICE_MODE_EXEC, 
	DICE_MODE_EXIT
}DICE_MODE_ACT;

typedef struct{
	
	u16 act;
	
	int dice[DICE_MAX];
	int dice_cur;
	int dice_wait;
	
}DiceModeStatus;

static DiceModeStatus st_dice_mode;


void diceMode_Init(void);
void diceMode_Ready(void);
void diceMode_Exec(void);
void diceMode_Exit(void);
void diceMode_ExecDice(void);
void diceMode_DrawDice(void);


//---------------------------------------------------------------------------------
void DiceMode_Clear(void){
//---------------------------------------------------------------------------------
	
	diceMode_Exit();
	
}

//---------------------------------------------------------------------------------
void DiceMode_Update(void){
//---------------------------------------------------------------------------------
	
	switch(st_dice_mode.act){
		
	case DICE_MODE_INIT:
		diceMode_Init();
		break;
		
	case DICE_MODE_READY:
		diceMode_Ready();
		break;
		
	case DICE_MODE_EXEC:
		diceMode_Exec();
		break;
		
	case DICE_MODE_EXIT:
		diceMode_Exit();
		break;
		
	}
	
}

//---------------------------------------------------------------------------------
void diceMode_Init(void){
//---------------------------------------------------------------------------------
	
	if(State_GetDiceMode() == false){
		st_dice_mode.act = DICE_MODE_EXIT;
		return;
	}
	
	memset(&st_dice_mode, 0, sizeof(st_dice_mode));
	srand(time(NULL));
	
	Spr_SetColon(0);
	Spr_SetCursor(BIT(3));
	Spr_SetSegment(0, 0, SEG_SECOND);
	diceMode_DrawDice();
	
	st_dice_mode.act = DICE_MODE_READY;
	
}

//---------------------------------------------------------------------------------
void diceMode_Ready(void){
//---------------------------------------------------------------------------------
	
	if( (keysDown() & KEY_START) && ( (keysCurrent() & ~KEY_START) == 0) ){
		
		st_dice_mode.dice_cur = 0;
		
		int i;
		for(i = st_dice_mode.dice_cur;i < DICE_MAX;i++){
			st_dice_mode.dice[i] = rand() % 6 + 1;
		}
		
		st_dice_mode.act = DICE_MODE_EXEC;
		
	}
	
	
	if( (keysDown() & KEY_SELECT) && ( (keysCurrent() & ~KEY_SELECT) == 0) ){
		st_dice_mode.act = DICE_MODE_EXIT;
	}
	
}

//---------------------------------------------------------------------------------
void diceMode_Exec(void){
//---------------------------------------------------------------------------------
	
	diceMode_ExecDice();
	
	
	if( (keysDown() & KEY_A) && ( (keysCurrent() & ~KEY_A) == 0) ){
		st_dice_mode.dice_cur++;
	}
	
	if(st_dice_mode.dice_cur == DICE_MAX){
		st_dice_mode.act = DICE_MODE_READY;
	}
	
	
	if( (keysDown() & KEY_SELECT) && ( (keysCurrent() & ~KEY_SELECT) == 0) ){
		st_dice_mode.act = DICE_MODE_EXIT;
	}
	
}

//---------------------------------------------------------------------------------
void diceMode_Exit(void){
//---------------------------------------------------------------------------------
	
	Spr_Clear();
	st_dice_mode.act = DICE_MODE_INIT;
	
}

//---------------------------------------------------------------------------------
void diceMode_ExecDice(void){
//---------------------------------------------------------------------------------
	
	if(st_dice_mode.dice_wait != 0){
		st_dice_mode.dice_wait--;
		return;
	}
	
	st_dice_mode.dice_wait = SET_WAIT(st_dice_mode.dice_cur);
	
	int i;
	for(i = st_dice_mode.dice_cur;i < DICE_MAX;i++){
		
		if(st_dice_mode.dice[i] < 6){
			st_dice_mode.dice[i]++;
		}else{
			st_dice_mode.dice[i] = 1;
		}
		
	}
	
	diceMode_DrawDice();
	
}

//---------------------------------------------------------------------------------
void diceMode_DrawDice(void){
//---------------------------------------------------------------------------------
	
	int dice_high, dice_low;
	
	dice_high = st_dice_mode.dice[0];
	dice_low  = (st_dice_mode.dice[1] * 10) + st_dice_mode.dice[2];
	
	//debug print
	printf("\x01b[9;0H %2d %02d", dice_high, dice_low);
		
	Spr_SetNumber(SEG_HOUR, dice_high, false);
	Spr_SetNumber(SEG_MINUTE, dice_low, true);
	
}

//---------------------------------------------------------------------------------
bool DiceMode_IsExit(void){
//---------------------------------------------------------------------------------
	
	return (st_dice_mode.act == DICE_MODE_INIT) ? true:false;
	
}

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