メニュー画面からゲーム画面へうまくいけないです。基本メニュー画面は動作正常。
ゲーム開始選んだらバグる、そしてゲーム説明の画面行ってからゲーム画面行って続こうとしたら何キー押しても無反応。
よろしくお願いいたします。
#include "DxLib.h"
////自作関数
int Game();
int Arasuzi();
int ume();
int take();
int matu();
int Key[256];
int gpUpdateKey()
{
char key[256];
GetHitKeyStateAll(key);
for(int i = 0; i < 256; i++)
{
if ( key[i] != 0)
{
Key[i]++;
}
else
{
Key[i] = 0;
}
}
return 0;
}
///色
int White = GetColor(255, 255, 255);
int Red = GetColor(255, 0, 0);
///menu構造体
typedef struct {
int x, y;
char name[ 128 ];
}MenuElement_t;
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int)
{
/// ウインドウモード
ChangeWindowMode(TRUE);
SetGraphMode(1024, 768,32);
// DXライブラリの初期化
DxLib_Init();
///裏画面設定
SetDrawScreen(DX_SCREEN_BACK);
PlayMusic("BGM.mp3", DX_PLAYTYPE_LOOP);
/////メニュー画面
////操作説明
int x = 100, y = 300;
MenuElement_t MenuElement[3]={
{80,100,"ゲーム説明"},{100,150,"ゲーム開始"},{100,200,"ゲーム終了"}
};
int SelectNum = 0;
////裏画面を表画面反映&メッセージ処理&画面クリア&キーの状態更新
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && gpUpdateKey() == 0)
{
DrawFormatString(50, 50, White, "【焼肉の神】");
////選択処理
if (Key[KEY_INPUT_DOWN] == 1)
{
SelectNum = (SelectNum + 1) % 3;
}
if ( Key[KEY_INPUT_UP] == 1)
{
SelectNum = (SelectNum + 2) % 3;
}
if (Key[KEY_INPUT_DOWN] == 1 || Key[KEY_INPUT_UP] == 1)
{
for (int i = 0; i < 3; i++)
{
if (i == SelectNum)
{
MenuElement[i].x = 80;
}
else
{
MenuElement[i].x = 100;
}
}
}
////ゲーム説明
if (Key[KEY_INPUT_RETURN] == 1 && MenuElement[SelectNum].y == 100)
{
ClearDrawScreen();
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && gpUpdateKey() == 0)
{
Arasuzi();
}
ScreenFlip();
}
////ゲーム終了処理
if (Key[KEY_INPUT_RETURN] == 1 && MenuElement[SelectNum].y == 200)
{
break;
}
/////ゲーム画面処理
if (Key[KEY_INPUT_RETURN] == 1 && MenuElement[SelectNum].y == 150)
{
SetDrawScreen(DX_SCREEN_BACK);
ScreenFlip();
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && gpUpdateKey() == 0)
{
Game();
}
}
///描画処理
for (int i = 0; i < 5; i++)
{
DrawFormatString(MenuElement[i].x, MenuElement[i].y, GetColor(255, 255, 255), MenuElement[i].name);
}
DrawFormatString(x, y, White, "【下キーを押して選択、Enterキー押して動作】");
ScreenFlip();
}
// DXライブラリの後始末
DxLib_End();
// ソフトの終了
return 0;
}
int Arasuzi(void)
{
printfDx("\n");
printfDx("◎焼肉の神は俺がなる!\n");
printfDx("あらすじ:\n");
printfDx("ある日、<焼肉の王>という焼肉屋さんは焼肉の神を求めていた―\n");
printfDx("「当店三つのコースのメニューそして出されている肉の種類を覚えるお客様は当店の永世VIPになります。\n");
printfDx(" つまり、いつでも当店のご利用は無料になります。」\n");
printfDx("\n");
printfDx("貧乏学生のあなたの戦いは、いざ開幕ーー\n");
printfDx("\n");
printfDx("◎操作説明:");
printfDx("各コースのメニューを覚えてください。\n");
printfDx("梅コース3品、竹コース4品、松コース5品っていう形で難易度が違います。\n");
printfDx("一品には二つ種類の肉が出されます。メニューに書いてある方を見分けて答えを入力しましょう。\n");
printfDx("\n");
printfDx("頑張って全コース制覇しましょう!\n");
printfDx("\n");
printfDx("【ESCキーでそのままゲームはじめます。】\n");
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && gpUpdateKey() == 0)
{
ClearDrawScreen();
if (Key[KEY_INPUT_RETURN] == 1)
{
Game();
}
ScreenFlip();
}
return 0;
}
int Game(void)
{
ClearDrawScreen();
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && gpUpdateKey() == 0)
{
printfDx("コースを選んでください(対応するキーを押してください)\n");
printfDx("上キー.梅コース 右キー.竹コース SPACEキー.松コース\n");
if (Key[KEY_INPUT_UP] == 1)
{
ume();
}
if (Key[KEY_INPUT_RIGHT] == 1)
{
take();
}
if (Key[KEY_INPUT_SPACE] == 1)
{
matu();
}
break;
}
ScreenFlip();
return 0;
}
int ume(void)
{
while (ScreenFlip() == 0 && ProcessMessage() == 0 && ClearDrawScreen() == 0 && gpUpdateKey() == 0)
{
ClearDrawScreen();
printfDx("梅コースのメニューは以下となります。\n");
printfDx("カルビ、ハラミ、ロース。\n");
ScreenFlip();
////一品目
////画像表示
ClearDrawScreen();
printfDx("\n");
printfDx("カルビはどちらですか?(右ならAを入力、左ならBを入力)\n");
int Harami;
Harami = LoadGraph("ハラミ.png");
DrawGraph(50, 100, Harami, TRUE);
int Karubi;
Karubi = LoadGraph("カルビ.png");
DrawGraph(450, 100, Karubi, TRUE);
if (Key[KEY_INPUT_A] == 1)
{
printfDx("正解です!\n");
////二品目
printf("\n");
printf("ハラミはどちらですか?(右ならAを入力、左ならSを入力)\n");
int Harami;
Harami = LoadGraph("ハラミ.png");
DrawGraph(50, 100, Harami, TRUE);
int rose;
rose = LoadGraph("ロース.png");
DrawGraph(450, 100, rose, TRUE);
if (Key[KEY_INPUT_A] == 1)
{
printf("正解です!\n");
////三品目
printf("\n");
printf("ロースはどちらですか?(右ならAを入力、左ならSを入力)\n");
int Karubi;
Karubi = LoadGraph("カルビ.png");
DrawGraph(50, 100, Karubi, TRUE);
int rose;
rose = LoadGraph("ロース.png");
DrawGraph(450, 100, rose, TRUE);
if (Key[KEY_INPUT_A] == 1)
{
DrawFormatString(100, 100, Red, "正解です!\n");
DrawFormatString(100, 200, Red, "梅コースクリアです!\n");
DrawFormatString(100, 400, Red, "Enterキーでゲーム終了です");
if (Key[KEY_INPUT_RETURN] == 1)
{
break;
}
}
else
{
DrawFormatString(100, 100, Red, "間違えました。また次回です。\n");
return 0;
}
}
else
{
DrawFormatString(100, 100, Red, "間違えました。また次回です。\n");
return 0;
}
}
else
{
DrawFormatString(100, 100, Red, "間違えました。また次回です。\n");
return 0;
}
ScreenFlip();
}
return 0;
}