Esempio n. 1
0
//==============================================================================================
// ゲームメイン処理
//==============================================================================================
void GameMain(void) {

	TIMECAPS Caps;

	timeGetDevCaps(&Caps, sizeof(TIMECAPS)); // 性能取得
	timeBeginPeriod(Caps.wPeriodMin); // 設定
	HDC hDC_Back = CreateEmptyBMP(hDC_Wnd, pWid, pHei);
	HDC hDC_Wheel = LoadBMPfromFile(hDC_Wnd, TEXT("wheel.bmp"));
	HDC hDC_Block = LoadBMPfromResourceSTR(hDC_Wnd, hInst, TEXT("IDB_BLOCKIDB_BLOCK"));
	HDC hDC_org = LoadBMPfromResourceSTR(hDC_Wnd, hInst, TEXT("IDB_ORG"));
	HDC hDC_Mask = CreateMask(hDC_org, RGB(0, 0, 0));
	HANDLE hfile;
	DWORD file_size, read_byte;
	mciSendString(_T("close BGM"), NULL, 0, NULL); // (前回ちゃんと閉じられなかったかも…)
	mciSendString(_T("open SHOOT!.mid type sequencer alias BGM"), NULL, 0, NULL); // 開く

	TCHAR BGMStatus[256] = { 0 };
	mciSendString(_T("status BGM mode"), BGMStatus, 256, NULL); // 状態の取得
	if (lstrcmp(BGMStatus, TEXT("stopped")) == 0) {
		mciSendString(TEXT("play BGM from 0"), NULL, 0, NULL); // 停止中なら演奏
	}


	Sleep(15000);
	LPCTSTR Sound = LoadSound(_T("notify.wav"));
	PlaySound(Sound, NULL, SND_ASYNC | SND_MEMORY);
	
	//メインループ
	while (!EndFlag) {
		const DWORD StartTime = timeGetTime();
		//~ ゲーム処理いろいろ ~
		//PatBlt(hDC_Back, 0, 0, pWid, pHei, WHITENESS);
		BitBlt(hDC_Back, 0, 0, 32, 32, hDC_Wheel, 0, 0, SRCCOPY);
		BitBlt(hDC_Back, 64, 0, 32, 32, hDC_Block, 0, 0, SRCCOPY);
		//SpriteBlt(hDC_Back, 32, 0, 32, 32, hDC_org, 0, 0, hDC_Mask);
		BitBlt(hDC_Wnd, 0, 0, pWid, pHei, hDC_Back, 0, 0, SRCCOPY);
		const DWORD PassTime = timeGetTime() - StartTime; // 経過時間の計算
		(1000 / FPS > PassTime) ? Wait(1000 / FPS - PassTime) : Wait(0); // 待つ。
		mciSendString(TEXT("status BGM mode"), BGMStatus, 256, NULL); // 状態の取得
		if (lstrcmp(BGMStatus, TEXT("stopped")) == 0) {
			mciSendString(TEXT("play BGM from 0"), NULL, 0, NULL); // 停止中なら演奏
		}

		FPSCount(&fps); // FPS の計測
	}
	timeEndPeriod(Caps.wPeriodMin); // 後処理
	HeapFree(GetProcessHeap(), 0, (LPVOID)Sound); // 解放
	DeleteDC(hDC_Wheel);
	DeleteDC(hDC_Block);
}
Esempio n. 2
0
void MainLoop()
{
    //QueryPerformanceFrequency(&nFreq);
    //QueryPerformanceCounter(&nBefore);
    
    DWORD StartTime,EndTime,PassTime;
    double l_StartTime,l_EndTime,l_PassTime;
#ifdef _WIN32
    StartTime=timeGetTime();
#else
    l_StartTime=gettimeofday_sec();
#endif
    ARUint8		*image;
    ARMarkerInfo	*marker_info;
    int			 marker_num;
    int			 j,k;

    if( (image = (ARUint8*)arVideoGetImage() )==NULL){
	arUtilSleep(2);
	return;
    }

    argDrawMode2D();
    argDispImage(image, 0, 0);


    if(arDetectMarker(image, thresh, &marker_info, &marker_num) < 0){
	CleanUp();
	exit(0);
    }
    arVideoCapNext();

    k=-1;
    for(j=0;j<marker_num;j++){   
	if(patt_id==marker_info[j].id){
	    k = (k==-1)  ?   j : k;
	    k = (marker_info[k].cf < marker_info[j].cf)   ?  j: k;
	}
    }

    if(k!=-1) {
	if(isFirst==true)
	    nyar_NyARTransMat_O2_transMat(nyobj,&marker_info[k],patt_center,patt_width,patt_trans);
	else
	    nyar_NyARTransMat_O2_transMatCont(nyobj,&marker_info[k],patt_trans,patt_center,patt_width,patt_trans);

	isFirst=false;

	if(GameOver==false){
	    if(arUtilTimer()>1.0){
		MovePiece(3,f,p); 
		score+=f.ShiftPiece(f.deletePiece());
		arUtilTimerReset();
		GameOver=GameOverCheck(f,p);
	    }
	}
	else{
	    if(arUtilTimer()>15.0)
		InitGame();
	}
	DrawObject();
    }

    argSwapBuffers();
#ifdef _WIN32
    EndTime=timeGetTime();
    PassTime=EndTime-StartTime;
    (1000/FPS>PassTime)?Wait(1000/FPS-PassTime):Wait(0);
    FPSCount(&fps);
    printf("FPS=%d\n",fps);
#else
l_EndTime=gettimeofday_sec();
l_PassTime=l_EndTime-l_StartTime;
    ((double)(1000/FPS)>l_PassTime)?Wait((double)1000/FPS-l_PassTime):Wait(0);
    FPSCount(&fps);
    printf("FPS=%d\n",fps);
#endif
   
}