DXライブラリを使ったゲーム制作で・・・

フォーラム(掲示板)ルール
フォーラム(掲示板)ルールはこちら  ※コードを貼り付ける場合は [code][/code] で囲って下さい。詳しくはこちら
風神雷神

DXライブラリを使ったゲーム制作で・・・

#1

投稿記事 by 風神雷神 » 11年前

下に記載するプログラミングでRPGの戦闘画面を制作しています。
初期画面→ボタン入力で技の選択画面→技の選択→敵ダメージ値の減少→敵ダメージの値が0になれば次の戦闘へ
という工程が制作したいのですが、
技の選択→敵ダメージ値の減少の過程で思うようにいきません。

1、選択画面で下キーを押したら移動を開始してほしいのに、「下キー→Zキー」を押さないと項目が下に行かない。

2、ダメージ計算を行うにあたりダメージが20ずつしか減少しない。

この2つの原因はなんなのでしょうか?
_______________________________________
#include "DxLib.h"
int Key[256]; // キーが押されているフレーム数を格納する

// キーの入力状態を更新する
int gpUpdateKey(){
char tmpKey[256]; // 現在のキーの入力状態を格納する
GetHitKeyStateAll( tmpKey ); // 全てのキーの入力状態を得る
for( int i=0; i<256; i++ ){
if( tmpKey != 0 ){ // i番のキーコードに対応するキーが押されていたら
Key++; // 加算
} else { // 押されていなければ
Key = 0; // 0にする
}
}
return 0;
}
typedef struct{
int x,y;
char name[128];
} MenuElement_t ;

int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int){
ChangeWindowMode(TRUE); //ウィンドウモード
SetWindowSizeChangeEnableFlag(TRUE);//ウィンドウモードサイズ変更
DxLib_Init(); //初期化

LoadGraphScreen(0,0,"op.jpg",TRUE);

int op,Count=0;
op=LoadSoundMem("op.mp3");
PlaySoundMem(op,DX_PLAYTYPE_BACK);
WaitKey();




MenuElement_t MenuElement[5]={
{ 450,250,"昇竜拳"},
{ 450,300,"竜巻旋風脚"},
{ 450,350,"ヨガファイア"},
{ 450,400,"ヨガフレイム"},
{ 450,450,"火中天津甘栗拳"},
};
int SelectNum = 0;
int x=0;
while(ScreenFlip() == 0&&
ProcessMessage()==0&&ClearDrawScreen()==0&&gpUpdateKey()==0){
if(Key[ KEY_INPUT_DOWN] == 1){
SelectNum = (SelectNum +1) %5;
for(int i=0; i<5; i++){
if( i== SelectNum){
MenuElement.x=430;
}else{
MenuElement.x=450;
}
}
if(Key[KEY_INPUT_Z] == 1){
if(SelectNum == 1){
DrawFormatString(250,175,GetColor(255,255,255),"10ダメージ");
}else if(SelectNum == 2){
DrawFormatString(250,175,GetColor(255,255,255),"20ダメージ");
}else if(SelectNum == 3){
DrawFormatString(250,175,GetColor(255,255,255),"30ダメージ");
}else if(SelectNum == 4){
DrawFormatString(250,175,GetColor(255,255,255),"40ダメージ");
}else if(SelectNum == 5){
DrawFormatString(250,175,GetColor(255,255,255),"50ダメージ");
}

}



if(vz<=0)
LoadGraphScreen(0,0,"op.jpg",TRUE);
WaitKey();
}
for(int i=0; i<5; i++){
DrawFormatString( MenuE
int damage;
int life;
int vx,vy,vz;

if(SelectNum == 0){
damage=10;
}else if(SelectNum == 1){
damage=20;
}else if(SelectNum == 2){
damage=30;
}else if(SelectNum == 3){
damage=40;
}else if(SelectNum == 4){
damage=50;
}
vx=100;
vy=damage;
life = vx - damage;
vz=life-damage;

DrawFormatString(0,0,GetColor(255,255,255),"%d",vz);
WaitKey(); lement.x,
MenuElement.y,GetColor(255,255,255),MenuElement.name);
}
}
return 0;
}

アバター
みけCAT
記事: 6734
登録日時: 13年前
住所: 千葉県
連絡を取る:

Re: DXライブラリを使ったゲーム制作で・・・

#2

投稿記事 by みけCAT » 11年前

まずコードはcodeタグで囲んでいただけるとありがたいです。

ソースコードを見る限り、コンパイルエラーが出そうですね。

コード:

if(vz<=0)
に有効な範囲で変数vzの宣言が見つかりません。

コード:

DrawFormatString( MenuE
これはどう考えてもコンパイルエラーですね。

コード:

 lement[i].x,
			MenuElement[i].y,GetColor(255,255,255),MenuElement[i].name);
とおそらく繋がるのでしょう。
Zキーを押した時にしか描画していませんし、WaitKeyはなるべく使うべきではありません。
最後に編集したユーザー みけCAT on 2013年1月31日(木) 21:36 [ 編集 1 回目 ]
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

zxc
記事: 79
登録日時: 11年前
住所: 日本の背骨(?)あたり

Re: DXライブラリを使ったゲーム制作で・・・

#3

投稿記事 by zxc » 11年前

  コードタグとインデントで見やすく整理したほうが、ミスが減ると思いますし、問題が分かりやすくなるので今後お願いします。
気になったので自分なりに整理しましたが、これ動くんでしょうか?
最後にDxlib_End関数が無いのは、結構まずいような気がします。関数の括弧の対応等もあってますか?

コード:

#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); //ウィンドウモード
	SetWindowSizeChangeEnableFlag(TRUE);//ウィンドウモードサイズ変更
	DxLib_Init(); //初期化

	LoadGraphScreen(0,0,"op.jpg",TRUE);

	int op,Count=0;
	op=LoadSoundMem("op.mp3");
	PlaySoundMem(op,DX_PLAYTYPE_BACK);
	WaitKey();




	MenuElement_t MenuElement[5]={
		{ 450,250,"昇竜拳"},
		{ 450,300,"竜巻旋風脚"},
		{ 450,350,"ヨガファイア"},
		{ 450,400,"ヨガフレイム"},
		{ 450,450,"火中天津甘栗拳"},
	};

	int SelectNum = 0;
	int x=0;

	while(ScreenFlip() == 0&&ProcessMessage()==0&&
		ClearDrawScreen()==0&&gpUpdateKey()==0){

		if(Key[ KEY_INPUT_DOWN] == 1){
			SelectNum = (SelectNum +1) %5;
			
			for(int i=0; i<5; i++){

				if( i== SelectNum){
					MenuElement[i].x=430;
				}else{
					MenuElement[i].x=450;
				}
			}

		if(Key[KEY_INPUT_Z] == 1){
			if(SelectNum == 1){
				DrawFormatString(250,175,GetColor(255,255,255),"10ダメージ");
			}else if(SelectNum == 2){
				DrawFormatString(250,175,GetColor(255,255,255),"20ダメージ");
			}else if(SelectNum == 3){
				DrawFormatString(250,175,GetColor(255,255,255),"30ダメージ");
			}else if(SelectNum == 4){
				DrawFormatString(250,175,GetColor(255,255,255),"40ダメージ");
			}else if(SelectNum == 5){
				DrawFormatString(250,175,GetColor(255,255,255),"50ダメージ");
			}

		}



		if(vz<=0)
			LoadGraphScreen(0,0,"op.jpg",TRUE);
			WaitKey();
		}
	
		for(int i=0; i<5; i++){
			DrawFormatString( MenuE
			int damage;
			int life;
			int vx,vy,vz;


			if(SelectNum == 0){
				damage=10;
			}else if(SelectNum == 1){
				damage=20;
			}else if(SelectNum == 2){
				damage=30;
			}else if(SelectNum == 3){	
				damage=40;
			}else if(SelectNum == 4){
				damage=50;
			}


			vx=100;
			vy=damage;
			life = vx - damage;	
			vz=life-damage;

			DrawFormatString(0,0,GetColor(255,255,255),"%d",vz);
			WaitKey(); lement[i].x,
			MenuElement[i].y,GetColor(255,255,255),MenuElement[i].name);
		}
	}//ループの閉じか

	return 0;
}

アバター
softya(ソフト屋)
副管理人
記事: 11677
登録日時: 13年前
住所: 東海地方
連絡を取る:

Re: DXライブラリを使ったゲーム制作で・・・

#4

投稿記事 by softya(ソフト屋) » 11年前

まず、コンパイルが通るコードにしてもらえると良いかと思います。
by softya(ソフト屋) 方針:私は仕組み・考え方を理解して欲しいので直接的なコードを回答することはまれですので、すぐコードがほしい方はその旨をご明記下さい。私以外の方と交代したいと思います(代わりの方がいる保証は出来かねます)。

閉鎖

“C言語何でも質問掲示板” へ戻る