#include "DxLib.h"
int Key[256]; // キーが押されているフレーム数を格納する
// キーの入力状態を更新する
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[5]={
{ 80, 100, "ゲームスタート" }, // タグの中身の順番で格納される。xに80が、yに100が、nameに"ゲームスタート"が
{ 100, 150, "おまけ" },
{ 100, 200, "ヘルプ" },
{ 100, 250, "コンフィグ" },
{ 100, 300, "ゲーム終了" },
};
int SelectNum = 0; // 現在の選択番号
// while(裏画面を表画面に反映, メッセージ処理, 画面クリア, キー更新)
while( ScreenFlip()==0 && ProcessMessage()==0 && ClearDrawScreen()==0 && gpUpdateKey()==0 ){
// 計算フェーズ
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++ ){ // メニュー項目数である5個ループ処理
if( i == SelectNum ){ // 今処理しているのが、選択番号と同じ要素なら
MenuElement[i].x = 80; // 座標を80にする
} else { // 今処理しているのが、選択番号以外なら
MenuElement[i].x = 100;// 座標を100にする
}
}
}
// 描画フェーズ
for( int i=0; i<5; i++ ){ // メニュー項目を描画
DrawFormatString( MenuElement[i].x, MenuElement[i].y, GetColor(255,255,255), MenuElement[i].name );
}
}
DxLib_End(); // DXライブラリ終了処理
return 0;
}
#include "DxLib.h"
int function_status=0,White;
char KeyBuf[ 256 ] ;
void Opening(){
DrawString(100,100,"オープニング画面 (zをプッシュ)",White);
if(KeyBuf[KEY_INPUT_Z]==1)
function_status=1;
}
void Menu(){
DrawString(100,140,"メニュー画面 (xをプッシュ)",White);
if(KeyBuf[KEY_INPUT_X]==1)
function_status=2;
}
void Danjon(){
DrawString(100,180,"ダンジョン画面 (cをプッシュ)",White);
if(KeyBuf[KEY_INPUT_C]==1)
function_status=3;
}
void attack(){
DrawString(100,220,"戦闘画面 (vをプッシュ)",White);
if(KeyBuf[KEY_INPUT_V]==1)
function_status=4;
}
void Ending(){
DrawString(100,260,"エンディング画面 (bをプッシュ)",White);
if(KeyBuf[KEY_INPUT_B]==1)
function_status=5;
}
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow ){
ChangeWindowMode( TRUE ) ; //ウィンドウモードに変更
if( DxLib_Init() == -1 ) return -1; // DXライブラリ初期化処理 エラーが起きたら終了
White = GetColor( 255 , 255 , 255 ) ; //色の取得
SetDrawScreen( DX_SCREEN_BACK ) ; // 描画先を裏画面に設定
while( 1 ){
ClearDrawScreen(); // 裏画面のデータを全て削除
GetHitKeyStateAll( KeyBuf ) ; // すべてのキーの状態を得る
switch(function_status){
case 0:
Opening();
break;
case 1:
Menu();
break;
case 2:
Danjon();
break;
case 3:
attack();
break;
case 4:
Ending();
break;
default:
DxLib_End() ; // DXライブラリ使用の終了処理
return 0;
break;
}
if( ProcessMessage() == -1 ) break ; //エラーが起きたら終了
ScreenFlip() ; // 裏画面データを表画面へ反映
}
DxLib_End() ; // DXライブラリ使用の終了処理
return 0 ; // ソフトの終了
}
キーを押したときの次の画面へ進める方法がいまいち、わからなくて、
下のソースだと、選択文字が一文ずつしかひょうじできないので、・・・・
要点をまとめると
・選択メニューが何列でも表示できて、決定キーみたいなのは、一つのキーで行いたい
*これでわからなかったらすいません(説明が下手なもので・・・