現在、僕はメニュー画面を作っている最中なのですが、画面の移動ができずに困っています。メニュー画面はhttp://dixq.net/g/03_04.html(新・C言語~ゲームプログラミングの館~3-4)と、
(C言語何でも質問掲示板「画面移動について」)を参考にして作っています。使用OSはwindows7で、C++とDxlibを使用しています。ソースコードを乗せますので、どこが違うか教えてください。
コード:
#include "DxLib.h"
int Key[256];
int menunum;
int menuNo=0;
int z=1;
// キーの入力状態を更新する
int gpUpdateKey(){
char tmpKey[256]; // 現在のキーの入力状態を格納する
GetHitKeyStateAll( tmpKey ); // 全てのキーの入力状態を得る
for( int i=0; i<256; i++ ){
if( tmpKey[i] != 0 ){ // i番のキーコードに対応するキーが押されていたら
Key[i]++; // 加算
} else { // 押されていなければ
Key[i] = 0; // 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 ); //ウィンドウモード変更と初期化と裏画面設定
// メニュー項目要素を5つ作る
MenuElement_t MenuElement[6]={
{ 80, 100, "ゲームスタート" }, // タグの中身の順番で格納される。xに80が、yに100が、nameに"ゲームスタート"が
{ 100, 150, "?????" },
{ 100, 200, "?????" },
{ 100, 250, "レコード" },
{ 100, 300, "オプション" },
{ 100, 350, "ゲーム終了"},
};
int SelectNum = 0; // 現在の選択番号
// while(裏画面を表画面に反映, メッセージ処理, 画面クリア, キー更新)
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && gpUpdateKey()==0 && z<180){
// 計算フェーズ
if( Key[ KEY_INPUT_DOWN ] == 1 ){ // 下キーが押された瞬間だけ処理
SelectNum = ( SelectNum + 1 ) % 6; // 現在の選択項目を一つ下にずらす(ループする)
}
if( Key[ KEY_INPUT_UP ] == 1 ){ // 上キーが押された瞬間だけ処理
SelectNum = ( SelectNum + 5 ) % 6; // 現在の選択項目を一つ上にずらす(逆ループする)
}
if( Key[ KEY_INPUT_DOWN ] == 1 || Key[ KEY_INPUT_UP ] == 1 ){ // 下キーか、上キーが押された瞬間
for( int i=0; i<6; i++ ){ // メニュー項目数である5個ループ処理
if( i == SelectNum ){ // 今処理しているのが、選択番号と同じ要素なら
MenuElement[i].x = 80; // 座標を80にする
} else { // 今処理しているのが、選択番号以外なら
MenuElement[i].x = 100;// 座標を100にする
}
}
}
// 描画フェーズ
for( int i=0; i<6; i++ ){ // メニュー項目を描画
if( i == SelectNum ){
DrawFormatString( MenuElement[i].x-20, MenuElement[i].y, GetColor(255,255,255), MenuElement[i].name );
} else {
DrawFormatString( MenuElement[i].x, MenuElement[i].y, GetColor(255,255,255), MenuElement[i].name );
}
}
if(Key[KEY_INPUT_Z]==1 && z==1)
{
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;
case 5:
DxLib_End();
break;
}
z++;
}
if(Key[KEY_INPUT_X]==1 && z>1 )
{
z--;
}
if(Key[KEY_INPUT_Z]==1 && z==2)
{
if(menunum==0)
{
MenuElement_t MenuElement[4]=
{
{ 80,100,"Easy(徒歩級)"},
{100,150,"Normal(自転車級)"},
{100,200,"Hard(乗用車級)"},
{100,250,"HardPlus(在来線級)"},
};
}else if(menunum==1){
MenuElement_t MenuElement[3]=
{
{ 80,100,"???"},
{100,150,"???"},
{100,200,"???"},
};
}else if(menunum==2){
MenuElement_t MenuElement[2]=
{
{ 80,100,"???"},
{100,150,"???"},
};
z++;
}else if(menunum==3){
MenuElement_t MenuElement[2]=
{
{80,100,"成績"},
{100,150,"ランキング"},
};
z++;
}else{
MenuElement_t MenuElement[2]=
{
{80,100,"BGM音量"},
{100,150,"SE音量"},
};
}
}
}
DxLib_End(); // DXライブラリ終了処理
return 0;
}