ゲーム制作 シーン分けると未解決に

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

トピックに返信する


答えを正確にご入力ください。答えられるかどうかでスパムボットか否かを判定します。

BBCode: ON
[img]: ON
[flash]: OFF
[url]: ON
スマイリー: OFF

トピックのレビュー
   

展開ビュー トピックのレビュー: ゲーム制作 シーン分けると未解決に

Re: ゲーム制作 シーン分けると未解決に

#5

by 若葉マークぺらひこ » 7年前

セミコロンを消すことも含めて魔改造したところ、動きました!
ありがとうございました!

Re: ゲーム制作 シーン分けると未解決に

#4

by nakagawa » 7年前

int IsAbleToGo1(int x, int y, int direction_a);{

の行で、セミコロンを削除すればエラーがなくなるんじゃないかな?

直接会って話すことが出来れば、色々と教えられんだけどなあ

Re: ゲーム制作 シーン分けると未解決に

#3

by 若葉マークぺらひこ » 7年前

なるほど・・・
自作関数の基礎から頑張ってみます。

Re: ゲーム制作 シーン分けると未解決に

#2

by みけCAT » 7年前

Danjon関数内の
若葉マークぺらひこ さんが書きました:

コード:

	int IsAbleToGo1(int x, int y, int direction_a); {//進む方向が通れるか通れないかを判定
		if (direction_a == 0)//上向きなら
			if (hantei[y / 32 - 1][x / 32] == 1)//進めるか判定
				return 1;//エラー
		if (direction_a == 1)//左向きなら
			if (hantei[y / 32][x / 32 - 1] == 1)
				return 1;
		if (direction_a == 2)//下向きなら
			if (hantei[y / 32 + 1][x / 32] == 1)
				return 1;
		if (direction_a == 3)//右向きなら
			if (hantei[y / 32][x / 32 + 1] == 1)
				return 1;

		return 0;//正常
	}
のようなものは、関数の定義ではなく、関数の宣言の後に(Danjon関数の一部をなす)普通のブロックが続いたものです。
定義されていない関数を使おうとしたから未定義のエラーが出ているのであり、
(まとめたければクラスのメンバ関数として?)使いたい関数を定義してそれを呼び出すようにするなどするといいでしょう。

ゲーム制作 シーン分けると未解決に

#1

by 若葉マークぺらひこ » 7年前

自分はDXライブラリ初心者で、今回VisualStudio2017のゲーム作りでシーン分け(タイトルとプレイ画面などを分けること)に挑戦しています。
シーン分けをする前は問題なく動いていた移動画面が、シーン分けしようとした途端に動かなくなりました。新・ゲームプログラミングの館のmain関数作りを参考にしたのですが、何故こうなってしまうのでしょうか。原因と改善方法を教えて下さい。
*プレイヤーキャラクターらしきものが二人いるのは仕様です。

コード:

#include "DxLib.h"
int function_status = 0, White;
typedef struct {
	int x, y;       // 座標格納用変数
	char name[128]; // 項目名格納用変数
} MenuElement_t;
MenuElement_t MenuElement[5] = {
	{ 80, 100, "ゲームスタート" }, // タグの中身の順番で格納される。xに80が、 
                                                           y に100が、nameに"ゲームスタート"が
	{ 100, 150, "おまけ" },
	{ 100, 200, "ヘルプ" },
	{ 100, 250, "コンフィグ" },
	{ 100, 300, "ゲーム終了" },
};
int SelectNum = 0; // 現在の選択番号

int hantei[15][20] = {
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,1,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,1,0,0,0,1,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,1,1,1,0,0,0,1,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,1,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
	{ 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 },
};
int x = 320, y = 160;
int v = 160, z = 160;
int Handle1;
int Handle2;
int walking_flag1 = 0;
int walking_flag2 = 0;
int direction_a = 3;
int direction_b = 3;
int Image_a[16];//16個の画像を格納する配列
int Image_b[16];//16個の画像を格納する配列
int Green = GetColor(0, 255, 0);//座標表示用

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;
}

void Opening() {
	DrawString(100, 100, "オープニング画面 (zをプッシュ)", White);
	if (Key[KEY_INPUT_Z] == 1)
		function_status = 1;
}

void Menu() {
	DrawString(100, 140, "メニュー画面 (Qをプッシュ)", White);
	// 計算フェーズ 
	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にする
			}
		}
	}
	if (SelectNum == 0 && Key[KEY_INPUT_Q] == 1) {
		function_status = 2;
	}
}

int Danjon() {
	DrawString(100, 180, "ダンジョン画面 (Qをプッシュ)", White);

	int IsAbleToGo1(int x, int y, int direction_a); {//進む方向が通れるか通れないかを判定
		if (direction_a == 0)//上向きなら
			if (hantei[y / 32 - 1][x / 32] == 1)//進めるか判定
				return 1;//エラー
		if (direction_a == 1)//左向きなら
			if (hantei[y / 32][x / 32 - 1] == 1)
				return 1;
		if (direction_a == 2)//下向きなら
			if (hantei[y / 32 + 1][x / 32] == 1)
				return 1;
		if (direction_a == 3)//右向きなら
			if (hantei[y / 32][x / 32 + 1] == 1)
				return 1;

		return 0;//正常
	}

	int gpCalc1(); {
		if (x % 32 == 0 && y % 32 == 0) {
			walking_flag1 = 1;
			if (Key[KEY_INPUT_UP] >= 1) {         //上ボタンが押されたら
				direction_a = 0;
			}
			else if (Key[KEY_INPUT_LEFT] >= 1) {  //左ボタンが押されたら
				direction_a = 1;
			}
			else if (Key[KEY_INPUT_DOWN] >= 1) {   //下ボタンが押されたら
				direction_a = 2;
			}
			else if (Key[KEY_INPUT_RIGHT] >= 1) {  //右ボタン
				direction_a = 3;
			}
			else {
				walking_flag1 = 0;
			}
		}
		if (walking_flag1 == 1) {
			if (direction_a == 0) {
				y--;
			}
			else if (direction_a == 1) {
				x--;
			}
			else if (direction_a == 2) {
				y++;
			}
			else if (direction_a == 3) {
				x++;
			}
			if (walking_flag1 == 1) {    //もし歩くなら
				if (IsAbleToGo1(x, y, direction_a) == 1)//行き先が歩けないなら
					walking_flag1 = 0;    //歩かないフラグを立てる。
			}
			if (walking_flag1 == 0) {
				if (IsAbleToGo1(x, y, direction_a) == 0)//行き先が歩けるなら
					walking_flag1 = 1;    //歩くフラグを立てる。
			}
		}
	}

	int IsAbleToGo2(int v, int z, int direction_b); {//進む方向が通れるか通れないかを判定
		if (direction_b == 0)//上向きなら
			if (hantei[z / 32 - 1][v / 32] == 1)//進めるか判定
				return 1;//エラー
		if (direction_b == 1)//左向きなら
			if (hantei[z / 32][v / 32 - 1] == 1)
				return 1;
		if (direction_b == 2)//下向きなら
			if (hantei[z / 32 + 1][v / 32] == 1)
				return 1;
		if (direction_b == 3)//右向きなら
			if (hantei[z / 32][v / 32 + 1] == 1)
				return 1;

		return 0;//正常
	}

	int gpCalc2(); {
		if (v % 32 == 0 && z % 32 == 0) {
			walking_flag2 = 1;
			if (Key[KEY_INPUT_W] >= 1) {         //Wボタンが押されたら
				direction_b = 0;
			}
			else if (Key[KEY_INPUT_A] >= 1) {  //Aボタンが押されたら
				direction_b = 1;
			}
			else if (Key[KEY_INPUT_Z] >= 1) {   //Sボタンが押されたら
				direction_b = 2;
			}
			else if (Key[KEY_INPUT_S] >= 1) {  //Zボタン
				direction_b = 3;
			}
			else {
				walking_flag2 = 0;
			}
		}
		if (walking_flag2 == 1) {
			if (direction_b == 0) {
				z--;
			}
			else if (direction_b == 1) {
				v--;
			}
			else if (direction_b == 2) {
				z++;
			}
			else if (direction_b == 3) {
				v++;
			}
			if (walking_flag2 == 1) {    //もし歩くなら
				if (IsAbleToGo2(v, z, direction_b) == 1)//行き先が歩けないなら
					walking_flag2 = 0;    //歩かないフラグを立てる。
			}
			if (walking_flag2 == 0) {
				if (IsAbleToGo2(v, z, direction_b) == 0)//行き先が歩けるなら
					walking_flag2 = 1;    //歩くフラグを立てる。
			}
		}
	}

	int gpDraw1(); {
		DrawRotaGraph(x, y, 1.0, 0.0, Handle1, TRUE);
	}

	int gpDraw2(); {
		DrawRotaGraph(v, z, 1.0, 0.0, Handle2, TRUE);
	}
	gpCalc1();
	gpDraw1();
	gpCalc2();
	gpDraw2();
	LoadDivGraph("画像/キャラクタ10.png", 16, 4, 4, 32, 32, Image_a);//画像を16個に分割してImage_a配列に保存
	LoadDivGraph("画像/キャラクタ10.png", 16, 4, 4, 32, 32, Image_b);//画像を16個に分割してImage_b配列に保存
	if (Key[KEY_INPUT_Q]) {
		function_status = 3;
	}
}

void attack() {
	DrawString(100, 220, "戦闘画面 (vをプッシュ)", White);
	if (Key[KEY_INPUT_V] == 1)
		function_status = 4;
}

void Ending() {
	DrawString(100, 260, "エンディング画面 (bをプッシュ)", White);
	if (Key[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();                                                               // 裏画面のデータを全て削除
		gpUpdateKey();                                 // すべてのキーの状態を得る

		switch (function_status) {
		case 0:
			Opening();
			break;
		case 1:
			// メニュー項目の表示に必要な構造体を用意する
			Menu();
			for (int i = 0; i<5; i++) { // メニュー項目を描画
				DrawFormatString(MenuElement[i].x, MenuElement[i].y, GetColor(255, 255, 255), MenuElement[i].name);
			}
			break;

		case 2:
			Danjon();
			 /*白い壁を描画*/
			for (int i = 0; i<15; i++)
				for (int j = 0; j<20; j++)
					if (hantei[i][j] == 1)
						DrawBox(j * 32, i * 32, (j + 1) * 32, (i + 1) * 32, GetColor(255, 255, 255), TRUE);
			DrawGraph(x, y, Image_a[(x % 32 + y % 32) / 8 + direction_a * 4], TRUE);
			DrawGraph(v, z, Image_b[(v % 32 + z % 32) / 8 + direction_b * 4], TRUE);

			//座標表示装置
			DrawFormatString(0, 0, Green, "座標[%d,%d]", x, y); // 文字を描画する
			DrawFormatString(0, 15, Green, "座標[%d,%d]", v, z); // 文字を描画する
			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;                                               // ソフトの終了
}

以下がエラーメッセージです。

1>------ ビルド開始: プロジェクト: GameProg, 構成: Debug x64 ------
1>Brain.cpp
1>Brain.obj : error LNK2019: 未解決の外部シンボル "int __cdecl IsAbleToGo1(int,int,int)" (?IsAbleToGo1@@YAHHHH@Z) が関数 "int __cdecl Danjon(void)" (?Danjon@@YAHXZ) で参照されました。
1>Brain.obj : error LNK2019: 未解決の外部シンボル "int __cdecl gpCalc1(void)" (?gpCalc1@@YAHXZ) が関数 "int __cdecl Danjon(void)" (?Danjon@@YAHXZ) で参照されました。
1>Brain.obj : error LNK2019: 未解決の外部シンボル "int __cdecl IsAbleToGo2(int,int,int)" (?IsAbleToGo2@@YAHHHH@Z) が関数 "int __cdecl Danjon(void)" (?Danjon@@YAHXZ) で参照されました。
1>Brain.obj : error LNK2019: 未解決の外部シンボル "int __cdecl gpCalc2(void)" (?gpCalc2@@YAHXZ) が関数 "int __cdecl Danjon(void)" (?Danjon@@YAHXZ) で参照されました。
1>Brain.obj : error LNK2019: 未解決の外部シンボル "int __cdecl gpDraw1(void)" (?gpDraw1@@YAHXZ) が関数 "int __cdecl Danjon(void)" (?Danjon@@YAHXZ) で参照されました。
1>Brain.obj : error LNK2019: 未解決の外部シンボル "int __cdecl gpDraw2(void)" (?gpDraw2@@YAHXZ) が関数 "int __cdecl Danjon(void)" (?Danjon@@YAHXZ) で参照されました。
1>C:\Users\Mayu\Desktop\続・ゲームプログラミング2017\GameProg\GameProg\x64\Debug\GameProg.exe : fatal error LNK1120: 6 件の未解決の外部参照
1>プロジェクト "GameProg.vcxproj" のビルドが終了しました -- 失敗。
========== ビルド: 0 正常終了、1 失敗、0 更新不要、0 スキップ ==========

ページトップ