Exemple #1
0
int main(void) {
	char cIn;
	int iStatus;
	CMouse mouseX; // 建立時就會自動呼叫 CMouse 建構元
	mouseX.Show(); // 讓老鼠自己畫出自己的位置
	iStatus = mouseX.GetStatus();
	while( iStatus != 0 ) { // 只要老鼠還在正常狀態就繼續讓使用者輸入
		cIn = getch();
		if( cIn == 'b' ) g_bBoss = !g_bBoss; // 判斷是否按下按鍵 b 
		iStatus = mouseX.Update(cIn); // 讓老鼠自己更新狀態
		if( iStatus ) mouseX.Show(); // 老鼠沒有死亡, 就必須更新老鼠位置的顯示
		else cout << "老鼠已經死亡,遊戲結束" << endl;
	}
	system("pause"); return(0);
}
Exemple #2
0
//=============================================================================
//	エントリー関数
//=============================================================================
int APIENTRY WinMain(HINSTANCE _instanceHandle ,HINSTANCE _instanceHandlePrev, LPSTR _cmdLine, int _cmdShow)
{
	_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);

	UNREFERENCED_PARAMETER(_instanceHandlePrev);
	UNREFERENCED_PARAMETER(_cmdLine);

	DWORD execLastTime;
	DWORD LastTimeFPS;
	DWORD currentTime;
	DWORD flameCount;

	WNDCLASSEX wcex =
	{
		sizeof(WNDCLASSEX),
		CS_CLASSDC,
		WndProc,
		0,
		0,
		_instanceHandle,
		NULL,
		LoadCursor(NULL, IDC_ARROW),
		(HBRUSH)(COLOR_WINDOW + 1),
		NULL,
		CLASS_NAME,
		NULL
	};

	HWND windowHandle;
	MSG msg;
	
	//	ウィンドウクラスの登録
	RegisterClassEx(&wcex);

	//	ウィンドウの作成
	windowHandle = CreateWindowEx(0,
								  CLASS_NAME,
								  WINDOW_NAME,
								  WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX & ~WS_THICKFRAME,
								  CW_USEDEFAULT,
								  CW_USEDEFAULT,
								  static_cast<int>(SCREEN_WIDTH + GetSystemMetrics(SM_CXDLGFRAME) * 2),
								  static_cast<int>(SCREEN_HEIGHT + GetSystemMetrics(SM_CXDLGFRAME) * 2 + GetSystemMetrics(SM_CYCAPTION)),
								  NULL,
								  NULL,
								  _instanceHandle,
								  NULL);

	//	フレームカウント初期化
	timeBeginPeriod(1);	//	分解能を設定
	execLastTime = LastTimeFPS = timeGetTime();
	currentTime = flameCount = 0;

	//	ウインドウの表示(初期化処理の後に呼ばないと駄目)
	ShowWindow(windowHandle, _cmdShow);
	UpdateWindow(windowHandle);


#ifndef _DEBUG
	LoadLibraryA("WiiYourself.dll");
#else
	LoadLibraryA("WiiYourself_debug.dll");
#endif



	LPDIRECT3D9 direct3D;	//	Direct3D9用デバイス
	LPDIRECT3DDEVICE9 device;	//	_deviceオブジェクト(描画に必要)
	D3DDISPLAYMODE displayMode;
	D3DPRESENT_PARAMETERS presentParameter;

	//	Direct3Dオブジェクトの作成
	direct3D = Direct3DCreate9(D3D_SDK_VERSION);
	direct3D->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode);

	//	デバイスのプレゼンテーションパラメータの設定
	//--------------------------------------------------------------------
	//	ワークをゼロクリア
	ZeroMemory(&presentParameter, sizeof(presentParameter));

	//	バックバッファの数をセット
	presentParameter.BackBufferCount = 1;

	//ゲーム画面サイズ
	presentParameter.BackBufferWidth = static_cast<int>SCREEN_WIDTH;
	presentParameter.BackBufferHeight = static_cast<int>SCREEN_HEIGHT;

	//	バックバッファフォーマットはディスプレイモードに合わせて使う
	presentParameter.BackBufferFormat = displayMode.Format;

	//	映像信号に同期してフリップする
	presentParameter.SwapEffect = D3DSWAPEFFECT_DISCARD;

	//	ウィンドウモード
	presentParameter.Windowed = TRUE;

	//	デプスバッファ(Zバッファ)とステンシルバッファを作成
	presentParameter.EnableAutoDepthStencil = TRUE;

	//	デプスバッファの利用方法
	//	D3DFMT_D16		デプスバッファのみを16bitとして扱う
	//	D3DFMT_D24S8	デプスバッファを24bit ステンシルバッファを8bitとして扱う
	presentParameter.AutoDepthStencilFormat = D3DFMT_D24S8;

	//	ウィンドウモード
	presentParameter.FullScreen_RefreshRateInHz = 0;
	presentParameter.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
	//--------------------------------------------------------------------

	direct3D->CreateDevice(D3DADAPTER_DEFAULT,
		D3DDEVTYPE_HAL,
		windowHandle,
		D3DCREATE_HARDWARE_VERTEXPROCESSING,
		&presentParameter,
		&device);




	CDebug* debug = new CDebug();
	debug->Init(device);

	CKeyboard* keyboard = new CKeyboard();
	keyboard->Init(_instanceHandle, windowHandle);

	CMouse* mouse = new CMouse();
	mouse->Init(_instanceHandle, windowHandle);

	CWiiController* wiiController = new CWiiController();


	//	メッセージループ
	for (;;)
	{
		if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if (msg.message == WM_QUIT)
			{
				//	PostQuitMessage()が呼ばれたらループ終了
				break;
			}
			else
			{
				//	メッセージの翻訳とディスパッチ
				TranslateMessage(&msg);
				DispatchMessage(&msg);
			}
		}
		else
		{
			currentTime = timeGetTime();
			if ((currentTime - LastTimeFPS) >= 500)
			{
				#ifdef _DEBUG
					countFPS = flameCount * 1000 / (currentTime - LastTimeFPS);
				#endif

				LastTimeFPS = currentTime;
				flameCount = 0;
			}

			if ((currentTime - execLastTime) >= (1000 / 60))
			{
				execLastTime = currentTime ;


				keyboard->Update();
				mouse->Update();
				wiiController->update();


				{
					//	本体
					{
						debug->SetDebug("本体の加速度X [%f]\n", wiiController->getAccelerationX());
						debug->SetDebug("本体の加速度Y [%f]\n", wiiController->getAccelerationY());
						debug->SetDebug("本体の加速度Z [%f]\n", wiiController->getAccelerationZ());

						debug->SetDebug("本体の回転角X [%f]\n", wiiController->getRotX());
						debug->SetDebug("本体の回転角Y [%f]\n", wiiController->getRotY());
						debug->SetDebug("本体の回転角Z [%f]\n", wiiController->getRotZ());

						debug->SetDebug("本体の回転角の変異X [%f]\n", wiiController->getChangeRotX());
						debug->SetDebug("本体の回転角の変異Y [%f]\n", wiiController->getChangeRotY());
						debug->SetDebug("本体の回転角の変異Z [%f]\n", wiiController->getChangeRotZ());

						debug->SetDebug("本体の角速度X [%f]\n", wiiController->getRotSpeedX());
						debug->SetDebug("本体の角速度Y [%f]\n", wiiController->getRotSpeedY());
						debug->SetDebug("本体の角速度Z [%f]\n", wiiController->getRotSpeedZ());
					}

					//	ヌンチャク
					{
						debug->SetDebug("ヌンチャクの加速度X [%f]\n", wiiController->getAccelerationNX());
						debug->SetDebug("ヌンチャクの加速度Y [%f]\n", wiiController->getAccelerationNY());
						debug->SetDebug("ヌンチャクの加速度Z [%f]\n", wiiController->getAccelerationNZ());

						debug->SetDebug("ヌンチャクの回転角X [%f]\n", wiiController->getRotNX());
						debug->SetDebug("ヌンチャクの回転角Y [%f]\n", wiiController->getRotNY());
						debug->SetDebug("ヌンチャクの回転角Z [%f]\n", wiiController->getRotNZ());

						debug->SetDebug("ヌンチャクの位置X [%f]\n", wiiController->getJoystick().x);
						debug->SetDebug("ヌンチャクの位置Y [%f]\n", wiiController->getJoystick().y);
					}

					//	赤外線
					{
						debug->SetDebug("赤外線X [%f]\n", wiiController->getIR().x);
						debug->SetDebug("赤外線Y [%f]\n", wiiController->getIR().y);
					}

					debug->SetDebug("バッテリー残量[%d%]\n", wiiController->battery());

					debug->SetDebug("モーションPlusの接続状態[%d]\n", wiiController->getMotionConnect());

					/*if (wiiController->getTrigger(WC_A))
						wiiController->rumble(true);

					if (wiiController->getTrigger(WC_B))
						wiiController->rumble(false);

					if (wiiController->getTrigger(WC_UP))
						wiiController->rumble((unsigned int)1000);*/

					//	Aボタン
					{
						if (wiiController->getPress(WC_A))
							debug->SetDebug("A [ON]\n");
						else
							debug->SetDebug("A [OFF]\n");
					}

					//	Bボタン
					{
						if (wiiController->getPress(WC_B))
							debug->SetDebug("B [ON]\n");
						else
							debug->SetDebug("B [OFF]\n");
					}

					//	Cボタン
					{
						if (wiiController->getPress(WC_C))
							debug->SetDebug("C [ON]\n");
						else
							debug->SetDebug("C [OFF]\n");
					}

					//	Zボタン
					{
						if (wiiController->getPress(WC_Z))
							debug->SetDebug("Z [ON]\n");
						else
							debug->SetDebug("Z [OFF]\n");
					}

					//	↑ボタン
					{
						if (wiiController->getPress(WC_UP))
							debug->SetDebug("UP [ON]\n");
						else
							debug->SetDebug("UP [OFF]\n");
					}

					//	↓ボタン
					{
						if (wiiController->getPress(WC_DOWN))
							debug->SetDebug("DOWN [ON]\n");
						else
							debug->SetDebug("DOWN [OFF]\n");
					}

					//	←ボタン
					{
						if (wiiController->getPress(WC_LEFT))
							debug->SetDebug("LEFT [ON]\n");
						else
							debug->SetDebug("LEFT [OFF]\n");
					}

					//	→ボタン
					{
						if (wiiController->getPress(WC_RIGHT))
							debug->SetDebug("RIGHT [ON]\n");
						else
							debug->SetDebug("RIGHT [OFF]\n");
					}

					//	-ボタン
					{
						if (wiiController->getPress(WC_MINUS))
							debug->SetDebug("MINUS [ON]\n");
						else
							debug->SetDebug("MINUS [OFF]\n");

						if(wiiController->getTrigger(WC_MINUS))
							wiiController->rotSpeedCalibration();
					}

					//	+ボタン
					{
						if (wiiController->getPress(WC_PLUS))
							debug->SetDebug("PLUS [ON]\n");
						else
							debug->SetDebug("PLUS [OFF]\n");

						if(wiiController->getTrigger(WC_PLUS))
							wiiController->rotReset();
					}

					//	1ボタン
					{
						if (wiiController->getPress(WC_ONE))
							debug->SetDebug("ONE [ON]\n");
						else
							debug->SetDebug("ONE [OFF]\n");
					}

					//	2ボタン
					{
						if (wiiController->getPress(WC_TWO))
							debug->SetDebug("TWO [ON]\n");
						else
							debug->SetDebug("TWO [OFF]\n");
					}

					//	HOMEボタン
					{
						if (wiiController->getPress(WC_HOME))
							debug->SetDebug("HOME [ON]\n");
						else
							debug->SetDebug("HOME [OFF]\n");
					}
				}

				//	バックバッファ&Zバッファのクリア
				device->Clear(0,
					NULL,
					(D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER),
					D3DCOLOR_RGBA(255, 255, 255, 255),
					1.0f,
					0);

				//	Direct3Dによる描画の開始
				if (SUCCEEDED(device->BeginScene()))
				{
					CDebug::Draw();

					//	Direct3Dによる描画の終了
					device->EndScene();
				}

				//	バックバッファとフロントバッファの入れ替える
				device->Present(NULL, NULL, NULL, NULL);

				flameCount++;
			}
		}
	}

	SAFE_DELETE(wiiController);
	SAFE_DELETE(keyboard);
	SAFE_DELETE(mouse);
	SAFE_DELETE(debug);

	//	ウィンドウクラスの登録を解除
	UnregisterClass(CLASS_NAME, wcex.hInstance);

	timeEndPeriod(1);	//	分解能を戻す

	return static_cast<int>(msg.wParam);
}