ゲームメインからゲームオーバー画面への遷移

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

ゲームメインからゲームオーバー画面への遷移

#1

投稿記事 by foo » 8年前

dxlibをつかって2dアクションゲームを作っています
環境はvs2015です

ゲームメインの終了がうまくいきません

Source.cppの一部

コード:

#include "DxLib.h"
#include "Header.h"
#include "map.h"
#include "enemy.h"
#include "camera.h"
#include "player.h"
#include "sound.h"

// 入力状態の初期化
int Input = 0;
int EdgeInput = 0;
int FrameStartTime = 0;
GameState g_gamestate = GAME_TITLE;
int Key[256]; // キーが押されているフレーム数を格納する

// WinMain関数
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
	LPSTR lpCmdLine, int nCmdShow)
{
	ChangeWindowMode(TRUE);

	// DXライブラリの初期化
	if (DxLib_Init() == -1) return -1;

	while (1)
	{	
		// 画面のクリア
		ClsDrawScreen();

		switch (g_gamestate){
		case GAME_TITLE:
			//ゲームのタイトルを表示
			gameTitle();
			break;
		case GAME_MAIN:
			// アクションゲームのメイン関数を呼ぶ
			ActMain();
			break;
		case GAME_CLEAR:
			break;
		case GAME_OVER:
			gameOver();
			break;
		}

		// 画面の更新
		ScreenFlip();
	}
	// DXライブラリの後始末
	DxLib_End();

	// 終了
	return 0;
}

// アクションサンプルプログラムメイン
int ActMain(void)
{
	// 描画先を裏画面にセット
	SetDrawScreen(DX_SCREEN_BACK);

	// 垂直同期信号を待たない
	SetWaitVSyncFlag(FALSE);

	// 60FPS固定用、時間保存用変数を現在のカウント値にセット
	FrameStartTime = GetNowCount();

	//グラフィックを読込む
	Init();

	sound();

	enemySet();

	// メインループ開始、ESCキーで外に出る
	while (ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0)
	{
		// 画面のクリア
		ClsDrawScreen();

		// 1/60秒立つまで待つ
		while (GetNowCount() - FrameStartTime < 1000 / 60) {}

		// 現在のカウント値を保存
		FrameStartTime = GetNowCount();

		keyUpdate();

		//マップ・背景描画
		DrawMap(&camerax, &cameray);

		//敵の移動処理
		MoveEnemy();
		EnemyControl();

		//敵のマップとのあたり判定
		CalcEnemy(); 

		//プレイヤーの移動処理
		MovePlayer();

		// プレイヤーのマップとのあたり判定
		CalcPlayer();

		//カメラスクロール
		MoveCamera();

		//衝突判定
		if (CollisionCheck() == 2) { 
			g_gamestate = GAME_CLEAR;
			break; 
		}else{ 
			g_gamestate = GAME_OVER;
		}
		//プレイヤーの攻撃
		PlayerAttack();

		EnemyAttackCheck();
		
		//敵の表示
		EnemyDisp();
		EnemyEffectDisp();
		EnemyEffectSet();
		EnemyEffectControl();
		
		//キャラクター描画
		PlayerDisp();
		EffDisp();

		DrawHP();

		#if DEBUG
		debug();
		#endif

		// 画面の更新
		ScreenFlip();
	}
	stop();

	// 終了
	return 0;
}
ESCキーを入力しても例外が発生しましたと出て、画面遷移してくれません。

例外が発生した場所は

コード:

void debug() {

	DrawFormatString(0, 0, GetColor(0, 255, 0), "エリア1=keyX");←←←ココ
	DrawFormatString(0, 30, GetColor(0, 255, 0), "エリア2=keyC");
	DrawFormatString(0, 60, GetColor(0, 255, 0), "エリア3=keyA");
	DrawFormatString(0, 90, GetColor(0, 255, 0), "エリア4=keyS");
	DrawFormatString(0, 120, GetColor(0, 255, 0), "エリア5=keyD");
	
	if ((Input & PAD_INPUT_2) != 0) {
		player.x = warpPoint_x[0];
		player.y = warpPoint_y[0];
	}
	if ((Input & PAD_INPUT_3) != 0) {
		player.x = warpPoint_x[1];
		player.y = warpPoint_y[1];
	}
	if ((Input & PAD_INPUT_4) != 0) {
		player.x = warpPoint_x[2];
		player.y = warpPoint_y[2];
	}
	if ((Input & PAD_INPUT_5) != 0) {
		player.x = warpPoint_x[3];
		player.y = warpPoint_y[3];
	}
	if ((Input & PAD_INPUT_6) != 0) {
		player.x = warpPoint_x[4];
		player.y = warpPoint_y[4];
	}
}
でした。ここ以外の場所にも例外が発生したときがあり、それは特にいじったわけでもないのですが治って、今度はここに例外が発生しました。

コンパイル時には問題なくゲームの動作も正常なのですが、ゲームを終了しようとすると例外が発生してしまいます

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

Re: ゲームメインからゲームオーバー画面への遷移

#2

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

とりあえずループの中にメインループが入っているのはダメそうですが、未定義の要素が多すぎます。
最小限の・自己完結した・確認可能なサンプルコードを提示していただけないでしょうか?
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

Math

Re: ゲームメインからゲームオーバー画面への遷移

#3

投稿記事 by Math » 8年前

これだけではわからないので①から(6)までとプロジェクトファイル(.vcxproj)他をお送りいただくようお願いいたします。

コード:

#include "DxLib.h"
#include "Header.h"/// ヘッダー部分①
#include "map.h"////// マップ   ②
#include "enemy.h"//// 敵     ③
#include "camera.h"/// カメラ   ④
#include "player.h"/// プレイヤー ⑤
#include "sound.h"//// 音     (6)
 
// 入力状態の初期化--------------------------------------------------
int Input = 0;
int EdgeInput = 0;
int FrameStartTime = 0;
GameState g_gamestate = GAME_TITLE;
int Key[256]; // キーが押されているフレーム数を格納する--------------key
//------------------------------------------------------------------- 
// WinMain関数
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{
    ChangeWindowMode(TRUE);if (DxLib_Init() == -1){ return -1;}// DXライブラリの初期化
 
    while (1)
    {   
        ClsDrawScreen();// 画面のクリア                //      [画面のクリア]
                                                       //           ↓
        switch (g_gamestate){                          //       <g_gamestate>
        case GAME_TITLE:                               //           ↓
                                                       //       <GAME_TITLE>→[gameTitle()]
            gameTitle();//ゲームのタイトルを表示       //           ↓
            break;                                     //       <GAME_MAIN>→[ActMain()]
        case GAME_MAIN:                                //           ↓
                                                       //       <GAME_CLEAR>→[?]
            ActMain();// アクションゲームのメイン関数を呼ぶ//       ↓
            break;                                     //       <GAME_OVER>→[gameOver()]
        case GAME_CLEAR:                               //
            break;                                     //
        case GAME_OVER:
            gameOverC();
            break;
        }
         
        ScreenFlip();// 画面の更新
    }
    DxLib_End();// DXライブラリの後始末

    return 0;// 終了
}
 
int ActMain(void)// アクションサンプルプログラムメイン
{
    SetDrawScreen(DX_SCREEN_BACK);// 描画先を裏画面にセット
    
    SetWaitVSyncFlag(FALSE);// 垂直同期信号を待たない
 
    FrameStartTime = GetNowCount();// 60FPS固定用、時間保存用変数を現在のカウント値にセット

    Init();//グラフィックを読込む
 
    sound();
 
    enemySet();
 
    
    while (ProcessMessage() == 0 && CheckHitKey(KEY_INPUT_ESCAPE) == 0)// メインループ開始、ESCキーで外に出る
    {
        ClsDrawScreen();// 画面のクリア
 
        while (GetNowCount() - FrameStartTime < 1000 / 60) {}// 1/60秒立つまで待つ
        
        FrameStartTime = GetNowCount();// 現在のカウント値を保存
 
        keyUpdate();
 
        DrawMap(&camerax, &cameray); //マップ・背景描画
         
        MoveEnemy();//敵の移動処理
        EnemyControl();
 
        CalcEnemy(); //敵のマップとのあたり判定
 
        MovePlayer();//プレイヤーの移動処理

        CalcPlayer();// プレイヤーのマップとのあたり判定

        MoveCamera();//カメラスクロール

        if (CollisionCheck() == 2) {  //衝突判定
            g_gamestate = GAME_CLEAR;
            break; 
        }else{ 
            g_gamestate = GAME_OVER;
        }
        PlayerAttack();
 
        EnemyAttackCheck(); //プレイヤーの攻撃
        
        EnemyDisp();//敵の表示
        EnemyEffectDisp();
        EnemyEffectSet();
        EnemyEffectControl();
        
        
        PlayerDisp();//キャラクター描画
        EffDisp();

        DrawHP();
 
        #if DEBUG
        debug();
        #endif
 
        // 画面の更新
        ScreenFlip();
    }
    stop();
 
    // 終了
    return 0;
}

foo

Re: ゲームメインからゲームオーバー画面への遷移

#4

投稿記事 by foo » 8年前

一度作り直したら、画面遷移はうまくいくようになりました。

あとは、敵をゲームが始まるときに毎回初期化できれば完成なのですが、その初期化がうまくいきません

あと、すみません。

プロジェクトファイルの送り方が分かりませんでした。

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

Re: ゲームメインからゲームオーバー画面への遷移

#5

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

foo さんが書きました:一度作り直したら、画面遷移はうまくいくようになりました。
おめでとうございます。
foo さんが書きました:あとは、敵をゲームが始まるときに毎回初期化できれば完成なのですが、その初期化がうまくいきません
そうですか。
今のところ、質問は無いのですね。
デバッグがんばってください。
foo さんが書きました:あと、すみません。

プロジェクトファイルの送り方が分かりませんでした。
ユーザー登録をしてログインすると添付ファイルを送れるようになるので、
プロジェクトをzipかなんかに圧縮して添付するといいでしょう。
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

foo
記事: 2
登録日時: 8年前

Re: ゲームメインからゲームオーバー画面への遷移

#6

投稿記事 by foo » 8年前

zipファイルをアップロードできたのでしょうか?

どこで確認すればいいんでしょう?

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

Re: ゲームメインからゲームオーバー画面への遷移

#7

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

foo さんが書きました:zipファイルをアップロードできたのでしょうか?

どこで確認すればいいんでしょう?
「返信する」画面の左下の「ファイル添付」をクリックしてください。
すると、ファイルとコメントを指定するフォームが出るはずなので、埋めて「ファイルの追加」を押します。
その後、記事自体の「送信」をします。
複雑な問題?マシンの性能を上げてOpenMPで殴ればいい!(死亡フラグ)

foo
記事: 2
登録日時: 8年前

Re: ゲームメインからゲームオーバー画面への遷移

#8

投稿記事 by foo » 8年前

ファイルアップロードの%は出るのですが、100%になった後、ページがリロードされるのですがこれは正常ですか?

Math

Re: ゲームメインからゲームオーバー画面への遷移

#9

投稿記事 by Math » 8年前

You can display project file like this.You need use context menu "送る" And "メモ張” or TextEditor(Like TeraPad).

コード:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup Label="ProjectConfigurations">
    <ProjectConfiguration Include="Debug|Win32">
      <Configuration>Debug</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|Win32">
      <Configuration>Release</Configuration>
      <Platform>Win32</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Debug|x64">
      <Configuration>Debug</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
    <ProjectConfiguration Include="Release|x64">
      <Configuration>Release</Configuration>
      <Platform>x64</Platform>
    </ProjectConfiguration>
  </ItemGroup>
  <PropertyGroup Label="Globals">
    <ProjectGuid>{1FA075A3-9F75-4BBE-A650-4DEDAA6A0F2E}</ProjectGuid>
    <Keyword>Win32Proj</Keyword>
    <RootNamespace>w32</RootNamespace>
    <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>MultiByte</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>true</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
    <ConfigurationType>Application</ConfigurationType>
    <UseDebugLibraries>false</UseDebugLibraries>
    <PlatformToolset>v140</PlatformToolset>
    <WholeProgramOptimization>true</WholeProgramOptimization>
    <CharacterSet>Unicode</CharacterSet>
  </PropertyGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
  <ImportGroup Label="ExtensionSettings">
  </ImportGroup>
  <ImportGroup Label="Shared">
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
  </ImportGroup>
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <LinkIncremental>true</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <LinkIncremental>false</LinkIncremental>
  </PropertyGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>D:\DxLib_VC\プロジェクトに追加すべきファイル_VC用;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalLibraryDirectories>D:\DxLib_VC\プロジェクトに追加すべきファイル_VC用;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <ClCompile>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <WarningLevel>Level3</WarningLevel>
      <Optimization>Disabled</Optimization>
      <PreprocessorDefinitions>_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
      <AdditionalIncludeDirectories>D:\DxLib_VC\プロジェクトに追加すべきファイル_VC用;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
      <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
      <AdditionalLibraryDirectories>D:\DxLib_VC\プロジェクトに追加すべきファイル_VC用;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
    </Link>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
      <PrecompiledHeader>
      </PrecompiledHeader>
      <Optimization>MaxSpeed</Optimization>
      <FunctionLevelLinking>true</FunctionLevelLinking>
      <IntrinsicFunctions>true</IntrinsicFunctions>
      <PreprocessorDefinitions>NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
    </ClCompile>
    <Link>
      <SubSystem>Windows</SubSystem>
      <EnableCOMDATFolding>true</EnableCOMDATFolding>
      <OptimizeReferences>true</OptimizeReferences>
      <GenerateDebugInformation>true</GenerateDebugInformation>
    </Link>
  </ItemDefinitionGroup>
  <ItemGroup>
    <ClCompile Include="g1.cpp" />
  </ItemGroup>
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
  <ImportGroup Label="ExtensionTargets">
  </ImportGroup>
</Project>

Math

Re: ゲームメインからゲームオーバー画面への遷移

#10

投稿記事 by Math » 8年前

Or .vcxproj file drag-&-drop into "メモ帳". It's easy.

Math

Re: ゲームメインからゲームオーバー画面への遷移

#11

投稿記事 by Math » 8年前

しかしプロジェクトファイル全体をzipで送ってもらえばベストです。

閉鎖

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