Esempio n. 1
0
void SelectBgImg(void){
FILE *F;
SDL_Surface *Img;
SDL_Rect Rct;
char Fls[256][256];
int I,J,C=1,Akt=0;
	Fls[0][0]='\0';
	F=fopen("./bgimages.txt","r");
	while ((!feof(F))&&(fgets(Fls[C],255,F)!=NULL)){
		while ((strlen(Fls[C]))&&(Fls[C][strlen(Fls[C])-1]<' '))
			Fls[C][strlen(Fls[C])-1]='\0';
		if (Fls[C][0]!='\0'){
//			fprintf(stdout,">%s\n",Fls[C]);
			if (!strcmp(Fls[C],Lvl[Level].BgFile)) Akt=C;
			C++;
		}
	}
	fclose(F);

	while ((!Fire)&&(!Quit)){
		strcpy(Lvl[Level].BgFile,Fls[Akt]);
		Img=IMG_Load(Lvl[Level].BgFile);
		if (Img!=NULL){
			Rct.w=Img->w;
			Rct.h=Img->h;
			for (I=0;I<400;I+=Rct.w)
				for (J=0;J<400;J+=Rct.h){
					Rct.x=I;
					Rct.y=J;
					SDL_BlitSurface(Img,NULL,Lvl[Level].Bg,&Rct);
				}
			SDL_FreeSurface(Img);
		}else
			boxRGBA(Lvl[Level].Bg,0,0,399,399,0x40,0x40,0x40,0xFF);
		DrawGame();
		boxRGBA(screen,0,0,200,200,32,32,32,0xFF);
		boxRGBA(screen,0,100,200,110,64,64,64,0xFF);
		stringRGBA(screen,1,1,"Select BgImage:",255,255,255,0xFF);
		for (I=0;I<19;I++)
			if ((Akt-9+I>=0)&&(Akt-9+I<C))
				stringRGBA(screen,1,10+I*10,Fls[Akt-9+I],200,200,200,0xFF);
		SDL_UpdateRect(screen,0,0,200,200);
		while ((Fire)||(Up)||(Down)) SDL_PollEvent(&event);
		while ((!Fire)&&(!Up)&&(!Down)&&(!Quit)) SDL_PollEvent(&event);
		if ((Up)&&(Akt>0)) Akt--;
		if ((Down)&&(Akt<C-1)) Akt++;
	}
	DrawGame();
}
Esempio n. 2
0
//-----------------------------------------------------------------------------
// Name : DrawObjects () (Private)
// Desc : Draws the game objects
//-----------------------------------------------------------------------------
void CGameApp::DrawObjects()
{
	m_pBBuffer->reset();

	HDC hdc = m_pBBuffer->getDC();

	m_imgBackground.Paint(hdc, 0, 0);

	if(GameOver == false && level.Winner == false && LevelChange == false)
	{
		DrawFunctor drawFn;
		std::for_each(m_vGameObjects.begin(), m_vGameObjects.end(), drawFn);
		std::for_each(m_vGameObjectsGift.begin(), m_vGameObjectsGift.end(), drawFn);
		std::for_each(m_vGameObjectsAnimate.begin(), m_vGameObjectsAnimate.end(), drawFn);
	}
	else
	{
		if(LevelChange == true)
			DrawGame(hdc,"level");
		if(level.Winner == true)
		{
			DrawGame(hdc,"winner");
			if(countGameOver == 0)
			{
				SaveScore();
				ScoreTable();
			}
			ShowScoreTable(hdc);
			countGameOver++;
		}
		if(GameOver == true)
		{
			DrawGame(hdc,"gameover");
			if(countGameOver == 0)
			{
				SaveScore();
				ScoreTable();
			}
			ShowScoreTable(hdc);
			countGameOver++;
		}
	}

	DrawScore(hdc);
	DrawLife(hdc);

	m_pBBuffer->present();
}
Esempio n. 3
0
int main(int argc, char *argv[])
{
  if(!InitGame())
    {
      printf("%s\n", SDL_GetError());
      FreeGame();   //If InitGame failed, kill the program
      return 0;
    }

  while(ProgramIsRunning())
    {
      long int oldTime = SDL_GetTicks();  //We will use this later to see how long it took to update the frame
      SDL_FillRect(Backbuffer, NULL, 0);  //Clear the screen
      RunGame();                          //Update the game
      DrawGame();                         //Draw the screen

      int frameTime = SDL_GetTicks() - oldTime;

      if(frameTime < FRAME_DELAY)                 //Dont delay if we dont need to
	SDL_Delay(FRAME_DELAY - frameTime);     //Delay

      //In SDL 2, SDL_UpdateWindowSurface replaces SDL_Flip
      SDL_UpdateWindowSurface(Window);            //Flip the screen
    }

  FreeGame();     //Gracefully release SDL and its resources.

  return 0;
}
Esempio n. 4
0
int main()
{
	//The window we'll be rendering to
	SDL_Window* window = NULL;

	Mix_Music *music = NULL;
	Mix_OpenAudio(22050, MIX_DEFAULT_FORMAT, 2, 4096) == -1;
	music = Mix_LoadMUS(("Assets/background.wav"));
	Mix_PlayMusic(music, -1);


	//SDL
#pragma region SDL STUFF
	//Initialize SDL
	if (SDL_Init(SDL_INIT_VIDEO) < 0)
	{
		printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError());
	}
	else
	{
		//Create window
		window = SDL_CreateWindow("SDL Template", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH, SCREEN_HEIGHT, SDL_WINDOW_SHOWN);
		if (window == NULL)
		{
			printf("Window could not be created! SDL_Error: %s\n", SDL_GetError());
		}
		else
		{
			//Create Renderer for the Window
			if (!Renderer::GetInstance()->Init(window, SCREEN_WIDTH, SCREEN_HEIGHT))
			{
				return 0;
			}

			bool quit = false;
			Init();


			SDL_Event e;
			while (!quit)
			{
				while (SDL_PollEvent(&e) != 0)
				{
					if (inputHandler.CheckInput(SDLK_ESCAPE, e))
					{
						quit = true;
					}
				}//Key Input Update

				//*******************
				// Update Method
				//*******************
				DrawGame();

			}

			return 0;
		}
	}
}
Esempio n. 5
0
void CCLLKDlg::OnPaint()
{
	CRect rect;
	GetClientRect(&rect);
	if (IsIconic())
	{
		CPaintDC dc(this); // 用于绘制的设备上下文

		SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);

		// 使图标在工作矩形中居中
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);

		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		// 绘制图标
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{

		CPaintDC dc(this);
		DrawGame(&m_memDC);
		dc.BitBlt(0,0,rect.Width(),rect.Height(),&m_memDC,0,0,SRCCOPY);
		CDialog::OnPaint();
	}
}
Esempio n. 6
0
// Main game loop
void MainGame::GameLoop()
{
	while (_gameState != GameState::EXIT)
	{
		// use for frame time measuring
		Uint32 startTicks = SDL_GetTicks();

		ProcessInput();
		_time += 0.01f;
		DrawGame();
		CalculateFPS();

		// print only once every 10 frames
		static int frameCounter = 0;
		frameCounter++;
		if (frameCounter == 10)
		{
			//std::cout << _fps << std::endl;
			frameCounter = 0;
		}

		// Limit fps to max fps
		Uint32 frameTicks = SDL_GetTicks() - startTicks;
		if (1000.0f / _maxFps > frameTicks)
		{
			SDL_Delay(1000.0f / _maxFps - frameTicks);
		}
	}
}
Esempio n. 7
0
void Game::Go(){
	//pWnd->ShowMouseCursor(false);

	//objeto para recibir eventos
	Event evt;

	//Inicializa los objetos del juego
	Init();
	
	if(pWnd->IsOpened())
	{
		Intro();
		ShowMenu();		
	}
	while(pWnd->IsOpened()){
		//procesar eventos
		while (pWnd->GetEvent(evt))
			ProcessEvent(evt);

		//procesar colisiones
		ProcessCollisions();
		
		//actualizar estados de objetos
		UpdateGame();
		
		pWnd->Clear();
		
		DrawGame();
		
		pWnd->Display();
	}
	StopMusic();	
}
Esempio n. 8
0
File: Main.cpp Progetto: m1h4/Xetrix
bool Draw(void)
{
	glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);

	if(!DrawGame())
		return false;
	
	return true;
}
Esempio n. 9
0
//	--------------------------------------------------------------------
//	様々なゲーム内処理を呼ぶ関数
//	--------------------------------------------------------------------
void GameMain()
{
    //	コントロール
    ControllGame();
    //	描画
    DrawGame();

    return;
}
/////////////////////////////////////////////////////////////////////////////
//void OnDraw(CDC* pDC)
//启动作图函数
void CRussiaRectView::OnDraw(CDC* pDC)
{
	CRussiaRectDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here

	DcEnvInitial();
	DrawGame(&m_memDC);  //在内存位图的游戏区域绘制

	pDC->BitBlt(0,0,m_nWidth,m_nHeight,&m_memDC,0,0,SRCCOPY);
}
Esempio n. 11
0
void SetMessages(void){
char M;
	DrawTxtMenu(M_Msg);
	DrawMsg("...Esc");
	DrawMessages();
	while (MB)
		SDL_PollEvent(&event);
	do{
		SDL_PollEvent(&event);
		if (M=OperTxtMenu(M_Msg)){
			InputScr("Enter message:");
			GetString(Lvl[Level].Text[M-1],50,1,195);
			DrawGame();
			DrawMessages();
		}
	} while (!Quit);
	DrawGame();
	DrawTxtMenu(M_Txt);
	DrawMsg("");
}
Esempio n. 12
0
void Game::ShowPuntaje()
{
	Image img;
	img.LoadFromFile("..//Imagenes//resumen.png");
	Sprite resumen;
	resumen.SetImage(img);
	resumen.SetPosition(200,200);	

	Font font;
	font.LoadFromFile("..\\Fonts\\Bolstbo_.ttf");
	String resumen_text;
	resumen_text.SetFont(font);
	resumen_text.SetPosition(240,270);

	stringstream st_s;
	string aux;
	string str;
		
	st_s << count_letras;			
	st_s >> aux;
	
	str = "Letras: " + aux;
	
	st_s.clear();
	st_s << puntos;
	st_s >> aux;

	str += "\nPuntos: " + aux;
		
	resumen_text.SetText(str);

	float sleep = 0.0;

	while(sleep < 5.0)
	{
		pWnd->Clear();
		
		DrawGame();
		pWnd->Draw(resumen);
		pWnd->Draw(resumen_text);
		
		pWnd->Display();
	
		sleep += pWnd->GetFrameTime();
	}
}
Esempio n. 13
0
//------------------------------------------------------------------------------------
// Program main entry point
//------------------------------------------------------------------------------------
int main()
{
    // Initialization
    //--------------------------------------------------------------------------------------
    InitWindow(screenWidth, screenHeight, "sample game: missile commander");

    InitGame();

#if defined(PLATFORM_WEB)
    emscripten_set_main_loop(UpdateDrawFrame, 0, 1);
#else

    SetTargetFPS(60);
    //--------------------------------------------------------------------------------------
    
    // Main game loop
    while (!WindowShouldClose())    // Detect window close button or ESC key
    {
        // Update
        //----------------------------------------------------------------------------------
        UpdateGame();
        //----------------------------------------------------------------------------------

        // Draw
        //----------------------------------------------------------------------------------
        DrawGame();
        //----------------------------------------------------------------------------------
    }
#endif

    // De-Initialization
    //--------------------------------------------------------------------------------------
    UnloadGame();         // Unload loaded data (textures, sounds, models...)
    
    CloseWindow();        // Close window and OpenGL context
    //--------------------------------------------------------------------------------------

    return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	Game game;

	InitGame(game);

	while (!IsGameFinished(game))
	{
		// Get game time
		game.t = timeGetTime();

		GetUserInput(game);
		PerformAI(game);
		DrawGame(game);
	}

	DisplayResults(game);

	TerminateGame(game);

	return 0;
}
Esempio n. 15
0
void CRS_ManContainer::GfxTimerFiredL(TInt /*aId*/)
{
    //先判断可能的来电事件,如果有来电,则触发 虚拟触摸事件,然后到暂停界面
    if (iCallStatus == CTelephony::EStatusRinging)
    {
        TRawEvent lEventDown;
        lEventDown.Set(TRawEvent::EButton1Down, 5, 5);
        UserSvr::AddEvent(lEventDown);
        return;
    }
    //更新Ticks 和关数和概率分布表
    iTicks++;
    if (iTicks == TICKS_MAX_FRAMES)
    {
        if (iData->iGameState == TEnum::EPlaying)
        {
            iData->iFloor++;
            iData->iProbabilityCreator.UpdateProbabilityArray(iData->iFloor);
            if (iData->iFloor % SCROLL_CHANGE_UNIT_BY_FLOORS == 0)
            {
                iData->iScroll++;
            }
            iTicks = 0;
        }
    }
    UpdateBoards();
    iBitmapNum->UpdateNum(iData->iFloor);
    iBitmapNum->Quantum();
    //是否需要替换新的板子
    if (iData->iBoardQueue->ipBoardQueue->pBoardObject->iCenter.iY < Y_AXIS_REPLACE_POSITION + 2)
    {
        iData->iBoardQueue->UpdateQueue(iData->GetObjectFromPoolNoNull());
    }
    DrawGame();
    HandleManMain();
    //DrawIndicator();
    DrawNow();
}
Esempio n. 16
0
//Output
void cGame::Render() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	gluPerspective(45.0,(float)SCREEN_WIDTH/(float)SCREEN_HEIGHT,0.01,100);
	
	glMatrixMode(GL_MODELVIEW);
	
	DrawSky();
	if(!Scene.IsInitialized) {
		DrawStartScreen();
	} else {
		DrawGame();
	}
	if (WireframeRendering)		DrawWireframeGame();
	if (IsGameover)				DrawGameOver();
	if (IsLevelUp)				DrawLevelUp();
	
	glutSwapBuffers();

	UpdateFrameVariables();
}
Esempio n. 17
0
void GameBase::DrawWorld()
{
	DrawGame();
}
Esempio n. 18
0
void GameBase::DrawWorld()
{
	if(isEnableDebugPhysics)
		PhysicManager::Instance()->Draw();
	DrawGame();
}
Esempio n. 19
0
// --------------------
void Edit(void){
char M,Str[256];
int I,LX,LY;
SetLevel(0);
DrawGame();
DrawMenu(M_Fg);
DrawMenu(M_Bg);
DrawTxtMenu(M_Txt);
DrawMsg("");
while (1){
	LX=MX;
	LY=MY;
	UC=0;
	if (!MB)
		SDL_Delay(200);
	else
		SDL_Delay(50);
	SDL_PollEvent(&event);
	OperMenu(&M_Fg);
	OperMenu(&M_Bg);
	if ((UC>='0')&&(UC<='9')){
		Lvl[Level].M[MX/20][MY/20].txt=UC-'0';
		DrawGame();
	}
	if (Shift){
		Lvl[Level].M[MX/20][MY/20].txt=-1;
		DrawGame();
	}
	if ((MB==1)&&(MX<400)&&(MY<400)){
		if ((LX/20!=MX/20)||(LY/2!=MY/20))
			MBlock=0;
		if (!MBlock){
			Lvl[Level].M[MX/20][MY/20].FSpr=M_Fg.E[M_Fg.Akt].Spr;
			Lvl[Level].M[MX/20][MY/20].FTyp=M_Fg.E[M_Fg.Akt].Typ;
			Lvl[Level].M[MX/20][MY/20].BSpr=M_Bg.E[M_Bg.Akt].Spr;
			Lvl[Level].M[MX/20][MY/20].BTyp=M_Bg.E[M_Bg.Akt].Typ;
			MBlock=1;
			DrawGame();
		}
	}
	if ((MB==2)&&(MX<400)&&(MY<400)){
		for (I=0;I<M_Fg.L;I++)
			if ((Lvl[Level].M[MX/20][MY/20].FSpr==M_Fg.E[I].Spr)&&(Lvl[Level].M[MX/20][MY/20].FTyp==M_Fg.E[I].Typ)){
				M_Fg.Top=M_Fg.Akt=I;
				DrawMenu(M_Fg);
			}
		for (I=0;I<M_Bg.L;I++)
			if ((Lvl[Level].M[MX/20][MY/20].BSpr==M_Bg.E[I].Spr)&&(Lvl[Level].M[MX/20][MY/20].BTyp==M_Bg.E[I].Typ)){
				M_Bg.Top=M_Bg.Akt=I;
				DrawMenu(M_Bg);
			}
		MBlock=1;
		DrawGame();
	}
	if (M=OperTxtMenu(M_Txt)){
		if (M==1){			//name
			InputScr("Enter level name:");
			GetString(Lvl[Level].Name,50,1,195);
			SetCaption();
			DrawGame();
		}
		else if (M==2){			//password
			InputScr("Enter level password:"******"Enter time limit (0-999 secs):");
			sprintf(Str,"%d",Lvl[Level].DL);
			GetString(Str,3,1,195);
			Lvl[Level].DL=atoi(Str);
			DrawGame();
		}
		else if (M==4)		//bgimg
			SelectBgImg();
		else if (M==5)		//txt
			SetMessages();
		else if (M==6){		//go to
			InputScr("Enter level no. (0-99):");
			sprintf(Str,"%d",Level);
			GetString(Str,2,1,195);
			Level=atoi(Str);
			SetLevel(Level);
			DrawGame();
		}
		else if (M==7){		//save
			InputScr("Enter filename:");
			if (GetString(LFile,255,1,195)){
				if (Save(LFile))
					DrawMsg("Saved...");
				else
					DrawMsg("Can't save!");
			}else
				DrawMsg("Aborted...");
			DrawGame();
		}
	}
	if (Up&&(Level<99)){
		SetLevel(Level+1);
		DrawGame();
		SDL_Delay(200);
	}
	if ((Down)&&(Level>0)){
		SetLevel(Level-1);
		DrawGame();
		SDL_Delay(200);
	}
	
	if (Quit==2)
		return;
}
}
Esempio n. 20
0
// Update and Draw (one frame)
void UpdateDrawFrame(void)
{
    UpdateGame();
    DrawGame();
}
Esempio n. 21
0
// -----------------------------------------------------------------------------
// CSIPExGameView::Draw
// From CCoeControl.
// -----------------------------------------------------------------------------
//
void CSIPExGameView::Draw( const TRect& /*aRect*/ ) const
    {
    CWindowGc& gc = SystemGc();
    DrawGame( gc, iRect );
    }
Esempio n. 22
0
// Handles OS messages, is driven by the 'main loop' above.
LRESULT CALLBACK MainWindowProcedure(HWND windowHandle, UINT messageCode, WPARAM wParam, LPARAM lParam)
{
	switch (messageCode) {
	// On window creation.
	case WM_CREATE:
		DEBUG_OUT(TEXT("WM_CREATE message"));
		// Start game loop timer.
		DEBUG_VAL(TEXT("SetTimer()"), SetTimer(windowHandle, MAIN_CYCLE_TIMER_ID, MAIN_CYCLE_WAIT, NULL));
		break;
	
	// Upon redraw request or something else changing we draw the window.
	case WM_PAINT:
		{
			PAINTSTRUCT paintJobStruct;
			HDC deviceContextHandle = BeginPaint(windowHandle, &paintJobStruct);
			HDC bufferDeviceContextHandle = CreateCompatibleDC(deviceContextHandle);
			HBITMAP bufferBitmapHandle = CreateCompatibleBitmap(deviceContextHandle, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT);
			HGDIOBJ oldBufferBitmapHandle = SelectObject(bufferDeviceContextHandle, bufferBitmapHandle);
			Gdiplus::Graphics graphics(bufferDeviceContextHandle);
			graphics.SetSmoothingMode(GRAPHICS_SMOOTHING_MODE);
			DrawGame(graphics, *mainGameObject);
			BitBlt(deviceContextHandle, 0, 0, MAIN_WINDOW_WIDTH, MAIN_WINDOW_HEIGHT, bufferDeviceContextHandle, 0, 0, SRCCOPY);
			SelectObject(bufferDeviceContextHandle, oldBufferBitmapHandle);
			DeleteDC(bufferDeviceContextHandle);
			DeleteObject(bufferBitmapHandle);
			EndPaint(windowHandle, &paintJobStruct);
		}
		break;
	
	// When a user presses a key (can be triggered by auto-repeat).
	case WM_KEYDOWN:
		DEBUG_OUT(TEXT("WM_KEYDOWN message"));
		DEBUG_VAL(TEXT("wParam"), wParam);
		switch(wParam) {
		case VK_LEFT:
		case VK_UP:
		case VK_RIGHT:
		case VK_DOWN:
			DEBUG_OUT(TEXT("Arrow key pressed"));
			mainGameObject->Input(wParam);
		}
		break;
		
	case WM_TIMER:
		if (wParam == MAIN_CYCLE_TIMER_ID) {
			// This is where the 'main game loop' kicks in.  This line should be reached at a frequency of about 60Hz.
			mainGameObject->Step(windowHandle);
			RedrawWindow(windowHandle, NULL, NULL, RDW_INVALIDATE);
			//InvalidateRect(windowHandle, NULL, TRUE);
			//UpdateWindow(windowHandle);
		}
		break;
		
	case WM_CLOSE:
		DEBUG_OUT(TEXT("WM_CLOSE message"));
		// Clean up Windows API objects and etc.
		KillTimer(windowHandle, MAIN_CYCLE_TIMER_ID);
		DestroyWindow(windowHandle);
		break;
		
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
		
	default:
		return DefWindowProc(windowHandle, messageCode, wParam, lParam);
		break;
	}
	return 0;
}