Esempio n. 1
0
int main(){
    initGame();
    while(1){
        printGame();
        advanceGame();
        fflush(stdin);
        sleep(1);
    }
    return 0;
}
Esempio n. 2
0
/*****************************************************************************
 *
 * Description:
 *    Implements example game
 *    
 ****************************************************************************/
void
playExample(void)
{
  gameStatus = GAME_NOT_STARTED;

  setupGame(FALSE);
  lcdGotoxy(5,40);
  lcdColor(0,0xe0);
  lcdPuts("Press to start");

  while(gameStatus != GAME_END)
  {
    tU8 anyKey;

    anyKey = checkKey();
    switch(gameStatus)
    {
      case GAME_NOT_STARTED:
        if (anyKey != KEY_NOTHING)
        {
          gameStatus = GAME_RUNNING;
          setupGame(TRUE);
        }
        break;
        
      case GAME_RUNNING:
        if (anyKey != KEY_NOTHING)
        {
          if (anyKey == KEY_UP)
          {
            if(isValid(currXpos, currYpos, shift[currFigure]))
              currFigure = shift[currFigure];
          }
          else if (anyKey == KEY_DOWN)
          {
            if(isValid(currXpos, currYpos+1, currFigure))
              currYpos++;
          }
          else if (anyKey == KEY_RIGHT)
          {
            if(isValid(currXpos+1, currYpos, currFigure))
              currXpos++;
          }
          else if (anyKey == KEY_LEFT)
          {
            if(isValid(currXpos-1, currYpos, currFigure))
              currXpos--;
          }
          else if (anyKey == KEY_CENTER)
            gameStatus = GAME_OVER;

          advanceGame();
          osSleep(1);
        }
        else
        {
          advanceGame();
          osSleep(1);
        }
        break;
        
      case GAME_OVER:
      {
        tMenu menu;
        
        menu.xPos = 10;
        menu.yPos = 40;
        menu.xLen = 6+(12*8);
        menu.yLen = 4*14;
        menu.noOfChoices = 2;
        menu.initialChoice = 0;
        menu.pHeaderText = "Game over!";
        menu.headerTextXpos = 20;
        menu.pChoice[0] = "Restart game";
        menu.pChoice[1] = "End game";
        menu.bgColor       = 0;
        menu.borderColor   = 0x6d;
        menu.headerColor   = 0;
        menu.choicesColor  = 0xfd;
        menu.selectedColor = 0xe0;
        
        switch(drawMenu(menu))
        {
          case 0: gameStatus = GAME_RUNNING; setupGame(TRUE); break;  //Restart game
          case 1: gameStatus = GAME_END; break;                       //End game
          default: break;
        }
      }
        break;
        
      default:
        gameStatus = GAME_END;
        break;
    }
  }
}
Esempio n. 3
0
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpszCmdLine, int nCmdShow) {
	wchar_t progname[] = L"CerealBox";


	windata.gameoutput.graphic.width = 1920/2;
	windata.gameoutput.graphic.height = 1080/2;

	windata.running = ootrue;
	windata.gameMemory = (void *) calloc((size_t)gameMemorySize(), 1L);

	oouint audioBufferSize = win32AudioBufferSize();
    windata.gameoutput.audio.buffer = (ooshort *) calloc((size_t)audioBufferSize, 1L);
	oouint audioFramesPerSecond = win32AudioFramesPerSecond();

	WNDCLASSEXW winclass;
	ZeroMemory(&winclass, sizeof(WNDCLASSEXW));

	
	MSG msg;

	winclass.cbSize = sizeof(WNDCLASSEXW);
	winclass.style = CS_DBLCLKS;
	winclass.lpfnWndProc = &winproc;
	winclass.cbClsExtra = 0;
	winclass.cbWndExtra = 0;
	winclass.hInstance = hInst;
	winclass.hIcon = LoadIcon(NULL,IDI_WINLOGO);
	winclass.hCursor = LoadCursor(NULL,IDC_ARROW);
	winclass.lpszClassName = progname;


	if(!RegisterClassExW(&winclass)) {
		return 0;
	}

	oouint startX = 100;
	oouint startY = 100;

	DWORD windowStyle =  WS_SYSMENU|WS_CAPTION|WS_BORDER|WS_OVERLAPPED|WS_VISIBLE|WS_MINIMIZEBOX;

#ifdef OO_FULLSCREEN
	windowStyle = WS_EX_TOPMOST | WS_POPUP;
	win32GetScreenResolution(&windata.gameoutput.graphic.width, &windata.gameoutput.graphic.height);
	startX = 0;
	startY = 0;
#endif
	RECT wr = {0, 0, windata.gameoutput.graphic.width, windata.gameoutput.graphic.height};
	AdjustWindowRect(&wr, windowStyle, FALSE);

	windata.window = CreateWindowW(
		progname,
		progname,
		windowStyle,
		startX,
		startY,
		wr.right - wr.left,
		wr.bottom - wr.top,
		NULL,
		NULL,
		hInst,
		NULL);

	initGraphics(&windata);
	win32AudioInit(windata.window);

	ShowWindow(windata.window,nCmdShow);
	UpdateWindow(windata.window);

	LARGE_INTEGER timeFrequency;
	QueryPerformanceFrequency(&timeFrequency);

	LARGE_INTEGER lastTime;
	ZeroMemory(&lastTime, sizeof(LARGE_INTEGER) );
	LARGE_INTEGER time;
	windata.gameinput.dt = 1.f/60.f;

	windata.windowDC = GetDC(windata.window);

	ooint monitorRefreshHz = 60;
	oofloat frameMs = 1.f / (oofloat)monitorRefreshHz;
	ooint win32RefreshRate = GetDeviceCaps(windata.windowDC, VREFRESH);
	if( win32RefreshRate>1 ) {
		monitorRefreshHz = win32RefreshRate;
		frameMs = 1.f / (oofloat)monitorRefreshHz;
	}

	while( windata.running ) {
		PeekMessage(&msg,NULL,0,0,PM_REMOVE);
		if(msg.message == WM_QUIT) {
			break;
		}


		TranslateMessage(&msg);
		DispatchMessage(&msg);

		win32ProcessMouseEvents(windata.window, &windata);

		QueryPerformanceCounter(&time);
		if( lastTime.QuadPart>0 ) {
			windata.gameinput.dt = (oofloat)(time.QuadPart - lastTime.QuadPart);
			windata.gameinput.dt /= timeFrequency.QuadPart;

			windata.gameoutput.audio.framesToWrite = (oouint)(windata.gameinput.dt*audioFramesPerSecond);
			if(windata.gameoutput.audio.framesToWrite>audioBufferSize) {
				windata.gameoutput.audio.framesToWrite = audioBufferSize;
			}

			advanceGame(windata.gameMemory,&windata.gameinput,&windata.gameoutput);

			win32AudioOutput(windata.gameoutput.audio.buffer, windata.gameoutput.audio.framesToWrite);
			renderGraphics(&windata);
		}
		
		lastTime = time;
		
	}

	ReleaseDC(windata.window, windata.windowDC);

	destroyGraphics(&windata);
	win32AudioDestroy();
	free(windata.gameMemory);
	free(windata.gameoutput.audio.buffer);

	return (msg.wParam);
}