新・ゲームプログラミングの館の 3.4 簡単な選択画面を作る(マイナス方向のループ) を参考にして、ゲームのスタート画面を作りました。
それで、次にスペースを押したら、選択している文字列によって、異なる計算をさせたいのですが、うまくいきません。
以下コードです。
#include "DxLib.h"
int Key[256];
int *menunum;
int menuNo = 0;
int z = 0;
int gpUpdateKey(){
char tmpKey[256];
GetHitKeyStateAll( tmpKey );
for( int i=0; i<256; i++ ){
if( tmpKey[i] != 0 ){
Key[i]++;
} else {
Key[i] = 0;
}
}
return 0;
}
typedef struct{
int x, y;
char name[128];
} MenuElement_t ;
int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE), DxLib_Init(), SetDrawScreen( DX_SCREEN_BACK );
int handle = LoadSoundMem("音楽/Squall -backing track-.mp3");
int backgraph = LoadGraph("画像/pipo-pic001.jpg");
MenuElement_t MenuElement[5]={
{ 80, 100, "ゲームスタート" },
{ 100, 150, "おまけ" },
{ 100, 200, "ヘルプ" },
{ 100, 250, "コンフィグ" },
{ 100, 300, "ゲーム終了" },
};
int SelectNum = 0;
PlaySoundMem(handle,DX_PLAYTYPE_LOOP);
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && gpUpdateKey()==0 && menuNo==0){
DrawGraph(0,0,backgraph,TRUE);
if( Key[ KEY_INPUT_DOWN ] == 1 ){
SelectNum = ( SelectNum + 1 ) % 5;
}
if( Key[ KEY_INPUT_UP ] == 1 ){
SelectNum = ( SelectNum + 4 ) % 5;
}
if( Key[ KEY_INPUT_DOWN ] == 1 || Key[ KEY_INPUT_UP ] == 1 ){
for( int i=0; i<5; i++ ){
if( i == SelectNum ){
MenuElement[i].x = 80;
} else {
MenuElement[i].x = 100;
}
}
}
for( int i=0; i<5; i++ ){
DrawFormatString( MenuElement[i].x, MenuElement[i].y, GetColor(0,0,0), MenuElement[i].name );
}
if( Key[KEY_INPUT_SPACE] ==1){
DeleteSoundMem( handle ) ;
switch (SelectNum){
case 0:
*menunum = 0;
break;
case 1:
*menunum = 1;
break;
case 2:
*menunum = 2;
break;
case 3:
*menunum = 3;
break;
case 4:
*menunum = 4;
break;
}
menuNo = 1;
}
}
if (*menunum == 0){
} else if (*menunum == 1) {
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && gpUpdateKey()==0){
}
} else if (*menunum == 2) {
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && gpUpdateKey()==0){
}
} else if (*menunum == 3) {
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && gpUpdateKey()==0){
}
} else {
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && gpUpdateKey()==0 && z>180){
DrawFormatString( 300, 240, GetColor(255,255,255),"ゲームを終了させます" );
z++;
}
}
DxLib_End();
return 0;
}
5番目の文字列の時スペースを押して、エラーが起きないか試したのですが、計算結果の「ゲームを終了させます」が表示せずにエラーで終了します。
非常に稚拙な質問で恐縮なのですが、答えてくださるとうれしいです。