読者です 読者をやめる 読者になる 読者になる

ハートに16連射。(16)


スロットゲームモード(シークレット 2)です。
実機ではリール回転速度が1/100秒で回ってる(?)ようなのですが
こちらは1/60秒で1コマを0〜9の順に表示させてます。
見比べでもしない限りそれっぽく動いてるのでこれで良しとします(笑)。


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


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


slotMode module test


main.c

/*---------------------------------------------------------------------------------
	
	shtwatch
	slotMode 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 "SlotMode.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:
			SlotMode_Update();
			
			if(SlotMode_IsExit()){
				return 0;
			}
			break;
			
		}
		
	}
	
}

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

//---------------------------------------------------------------------------------
void main_Reset(void){
//---------------------------------------------------------------------------------
	
	SlotMode_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;
	
}

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


slotMode.h

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

#ifndef _SLOT_MODE_H_
#define _SLOT_MODE_H_


#ifdef __cplusplus
extern "C" {
#endif


void SlotMode_Clear(void);
void SlotMode_Update(void);
bool SlotMode_IsExit(void);


#ifdef __cplusplus
}
#endif

#endif	//_SLOT_MODE_H_


slotMode.c

/*---------------------------------------------------------------------------------
	
	shtwatch
	slotMode 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 "SlotMode.h"
#include "Spr.h"
#include "State.h"


#define REEL_MAX 4


typedef enum{
	SLOT_MODE_INIT, 
	SLOT_MODE_READY, 
	SLOT_MODE_EXEC, 
	SLOT_MODE_EXIT
}SLOT_MODE_ACT;

typedef struct{
	
	u16 act;
	
	int reel[REEL_MAX];
	int reel_cur;
	
}SlotModeStatus;

static SlotModeStatus st_slot_mode;


void slotMode_Init(void);
void slotMode_Ready(void);
void slotMode_Exec(void);
void slotMode_Exit(void);
void slotMode_ExecReel(void);
void slotMode_DrawReel(void);


//---------------------------------------------------------------------------------
void SlotMode_Clear(void){
//---------------------------------------------------------------------------------
	
	slotMode_Exit();
	
}

//---------------------------------------------------------------------------------
void SlotMode_Update(void){
//---------------------------------------------------------------------------------
	
	switch(st_slot_mode.act){
		
	case SLOT_MODE_INIT:
		slotMode_Init();
		break;
		
	case SLOT_MODE_READY:
		slotMode_Ready();
		break;
		
	case SLOT_MODE_EXEC:
		slotMode_Exec();
		break;
		
	case SLOT_MODE_EXIT:
		slotMode_Exit();
		break;
		
	}
	
}

//---------------------------------------------------------------------------------
void slotMode_Init(void){
//---------------------------------------------------------------------------------
	
	if(State_GetSlotMode() == false){
		st_slot_mode.act = SLOT_MODE_EXIT;
		return;
	}
	
	memset(&st_slot_mode, 0, sizeof(st_slot_mode));
	srand(time(NULL));
	
	Spr_SetColon(0);
	Spr_SetCursor(BIT(4));
	Spr_SetSegment(0, 0, SEG_SECOND);
	slotMode_DrawReel();
	
	st_slot_mode.act = SLOT_MODE_READY;
	
}

//---------------------------------------------------------------------------------
void slotMode_Ready(void){
//---------------------------------------------------------------------------------
	
	if( (keysDown() & KEY_START) && ( (keysCurrent() & ~KEY_START) == 0) ){
		
		st_slot_mode.reel_cur = 0;
		
		int i;
		for(i = st_slot_mode.reel_cur;i < REEL_MAX;i++){
			st_slot_mode.reel[i] = rand() % 10;
		}
		
		st_slot_mode.act = SLOT_MODE_EXEC;
		
	}
	
	
	if( (keysDown() & KEY_SELECT) && ( (keysCurrent() & ~KEY_SELECT) == 0) ){
		st_slot_mode.act = SLOT_MODE_EXIT;
	}
	
}

//---------------------------------------------------------------------------------
void slotMode_Exec(void){
//---------------------------------------------------------------------------------
	
	slotMode_ExecReel();
	
	
	if( (keysDown() & KEY_A) && ( (keysCurrent() & ~KEY_A) == 0) ){
		st_slot_mode.reel_cur++;
	}
	
	if(st_slot_mode.reel_cur == REEL_MAX){
		st_slot_mode.act = SLOT_MODE_READY;
	}
	
	
	if( (keysDown() & KEY_SELECT) && ( (keysCurrent() & ~KEY_SELECT) == 0) ){
		st_slot_mode.act = SLOT_MODE_EXIT;
	}
	
}

//---------------------------------------------------------------------------------
void slotMode_Exit(void){
//---------------------------------------------------------------------------------
	
	Spr_Clear();
	st_slot_mode.act = SLOT_MODE_INIT;
	
}

//---------------------------------------------------------------------------------
void slotMode_ExecReel(void){
//---------------------------------------------------------------------------------
	
	int i;
	
	for(i = st_slot_mode.reel_cur;i < REEL_MAX;i++){
		
		if(st_slot_mode.reel[i] < 9){
			st_slot_mode.reel[i]++;
		}else{
			st_slot_mode.reel[i] = 0;
		}
		
	}
	
	slotMode_DrawReel();
	
}

//---------------------------------------------------------------------------------
void slotMode_DrawReel(void){
//---------------------------------------------------------------------------------
	
	int reel_high, reel_low;
	
	reel_high = (st_slot_mode.reel[0] * 10) + st_slot_mode.reel[1];
	reel_low  = (st_slot_mode.reel[2] * 10) + st_slot_mode.reel[3];
	
	//debug print
	printf("\x01b[9;0H %02d %02d", reel_high, reel_low);
		
	Spr_SetNumber(SEG_HOUR, reel_high, true);
	Spr_SetNumber(SEG_MINUTE, reel_low, true);
	
}

//---------------------------------------------------------------------------------
bool SlotMode_IsExit(void){
//---------------------------------------------------------------------------------
	
	return (st_slot_mode.act == SLOT_MODE_INIT) ? true:false;
	
}

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